1 //
2 // Copyright (c) 2017 The Khronos Group Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 #include "harness/compat.h"
17
18 #include <stdio.h>
19 #include <string.h>
20 #include <sys/types.h>
21 #include <sys/stat.h>
22
23 #include "procs.h"
24
25 #include "checker_image_mem_host_read_only.hpp"
26 #include "checker_image_mem_host_no_access.hpp"
27 #include "checker_image_mem_host_write_only.hpp"
28
29 //======================================
test_mem_host_read_only_RW_Image(cl_device_id deviceID,cl_context context,cl_command_queue queue,cl_bool blocking,cl_mem_flags buffer_mem_flag,cl_mem_object_type image_type_in,size_t array_size,size_t * img_dim)30 static cl_int test_mem_host_read_only_RW_Image(cl_device_id deviceID, cl_context context,
31 cl_command_queue queue, cl_bool blocking,
32 cl_mem_flags buffer_mem_flag,
33 cl_mem_object_type image_type_in,
34 size_t array_size, size_t *img_dim)
35 {
36 log_info("%s ... \n ", __FUNCTION__);
37 cl_int err = CL_SUCCESS;
38
39 cImage_check_mem_host_read_only< int > checker(deviceID, context, queue);
40 checker.m_blocking = blocking;
41 checker.buffer_mem_flag = buffer_mem_flag;
42
43 checker.m_cl_Image_desc.image_type = image_type_in;
44 checker.m_cl_Image_desc.image_width = img_dim[0];
45 checker.m_cl_Image_desc.image_height = img_dim[1];
46 checker.m_cl_Image_desc.image_depth = img_dim[2];
47 checker.m_cl_Image_desc.image_array_size = array_size;
48 checker.m_cl_Image_desc.image_row_pitch = 0;
49 checker.m_cl_Image_desc.image_slice_pitch = 0;
50 checker.m_cl_Image_desc.num_mip_levels = 0;
51 checker.m_cl_Image_desc.num_samples = 0;
52
53 checker.SetupImage();
54 checker.Init_rect();
55 err = checker.verify_RW_Image();
56 test_error(err, __FUNCTION__);
57 clFinish(queue);
58 return err;
59 }
60
test_mem_host_read_only_RW_Image_Mapping(cl_device_id deviceID,cl_context context,cl_command_queue queue,cl_bool blocking,cl_mem_flags buffer_mem_flag,cl_mem_object_type image_type_in,size_t array_size,size_t * img_dim)61 static cl_int test_mem_host_read_only_RW_Image_Mapping(cl_device_id deviceID, cl_context context,
62 cl_command_queue queue, cl_bool blocking,
63 cl_mem_flags buffer_mem_flag,
64 cl_mem_object_type image_type_in,
65 size_t array_size, size_t *img_dim)
66 {
67 log_info("%s ... \n ", __FUNCTION__);
68 cl_int err = CL_SUCCESS;
69
70 cImage_check_mem_host_read_only< int > checker(deviceID, context, queue);
71 checker.m_blocking = blocking;
72 checker.buffer_mem_flag = buffer_mem_flag;
73
74 checker.m_cl_Image_desc.image_type = image_type_in;
75 checker.m_cl_Image_desc.image_width = img_dim[0];
76 checker.m_cl_Image_desc.image_height = img_dim[1];
77 checker.m_cl_Image_desc.image_depth = img_dim[2];
78 checker.m_cl_Image_desc.image_array_size = array_size;
79 checker.m_cl_Image_desc.image_row_pitch = 0;
80 checker.m_cl_Image_desc.image_slice_pitch = 0;
81 checker.m_cl_Image_desc.num_mip_levels = 0;
82 checker.m_cl_Image_desc.num_samples = 0;
83
84 checker.SetupImage();
85 checker.Init_rect();
86 err = checker.verify_RW_Image_Mapping();
87 test_error(err, __FUNCTION__);
88 clFinish(queue);
89 return err;
90 }
91
test_mem_host_read_only_image(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)92 int test_mem_host_read_only_image(cl_device_id deviceID, cl_context context,
93 cl_command_queue queue, int num_elements)
94 {
95 cl_mem_flags buffer_mem_flags[2] = { CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR | CL_MEM_HOST_READ_ONLY,
96 CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR | CL_MEM_HOST_READ_ONLY };
97
98 cl_int err = CL_SUCCESS;
99
100 cl_bool image_support;
101 err = clGetDeviceInfo(deviceID, CL_DEVICE_IMAGE_SUPPORT, sizeof image_support, &image_support, NULL);
102 if (err) {
103 test_error(err, __FUNCTION__);
104 return err;
105 }
106 if (!image_support) {
107 log_info("Images are not supported by the device, skipping test...\n");
108 return 0;
109 }
110
111
112 cl_mem_object_type img_type[5] = {CL_MEM_OBJECT_IMAGE1D, CL_MEM_OBJECT_IMAGE2D, CL_MEM_OBJECT_IMAGE3D,CL_MEM_OBJECT_IMAGE1D_ARRAY, CL_MEM_OBJECT_IMAGE2D_ARRAY};
113
114 size_t img_dims[5][3] = {{200, 1, 1}, {200, 80, 1}, {200, 80, 5}, {200, 1, 1}, {200, 80, 10}}; // in elements
115
116 size_t array_size[5] = {1, 10, 1, 10, 1};
117
118 cl_bool blocking[2] = {CL_TRUE, CL_FALSE};
119 for (int flag=0; flag<2; flag++)
120 for (int i=0; i<2; i++) // blocking
121 {
122 for(int p=0; p<3; p++)
123 {
124 err = test_mem_host_read_only_RW_Image(deviceID, context, queue, blocking[i],
125 buffer_mem_flags[flag], img_type[p],
126 array_size[p], img_dims[p]);
127
128 test_error(err, __FUNCTION__);
129
130 err = test_mem_host_read_only_RW_Image_Mapping(deviceID, context, queue, blocking[i],
131 buffer_mem_flags[flag], img_type[p],
132 array_size[p], img_dims[p]);
133
134 test_error(err, __FUNCTION__);
135 }
136 }
137
138 return err;
139 }
140
141 //----------------------------
test_MEM_HOST_WRIE_ONLY_Image_RW(cl_device_id deviceID,cl_context context,cl_command_queue queue,cl_bool blocking,cl_mem_flags buffer_mem_flag,cl_mem_object_type image_type_in,size_t array_size,size_t * img_dim)142 static cl_int test_MEM_HOST_WRIE_ONLY_Image_RW (cl_device_id deviceID, cl_context context,
143 cl_command_queue queue, cl_bool blocking,
144 cl_mem_flags buffer_mem_flag,
145 cl_mem_object_type image_type_in,
146 size_t array_size, size_t *img_dim)
147 {
148 log_info(" %s ... \n ", __FUNCTION__);
149 cl_int err = CL_SUCCESS;
150
151 cImage_check_mem_host_write_only< int > checker(deviceID, context, queue);
152 checker.m_blocking = blocking;
153 checker.buffer_mem_flag = buffer_mem_flag;
154
155 checker.m_cl_Image_desc.image_type = image_type_in;
156 checker.m_cl_Image_desc.image_width = img_dim[0];
157 checker.m_cl_Image_desc.image_height = img_dim[1];
158 checker.m_cl_Image_desc.image_depth = img_dim[2];
159 checker.m_cl_Image_desc.image_array_size = array_size;
160 checker.m_cl_Image_desc.image_row_pitch = 0;
161 checker.m_cl_Image_desc.image_slice_pitch = 0;
162 checker.m_cl_Image_desc.num_mip_levels = 0;
163 checker.m_cl_Image_desc.num_samples = 0;
164
165 checker.SetupImage();
166 checker.Init_rect();
167 checker.Setup_Test_Environment();
168
169 err = checker.verify_RW_Image();
170 clFinish(queue);
171 test_error(err, __FUNCTION__);
172
173 return err;
174 }
175
test_MEM_HOST_WRITE_ONLY_Image_RW_Mapping(cl_device_id deviceID,cl_context context,cl_command_queue queue,cl_bool blocking,cl_mem_flags buffer_mem_flag,cl_mem_object_type image_type_in,size_t array_size,size_t * img_dim)176 static cl_int test_MEM_HOST_WRITE_ONLY_Image_RW_Mapping(cl_device_id deviceID, cl_context context,
177 cl_command_queue queue, cl_bool blocking,
178 cl_mem_flags buffer_mem_flag,
179 cl_mem_object_type image_type_in,
180 size_t array_size, size_t *img_dim)
181 {
182 log_info("%s ... \n ", __FUNCTION__);
183 cl_int err = CL_SUCCESS;
184
185 cImage_check_mem_host_write_only< int > checker(deviceID, context, queue);
186 checker.m_blocking = blocking;
187 checker.buffer_mem_flag = buffer_mem_flag;
188
189 checker.m_cl_Image_desc.image_type = image_type_in;
190 checker.m_cl_Image_desc.image_width = img_dim[0];
191 checker.m_cl_Image_desc.image_height = img_dim[1];
192 checker.m_cl_Image_desc.image_depth = img_dim[2];
193 checker.m_cl_Image_desc.image_array_size = array_size;
194 checker.m_cl_Image_desc.image_row_pitch = 0;
195 checker.m_cl_Image_desc.image_slice_pitch = 0;
196 checker.m_cl_Image_desc.num_mip_levels = 0;
197 checker.m_cl_Image_desc.num_samples = 0;
198
199 checker.SetupImage();
200 checker.Init_rect();
201 checker.Setup_Test_Environment();
202
203 err = checker.verify_RW_Image_Mapping();
204 clFinish(queue);
205 test_error(err, __FUNCTION__);
206
207 return err;
208 }
209
test_mem_host_write_only_image(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)210 int test_mem_host_write_only_image(cl_device_id deviceID, cl_context context,
211 cl_command_queue queue, int num_elements)
212 {
213 cl_mem_flags buffer_mem_flags[2] = { CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR | CL_MEM_HOST_WRITE_ONLY,
214 CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR | CL_MEM_HOST_WRITE_ONLY };
215
216 cl_int err = CL_SUCCESS;
217
218 cl_bool image_support;
219 err = clGetDeviceInfo(deviceID, CL_DEVICE_IMAGE_SUPPORT, sizeof image_support, &image_support, NULL);
220 if (err) {
221 test_error(err, __FUNCTION__);
222 return err;
223 }
224 if (!image_support) {
225 log_info("Images are not supported by the device, skipping test...\n");
226 return 0;
227 }
228
229 cl_mem_object_type img_type[5]= {CL_MEM_OBJECT_IMAGE1D, CL_MEM_OBJECT_IMAGE2D, CL_MEM_OBJECT_IMAGE3D,
230 CL_MEM_OBJECT_IMAGE1D_ARRAY, CL_MEM_OBJECT_IMAGE2D_ARRAY};
231
232 size_t img_dims[5][3]= {{200, 1, 1}, {200, 80, 1}, {200, 80, 5}, {200, 1, 1}, {200, 80, 1} }; // in elements
233
234 size_t array_size[5] = {1, 10, 1, 10, 1};
235
236 cl_bool blocking[2] = {CL_TRUE, CL_FALSE};
237 for (int k=0; k<2; k++)
238 for (int i=0; i<2; i++) // blocking
239 {
240 for (int p=0; p<3; p++)
241 {
242 err = test_MEM_HOST_WRIE_ONLY_Image_RW(deviceID, context, queue, blocking[i],
243 buffer_mem_flags[k], img_type[p], array_size[p], img_dims[p]);
244 test_error(err, __FUNCTION__);
245
246 err = test_MEM_HOST_WRITE_ONLY_Image_RW_Mapping(deviceID, context, queue, blocking[i],
247 buffer_mem_flags[k], img_type[p], array_size[p], img_dims[p]);
248 test_error(err, __FUNCTION__);
249 }
250 }
251
252 return err;
253 }
254
255 //--------
256
test_mem_host_no_access_Image_RW(cl_device_id deviceID,cl_context context,cl_command_queue queue,cl_bool blocking,cl_mem_flags buffer_mem_flag,cl_mem_object_type image_type_in,size_t array_size,size_t * img_dim)257 static cl_int test_mem_host_no_access_Image_RW(cl_device_id deviceID, cl_context context,
258 cl_command_queue queue, cl_bool blocking,
259 cl_mem_flags buffer_mem_flag,
260 cl_mem_object_type image_type_in,
261 size_t array_size, size_t *img_dim)
262 {
263 log_info("%s ... \n", __FUNCTION__);
264 cl_int err = CL_SUCCESS;
265
266 cImage_check_mem_host_no_access< int > checker(deviceID, context, queue);
267
268 checker.m_blocking = blocking;
269 checker.buffer_mem_flag = buffer_mem_flag;
270
271 checker.m_cl_Image_desc.image_type = image_type_in;
272 checker.m_cl_Image_desc.image_width = img_dim[0];
273 checker.m_cl_Image_desc.image_height = img_dim[1];
274 checker.m_cl_Image_desc.image_depth = img_dim[2];
275 checker.m_cl_Image_desc.image_array_size = array_size;
276 checker.m_cl_Image_desc.image_row_pitch = 0;
277 checker.m_cl_Image_desc.image_slice_pitch = 0;
278 checker.m_cl_Image_desc.num_mip_levels = 0;
279 checker.m_cl_Image_desc.num_samples = 0;
280
281 checker.SetupImage();
282 checker.Init_rect();
283 checker.Setup_Test_Environment();
284 err = checker.verify_RW_Image();
285 test_error(err, __FUNCTION__);
286 clFinish(queue);
287 return err;
288 }
289
test_mem_host_no_access_Image_RW_Mapping(cl_device_id deviceID,cl_context context,cl_command_queue queue,cl_bool blocking,cl_mem_flags buffer_mem_flag,cl_mem_object_type image_type_in,size_t array_size,size_t * img_dim)290 static cl_int test_mem_host_no_access_Image_RW_Mapping(cl_device_id deviceID, cl_context context,
291 cl_command_queue queue, cl_bool blocking,
292 cl_mem_flags buffer_mem_flag,
293 cl_mem_object_type image_type_in,
294 size_t array_size, size_t *img_dim)
295 {
296 log_info("%s ... \n ", __FUNCTION__);
297 cl_int err =CL_SUCCESS;
298
299 cImage_check_mem_host_no_access< int > checker(deviceID, context, queue);
300
301 checker.m_blocking = blocking;
302 checker.buffer_mem_flag = buffer_mem_flag;
303
304 checker.m_cl_Image_desc.image_type = image_type_in;
305 checker.m_cl_Image_desc.image_width = img_dim[0];
306 checker.m_cl_Image_desc.image_height = img_dim[1];
307 checker.m_cl_Image_desc.image_depth = img_dim[2];
308 checker.m_cl_Image_desc.image_array_size = array_size;
309 checker.m_cl_Image_desc.image_row_pitch = 0;
310 checker.m_cl_Image_desc.image_slice_pitch = 0;
311 checker.m_cl_Image_desc.num_mip_levels = 0;
312 checker.m_cl_Image_desc.num_samples = 0;
313
314 checker.SetupImage();
315 checker.Init_rect();
316 checker.Setup_Test_Environment();
317 err = checker.verify_RW_Image_Mapping();
318 test_error(err, __FUNCTION__);
319 clFinish(queue);
320 return err;
321 }
322
test_mem_host_no_access_image(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)323 int test_mem_host_no_access_image(cl_device_id deviceID, cl_context context,
324 cl_command_queue queue, int num_elements)
325 {
326 cl_mem_flags buffer_mem_flags[2] = {CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR | CL_MEM_HOST_NO_ACCESS,
327 CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR | CL_MEM_HOST_NO_ACCESS };
328
329 cl_int err = CL_SUCCESS;
330
331 cl_bool image_support;
332 err = clGetDeviceInfo(deviceID, CL_DEVICE_IMAGE_SUPPORT, sizeof image_support, &image_support, NULL);
333 if (err) {
334 test_error(err, __FUNCTION__);
335 return err;
336 }
337 if (!image_support) {
338 log_info("Images are not supported by the device, skipping test...\n");
339 return 0;
340 }
341
342 cl_mem_object_type img_type[5] = {CL_MEM_OBJECT_IMAGE1D, CL_MEM_OBJECT_IMAGE2D, CL_MEM_OBJECT_IMAGE3D,
343 CL_MEM_OBJECT_IMAGE1D_ARRAY, CL_MEM_OBJECT_IMAGE2D_ARRAY};
344
345 size_t img_dims[5][3]= {{200, 1, 1}, {200, 80, 1}, {100, 80, 5}, {200, 1, 1}, {200, 80, 1}}; // in elements
346
347 size_t array_size [5] = {1, 1, 1, 10, 10};
348
349 cl_bool blocking[2] = { CL_TRUE, CL_FALSE};
350 for (int k=0; k<2; k++)
351 for (int i=0; i<2; i++) // blocking
352 {
353 for (int p =0; p<3; p++)
354 {
355 err += test_mem_host_no_access_Image_RW (deviceID, context, queue, blocking[i],
356 buffer_mem_flags[k], img_type[p], array_size[p], img_dims[p]);
357
358 err += test_mem_host_no_access_Image_RW_Mapping(deviceID, context, queue, blocking[i],
359 buffer_mem_flags[k], img_type[p], array_size[p], img_dims[p]);
360 }
361 }
362
363 return err;
364 }
365