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 }
91
92 if ( gTestSmallImages )
93 {
94 for ( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
95 {
96 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
97
98 if (gEnablePitch)
99 {
100 rowPadding = rowPadding_default;
101 do {
102 rowPadding++;
103 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
104 } while ((imageInfo.rowPitch % pixelSize) != 0);
105 }
106
107 for ( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ )
108 {
109 imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + slicePadding);
110 for ( imageInfo.depth = 2; imageInfo.depth < 9; imageInfo.depth++ )
111 {
112 if ( gDebugTrace )
113 log_info( " at size %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.depth );
114 int ret = test_fill_image_3D( context, queue, &imageInfo, outputType, seed );
115 if ( ret )
116 return -1;
117 }
118 }
119 }
120 }
121 else if ( gTestMaxImages )
122 {
123 // Try a specific set of maximum sizes
124 size_t numbeOfSizes;
125 size_t sizes[100][3];
126 get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, maxHeight, maxDepth, 1, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE3D, imageInfo.format);
127
128 for ( size_t idx = 0; idx < numbeOfSizes; idx++ )
129 {
130 imageInfo.width = sizes[ idx ][ 0 ];
131 imageInfo.height = sizes[ idx ][ 1 ];
132 imageInfo.depth = sizes[ idx ][ 2 ];
133
134 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
135
136 if (gEnablePitch)
137 {
138 rowPadding = rowPadding_default;
139 do {
140 rowPadding++;
141 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
142 } while ((imageInfo.rowPitch % pixelSize) != 0);
143 }
144
145 imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + slicePadding);
146 log_info( "Testing %d x %d x %d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ] );
147 if ( gDebugTrace )
148 log_info( " at max size %d,%d,%d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ] );
149 if ( test_fill_image_3D( context, queue, &imageInfo, outputType, seed ) )
150 return -1;
151 }
152 }
153 else
154 {
155 for ( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
156 {
157 cl_ulong size;
158 // Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
159 // image, the result array, plus offset arrays, will fit in the global ram space
160 do
161 {
162 imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed );
163 imageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed );
164 imageInfo.depth = (size_t)random_log_in_range( 16, (int)maxDepth / 32, seed );
165
166 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
167
168 if (gEnablePitch)
169 {
170 rowPadding = rowPadding_default;
171 do {
172 rowPadding++;
173 imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
174 } while ((imageInfo.rowPitch % pixelSize) != 0);
175 }
176
177 imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + slicePadding);
178
179 size = (cl_ulong)imageInfo.slicePitch * (cl_ulong)imageInfo.depth * 4 * 4;
180 } while ( size > maxAllocSize || ( size * 3 ) > memSize );
181
182 if ( gDebugTrace )
183 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 );
184 int ret = test_fill_image_3D( context, queue, &imageInfo, outputType, seed );
185 if ( ret )
186 return -1;
187 }
188 }
189
190 return 0;
191 }
192