Re: [HSA, PATCH] Load an HSA runtime via dlopen mechanism
Hi! On Sun, 9 Apr 2017 18:22:00 +0200, Martin Jamborwrote: > On Wed, Apr 05, 2017 at 10:11:34AM +0200, Thomas Schwinge wrote: > > I ran into a case where the libgomp hsa plugin wouldn't load. The > > following patch helped me to quickly diagnose and then fix that. OK for > > trunk? > > Yes, thanks. Thanks, now finally, as posted, committed to trunk in r248277: commit b7d6170b96407c80b3e21dd6a665ebff7715d62e Author: tschwinge Date: Fri May 19 13:32:04 2017 + libgomp hsa plugin: debug output for HSA runtime library loading failure libgomp/ * plugin/plugin-hsa.c (DLSYM_FN, init_hsa_runtime_functions): Debug output for failure. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@248277 138bc75d-0d04-0410-961f-82ee72b054a4 --- libgomp/ChangeLog | 5 + libgomp/plugin/plugin-hsa.c | 8 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git libgomp/ChangeLog libgomp/ChangeLog index 083cb85..84d1c839 100644 --- libgomp/ChangeLog +++ libgomp/ChangeLog @@ -1,3 +1,8 @@ +2017-05-19 Thomas Schwinge + + * plugin/plugin-hsa.c (DLSYM_FN, init_hsa_runtime_functions): + Debug output for failure. + 2017-05-12 Rainer Orth * testsuite/lib/libgomp.exp: Load scanlang.exp. diff --git libgomp/plugin/plugin-hsa.c libgomp/plugin/plugin-hsa.c index 9cc243d..90ca247 100644 --- libgomp/plugin/plugin-hsa.c +++ libgomp/plugin/plugin-hsa.c @@ -491,14 +491,14 @@ static struct hsa_context_info hsa_context; #define DLSYM_FN(function) \ hsa_fns.function##_fn = dlsym (handle, #function); \ if (hsa_fns.function##_fn == NULL) \ -return false; +goto dl_fail; static bool init_hsa_runtime_functions (void) { void *handle = dlopen (hsa_runtime_lib, RTLD_LAZY); if (handle == NULL) -return false; +goto dl_fail; DLSYM_FN (hsa_status_string) DLSYM_FN (hsa_agent_get_info) @@ -530,6 +530,10 @@ init_hsa_runtime_functions (void) DLSYM_FN (hsa_ext_program_destroy) DLSYM_FN (hsa_ext_program_finalize) return true; + + dl_fail: + HSA_DEBUG ("while loading %s: %s\n", hsa_runtime_lib, dlerror ()); + return false; } /* Find kernel for an AGENT by name provided in KERNEL_NAME. */ Grüße Thomas
Re: [HSA, PATCH] Load an HSA runtime via dlopen mechanism
Hi, On Wed, Apr 05, 2017 at 10:11:34AM +0200, Thomas Schwinge wrote: > ... > > I ran into a case where the libgomp hsa plugin wouldn't load. The > following patch helped me to quickly diagnose and then fix that. OK for > trunk? Yes, thanks. Martin > > commit 54099202eb88464530dd3a55709c9afb85766ee0 > Author: Thomas Schwinge> Date: Wed Apr 5 09:58:02 2017 +0200 > > libgomp hsa plugin: debug output for HSA runtime library loading failure > > libgomp/ > * plugin/plugin-hsa.c (DLSYM_FN, init_hsa_runtime_functions): > Debug output for failure. > --- > libgomp/plugin/plugin-hsa.c | 8 ++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git libgomp/plugin/plugin-hsa.c libgomp/plugin/plugin-hsa.c > index 9cc243d..90ca247 100644 > --- libgomp/plugin/plugin-hsa.c > +++ libgomp/plugin/plugin-hsa.c > @@ -491,14 +491,14 @@ static struct hsa_context_info hsa_context; > #define DLSYM_FN(function) \ >hsa_fns.function##_fn = dlsym (handle, #function); \ >if (hsa_fns.function##_fn == NULL) \ > -return false; > +goto dl_fail; > > static bool > init_hsa_runtime_functions (void) > { >void *handle = dlopen (hsa_runtime_lib, RTLD_LAZY); >if (handle == NULL) > -return false; > +goto dl_fail; > >DLSYM_FN (hsa_status_string) >DLSYM_FN (hsa_agent_get_info) > @@ -530,6 +530,10 @@ init_hsa_runtime_functions (void) >DLSYM_FN (hsa_ext_program_destroy) >DLSYM_FN (hsa_ext_program_finalize) >return true; > + > + dl_fail: > + HSA_DEBUG ("while loading %s: %s\n", hsa_runtime_lib, dlerror ()); > + return false; > } > > /* Find kernel for an AGENT by name provided in KERNEL_NAME. */ > > > Grüße > Thomas
Re: [HSA, PATCH] Load an HSA runtime via dlopen mechanism
Hi! On Tue, 19 Apr 2016 10:24:36 +0200, Martin Liška <mli...@suse.cz> wrote: > After brief discussions about packaging of an HSA runtime, we've decided to > load > an HSA runtime via dlopen mechanism. Following patch introduces necessary > header > files and all functions within the HSA plug-in are loaded via dlsym. > > Patch survives HSA regression tests, installed to the HSA branch as r235189. (And later pushed into trunk.) > --- a/libgomp/plugin/plugin-hsa.c > +++ b/libgomp/plugin/plugin-hsa.c > +#define DLSYM_FN(function) \ > + hsa_fns.function##_fn = dlsym (handle, #function); \ > + if (hsa_fns.function##_fn == NULL) \ > +return false; > + > +static bool > +init_hsa_runtime_functions (void) > +{ > + void *handle = dlopen (hsa_runtime_lib, RTLD_LAZY); > + if (handle == NULL) > +return false; > + > + DLSYM_FN (hsa_status_string) > +[...] > + DLSYM_FN (hsa_ext_program_finalize) > + return true; > +} I ran into a case where the libgomp hsa plugin wouldn't load. The following patch helped me to quickly diagnose and then fix that. OK for trunk? commit 54099202eb88464530dd3a55709c9afb85766ee0 Author: Thomas Schwinge <tho...@codesourcery.com> Date: Wed Apr 5 09:58:02 2017 +0200 libgomp hsa plugin: debug output for HSA runtime library loading failure libgomp/ * plugin/plugin-hsa.c (DLSYM_FN, init_hsa_runtime_functions): Debug output for failure. --- libgomp/plugin/plugin-hsa.c | 8 ++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git libgomp/plugin/plugin-hsa.c libgomp/plugin/plugin-hsa.c index 9cc243d..90ca247 100644 --- libgomp/plugin/plugin-hsa.c +++ libgomp/plugin/plugin-hsa.c @@ -491,14 +491,14 @@ static struct hsa_context_info hsa_context; #define DLSYM_FN(function) \ hsa_fns.function##_fn = dlsym (handle, #function); \ if (hsa_fns.function##_fn == NULL) \ -return false; +goto dl_fail; static bool init_hsa_runtime_functions (void) { void *handle = dlopen (hsa_runtime_lib, RTLD_LAZY); if (handle == NULL) -return false; +goto dl_fail; DLSYM_FN (hsa_status_string) DLSYM_FN (hsa_agent_get_info) @@ -530,6 +530,10 @@ init_hsa_runtime_functions (void) DLSYM_FN (hsa_ext_program_destroy) DLSYM_FN (hsa_ext_program_finalize) return true; + + dl_fail: + HSA_DEBUG ("while loading %s: %s\n", hsa_runtime_lib, dlerror ()); + return false; } /* Find kernel for an AGENT by name provided in KERNEL_NAME. */ Grüße Thomas
[HSA, PATCH] Load an HSA runtime via dlopen mechanism
Hello. After brief discussions about packaging of an HSA runtime, we've decided to load an HSA runtime via dlopen mechanism. Following patch introduces necessary header files and all functions within the HSA plug-in are loaded via dlsym. Patch survives HSA regression tests, installed to the HSA branch as r235189. Thanks, Martin >From c93babc050cc31e1d370240568414dfa0f02f5d8 Mon Sep 17 00:00:00 2001 From: marxin <mli...@suse.cz> Date: Thu, 14 Apr 2016 14:25:58 +0200 Subject: [PATCH] Load an HSA runtime via dlopen mechanism gcc/ChangeLog: 2016-04-19 Martin Liska <mli...@suse.cz> * doc/install.texi: Remove entry about --with-hsa-kmt-lib. libgomp/ChangeLog: 2016-04-19 Martin Liska <mli...@suse.cz> * config.h.in: Introduce HSA_RUNTIME_LIB. * configure: Regerenated. * hsa.h: New file. * hsa_ext_finalize.h: New file. * plugin/configfrag.ac: Remove hsa-kmt-lib test. * plugin/plugin-hsa.c (struct hsa_runtime_fn_info): New structure. (init_enviroment_variables): Load newly introduced ENV variables. (hsa_warn): Call a function via hsa_fns data structure. (hsa_fatal): Likewise. (init_hsa_runtime_functions): Likewise. (suitable_hsa_agent_p): Likewise. (init_hsa_context): Likewise. (get_kernarg_memory_region): Likewise. (GOMP_OFFLOAD_init_device): Likewise. (destroy_hsa_program): Likewise. (create_and_finalize_hsa_program): Likewise. (create_single_kernel_dispatch): Likewise. (release_kernel_dispatch): Likewise. (init_single_kernel): Likewise. (GOMP_OFFLOAD_run): Likewise. (GOMP_OFFLOAD_fini_device): Likewise. * testsuite/lib/libgomp.exp: Remove hsa_kmt_lib support. * testsuite/libgomp-test-support.exp.in: Likewise. --- gcc/doc/install.texi | 6 - libgomp/config.h.in | 3 + libgomp/configure | 52 +-- libgomp/hsa.h | 630 ++ libgomp/hsa_ext_finalize.h| 265 +++ libgomp/plugin/configfrag.ac | 28 +- libgomp/plugin/plugin-hsa.c | 312 ++--- libgomp/testsuite/lib/libgomp.exp | 4 - libgomp/testsuite/libgomp-test-support.exp.in | 1 - 9 files changed, 1161 insertions(+), 140 deletions(-) create mode 100644 libgomp/hsa.h create mode 100644 libgomp/hsa_ext_finalize.h diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi index 4268036..644f9dd 100644 --- a/gcc/doc/install.texi +++ b/gcc/doc/install.texi @@ -2012,12 +2012,6 @@ explicitly specify the directory where they are installed. The shorthand for @option{--with-hsa-runtime-lib=@/@var{hsainstalldir}/lib} and @option{--with-hsa-runtime-include=@/@var{hsainstalldir}/include}. - -@item --with-hsa-kmt-lib=@var{pathname} - -If you configure GCC with HSA offloading but do not have the HSA -KMT library installed in a standard location then you can -explicitly specify the directory where it resides. @end table @subheading Cross-Compiler-Specific Options diff --git a/libgomp/config.h.in b/libgomp/config.h.in index 226ac53..4483a84 100644 --- a/libgomp/config.h.in +++ b/libgomp/config.h.in @@ -125,6 +125,9 @@ /* Define to 1 if the HSA plugin is built, 0 if not. */ #undef PLUGIN_HSA +/* Define path to HSA runtime. */ +#undef HSA_RUNTIME_LIB + /* Define to 1 if the NVIDIA plugin is built, 0 if not. */ #undef PLUGIN_NVPTX diff --git a/libgomp/configure b/libgomp/configure index 8d03eb6..9a09369 100755 --- a/libgomp/configure +++ b/libgomp/configure @@ -637,7 +637,6 @@ PLUGIN_HSA_LIBS PLUGIN_HSA_LDFLAGS PLUGIN_HSA_CPPFLAGS PLUGIN_HSA -HSA_KMT_LIB HSA_RUNTIME_LIB HSA_RUNTIME_INCLUDE PLUGIN_NVPTX_LIBS @@ -794,7 +793,6 @@ with_cuda_driver_lib with_hsa_runtime with_hsa_runtime_include with_hsa_runtime_lib -with_hsa_kmt_lib enable_linux_futex enable_tls enable_symvers @@ -1476,7 +1474,6 @@ Optional Packages: --with-hsa-runtime-lib=PATH specify directory for the installed HSA run-time library - --with-hsa-kmt-lib=PATH specify directory for installed HSA KMT library. Some influential environment variables: CC C compiler command @@ -11145,7 +11142,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11148 "configure" +#line 11145 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11251,7 +11248,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11254 "configure" +#line 11251 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -15293,22 +15290,6 @@ if test "x$HSA_RUNTIME_LIB" != x; then HSA_RUNTIME_LDFLAGS=-L$HSA_RUNTIME_LIB fi -HSA_KMT_LIB= - -HSA_KMT_LDFLAGS= - -# Check whether --with-hsa-kmt-lib was given. -if test &