summaryrefslogtreecommitdiff
path: root/get_global_id_2d.c
blob: ae940e7e12f830439b4618fdb7011e40e8d6bb71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <assert.h>
#include <stdio.h>

#include <CL/cl.h>

#include "util.h"


int main (int argc, char ** argv)
{
   unsigned i,j;
   cl_int error;

   cl_mem out_buffer;
   int out_data[10][10];
   size_t global_work_size[2] = {10, 10};

   struct clu_context context;

   cluSimpleInit(&context, "global_id2d");

   /* XXX: Delete this to see a missing error path */
   out_buffer = clCreateBuffer(context.cl_ctx,
                               CL_MEM_WRITE_ONLY,
                               sizeof(out_data),
                               NULL, &error);

   assert(error == CL_SUCCESS);

   if (!cluKernelSetArg(context.kernel, 0, sizeof(cl_mem), &out_buffer)) {
      return EXIT_FAILURE;
   }

   error = clEnqueueNDRangeKernel(context.command_queue,
                                  context.kernel,
                                  2, /* dimensions */
                                  NULL,
                                  global_work_size,
                                  global_work_size,
                                  0, NULL, NULL);

   assert(error == CL_SUCCESS);

   error = clEnqueueReadBuffer(context.command_queue,
                               out_buffer,
                               CL_TRUE,
                               0,
                               sizeof(out_data),
                               out_data,
                               0, NULL, NULL);

   assert(error == CL_SUCCESS);

   for (i = 0; i < 10; i++) {
      for (j = 0; j < 10; j++) {
         fprintf(stderr, "%2u ", out_data[i][j]);
      }
      fprintf(stderr, "\n");
   }
}