Branch data Line data Source code
1 : : /* StarPU --- Runtime system for heterogeneous multicore architectures.
2 : : *
3 : : * Copyright (C) 2011 Institut National de Recherche en Informatique et Automatique
4 : : *
5 : : * StarPU is free software; you can redistribute it and/or modify
6 : : * it under the terms of the GNU Lesser General Public License as published by
7 : : * the Free Software Foundation; either version 2.1 of the License, or (at
8 : : * your option) any later version.
9 : : *
10 : : * StarPU is distributed in the hope that it will be useful, but
11 : : * WITHOUT ANY WARRANTY; without even the implied warranty of
12 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 : : *
14 : : * See the GNU Lesser General Public License in COPYING.LGPL for more details.
15 : : */
16 : : #include <config.h>
17 : : #include <starpu.h>
18 : : #include "../test_interfaces.h"
19 : :
20 : : #define KERNEL_LOCATION "tests/datawizard/interfaces/block/block_opencl_kernel.cl"
21 : : extern struct test_config block_config;
22 : : static struct starpu_opencl_program opencl_program;
23 : :
24 : : void
25 : 2 : test_block_opencl_func(void *buffers[], void *args)
26 : : {
27 [ - + ][ # # ]: 4 : STARPU_SKIP_IF_VALGRIND;
[ # # ]
28 : :
29 : : int id, devid, ret;
30 : 2 : int factor = *(int *) args;
31 : :
32 : : cl_int err;
33 : : cl_kernel kernel;
34 : : cl_command_queue queue;
35 : : cl_event event;
36 : :
37 : 2 : ret = starpu_opencl_load_opencl_from_file(KERNEL_LOCATION, &opencl_program, NULL);
38 [ - + ]: 2 : STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_load_opencl_from_file");
39 : :
40 : 2 : int nx = STARPU_BLOCK_GET_NX(buffers[0]);
41 : 2 : int ny = STARPU_BLOCK_GET_NY(buffers[0]);
42 : 2 : int nz = STARPU_BLOCK_GET_NZ(buffers[0]);
43 : 2 : unsigned ldy = STARPU_BLOCK_GET_LDY(buffers[0]);
44 : 2 : unsigned ldz = STARPU_BLOCK_GET_LDZ(buffers[0]);
45 : 2 : cl_mem block = (cl_mem) STARPU_BLOCK_GET_DEV_HANDLE(buffers[0]);
46 : :
47 : : cl_context context;
48 : 2 : id = starpu_worker_get_id();
49 : 2 : devid = starpu_worker_get_devid(id);
50 : 2 : starpu_opencl_get_context(devid, &context);
51 : :
52 : 2 : cl_mem fail = clCreateBuffer(context, CL_MEM_COPY_HOST_PTR,
53 : : sizeof(int), &block_config.copy_failed, &err);
54 : :
55 [ - + ]: 2 : if (err != CL_SUCCESS)
56 : 0 : STARPU_OPENCL_REPORT_ERROR(err);
57 : :
58 : :
59 : 2 : err = starpu_opencl_load_kernel(&kernel,
60 : : &queue,
61 : : &opencl_program,
62 : : "block_opencl",
63 : : devid);
64 [ - + ]: 2 : if (err != CL_SUCCESS)
65 : 0 : STARPU_OPENCL_REPORT_ERROR(err);
66 : :
67 : : int nargs;
68 : 2 : nargs = starpu_opencl_set_kernel_args(&err, &kernel,
69 : : sizeof(block), &block,
70 : : sizeof(nx), &nx,
71 : : sizeof(ny), &ny,
72 : : sizeof(nz), &nz,
73 : : sizeof(ldy), &ldy,
74 : : sizeof(ldz), &ldz,
75 : : sizeof(factor), &factor,
76 : : sizeof(fail), &fail,
77 : : 0);
78 : :
79 [ - + ]: 2 : if (nargs != 8)
80 : : {
81 : 0 : fprintf(stderr, "Failed to set argument #%d\n", nargs);
82 : 0 : STARPU_OPENCL_REPORT_ERROR(err);
83 : : }
84 : :
85 : : {
86 : 2 : size_t global = nx * ny * nz;
87 : 2 : err = clEnqueueNDRangeKernel(queue,
88 : : kernel,
89 : : 1,
90 : : NULL,
91 : : &global,
92 : : NULL,
93 : : 0,
94 : : NULL,
95 : : &event);
96 : :
97 [ - + ]: 2 : if (err != CL_SUCCESS)
98 : 0 : STARPU_OPENCL_REPORT_ERROR(err);
99 : : }
100 : :
101 : 2 : err = clEnqueueReadBuffer(queue,
102 : : fail,
103 : : CL_TRUE,
104 : : 0,
105 : : sizeof(int),
106 : : &block_config.copy_failed,
107 : : 0,
108 : : NULL,
109 : : NULL);
110 [ - + ]: 2 : if (err != CL_SUCCESS)
111 : 0 : STARPU_OPENCL_REPORT_ERROR(err);
112 : :
113 : 2 : clFinish(queue);
114 : 2 : starpu_opencl_collect_stats(event);
115 : 2 : clReleaseEvent(event);
116 : :
117 : 2 : starpu_opencl_release_kernel(kernel);
118 : 2 : ret = starpu_opencl_unload_opencl(&opencl_program);
119 [ - + ]: 2 : STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_unload_opencl");
120 : : }
|