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
17 #include <stdio.h>
18 #include <string.h>
19 #include "../testBase.h"
20 #include "../harness/compat.h"
21 #include "../harness/fpcontrol.h"
22 #include "../harness/parseParameters.h"
23
24 #if defined(__PPC__)
25 // Global varaiable used to hold the FPU control register state. The FPSCR register can not
26 // be used because not all Power implementations retain or observed the NI (non-IEEE
27 // mode) bit.
28 __thread fpu_control_t fpu_control = 0;
29 #endif
30
31 bool gTestReadWrite;
32 bool gDebugTrace;
33 bool gTestMaxImages;
34 bool gTestSmallImages;
35 int gTypesToTest;
36 cl_channel_type gChannelTypeToUse = (cl_channel_type)-1;
37 cl_channel_order gChannelOrderToUse = (cl_channel_order)-1;
38 bool gEnablePitch = false;
39
40 static void printUsage( const char *execName );
41
42 extern int test_image_set( cl_device_id device, cl_context context, cl_command_queue queue, cl_mem_object_type imageType );
43
test_1D(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)44 int test_1D(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
45 {
46 return test_image_set(device, context, queue, CL_MEM_OBJECT_IMAGE1D);
47 }
test_1Dbuffer(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)48 int test_1Dbuffer(cl_device_id device, cl_context context,
49 cl_command_queue queue, int num_elements)
50 {
51 return test_image_set(device, context, queue, CL_MEM_OBJECT_IMAGE1D_BUFFER);
52 }
test_2D(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)53 int test_2D(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
54 {
55 return test_image_set( device, context, queue, CL_MEM_OBJECT_IMAGE2D );
56 }
test_3D(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)57 int test_3D(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
58 {
59 return test_image_set( device, context, queue, CL_MEM_OBJECT_IMAGE3D );
60 }
test_1Darray(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)61 int test_1Darray(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
62 {
63 return test_image_set( device, context, queue, CL_MEM_OBJECT_IMAGE1D_ARRAY );
64 }
test_2Darray(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)65 int test_2Darray(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
66 {
67 return test_image_set( device, context, queue, CL_MEM_OBJECT_IMAGE2D_ARRAY );
68 }
69
70 test_definition test_list[] = {
71 ADD_TEST(1D), ADD_TEST(1Dbuffer), ADD_TEST(2D),
72 ADD_TEST(3D), ADD_TEST(1Darray), ADD_TEST(2Darray),
73 };
74
75 const int test_num = ARRAY_SIZE( test_list );
76
main(int argc,const char * argv[])77 int main(int argc, const char *argv[])
78 {
79 cl_channel_type chanType;
80 cl_channel_order chanOrder;
81
82 argc = parseCustomParam(argc, argv);
83 if (argc == -1)
84 {
85 return -1;
86 }
87
88 const char ** argList = (const char **)calloc( argc, sizeof( char*) );
89
90 if( NULL == argList )
91 {
92 log_error( "Failed to allocate memory for argList array.\n" );
93 return 1;
94 }
95
96 argList[0] = argv[0];
97 size_t argCount = 1;
98
99 // Parse arguments
100 for ( int i = 1; i < argc; i++ )
101 {
102 if ( strcmp( argv[i], "debug_trace" ) == 0 )
103 gDebugTrace = true;
104 else if ( strcmp( argv[i], "read_write" ) == 0 )
105 gTestReadWrite = true;
106 else if ( strcmp( argv[i], "small_images" ) == 0 )
107 gTestSmallImages = true;
108 else if ( strcmp( argv[i], "max_images" ) == 0 )
109 gTestMaxImages = true;
110 else if ( strcmp( argv[i], "use_pitches" ) == 0 )
111 gEnablePitch = true;
112
113 else if ( strcmp( argv[i], "int" ) == 0 )
114 gTypesToTest |= kTestInt;
115 else if ( strcmp( argv[i], "uint" ) == 0 )
116 gTypesToTest |= kTestUInt;
117 else if ( strcmp( argv[i], "float" ) == 0 )
118 gTypesToTest |= kTestFloat;
119
120 else if ( strcmp( argv[i], "--help" ) == 0 || strcmp( argv[i], "-h" ) == 0 )
121 {
122 printUsage( argv[ 0 ] );
123 return -1;
124 }
125
126 else if ( ( chanType = get_channel_type_from_name( argv[i] ) ) != (cl_channel_type)-1 )
127 gChannelTypeToUse = chanType;
128
129 else if ( ( chanOrder = get_channel_order_from_name( argv[i] ) ) != (cl_channel_order)-1 )
130 gChannelOrderToUse = chanOrder;
131 else
132 {
133 argList[argCount] = argv[i];
134 argCount++;
135 }
136 }
137
138 if ( gTypesToTest == 0 )
139 gTypesToTest = kTestAllTypes;
140
141 if ( gTestSmallImages )
142 log_info( "Note: Using small test images\n" );
143
144 // On most platforms which support denorm, default is FTZ off. However,
145 // on some hardware where the reference is computed, default might be flush denorms to zero e.g. arm.
146 // This creates issues in result verification. Since spec allows the implementation to either flush or
147 // not flush denorms to zero, an implementation may choose not to flush i.e. return denorm result whereas
148 // reference result may be zero (flushed denorm). Hence we need to disable denorm flushing on host side
149 // where reference is being computed to make sure we get non-flushed reference result. If implementation
150 // returns flushed result, we correctly take care of that in verification code.
151
152 FPU_mode_type oldMode;
153 DisableFTZ(&oldMode);
154
155 int ret = runTestHarnessWithCheck(argCount, argList, test_num, test_list,
156 false, 0, verifyImageSupport);
157
158 // Restore FP state before leaving
159 RestoreFPState(&oldMode);
160
161 free(argList);
162 return ret;
163 }
164
printUsage(const char * execName)165 static void printUsage( const char *execName )
166 {
167 const char *p = strrchr( execName, '/' );
168 if ( p != NULL )
169 execName = p + 1;
170
171 log_info( "Usage: %s [options] [test_names]\n", execName );
172 log_info( "Options:\n" );
173 log_info( "\n" );
174 log_info( "\tThe following flags specify the types to test. They can be combined; if none are specified, all are tested:\n" );
175 log_info( "\t\tint - Test integer I/O (read_imagei)\n" );
176 log_info( "\t\tuint - Test unsigned integer I/O (read_imageui)\n" );
177 log_info( "\t\tfloat - Test float I/O (read_imagef)\n" );
178 log_info( "\n" );
179 log_info( "You may also use appropriate CL_ channel type and ordering constants.\n" );
180 log_info( "\n" );
181 log_info( "\tThe following modify the types of images tested:\n" );
182 log_info( "\t\tread_write - Runs the tests with read_write images which allow a kernel do both read and write to the same image \n" );
183 log_info( "\t\tsmall_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes\n" );
184 log_info( "\t\tmax_images - Runs every format through a set of size combinations with the max values, max values - 1, and max values / 128\n" );
185 log_info( "\n" );
186 log_info( "\tdebug_trace - Enables additional debug info logging\n" );
187 log_info( "\tuse_pitches - Enables row and slice pitches\n" );
188 log_info( "\n" );
189 log_info( "Test names:\n" );
190 for( int i = 0; i < test_num; i++ )
191 {
192 log_info( "\t%s\n", test_list[i].name );
193 }
194 }
195