File: test_kernel_cache_includes.c

package info (click to toggle)
pocl 0.13-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 18,452 kB
  • ctags: 13,529
  • sloc: lisp: 113,221; cpp: 57,376; ansic: 25,021; sh: 6,150; makefile: 2,067; python: 699; pascal: 98; java: 72; xml: 49
file content (80 lines) | stat: -rw-r--r-- 2,406 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
73
74
75
76
77
78
79
80
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <CL/opencl.h>
#include "poclu.h"
#include "config.h"
#include "pocl_tests.h"

char first_include[] =
    "#define PRINT_DEFINE \"This is printf from the first include\\n\"\n"
    "void test_include() { printf(\"A printf from inside a function 1\\n\"); }\n";

char second_include[] =
    "#define PRINT_DEFINE \"This is printf from the second include\\n\"\n"
    "void test_include() { printf(\"A printf from inside a function 2\\n\"); }\n";


int main(int argc, char **argv)
{
  cl_int err;
  const char *krn_src;
  cl_program program, program2;
  cl_context ctx;
  cl_command_queue queue;
  cl_device_id did;
  cl_kernel kernel, kernel2;

  poclu_get_any_device(&ctx, &did, &queue);
  TEST_ASSERT(ctx);
  TEST_ASSERT(did);
  TEST_ASSERT(queue);

  krn_src = poclu_read_file(SRCDIR "/tests/runtime/test_kernel_cache_includes.cl");
  TEST_ASSERT(krn_src);

  err = poclu_write_file(BUILDDIR "/tests/runtime/test_include.h", first_include,
                         sizeof(first_include)-1);
  TEST_ASSERT(err == 0);

  program = clCreateProgramWithSource(ctx, 1, &krn_src, NULL, &err);
  CHECK_OPENCL_ERROR_IN("clCreateProgramWithSource");

  err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL);
  CHECK_OPENCL_ERROR_IN("clBuildProgram 1");

  kernel = clCreateKernel(program, "testk", &err);
  CHECK_OPENCL_ERROR_IN("clCreateKernel 1");

  size_t off[3] = {0,0,0};
  size_t ws[3] = {1,1,1};

  err = clEnqueueNDRangeKernel(queue, kernel, 3, off, ws, ws, 0, NULL, 0);
  CHECK_OPENCL_ERROR_IN("clEnqueueNDRangeKernel 1");

  err = clFinish(queue);
  CHECK_OPENCL_ERROR_IN("clFinish 1");

  /***************************************/

  program2 = clCreateProgramWithSource(ctx, 1, &krn_src, NULL, &err);
  CHECK_OPENCL_ERROR_IN("clCreateProgramWithSource 2");

  err = poclu_write_file(BUILDDIR "/tests/runtime/test_include.h", second_include,
                         sizeof(second_include)-1);
  TEST_ASSERT(err == 0);

  err = clBuildProgram(program2, 0, NULL, NULL, NULL, NULL);
  CHECK_OPENCL_ERROR_IN("clBuildProgram 2");

  kernel2 = clCreateKernel(program2, "testk", &err);
  CHECK_OPENCL_ERROR_IN("clCreateKernel 2");

  err = clEnqueueNDRangeKernel(queue, kernel2, 3, off, ws, ws, 0, NULL, 0);
  CHECK_OPENCL_ERROR_IN("clEnqueueNDRangeKernel 2");

  err = clFinish(queue);
  CHECK_OPENCL_ERROR_IN("clFinish 2");

  return 0;
}