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 // Defined in test_fill_2D_3D.cpp
19 extern int test_fill_image_generic( cl_context context, cl_command_queue queue, image_descriptor *imageInfo,
20 const size_t origin[], const size_t region[], ExplicitType outputType, MTdata d );
21
22
test_fill_image_3D(cl_context context,cl_command_queue queue,image_descriptor * imageInfo,ExplicitType outputType,MTdata d)23 int test_fill_image_3D( cl_context context, cl_command_queue queue, image_descriptor *imageInfo, ExplicitType outputType, MTdata d )
24 {
25 size_t origin[ 3 ], region[ 3 ];
26 int ret = 0, retCode;
27
28 // First, try just a full covering region
29 origin[ 0 ] = origin[ 1 ] = origin[ 2 ] = 0;
30 region[ 0 ] = imageInfo->width;
31 region[ 1 ] = imageInfo->height;
32 region[ 2 ] = imageInfo->depth;
33
34 retCode = test_fill_image_generic( context, queue, imageInfo, origin, region, outputType, d );
35 if ( retCode < 0 )
36 return retCode;
37 else
38 ret += retCode;
39
40 // Now try a sampling of different random regions
41 for ( int i = 0; i < 8; i++ )
42 {
43 // Pick a random size
44 region[ 0 ] = ( imageInfo->width > 8 ) ? (size_t)random_in_range( 8, (int)imageInfo->width - 1, d ) : imageInfo->width;
45 region[ 1 ] = ( imageInfo->height > 8 ) ? (size_t)random_in_range( 8, (int)imageInfo->height - 1, d ) : imageInfo->height;
46 region[ 2 ] = ( imageInfo->depth > 8 ) ? (size_t)random_in_range( 8, (int)imageInfo->depth - 1, d ) : imageInfo->depth;
47
48 // Now pick positions within valid ranges
49 origin[ 0 ] = ( imageInfo->width > region[ 0 ] ) ? (size_t)random_in_range( 0, (int)( imageInfo->width - region[ 0 ] - 1 ), d ) : 0;
50 origin[ 1 ] = ( imageInfo->height > region[ 1 ] ) ? (size_t)random_in_range( 0, (int)( imageInfo->height - region[ 1 ] - 1 ), d ) : 0;
51 origin[ 2 ] = ( imageInfo->depth > region[ 2 ] ) ? (size_t)random_in_range( 0, (int)( imageInfo->depth - region[ 2 ] - 1 ), d ) : 0;
52
53 // Go for it!
54 retCode = test_fill_image_generic( context, queue, imageInfo, origin, region, outputType, d );
55 if ( retCode < 0 )
56 return retCode;
57 else
58 ret += retCode;
59 }
60
61 return ret;
62 }
63
64
test_fill_image_set_3D(cl_device_id device,cl_context context,cl_command_queue queue,cl_image_format * format,ExplicitType outputType)65 int test_fill_image_set_3D( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format, ExplicitType outputType )
66 {
67 size_t maxWidth, maxHeight, maxDepth;
68 cl_ulong maxAllocSize, memSize;
69 image_descriptor imageInfo = { 0 };
70 RandomSeed seed( gRandomSeed );
71 const size_t rowPadding_default = 80;
72 size_t rowPadding = gEnablePitch ? rowPadding_default : 0;
73 size_t slicePadding = gEnablePitch ? 3 : 0;
74 size_t pixelSize;
75
76 memset(&imageInfo, 0x0, sizeof(image_descriptor));
77 imageInfo.type = CL_MEM_OBJECT_IMAGE3D;
78 imageInfo.format = format;
79 pixelSize = get_pixel_size( imageInfo.format );
80
81 int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL );
82 error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_HEIGHT, sizeof( maxHeight ), &maxHeight, NULL );
83 error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_DEPTH, sizeof( maxDepth ), &maxDepth, NULL );
84 error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL );
85 error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL );
86 test_error( error, "Unable to get max image 3D size from device" );
87
88 if (memSize > (cl_ulong)SIZE_MAX) {
89 memSize = (cl_ulong)SIZE_MAX;
90 maxAllocSize = (cl_ulong)SIZE_MAX;
91 }
92
93 if ( gTestSmallImages )
94 {
95 for ( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
96 {
97 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
98
99 if (gEnablePitch)
100 {
101 rowPadding = rowPadding_default;
102 do {
103 rowPadding++;
104 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
105 } while ((imageInfo.rowPitch % pixelSize) != 0);
106 }
107
108 for ( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ )
109 {
110 imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + slicePadding);
111 for ( imageInfo.depth = 2; imageInfo.depth < 9; imageInfo.depth++ )
112 {
113 if ( gDebugTrace )
114 log_info( " at size %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.depth );
115 int ret = test_fill_image_3D( context, queue, &imageInfo, outputType, seed );
116 if ( ret )
117 return -1;
118 }
119 }
120 }
121 }
122 else if ( gTestMaxImages )
123 {
124 // Try a specific set of maximum sizes
125 size_t numbeOfSizes;
126 size_t sizes[100][3];
127 get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, maxHeight, maxDepth, 1, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE3D, imageInfo.format);
128
129 for ( size_t idx = 0; idx < numbeOfSizes; idx++ )
130 {
131 imageInfo.width = sizes[ idx ][ 0 ];
132 imageInfo.height = sizes[ idx ][ 1 ];
133 imageInfo.depth = sizes[ idx ][ 2 ];
134
135 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
136
137 if (gEnablePitch)
138 {
139 rowPadding = rowPadding_default;
140 do {
141 rowPadding++;
142 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
143 } while ((imageInfo.rowPitch % pixelSize) != 0);
144 }
145
146 imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + slicePadding);
147 log_info( "Testing %d x %d x %d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ] );
148 if ( gDebugTrace )
149 log_info( " at max size %d,%d,%d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ] );
150 if ( test_fill_image_3D( context, queue, &imageInfo, outputType, seed ) )
151 return -1;
152 }
153 }
154 else
155 {
156 for ( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
157 {
158 cl_ulong size;
159 // Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
160 // image, the result array, plus offset arrays, will fit in the global ram space
161 do
162 {
163 imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed );
164 imageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed );
165 imageInfo.depth = (size_t)random_log_in_range( 16, (int)maxDepth / 32, seed );
166
167 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
168
169 if (gEnablePitch)
170 {
171 rowPadding = rowPadding_default;
172 do {
173 rowPadding++;
174 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
175 } while ((imageInfo.rowPitch % pixelSize) != 0);
176 }
177
178 imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + slicePadding);
179
180 size = (cl_ulong)imageInfo.slicePitch * (cl_ulong)imageInfo.depth * 4 * 4;
181 } while ( size > maxAllocSize || ( size * 3 ) > memSize );
182
183 if ( gDebugTrace )
184 log_info( " at size %d,%d,%d (pitch %d,%d) out of %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.depth, (int)imageInfo.rowPitch, (int)imageInfo.slicePitch, (int)maxWidth, (int)maxHeight, (int)maxDepth );
185 int ret = test_fill_image_3D( context, queue, &imageInfo, outputType, seed );
186 if ( ret )
187 return -1;
188 }
189 }
190
191 return 0;
192 }
193