diff mbox

[HSA] Load an HSA runtime via dlopen mechanism

Message ID 87pogrgtop.fsf@euler.schwinge.homeip.net
State New
Headers show

Commit Message

Thomas Schwinge April 5, 2017, 8:11 a.m. UTC
Hi!

On Tue, 19 Apr 2016 10:24:36 +0200, Martin Liška <mliska@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 <thomas@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(-)



Grüße
 Thomas

Comments

Martin Jambor April 9, 2017, 4:22 p.m. UTC | #1
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 <thomas@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
diff mbox

Patch

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.  */