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