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