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 "testBase.h"
17 #include "harness/typeWrappers.h"
18 #include "harness/testHarness.h"
19
20
21 #define TEST_MEM_OBJECT_PARAM( mem, paramName, val, expected, name, type, cast ) \
22 error = clGetMemObjectInfo( mem, paramName, sizeof( val ), &val, &size ); \
23 test_error( error, "Unable to get mem object " name ); \
24 if( val != expected ) \
25 { \
26 log_error( "ERROR: Mem object " name " did not validate! (expected " type ", got " type " from %s:%d)\n", \
27 expected, (cast)val, __FILE__, __LINE__ ); \
28 return -1; \
29 } \
30 if( size != sizeof( val ) ) \
31 { \
32 log_error( "ERROR: Returned size of mem object " name " does not validate! (expected %d, got %d from %s:%d)\n", \
33 (int)sizeof( val ), (int)size , __FILE__, __LINE__ ); \
34 return -1; \
35 }
36
mem_obj_destructor_callback(cl_mem,void * data)37 static void CL_CALLBACK mem_obj_destructor_callback( cl_mem, void * data )
38 {
39 free( data );
40 }
41
42 static unsigned int
get_image_dim(MTdata * d,unsigned int mod)43 get_image_dim(MTdata *d, unsigned int mod)
44 {
45 unsigned int val = 0;
46
47 do
48 {
49 val = (unsigned int)genrand_int32(*d) % mod;
50 } while (val == 0);
51
52 return val;
53 }
54
55
test_get_buffer_info(cl_device_id deviceID,cl_context context,cl_command_queue ignoreQueue,int num_elements)56 int test_get_buffer_info( cl_device_id deviceID, cl_context context, cl_command_queue ignoreQueue, int num_elements )
57 {
58 int error;
59 size_t size;
60 void * buffer = NULL;
61
62 clMemWrapper bufferObject;
63 clMemWrapper subBufferObject;
64
65 cl_mem_flags bufferFlags[] = {
66 CL_MEM_READ_WRITE,
67 CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
68 CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR,
69 CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
70 CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,
71 CL_MEM_READ_ONLY,
72 CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
73 CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR,
74 CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
75 CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
76 CL_MEM_WRITE_ONLY,
77 CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR,
78 CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR,
79 CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
80 CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR,
81 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_WRITE,
82 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
83 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR,
84 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
85 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,
86 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_ONLY,
87 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
88 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR,
89 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
90 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
91 CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY,
92 CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR,
93 CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR,
94 CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
95 CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR,
96 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_WRITE,
97 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
98 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR,
99 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
100 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,
101 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_ONLY,
102 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
103 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR,
104 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
105 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
106 CL_MEM_HOST_WRITE_ONLY | CL_MEM_WRITE_ONLY,
107 CL_MEM_HOST_WRITE_ONLY | CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR,
108 CL_MEM_HOST_WRITE_ONLY | CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR,
109 CL_MEM_HOST_WRITE_ONLY | CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
110 CL_MEM_HOST_WRITE_ONLY | CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR,
111 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_WRITE,
112 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
113 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR,
114 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
115 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,
116 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_ONLY,
117 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
118 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR,
119 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
120 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
121 CL_MEM_HOST_NO_ACCESS | CL_MEM_WRITE_ONLY,
122 CL_MEM_HOST_NO_ACCESS | CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR,
123 CL_MEM_HOST_NO_ACCESS | CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR,
124 CL_MEM_HOST_NO_ACCESS | CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
125 CL_MEM_HOST_NO_ACCESS | CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR,
126 };
127
128 cl_mem_flags subBufferFlags[] = {
129 CL_MEM_READ_WRITE,
130 CL_MEM_READ_ONLY,
131 CL_MEM_WRITE_ONLY,
132 0,
133 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_WRITE,
134 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_ONLY,
135 CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY,
136 CL_MEM_HOST_READ_ONLY | 0,
137 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_WRITE,
138 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_ONLY,
139 CL_MEM_HOST_WRITE_ONLY | CL_MEM_WRITE_ONLY,
140 CL_MEM_HOST_WRITE_ONLY | 0,
141 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_WRITE,
142 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_ONLY,
143 CL_MEM_HOST_NO_ACCESS | CL_MEM_WRITE_ONLY,
144 CL_MEM_HOST_NO_ACCESS | 0,
145 };
146
147
148 // Get the address alignment, so we can make sure the sub-buffer test later works properly.
149 cl_uint addressAlignBits;
150 error = clGetDeviceInfo( deviceID, CL_DEVICE_MEM_BASE_ADDR_ALIGN, sizeof(addressAlignBits), &addressAlignBits, NULL );
151
152 size_t addressAlign = addressAlignBits/8;
153 if ( addressAlign < 128 )
154 {
155 addressAlign = 128;
156 }
157
158 for ( unsigned int i = 0; i < sizeof(bufferFlags) / sizeof(cl_mem_flags); ++i )
159 {
160 //printf("@@@ bufferFlags[%u]=0x%x\n", i, bufferFlags[ i ]);
161 if ( bufferFlags[ i ] & CL_MEM_USE_HOST_PTR )
162 {
163 // Create a buffer object to test against.
164 buffer = malloc( addressAlign * 4 );
165 bufferObject = clCreateBuffer( context, bufferFlags[ i ], addressAlign * 4, buffer, &error );
166 if ( error )
167 {
168 free( buffer );
169 test_error( error, "Unable to create buffer (CL_MEM_USE_HOST_PTR) to test with" );
170 }
171
172 // Make sure buffer is cleaned up appropriately if we encounter an error in the rest of the calls.
173 error = clSetMemObjectDestructorCallback( bufferObject, mem_obj_destructor_callback, buffer );
174 test_error( error, "Unable to set mem object destructor callback" );
175
176 void * ptr;
177 TEST_MEM_OBJECT_PARAM( bufferObject, CL_MEM_HOST_PTR, ptr, buffer, "host pointer", "%p", void * )
178 }
179 else if ( (bufferFlags[ i ] & CL_MEM_ALLOC_HOST_PTR) && (bufferFlags[ i ] & CL_MEM_COPY_HOST_PTR) )
180 {
181 // Create a buffer object to test against.
182 buffer = malloc( addressAlign * 4 );
183 bufferObject = clCreateBuffer( context, bufferFlags[ i ], addressAlign * 4, buffer, &error );
184 if ( error )
185 {
186 free( buffer );
187 test_error( error, "Unable to create buffer (CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR) to test with" );
188 }
189
190 // Make sure buffer is cleaned up appropriately if we encounter an error in the rest of the calls.
191 error = clSetMemObjectDestructorCallback( bufferObject, mem_obj_destructor_callback, buffer );
192 test_error( error, "Unable to set mem object destructor callback" );
193 }
194 else if ( bufferFlags[ i ] & CL_MEM_ALLOC_HOST_PTR )
195 {
196 // Create a buffer object to test against.
197 bufferObject = clCreateBuffer( context, bufferFlags[ i ], addressAlign * 4, NULL, &error );
198 test_error( error, "Unable to create buffer (CL_MEM_ALLOC_HOST_PTR) to test with" );
199 }
200 else if ( bufferFlags[ i ] & CL_MEM_COPY_HOST_PTR )
201 {
202 // Create a buffer object to test against.
203 buffer = malloc( addressAlign * 4 );
204 bufferObject = clCreateBuffer( context, bufferFlags[ i ], addressAlign * 4, buffer, &error );
205 if ( error )
206 {
207 free( buffer );
208 test_error( error, "Unable to create buffer (CL_MEM_COPY_HOST_PTR) to test with" );
209 }
210
211 // Make sure buffer is cleaned up appropriately if we encounter an error in the rest of the calls.
212 error = clSetMemObjectDestructorCallback( bufferObject, mem_obj_destructor_callback, buffer );
213 test_error( error, "Unable to set mem object destructor callback" );
214 }
215 else
216 {
217 // Create a buffer object to test against.
218 bufferObject = clCreateBuffer( context, bufferFlags[ i ], addressAlign * 4, NULL, &error );
219 test_error( error, "Unable to create buffer to test with" );
220 }
221
222 // Perform buffer object queries.
223 cl_mem_object_type type;
224 TEST_MEM_OBJECT_PARAM( bufferObject, CL_MEM_TYPE, type, CL_MEM_OBJECT_BUFFER, "type", "%d", int )
225
226 cl_mem_flags flags;
227 TEST_MEM_OBJECT_PARAM( bufferObject, CL_MEM_FLAGS, flags, (unsigned int)bufferFlags[ i ], "flags", "%d", unsigned int )
228
229 size_t sz;
230 TEST_MEM_OBJECT_PARAM( bufferObject, CL_MEM_SIZE, sz, (size_t)( addressAlign * 4 ), "size", "%ld", size_t )
231
232 cl_uint mapCount;
233 error = clGetMemObjectInfo( bufferObject, CL_MEM_MAP_COUNT, sizeof( mapCount ), &mapCount, &size );
234 test_error( error, "Unable to get mem object map count" );
235 if( size != sizeof( mapCount ) )
236 {
237 log_error( "ERROR: Returned size of mem object map count does not validate! (expected %d, got %d from %s:%d)\n",
238 (int)sizeof( mapCount ), (int)size, __FILE__, __LINE__ );
239 return -1;
240 }
241
242 cl_uint refCount;
243 error = clGetMemObjectInfo( bufferObject, CL_MEM_REFERENCE_COUNT, sizeof( refCount ), &refCount, &size );
244 test_error( error, "Unable to get mem object reference count" );
245 if( size != sizeof( refCount ) )
246 {
247 log_error( "ERROR: Returned size of mem object reference count does not validate! (expected %d, got %d from %s:%d)\n",
248 (int)sizeof( refCount ), (int)size, __FILE__, __LINE__ );
249 return -1;
250 }
251
252 cl_context otherCtx;
253 TEST_MEM_OBJECT_PARAM( bufferObject, CL_MEM_CONTEXT, otherCtx, context, "context", "%p", cl_context )
254
255 cl_mem origObj;
256 TEST_MEM_OBJECT_PARAM( bufferObject, CL_MEM_ASSOCIATED_MEMOBJECT, origObj, (void *)NULL, "associated mem object", "%p", void * )
257
258 size_t offset;
259 TEST_MEM_OBJECT_PARAM( bufferObject, CL_MEM_OFFSET, offset, 0L, "offset", "%ld", size_t )
260
261 cl_buffer_region region;
262 region.origin = addressAlign;
263 region.size = addressAlign;
264
265 // Loop over possible sub-buffer objects to create.
266 for ( unsigned int j = 0; j < sizeof(subBufferFlags) / sizeof(cl_mem_flags); ++j )
267 {
268 if ( subBufferFlags[ j ] & CL_MEM_READ_WRITE )
269 {
270 if ( !(bufferFlags[ i ] & CL_MEM_READ_WRITE) )
271 continue; // Buffer must be read_write for sub-buffer to be read_write.
272 }
273 if ( subBufferFlags[ j ] & CL_MEM_READ_ONLY )
274 {
275 if ( !(bufferFlags[ i ] & CL_MEM_READ_WRITE) && !(bufferFlags[ i ] & CL_MEM_READ_ONLY) )
276 continue; // Buffer must be read_write or read_only for sub-buffer to be read_only
277 }
278 if ( subBufferFlags[ j ] & CL_MEM_WRITE_ONLY )
279 {
280 if ( !(bufferFlags[ i ] & CL_MEM_READ_WRITE) && !(bufferFlags[ i ] & CL_MEM_WRITE_ONLY) )
281 continue; // Buffer must be read_write or write_only for sub-buffer to be write_only
282 }
283 if ( subBufferFlags[ j ] & CL_MEM_HOST_READ_ONLY )
284 {
285 if ( (bufferFlags[ i ] & CL_MEM_HOST_NO_ACCESS) || (bufferFlags[ i ] & CL_MEM_HOST_WRITE_ONLY) )
286 continue; // Buffer must be host all access or host read_only for sub-buffer to be host read_only
287 }
288 if ( subBufferFlags[ j ] & CL_MEM_HOST_WRITE_ONLY )
289 {
290 if ( (bufferFlags[ i ] & CL_MEM_HOST_NO_ACCESS) || (bufferFlags[ i ] & CL_MEM_HOST_READ_ONLY) )
291 continue; // Buffer must be host all access or host write_only for sub-buffer to be host write_only
292 }
293 //printf("@@@ bufferFlags[%u]=0x%x subBufferFlags[%u]=0x%x\n", i, bufferFlags[ i ], j, subBufferFlags[ j ]);
294
295 subBufferObject = clCreateSubBuffer( bufferObject, subBufferFlags[ j ], CL_BUFFER_CREATE_TYPE_REGION, ®ion, &error );
296 test_error( error, "Unable to create sub-buffer to test against" );
297
298 // Perform sub-buffer object queries.
299 cl_mem_object_type type;
300 TEST_MEM_OBJECT_PARAM( subBufferObject, CL_MEM_TYPE, type, CL_MEM_OBJECT_BUFFER, "type", "%d", int )
301
302 cl_mem_flags flags;
303 cl_mem_flags inheritedFlags = subBufferFlags[ j ];
304 if ( (subBufferFlags[ j ] & (CL_MEM_READ_WRITE | CL_MEM_READ_ONLY | CL_MEM_WRITE_ONLY)) == 0 )
305 {
306 inheritedFlags |= bufferFlags[ i ] & (CL_MEM_READ_WRITE | CL_MEM_READ_ONLY | CL_MEM_WRITE_ONLY);
307 }
308 inheritedFlags |= bufferFlags[ i ] & (CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR);
309 if ( (subBufferFlags[ j ] & (CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS)) == 0)
310 {
311 inheritedFlags |= bufferFlags[ i ] & (CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS);
312 }
313 TEST_MEM_OBJECT_PARAM( subBufferObject, CL_MEM_FLAGS, flags, (unsigned int)inheritedFlags, "flags", "%d", unsigned int )
314
315 TEST_MEM_OBJECT_PARAM( subBufferObject, CL_MEM_SIZE, sz, (size_t)( addressAlign ), "size", "%ld", size_t )
316
317 if ( bufferFlags[ i ] & CL_MEM_USE_HOST_PTR )
318 {
319 void * ptr;
320 void * offsetInBuffer = (char *)buffer + addressAlign;
321
322 TEST_MEM_OBJECT_PARAM( subBufferObject, CL_MEM_HOST_PTR, ptr, offsetInBuffer, "host pointer", "%p", void * )
323 }
324
325 cl_uint mapCount;
326 error = clGetMemObjectInfo( subBufferObject, CL_MEM_MAP_COUNT, sizeof( mapCount ), &mapCount, &size );
327 test_error( error, "Unable to get mem object map count" );
328 if( size != sizeof( mapCount ) )
329 {
330 log_error( "ERROR: Returned size of mem object map count does not validate! (expected %d, got %d from %s:%d)\n",
331 (int)sizeof( mapCount ), (int)size, __FILE__, __LINE__ );
332 return -1;
333 }
334
335 cl_uint refCount;
336 error = clGetMemObjectInfo( subBufferObject, CL_MEM_REFERENCE_COUNT, sizeof( refCount ), &refCount, &size );
337 test_error( error, "Unable to get mem object reference count" );
338 if( size != sizeof( refCount ) )
339 {
340 log_error( "ERROR: Returned size of mem object reference count does not validate! (expected %d, got %d from %s:%d)\n",
341 (int)sizeof( refCount ), (int)size, __FILE__, __LINE__ );
342 return -1;
343 }
344
345 cl_context otherCtx;
346 TEST_MEM_OBJECT_PARAM( subBufferObject, CL_MEM_CONTEXT, otherCtx, context, "context", "%p", cl_context )
347
348 TEST_MEM_OBJECT_PARAM( subBufferObject, CL_MEM_ASSOCIATED_MEMOBJECT, origObj, (cl_mem)bufferObject, "associated mem object", "%p", void * )
349
350 TEST_MEM_OBJECT_PARAM( subBufferObject, CL_MEM_OFFSET, offset, (size_t)( addressAlign ), "offset", "%ld", size_t )
351 }
352 }
353
354 return CL_SUCCESS;
355 }
356
357
test_get_imageObject_info(cl_mem * image,cl_mem_flags objectFlags,cl_image_desc * imageInfo,cl_image_format * imageFormat,size_t pixelSize,cl_context context)358 int test_get_imageObject_info( cl_mem * image, cl_mem_flags objectFlags, cl_image_desc *imageInfo, cl_image_format *imageFormat, size_t pixelSize, cl_context context )
359 {
360 int error;
361 size_t size;
362 cl_mem_object_type type;
363 cl_mem_flags flags;
364 cl_uint mapCount;
365 cl_uint refCount;
366 cl_context otherCtx;
367 size_t offset;
368 size_t sz;
369
370 TEST_MEM_OBJECT_PARAM( *image, CL_MEM_TYPE, type, imageInfo->image_type, "type", "%d", int )
371
372 TEST_MEM_OBJECT_PARAM( *image, CL_MEM_FLAGS, flags, (unsigned int)objectFlags, "flags", "%d", unsigned int )
373
374 error = clGetMemObjectInfo( *image, CL_MEM_SIZE, sizeof( sz ), &sz, NULL );
375 test_error( error, "Unable to get mem size" );
376
377 // The size returned is not constrained by the spec.
378
379 error = clGetMemObjectInfo( *image, CL_MEM_MAP_COUNT, sizeof( mapCount ), &mapCount, &size );
380 test_error( error, "Unable to get mem object map count" );
381 if( size != sizeof( mapCount ) )
382 {
383 log_error( "ERROR: Returned size of mem object map count does not validate! (expected %d, got %d from %s:%d)\n",
384 (int)sizeof( mapCount ), (int)size, __FILE__, __LINE__ );
385 return -1;
386 }
387
388 error = clGetMemObjectInfo( *image, CL_MEM_REFERENCE_COUNT, sizeof( refCount ), &refCount, &size );
389 test_error( error, "Unable to get mem object reference count" );
390 if( size != sizeof( refCount ) )
391 {
392 log_error( "ERROR: Returned size of mem object reference count does not validate! (expected %d, got %d from %s:%d)\n",
393 (int)sizeof( refCount ), (int)size, __FILE__, __LINE__ );
394 return -1;
395 }
396
397 TEST_MEM_OBJECT_PARAM( *image, CL_MEM_CONTEXT, otherCtx, context, "context", "%p", cl_context )
398
399 TEST_MEM_OBJECT_PARAM( *image, CL_MEM_OFFSET, offset, 0L, "offset", "%ld", size_t )
400
401 return CL_SUCCESS;
402 }
403
404
test_get_image_info(cl_device_id deviceID,cl_context context,cl_mem_object_type type)405 int test_get_image_info( cl_device_id deviceID, cl_context context, cl_mem_object_type type )
406 {
407 int error;
408 size_t size;
409 void * image = NULL;
410
411 cl_mem imageObject;
412 cl_image_desc imageInfo;
413
414 cl_mem_flags imageFlags[] = {
415 CL_MEM_READ_WRITE,
416 CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
417 CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR,
418 CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
419 CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,
420 CL_MEM_READ_ONLY,
421 CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
422 CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR,
423 CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
424 CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
425 CL_MEM_WRITE_ONLY,
426 CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR,
427 CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR,
428 CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
429 CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR,
430 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_WRITE,
431 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
432 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR,
433 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
434 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,
435 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_ONLY,
436 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
437 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR,
438 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
439 CL_MEM_HOST_READ_ONLY | CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
440 CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY,
441 CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR,
442 CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR,
443 CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
444 CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR,
445 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_WRITE,
446 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
447 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR,
448 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
449 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,
450 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_ONLY,
451 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
452 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR,
453 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
454 CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
455 CL_MEM_HOST_WRITE_ONLY | CL_MEM_WRITE_ONLY,
456 CL_MEM_HOST_WRITE_ONLY | CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR,
457 CL_MEM_HOST_WRITE_ONLY | CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR,
458 CL_MEM_HOST_WRITE_ONLY | CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
459 CL_MEM_HOST_WRITE_ONLY | CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR,
460 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_WRITE,
461 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
462 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR,
463 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
464 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,
465 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_ONLY,
466 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
467 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR,
468 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
469 CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
470 CL_MEM_HOST_NO_ACCESS | CL_MEM_WRITE_ONLY,
471 CL_MEM_HOST_NO_ACCESS | CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR,
472 CL_MEM_HOST_NO_ACCESS | CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR,
473 CL_MEM_HOST_NO_ACCESS | CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
474 CL_MEM_HOST_NO_ACCESS | CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR,
475 };
476 MTdata d;
477
478 PASSIVE_REQUIRE_IMAGE_SUPPORT( deviceID )
479
480 cl_image_format imageFormat;
481 size_t pixelSize = 4;
482
483 imageFormat.image_channel_order = CL_RGBA;
484 imageFormat.image_channel_data_type = CL_UNORM_INT8;
485
486 imageInfo.image_width = imageInfo.image_height = imageInfo.image_depth = 1;
487 imageInfo.image_array_size = 0;
488 imageInfo.num_mip_levels = imageInfo.num_samples = 0;
489 #ifdef CL_VERSION_2_0
490 imageInfo.mem_object = NULL;
491 #else
492 imageInfo.buffer = NULL;
493 #endif
494
495 d = init_genrand( gRandomSeed );
496
497 for ( unsigned int i = 0; i < sizeof(imageFlags) / sizeof(cl_mem_flags); ++i )
498 {
499 imageInfo.image_row_pitch = 0;
500 imageInfo.image_slice_pitch = 0;
501
502 switch (type)
503 {
504 case CL_MEM_OBJECT_IMAGE1D:
505 imageInfo.image_width = get_image_dim(&d, 1023);
506 imageInfo.image_type = CL_MEM_OBJECT_IMAGE1D;
507 break;
508
509 case CL_MEM_OBJECT_IMAGE2D:
510 imageInfo.image_width = get_image_dim(&d, 1023);
511 imageInfo.image_height = get_image_dim(&d, 1023);
512 imageInfo.image_type = CL_MEM_OBJECT_IMAGE2D;
513 break;
514
515 case CL_MEM_OBJECT_IMAGE3D:
516 error = checkFor3DImageSupport(deviceID);
517 if (error == CL_IMAGE_FORMAT_NOT_SUPPORTED)
518 {
519 log_info("Device doesn't support 3D images. Skipping test.\n");
520 return CL_SUCCESS;
521 }
522 imageInfo.image_width = get_image_dim(&d, 127);
523 imageInfo.image_height = get_image_dim(&d, 127);
524 imageInfo.image_depth = get_image_dim(&d, 127);
525 imageInfo.image_type = CL_MEM_OBJECT_IMAGE3D;
526 break;
527
528 case CL_MEM_OBJECT_IMAGE1D_ARRAY:
529 imageInfo.image_width = get_image_dim(&d, 1023);
530 imageInfo.image_array_size = get_image_dim(&d, 1023);
531 imageInfo.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
532 break;
533
534 case CL_MEM_OBJECT_IMAGE2D_ARRAY:
535 imageInfo.image_width = get_image_dim(&d, 255);
536 imageInfo.image_height = get_image_dim(&d, 255);
537 imageInfo.image_array_size = get_image_dim(&d, 255);
538 imageInfo.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
539 break;
540 }
541
542 if ( imageFlags[i] & CL_MEM_USE_HOST_PTR )
543 {
544 // Create an image object to test against.
545 image = malloc( imageInfo.image_width * imageInfo.image_height * imageInfo.image_depth * pixelSize *
546 ((imageInfo.image_array_size == 0) ? 1 : imageInfo.image_array_size) );
547 imageObject = clCreateImage( context, imageFlags[i], &imageFormat, &imageInfo, image, &error );
548 if ( error )
549 {
550 free( image );
551 test_error( error, "Unable to create image with (CL_MEM_USE_HOST_PTR) to test with" );
552 }
553
554 // Make sure image is cleaned up appropriately if we encounter an error in the rest of the calls.
555 error = clSetMemObjectDestructorCallback( imageObject, mem_obj_destructor_callback, image );
556 test_error( error, "Unable to set mem object destructor callback" );
557
558 void * ptr;
559 TEST_MEM_OBJECT_PARAM( imageObject, CL_MEM_HOST_PTR, ptr, image, "host pointer", "%p", void * )
560 int ret = test_get_imageObject_info( &imageObject, imageFlags[i], &imageInfo, &imageFormat, pixelSize, context );
561 if (ret)
562 return ret;
563
564 // release image object
565 clReleaseMemObject(imageObject);
566
567 // Try again with non-zero rowPitch.
568 imageInfo.image_row_pitch = imageInfo.image_width * pixelSize;
569 switch (type)
570 {
571 case CL_MEM_OBJECT_IMAGE1D_ARRAY:
572 case CL_MEM_OBJECT_IMAGE2D_ARRAY:
573 case CL_MEM_OBJECT_IMAGE3D:
574 imageInfo.image_slice_pitch = imageInfo.image_row_pitch * imageInfo.image_height;
575 break;
576 }
577
578 image = malloc( imageInfo.image_width * imageInfo.image_height * imageInfo.image_depth * pixelSize *
579 ((imageInfo.image_array_size == 0) ? 1 : imageInfo.image_array_size) );
580 imageObject = clCreateImage( context, imageFlags[i], &imageFormat, &imageInfo, image, &error );
581 if ( error )
582 {
583 free( image );
584 test_error( error, "Unable to create image2d (CL_MEM_USE_HOST_PTR) to test with" );
585 }
586
587 // Make sure image2d is cleaned up appropriately if we encounter an error in the rest of the calls.
588 error = clSetMemObjectDestructorCallback( imageObject, mem_obj_destructor_callback, image );
589 test_error( error, "Unable to set mem object destructor callback" );
590
591 TEST_MEM_OBJECT_PARAM( imageObject, CL_MEM_HOST_PTR, ptr, image, "host pointer", "%p", void * )
592 ret = test_get_imageObject_info( &imageObject, imageFlags[i], &imageInfo, &imageFormat, pixelSize, context );
593 if (ret)
594 return ret;
595
596 }
597 else if ( (imageFlags[i] & CL_MEM_ALLOC_HOST_PTR) && (imageFlags[i] & CL_MEM_COPY_HOST_PTR) )
598 {
599 // Create an image object to test against.
600 image = malloc( imageInfo.image_width * imageInfo.image_height * imageInfo.image_depth * pixelSize *
601 ((imageInfo.image_array_size == 0) ? 1 : imageInfo.image_array_size) );
602 imageObject = clCreateImage( context, imageFlags[i], &imageFormat, &imageInfo, image, &error );
603 if ( error )
604 {
605 free( image );
606 test_error( error, "Unable to create image with (CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR) to test with" );
607 }
608
609 // Make sure image is cleaned up appropriately if we encounter an error in the rest of the calls.
610 error = clSetMemObjectDestructorCallback( imageObject, mem_obj_destructor_callback, image );
611 test_error( error, "Unable to set mem object destructor callback" );
612 int ret = test_get_imageObject_info( &imageObject, imageFlags[ i ], &imageInfo, &imageFormat, pixelSize, context );
613 if (ret)
614 return ret;
615
616 // release image object
617 clReleaseMemObject(imageObject);
618
619 // Try again with non-zero rowPitch.
620 imageInfo.image_row_pitch = imageInfo.image_width * pixelSize;
621 switch (type)
622 {
623 case CL_MEM_OBJECT_IMAGE1D_ARRAY:
624 case CL_MEM_OBJECT_IMAGE2D_ARRAY:
625 case CL_MEM_OBJECT_IMAGE3D:
626 imageInfo.image_slice_pitch = imageInfo.image_row_pitch * imageInfo.image_height;
627 break;
628 }
629
630 image = malloc( imageInfo.image_width * imageInfo.image_height * imageInfo.image_depth * pixelSize *
631 ((imageInfo.image_array_size == 0) ? 1 : imageInfo.image_array_size) );
632 imageObject = clCreateImage( context, imageFlags[i], &imageFormat, &imageInfo, image, &error );
633 if ( error )
634 {
635 free( image );
636 test_error( error, "Unable to create image with (CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR) to test with" );
637 }
638
639 // Make sure image is cleaned up appropriately if we encounter an error in the rest of the calls.
640 error = clSetMemObjectDestructorCallback( imageObject, mem_obj_destructor_callback, image );
641 test_error( error, "Unable to set mem object destructor callback" );
642 ret = test_get_imageObject_info( &imageObject, imageFlags[i], &imageInfo, &imageFormat, pixelSize, context );
643 if (ret)
644 return ret;
645
646 }
647 else if ( imageFlags[i] & CL_MEM_ALLOC_HOST_PTR )
648 {
649 // Create an image object to test against.
650 imageObject = clCreateImage( context, imageFlags[i], &imageFormat, &imageInfo, NULL, &error );
651 test_error( error, "Unable to create image with (CL_MEM_ALLOC_HOST_PTR) to test with" );
652 int ret = test_get_imageObject_info( &imageObject, imageFlags[i], &imageInfo, &imageFormat, pixelSize, context );
653 if (ret)
654 return ret;
655
656 }
657 else if ( imageFlags[i] & CL_MEM_COPY_HOST_PTR )
658 {
659 // Create an image object to test against.
660 image = malloc( imageInfo.image_width * imageInfo.image_height * imageInfo.image_depth * pixelSize *
661 ((imageInfo.image_array_size == 0) ? 1 : imageInfo.image_array_size) );
662 imageObject = clCreateImage( context, imageFlags[i], &imageFormat, &imageInfo, image, &error );
663 if ( error )
664 {
665 free( image );
666 test_error( error, "Unable to create image with (CL_MEM_COPY_HOST_PTR) to test with" );
667 }
668
669 // Make sure image is cleaned up appropriately if we encounter an error in the rest of the calls.
670 error = clSetMemObjectDestructorCallback( imageObject, mem_obj_destructor_callback, image );
671 test_error( error, "Unable to set mem object destructor callback" );
672 int ret = test_get_imageObject_info( &imageObject, imageFlags[i], &imageInfo, &imageFormat, pixelSize, context );
673 if (ret)
674 return ret;
675
676 clReleaseMemObject(imageObject);
677
678 // Try again with non-zero rowPitch.
679 imageInfo.image_row_pitch = imageInfo.image_width * pixelSize;
680 switch (type)
681 {
682 case CL_MEM_OBJECT_IMAGE1D_ARRAY:
683 case CL_MEM_OBJECT_IMAGE2D_ARRAY:
684 case CL_MEM_OBJECT_IMAGE3D:
685 imageInfo.image_slice_pitch = imageInfo.image_row_pitch * imageInfo.image_height;
686 break;
687 }
688
689 image = malloc( imageInfo.image_width * imageInfo.image_height * imageInfo.image_depth * pixelSize *
690 ((imageInfo.image_array_size == 0) ? 1 : imageInfo.image_array_size) );
691 imageObject = clCreateImage( context, imageFlags[i], &imageFormat, &imageInfo, image, &error );
692 if ( error )
693 {
694 free( image );
695 test_error( error, "Unable to create image with (CL_MEM_COPY_HOST_PTR) to test with" );
696 }
697
698 // Make sure image is cleaned up appropriately if we encounter an error in the rest of the calls.
699 error = clSetMemObjectDestructorCallback( imageObject, mem_obj_destructor_callback, image );
700 test_error( error, "Unable to set mem object destructor callback" );
701 ret = test_get_imageObject_info( &imageObject, imageFlags[i], &imageInfo, &imageFormat, pixelSize, context );
702 if (ret)
703 return ret;
704
705 }
706 else
707 {
708 // Create an image object to test against.
709 imageObject = clCreateImage( context, imageFlags[i], &imageFormat, &imageInfo, NULL, &error );
710 test_error( error, "Unable to create image to test with" );
711 int ret = test_get_imageObject_info( &imageObject, imageFlags[i], &imageInfo, &imageFormat, pixelSize, context );
712 if (ret)
713 return ret;
714
715 }
716
717 clReleaseMemObject( imageObject );
718 }
719
720 return CL_SUCCESS;
721 }
722
723
test_get_image2d_info(cl_device_id deviceID,cl_context context,cl_command_queue ignoreQueue,int num_elements)724 int test_get_image2d_info( cl_device_id deviceID, cl_context context, cl_command_queue ignoreQueue, int num_elements )
725 {
726 return test_get_image_info(deviceID, context, CL_MEM_OBJECT_IMAGE2D);
727 }
728
test_get_image3d_info(cl_device_id deviceID,cl_context context,cl_command_queue ignoreQueue,int num_elements)729 int test_get_image3d_info( cl_device_id deviceID, cl_context context, cl_command_queue ignoreQueue, int num_elements )
730 {
731 return test_get_image_info(deviceID, context, CL_MEM_OBJECT_IMAGE3D);
732 }
733
test_get_image1d_info(cl_device_id deviceID,cl_context context,cl_command_queue ignoreQueue,int num_elements)734 int test_get_image1d_info( cl_device_id deviceID, cl_context context, cl_command_queue ignoreQueue, int num_elements )
735 {
736 return test_get_image_info(deviceID, context, CL_MEM_OBJECT_IMAGE1D);
737 }
738
test_get_image1d_array_info(cl_device_id deviceID,cl_context context,cl_command_queue ignoreQueue,int num_elements)739 int test_get_image1d_array_info( cl_device_id deviceID, cl_context context, cl_command_queue ignoreQueue, int num_elements )
740 {
741 return test_get_image_info(deviceID, context, CL_MEM_OBJECT_IMAGE1D_ARRAY);
742 }
743
test_get_image2d_array_info(cl_device_id deviceID,cl_context context,cl_command_queue ignoreQueue,int num_elements)744 int test_get_image2d_array_info( cl_device_id deviceID, cl_context context, cl_command_queue ignoreQueue, int num_elements )
745 {
746 return test_get_image_info(deviceID, context, CL_MEM_OBJECT_IMAGE2D_ARRAY);
747 }
748
749
750