+2019-01-23 Tom de Vries <tdevries@suse.de>
+
+ PR target/87835
+ * plugin/plugin-nvptx.c (map_push): Fix adding of allocated element.
+ * testsuite/libgomp.oacc-c-c++-common/pr87835.c: New test.
+
2019-01-15 Tom de Vries <tdevries@suse.de>
PR target/80547
static CUdeviceptr
map_push (struct ptx_stream *s, size_t size)
{
- struct cuda_map *map = NULL, *t = NULL;
+ struct cuda_map *map = NULL;
+ struct cuda_map **t;
assert (s);
assert (s->map);
- /* Each PTX stream requires a separate data region to store the
- launch arguments for cuLaunchKernel. Allocate a new
- cuda_map and push it to the end of the list. */
+ /* Select an element to push. */
if (s->map->active)
+ map = cuda_map_create (size);
+ else
{
- map = cuda_map_create (size);
+ /* Pop the inactive front element. */
+ struct cuda_map *pop = s->map;
+ s->map = pop->next;
+ pop->next = NULL;
- for (t = s->map; t->next != NULL; t = t->next)
- ;
+ if (pop->size < size)
+ {
+ cuda_map_destroy (pop);
- t->next = map;
- }
- else if (s->map->size < size)
- {
- cuda_map_destroy (s->map);
- map = cuda_map_create (size);
+ map = cuda_map_create (size);
+ }
+ else
+ map = pop;
}
- else
- map = s->map;
- s->map = map;
- s->map->active = true;
+ /* Check that the element is as expected. */
+ assert (map->next == NULL);
+ assert (!map->active);
+
+ /* Mark the element active. */
+ map->active = true;
+
+ /* Push the element to the back of the list. */
+ for (t = &s->map; (*t) != NULL; t = &(*t)->next)
+ ;
+ assert (t != NULL && *t == NULL);
+ *t = map;
- return s->map->d;
+ return map->d;
}
/* Target data function launch information. */
--- /dev/null
+/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* { dg-additional-options "-lcuda" } */
+
+#include <openacc.h>
+#include <stdlib.h>
+#include "cuda.h"
+
+#include <stdio.h>
+
+#define n 128
+
+int
+main (void)
+{
+ CUresult r;
+ CUstream stream1;
+ int N = n;
+ int a[n];
+ int b[n];
+ int c[n];
+
+ acc_init (acc_device_nvidia);
+
+ r = cuStreamCreate (&stream1, CU_STREAM_NON_BLOCKING);
+ if (r != CUDA_SUCCESS)
+ {
+ fprintf (stderr, "cuStreamCreate failed: %d\n", r);
+ abort ();
+ }
+
+ acc_set_cuda_stream (1, stream1);
+
+ for (int i = 0; i < n; i++)
+ {
+ a[i] = 3;
+ c[i] = 0;
+ }
+
+#pragma acc data copy (a, b, c) copyin (N)
+ {
+#pragma acc parallel async (1)
+ ;
+
+#pragma acc parallel async (1) num_gangs (320)
+ #pragma loop gang
+ for (int ii = 0; ii < N; ii++)
+ c[ii] = (a[ii] + a[N - ii - 1]);
+
+#pragma acc parallel async (1)
+ #pragma acc loop seq
+ for (int ii = 0; ii < n; ii++)
+ a[ii] = 6;
+
+#pragma acc wait (1)
+ }
+
+ for (int i = 0; i < n; i++)
+ if (c[i] != 6)
+ abort ();
+
+ return 0;
+}