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_3D(cl_device_id device,cl_context context,cl_image_format * format,cl_mem_flags flags)20 int test_get_image_info_3D( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags )
21 {
22 size_t maxWidth, maxHeight, maxDepth;
23 cl_ulong maxAllocSize, memSize;
24 image_descriptor imageInfo = { 0 };
25 RandomSeed seed( gRandomSeed );
26 size_t pixelSize;
27
28 cl_mem_flags all_host_ptr_flags[] = {
29 flags,
30 CL_MEM_ALLOC_HOST_PTR | flags,
31 CL_MEM_COPY_HOST_PTR | flags,
32 CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | flags,
33 CL_MEM_USE_HOST_PTR | flags
34 };
35
36 memset(&imageInfo, 0x0, sizeof(image_descriptor));
37 imageInfo.format = format;
38 imageInfo.type = CL_MEM_OBJECT_IMAGE3D;
39 pixelSize = get_pixel_size( imageInfo.format );
40
41 int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL );
42 error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_HEIGHT, sizeof( maxHeight ), &maxHeight, NULL );
43 error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_DEPTH, sizeof( maxDepth ), &maxDepth, NULL );
44 error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL );
45 error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL );
46 test_error( error, "Unable to get max image 3D size from device" );
47
48 if (memSize > (cl_ulong)SIZE_MAX) {
49 memSize = (cl_ulong)SIZE_MAX;
50 maxAllocSize = (cl_ulong)SIZE_MAX;
51 }
52
53 if( gTestSmallImages )
54 {
55 for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
56 {
57 imageInfo.rowPitch = imageInfo.width * pixelSize;
58
59 for( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ )
60 {
61 imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
62 for( imageInfo.depth = 2; imageInfo.depth < 9; imageInfo.depth++ )
63 {
64 for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++)
65 {
66 if( gDebugTrace )
67 log_info( " at size %d,%d,%d (flags[%u] 0x%lx pitch %d,%d)\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.depth, j, (unsigned long)all_host_ptr_flags[j], (int)imageInfo.rowPitch, (int)imageInfo.slicePitch );
68 if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) )
69 return -1;
70 if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL
71 if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, imageInfo.slicePitch ) )
72 return -1;
73 }
74 }
75 }
76 }
77 }
78 }
79 else if( gTestMaxImages )
80 {
81 // Try a specific set of maximum sizes
82 size_t numbeOfSizes;
83 size_t sizes[100][3];
84
85 get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, maxHeight, maxDepth, 1, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE3D, imageInfo.format);
86
87 for( size_t idx = 0; idx < numbeOfSizes; idx++ )
88 {
89 imageInfo.width = sizes[ idx ][ 0 ];
90 imageInfo.height = sizes[ idx ][ 1 ];
91 imageInfo.depth = sizes[ idx ][ 2 ];
92 imageInfo.rowPitch = imageInfo.width * pixelSize;
93 imageInfo.slicePitch = imageInfo.height * imageInfo.rowPitch;
94
95 log_info( "Testing %d x %d x %d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ] );
96 for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++)
97 {
98 if( gDebugTrace )
99 log_info( " at max size %d,%d,%d (flags[%u] 0x%lx pitch %d,%d)\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ], j, (unsigned long)all_host_ptr_flags[j], (int)imageInfo.rowPitch, (int)imageInfo.slicePitch );
100 if( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) )
101 return -1;
102 if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL
103 if( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, imageInfo.slicePitch ) )
104 return -1;
105 }
106 }
107 }
108 }
109 else
110 {
111 for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
112 {
113 cl_ulong size;
114 // Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
115 // image, the result array, plus offset arrays, will fit in the global ram space
116 do
117 {
118 imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed );
119 imageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed );
120 imageInfo.depth = (size_t)random_log_in_range( 16, (int)maxDepth / 32, seed );
121
122 imageInfo.rowPitch = imageInfo.width * pixelSize;
123 imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
124
125 size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
126 imageInfo.rowPitch += extraWidth;
127
128 do {
129 extraWidth++;
130 imageInfo.rowPitch += extraWidth;
131 } while ((imageInfo.rowPitch % pixelSize) != 0);
132
133 size_t extraHeight = (int)random_log_in_range( 0, 8, seed );
134 imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + extraHeight);
135
136 size = (cl_ulong)imageInfo.slicePitch * (cl_ulong)imageInfo.depth * 4 * 4;
137 } while( size > maxAllocSize || ( size * 3 ) > memSize );
138
139 for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++)
140 {
141 if( gDebugTrace )
142 log_info( " at size %d,%d,%d (flags[%u] 0x%lx pitch %d,%d) out of %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.depth, j, (unsigned long) all_host_ptr_flags[i], (int)imageInfo.rowPitch, (int)imageInfo.slicePitch, (int)maxWidth, (int)maxHeight, (int)maxDepth );
143 if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) )
144 return -1;
145 if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL
146 if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, imageInfo.slicePitch ) )
147 return -1;
148 }
149 }
150 }
151 }
152
153 return 0;
154 }
155