File: test_clSetMemObjectDestructorCallback.c

package info (click to toggle)
pocl 6.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,320 kB
  • sloc: lisp: 149,513; ansic: 103,778; cpp: 54,947; python: 1,513; sh: 949; ruby: 255; pascal: 226; tcl: 180; makefile: 175; java: 72; xml: 49
file content (50 lines) | stat: -rw-r--r-- 1,222 bytes parent folder | download | duplicates (2)
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
#include <stdio.h>
#include <stdlib.h>

#include "poclu.h"

#define MAX_DEVICES   1

#define FAKE_PTR 0xDEADBEEF

void callback(cl_mem memobj, void *user_data)
{
  if (user_data == (void*)FAKE_PTR)
    printf("OK\n");
  else
    printf("FAIL\n");
}

int
main(void)
{
  cl_int err;
  cl_platform_id platform[1];
  cl_uint nplatforms;
  cl_device_id devices[MAX_DEVICES];
  cl_uint ndevices;

  err = clGetPlatformIDs (1, platform, &nplatforms);
  CHECK_OPENCL_ERROR_IN("clGetPlatformIDs");

  err = clGetDeviceIDs (platform[0], CL_DEVICE_TYPE_ALL, MAX_DEVICES,
                        devices, &ndevices);
  CHECK_OPENCL_ERROR_IN("clGetDeviceIDs");

  TEST_ASSERT(ndevices >= 1);

  cl_context context = clCreateContext (NULL, 1, devices, NULL, NULL, &err);
  CHECK_OPENCL_ERROR_IN("clCreateContext");

  cl_mem mem = clCreateBuffer (context, 0, 1024, NULL, &err);
  CHECK_OPENCL_ERROR_IN("clCreateBuffer");

  err = clSetMemObjectDestructorCallback (mem, callback, (void*)FAKE_PTR);
  CHECK_OPENCL_ERROR_IN("clSetMemObjectDestructorCallback");

  CHECK_CL_ERROR (clReleaseMemObject (mem));
  CHECK_CL_ERROR (clReleaseContext (context));
  CHECK_CL_ERROR (clUnloadPlatformCompiler (platform[0]));

  return EXIT_SUCCESS;
}