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