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