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