summaryrefslogtreecommitdiff
path: root/get_global_id.c
blob: 9f347fcfb0e0c9e8f0d883d0ab711c43711b5da1 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <stdio.h>
#include <stdlib.h>

#include <CL/cl.h>

#include "util.h"

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

   struct cltest_context context;

   cl_mem out_buffer;

   unsigned i;
   int out_data[10];
   size_t global_work_size = 10;

   clTestSimpleInit(&context, "global_id");

   out_buffer = clCreateBuffer(context.cl_ctx,
                               CL_MEM_WRITE_ONLY, /* Flags */
                               sizeof(out_data), /* Size of buffer */
                               NULL, /* Pointer to the data */
                               &error); /* error code */

   if (error != CL_SUCCESS) {
      fprintf(stderr, "clCreateBuffer() failed: %s\n", clTestErrorString(error));
      return EXIT_FAILURE;
   }

   fprintf(stderr, "clCreateBuffer() succeeded.\n");

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

   error = clEnqueueNDRangeKernel(context.command_queue,
                                  context.kernel,
                                  1, /* Number of dimensions */
                                  NULL, /* Global work offset */
                                  &global_work_size,
                                  &global_work_size, /* local work size */
                                  0, /* Events in wait list */
                                  NULL, /* Wait list */
                                  NULL); /* Event object for this event */

   if (error != CL_SUCCESS) {
      fprintf(stderr, "clEnqueueNDRangeKernel() failed: %s\n",
                      clTestErrorString(error));
      return EXIT_FAILURE;
   }

   fprintf(stderr, "clEnqueueNDRangeKernel() suceeded.\n");

   error = clEnqueueReadBuffer(context.command_queue,
                                out_buffer,
                                CL_TRUE, /* TRUE means it is a blocking read. */
                                0, /* Buffer offset to read from. */
                                sizeof(out_data), /* Bytes to read */
                                out_data, /* Pointer to store the data */
                                0, /* Events in wait list */
                                NULL, /* Wait list */
                                NULL); /* Event object */


   if (error != CL_SUCCESS) {
      fprintf(stderr, "clEnqueueReadBuffer() failed: %s\n",
                      clTestErrorString(error));
      return EXIT_FAILURE;
   }

   fprintf(stderr, "clEnqueueReadBuffer() suceeded.\n");

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

/*

   if (out_value == expected) {
      fprintf(stderr, "Pass\n");
      return EXIT_SUCCESS;
   } else {
      fprintf(stderr, "Expected %d, but got %d\n", expected, out_value);
      return EXIT_FAILURE;
   }
*/
}