diff mbox

[HSA] Allocate memory for shadow arg (PR hsa/70337)

Message ID 56F05ECF.3020005@suse.cz
State New
Headers show

Commit Message

Martin Liška March 21, 2016, 8:51 p.m. UTC
On 03/21/2016 07:23 PM, Martin Jambor wrote:
> This is strange.  The pointer to the shadow data structure is, from
> the HSA perspective, a normal kernel argument and therefore should
> already be included in the kernel->kernarg_segment_size.  Have you
> checked that the values are indeed off?

Hi Martin.

You are right that size of a shadow argument pointer should be
included in the kernel->kernarg_segment_size. I've been currently
testing a proper patch which conditionally copies shadow argument.

Thanks,
Martin

Comments

Martin Jambor March 22, 2016, 4:09 p.m. UTC | #1
On Mon, Mar 21, 2016 at 09:51:27PM +0100, Martin Liska wrote:
> On 03/21/2016 07:23 PM, Martin Jambor wrote:
> >This is strange.  The pointer to the shadow data structure is, from
> >the HSA perspective, a normal kernel argument and therefore should
> >already be included in the kernel->kernarg_segment_size.  Have you
> >checked that the values are indeed off?
> 
> Hi Martin.
> 
> You are right that size of a shadow argument pointer should be
> included in the kernel->kernarg_segment_size. I've been currently
> testing a proper patch which conditionally copies shadow argument.
> 
> Thanks,
> Martin
> 

> From 413707c51bf4b0ac7f8dac6421be9955c18767dd Mon Sep 17 00:00:00 2001
> From: marxin <mliska@suse.cz>
> Date: Mon, 21 Mar 2016 21:40:03 +0100
> Subject: [PATCH] Copy shadow argument conditionally (PR hsa/70337)
> 
> libgomp/ChangeLog:
> 
> 2016-03-21  Martin Liska  <mliska@suse.cz>
> 
> 	PR hsa/70337
> 	* plugin/plugin-hsa.c (GOMP_OFFLOAD_run): Copy shadow
> 	argument just in case a dispatched kernel uses that argument.

This is OK, thanks,

Martin

> ---
>  libgomp/plugin/plugin-hsa.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/libgomp/plugin/plugin-hsa.c b/libgomp/plugin/plugin-hsa.c
> index d888493..f7ef600 100644
> --- a/libgomp/plugin/plugin-hsa.c
> +++ b/libgomp/plugin/plugin-hsa.c
> @@ -1255,8 +1255,16 @@ GOMP_OFFLOAD_run (int n, void *fn_ptr, void *vars, void **args)
>    hsa_signal_store_relaxed (s, 1);
>    memcpy (shadow->kernarg_address, &vars, sizeof (vars));
>  
> -  memcpy (shadow->kernarg_address + sizeof (vars), &shadow,
> -	  sizeof (struct hsa_kernel_runtime *));
> +  /* PR hsa/70337.  */
> +  size_t vars_size = sizeof (vars);
> +  if (kernel->kernarg_segment_size > vars_size)
> +    {
> +      if (kernel->kernarg_segment_size != vars_size
> +	  + sizeof (struct hsa_kernel_runtime *))
> +	GOMP_PLUGIN_fatal ("Kernel segment size has an unexpected value");
> +      memcpy (packet->kernarg_address + vars_size, &shadow,
> +	      sizeof (struct hsa_kernel_runtime *));
> +    }
>  
>    HSA_DEBUG ("Copying kernel runtime pointer to kernarg_address\n");
>  
> -- 
> 2.7.1
>
diff mbox

Patch

From 413707c51bf4b0ac7f8dac6421be9955c18767dd Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Mon, 21 Mar 2016 21:40:03 +0100
Subject: [PATCH] Copy shadow argument conditionally (PR hsa/70337)

libgomp/ChangeLog:

2016-03-21  Martin Liska  <mliska@suse.cz>

	PR hsa/70337
	* plugin/plugin-hsa.c (GOMP_OFFLOAD_run): Copy shadow
	argument just in case a dispatched kernel uses that argument.
---
 libgomp/plugin/plugin-hsa.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/libgomp/plugin/plugin-hsa.c b/libgomp/plugin/plugin-hsa.c
index d888493..f7ef600 100644
--- a/libgomp/plugin/plugin-hsa.c
+++ b/libgomp/plugin/plugin-hsa.c
@@ -1255,8 +1255,16 @@  GOMP_OFFLOAD_run (int n, void *fn_ptr, void *vars, void **args)
   hsa_signal_store_relaxed (s, 1);
   memcpy (shadow->kernarg_address, &vars, sizeof (vars));
 
-  memcpy (shadow->kernarg_address + sizeof (vars), &shadow,
-	  sizeof (struct hsa_kernel_runtime *));
+  /* PR hsa/70337.  */
+  size_t vars_size = sizeof (vars);
+  if (kernel->kernarg_segment_size > vars_size)
+    {
+      if (kernel->kernarg_segment_size != vars_size
+	  + sizeof (struct hsa_kernel_runtime *))
+	GOMP_PLUGIN_fatal ("Kernel segment size has an unexpected value");
+      memcpy (packet->kernarg_address + vars_size, &shadow,
+	      sizeof (struct hsa_kernel_runtime *));
+    }
 
   HSA_DEBUG ("Copying kernel runtime pointer to kernarg_address\n");
 
-- 
2.7.1