File: test_clGetEventInfo.c

package info (click to toggle)
pocl 7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 29,768 kB
  • sloc: lisp: 151,669; ansic: 135,425; cpp: 65,801; python: 1,846; sh: 1,084; ruby: 255; pascal: 231; tcl: 180; makefile: 174; asm: 81; java: 72; xml: 49
file content (72 lines) | stat: -rw-r--r-- 2,528 bytes parent folder | download
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
#include <stdio.h>
#include <stdlib.h>

#include "poclu.h"

#define MAX_PLATFORMS 32
#define MAX_DEVICES   32
#define BUF_SIZE 1024
int
main(void)
{
  cl_int err;
  cl_platform_id platforms[MAX_PLATFORMS];
  cl_uint nplatforms;
  cl_device_id devices[MAX_DEVICES];
  cl_uint ndevices;
  cl_uint i, j;
  cl_context context;
  cl_command_queue queue;
  cl_mem buf;
  cl_event buf_event;
  cl_command_queue event_command_queue;

  CHECK_CL_ERROR(clGetPlatformIDs(MAX_PLATFORMS, platforms, &nplatforms));

  for (i = 0; i < nplatforms; i++)
    {
      CHECK_CL_ERROR(clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, MAX_DEVICES,
                           devices, &ndevices));
      
      for (j = 0; j < ndevices; j++)
        {
          context = clCreateContext (NULL, 1, &devices[j], NULL, NULL, &err);
          queue = clCreateCommandQueue (context, devices[j], 0, &err);

          cl_int host_buf[BUF_SIZE];

          buf = clCreateBuffer (context, CL_MEM_READ_WRITE,
                                sizeof (cl_int) * BUF_SIZE, NULL, &err);
          CHECK_CL_ERROR (clEnqueueReadBuffer (
              queue, buf, CL_TRUE, 0, sizeof (cl_int) * BUF_SIZE, &host_buf, 0,
              NULL, &buf_event));
          CHECK_CL_ERROR(clFinish(queue));
          size_t param_val_size_ret;
          CHECK_CL_ERROR(clGetEventInfo(buf_event, CL_EVENT_COMMAND_QUEUE, sizeof(cl_command_queue), &event_command_queue, &param_val_size_ret));
          TEST_ASSERT(param_val_size_ret == sizeof(cl_command_queue));
          TEST_ASSERT(event_command_queue == queue);
          
          cl_command_type command_type;
          CHECK_CL_ERROR(clGetEventInfo(buf_event, CL_EVENT_COMMAND_TYPE, sizeof(cl_command_type), &command_type, &param_val_size_ret));
          TEST_ASSERT(param_val_size_ret == sizeof(cl_command_type));
          TEST_ASSERT(command_type == CL_COMMAND_READ_BUFFER);

          cl_int execution_status;
          CHECK_CL_ERROR(clGetEventInfo(buf_event, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof(cl_int), &execution_status, &param_val_size_ret));
          TEST_ASSERT(param_val_size_ret == sizeof(cl_int));
          TEST_ASSERT(execution_status == CL_COMPLETE);

          CHECK_CL_ERROR(clReleaseEvent(buf_event));

          CHECK_CL_ERROR(clReleaseMemObject(buf));

          CHECK_CL_ERROR(clReleaseCommandQueue(queue));

          CHECK_CL_ERROR (clReleaseContext (context));
          CHECK_CL_ERROR (clUnloadPlatformCompiler (platforms[i]));
        }
    }

  printf ("OK\n");
  return EXIT_SUCCESS;
}