summaryrefslogtreecommitdiff
path: root/get_global_id_2d.c
blob: f127d3ab956882111c6693a97893cfbca33058b8 (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
61
62
63
#include <assert.h>
#include <stdio.h>

#include <CL/cl.h>

#include "util.h"

#define GLOBAL_DIM_X 10
#define GLOBAL_DIM_Y 10

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

   cl_mem out_buffer;
   int out_data[GLOBAL_DIM_X * GLOBAL_DIM_Y];
   size_t global_work_size[2] = {GLOBAL_DIM_X, GLOBAL_DIM_Y};
   size_t local_work_size[2] = {5, 5};

   struct cltest_context context;

   clTestSimpleInit(&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 (!clTestKernelSetArg(context.kernel, 0, sizeof(cl_mem), &out_buffer)) {
      return EXIT_FAILURE;
   }

   error = clEnqueueNDRangeKernel(context.command_queue,
                                  context.kernel,
                                  2, /* dimensions */
                                  NULL,
                                  global_work_size,
                                  local_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 < GLOBAL_DIM_X; i++) {
      for (j = 0; j < GLOBAL_DIM_Y; j++) {
         fprintf(stderr, "%2u ", out_data[i * GLOBAL_DIM_Y + j]);
      }
      fprintf(stderr, "\n");
   }
}