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
18 extern int test_get_image_info_single( cl_context context, image_descriptor *imageInfo, MTdata d, cl_mem_flags flags, size_t row_pitch, size_t slice_pitch );
19
test_get_image_info_1D_array(cl_device_id device,cl_context context,cl_image_format * format,cl_mem_flags flags)20 int test_get_image_info_1D_array( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags )
21 {
22 size_t maxWidth, maxArraySize;
23 cl_ulong maxAllocSize, memSize;
24 image_descriptor imageInfo = { 0 };
25 RandomSeed seed( gRandomSeed );
26
27 cl_mem_flags all_host_ptr_flags[5] = {
28 flags,
29 CL_MEM_ALLOC_HOST_PTR | flags,
30 CL_MEM_COPY_HOST_PTR | flags,
31 CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | flags,
32 CL_MEM_USE_HOST_PTR | flags
33 };
34
35 memset(&imageInfo, 0x0, sizeof(image_descriptor));
36 imageInfo.format = format;
37 imageInfo.type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
38
39 int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL );
40 error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, sizeof( maxArraySize ), &maxArraySize, NULL );
41 error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL );
42 error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL );
43 test_error( error, "Unable to get max image 1D array size from device" );
44
45 if (memSize > (cl_ulong)SIZE_MAX) {
46 memSize = (cl_ulong)SIZE_MAX;
47 maxAllocSize = (cl_ulong)SIZE_MAX;
48 }
49
50 if( gTestSmallImages )
51 {
52 for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
53 {
54 imageInfo.rowPitch = imageInfo.width * get_pixel_size( imageInfo.format );
55 imageInfo.slicePitch = imageInfo.rowPitch;
56 for( imageInfo.arraySize = 2; imageInfo.arraySize < 9; imageInfo.arraySize++ )
57 {
58 for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++)
59 {
60 if( gDebugTrace )
61 log_info( " at size %d,%d (flags[%u] 0x%x pitch %d)\n", (int)imageInfo.width, (int)imageInfo.arraySize, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch );
62 if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) )
63 return -1;
64 if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL
65 if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) )
66 return -1;
67 }
68 }
69 }
70 }
71 }
72 else if( gTestMaxImages )
73 {
74 // Try a specific set of maximum sizes
75 size_t numbeOfSizes;
76 size_t sizes[100][3];
77
78 get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, 1, 1, maxArraySize, maxAllocSize, memSize,
79 CL_MEM_OBJECT_IMAGE1D_ARRAY, imageInfo.format);
80
81 for( size_t idx = 0; idx < numbeOfSizes; idx++ )
82 {
83 imageInfo.width = sizes[ idx ][ 0 ];
84 imageInfo.arraySize = sizes [ idx] [ 2 ];
85 imageInfo.rowPitch = imageInfo.width * get_pixel_size( imageInfo.format );
86 imageInfo.slicePitch = imageInfo.rowPitch;
87
88 log_info( "Testing %d x %d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 2 ] );
89 for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++)
90 {
91 if( gDebugTrace )
92 log_info( " at max size %d,%d (flags[%u] 0x%x pitch %d)\n", (int)imageInfo.width, (int)imageInfo.arraySize, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch );
93 if( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) )
94 return -1;
95 if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL
96 if( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) )
97 return -1;
98 }
99 }
100 }
101 }
102 else
103 {
104 for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
105 {
106 cl_ulong size;
107 // Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
108 // image, the result array, plus offset arrays, will fit in the global ram space
109 do
110 {
111 imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed );
112 imageInfo.arraySize = (size_t)random_log_in_range( 16, (int)maxArraySize / 32, seed );
113
114 imageInfo.rowPitch = imageInfo.width * get_pixel_size( imageInfo.format );
115
116 size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
117 imageInfo.rowPitch += extraWidth;
118
119 imageInfo.slicePitch = imageInfo.rowPitch;
120
121 size = (cl_ulong)imageInfo.slicePitch * (cl_ulong)imageInfo.arraySize * 4 * 4;
122 } while( size > maxAllocSize || ( size * 3 ) > memSize );
123
124 for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++)
125 {
126 if( gDebugTrace )
127 log_info( " at size %d,%d (flags[%u] 0x%x pitch %d) out of %d,%d\n", (int)imageInfo.width, (int)imageInfo.arraySize, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch, (int)maxWidth, (int)maxArraySize );
128 if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) )
129 return -1;
130 if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL
131 if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) )
132 return -1;
133 }
134 }
135 }
136 }
137
138 return 0;
139 }
140
141
test_get_image_info_2D_array(cl_device_id device,cl_context context,cl_image_format * format,cl_mem_flags flags)142 int test_get_image_info_2D_array( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags )
143 {
144 size_t maxWidth, maxHeight, maxArraySize;
145 cl_ulong maxAllocSize, memSize;
146 image_descriptor imageInfo = { 0 };
147 RandomSeed seed( gRandomSeed );
148 size_t pixelSize;
149
150 cl_mem_flags all_host_ptr_flags[5] = {
151 flags,
152 CL_MEM_ALLOC_HOST_PTR | flags,
153 CL_MEM_COPY_HOST_PTR | flags,
154 CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | flags,
155 CL_MEM_USE_HOST_PTR | flags
156 };
157
158 memset(&imageInfo, 0x0, sizeof(image_descriptor));
159 imageInfo.format = format;
160 imageInfo.type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
161 pixelSize = get_pixel_size( imageInfo.format );
162
163 int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL );
164 error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_HEIGHT, sizeof( maxHeight ), &maxHeight, NULL );
165 error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, sizeof( maxArraySize ), &maxArraySize, NULL );
166 error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL );
167 error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL );
168 test_error( error, "Unable to get max image 1D array size from device" );
169
170 if (memSize > (cl_ulong)SIZE_MAX) {
171 memSize = (cl_ulong)SIZE_MAX;
172 maxAllocSize = (cl_ulong)SIZE_MAX;
173 }
174
175 if( gTestSmallImages )
176 {
177 for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
178 {
179 imageInfo.rowPitch = imageInfo.width * pixelSize;
180
181 for( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ )
182 {
183 imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
184 for( imageInfo.arraySize = 2; imageInfo.arraySize < 9; imageInfo.arraySize++ )
185 {
186 for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++)
187 {
188 if( gDebugTrace )
189 log_info( " at size %d,%d,%d (flags[%u] 0x%x pitch %d)\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.arraySize, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch );
190 if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) )
191 return -1;
192 if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL
193 if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) )
194 return -1;
195 }
196 }
197 }
198 }
199 }
200 }
201 else if( gTestMaxImages )
202 {
203 // Try a specific set of maximum sizes
204 size_t numbeOfSizes;
205 size_t sizes[100][3];
206
207 get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, maxHeight, 1, maxArraySize, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE2D_ARRAY, imageInfo.format);
208
209 for( size_t idx = 0; idx < numbeOfSizes; idx++ )
210 {
211 imageInfo.width = sizes[ idx ][ 0 ];
212 imageInfo.height = sizes[ idx ][ 1 ];
213 imageInfo.arraySize = sizes[ idx ][ 2 ];
214 imageInfo.rowPitch = imageInfo.width * pixelSize;
215 imageInfo.slicePitch = imageInfo.height * imageInfo.rowPitch;
216
217 log_info( "Testing %d x %d x %d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ] );
218 for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++)
219 {
220 if( gDebugTrace )
221 log_info( " at max size %d,%d,%d (flags[%u] 0x%x pitch %d)\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.arraySize, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch );
222 if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) )
223 return -1;
224 if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL
225 if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) )
226 return -1;
227 }
228 }
229 }
230 }
231 else
232 {
233 for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
234 {
235 cl_ulong size;
236 // Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
237 // image, the result array, plus offset arrays, will fit in the global ram space
238 do
239 {
240 imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed );
241 imageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed );
242 imageInfo.arraySize = (size_t)random_log_in_range( 16, (int)maxArraySize / 32, seed );
243
244 imageInfo.rowPitch = imageInfo.width * pixelSize;
245 imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
246
247 size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
248 imageInfo.rowPitch += extraWidth;
249
250 do {
251 extraWidth++;
252 imageInfo.rowPitch += extraWidth;
253 } while ((imageInfo.rowPitch % pixelSize) != 0);
254
255 size_t extraHeight = (int)random_log_in_range( 0, 8, seed );
256 imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + extraHeight);
257
258 size = (cl_ulong)imageInfo.slicePitch * (cl_ulong)imageInfo.arraySize * 4 * 4;
259 } while( size > maxAllocSize || ( size * 3 ) > memSize );
260
261 for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++)
262 {
263 if( gDebugTrace )
264 log_info( " at size %d,%d,%d (flags[%u] 0x%x pitch %d) out of %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.arraySize, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch, (int)maxWidth, (int)maxHeight, (int)maxArraySize );
265 if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) )
266 return -1;
267 if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL
268 if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) )
269 return -1;
270 }
271 }
272 }
273 }
274
275 return 0;
276 }
277