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_image_set( device, context, queue, CL_MEM_OBJECT_IMAGE1D_BUFFER );
48 }
test_2D(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)49 int test_2D(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
50 {
51 return test_image_set( device, context, queue, CL_MEM_OBJECT_IMAGE2D );
52 }
test_3D(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)53 int test_3D(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_IMAGE3D );
56 }
test_1Darray(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)57 int test_1Darray(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_IMAGE1D_ARRAY );
60 }
test_2Darray(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)61 int test_2Darray(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_IMAGE2D_ARRAY );
64 }
65
66 test_definition test_list[] = {
67 ADD_TEST( 1D ),
68 ADD_TEST( 2D ),
69 ADD_TEST( 3D ),
70 ADD_TEST( 1Darray ),
71 ADD_TEST( 2Darray ),
72 };
73
74 const int test_num = ARRAY_SIZE( test_list );
75
main(int argc,const char * argv[])76 int main(int argc, const char *argv[])
77 {
78 cl_channel_type chanType;
79 cl_channel_order chanOrder;
80
81 argc = parseCustomParam(argc, argv);
82 if (argc == -1)
83 {
84 return -1;
85 }
86
87 const char ** argList = (const char **)calloc( argc, sizeof( char*) );
88
89 if( NULL == argList )
90 {
91 log_error( "Failed to allocate memory for argList array.\n" );
92 return 1;
93 }
94
95 argList[0] = argv[0];
96 size_t argCount = 1;
97
98 // Parse arguments
99 for ( int i = 1; i < argc; i++ )
100 {
101 if ( strcmp( argv[i], "debug_trace" ) == 0 )
102 gDebugTrace = true;
103 else if ( strcmp( argv[i], "read_write" ) == 0 )
104 gTestReadWrite = true;
105 else if ( strcmp( argv[i], "small_images" ) == 0 )
106 gTestSmallImages = true;
107 else if ( strcmp( argv[i], "max_images" ) == 0 )
108 gTestMaxImages = true;
109 else if ( strcmp( argv[i], "use_pitches" ) == 0 )
110 gEnablePitch = true;
111
112 else if ( strcmp( argv[i], "int" ) == 0 )
113 gTypesToTest |= kTestInt;
114 else if ( strcmp( argv[i], "uint" ) == 0 )
115 gTypesToTest |= kTestUInt;
116 else if ( strcmp( argv[i], "float" ) == 0 )
117 gTypesToTest |= kTestFloat;
118
119 else if ( strcmp( argv[i], "--help" ) == 0 || strcmp( argv[i], "-h" ) == 0 )
120 {
121 printUsage( argv[ 0 ] );
122 return -1;
123 }
124
125 else if ( ( chanType = get_channel_type_from_name( argv[i] ) ) != (cl_channel_type)-1 )
126 gChannelTypeToUse = chanType;
127
128 else if ( ( chanOrder = get_channel_order_from_name( argv[i] ) ) != (cl_channel_order)-1 )
129 gChannelOrderToUse = chanOrder;
130 else
131 {
132 argList[argCount] = argv[i];
133 argCount++;
134 }
135 }
136
137 if ( gTypesToTest == 0 )
138 gTypesToTest = kTestAllTypes;
139
140 if ( gTestSmallImages )
141 log_info( "Note: Using small test images\n" );
142
143 // On most platforms which support denorm, default is FTZ off. However,
144 // on some hardware where the reference is computed, default might be flush denorms to zero e.g. arm.
145 // This creates issues in result verification. Since spec allows the implementation to either flush or
146 // not flush denorms to zero, an implementation may choose not to flush i.e. return denorm result whereas
147 // reference result may be zero (flushed denorm). Hence we need to disable denorm flushing on host side
148 // where reference is being computed to make sure we get non-flushed reference result. If implementation
149 // returns flushed result, we correctly take care of that in verification code.
150
151 FPU_mode_type oldMode;
152 DisableFTZ(&oldMode);
153
154 int ret = runTestHarnessWithCheck(argCount, argList, test_num, test_list,
155 false, 0, verifyImageSupport);
156
157 // Restore FP state before leaving
158 RestoreFPState(&oldMode);
159
160 free(argList);
161 return ret;
162 }
163
printUsage(const char * execName)164 static void printUsage( const char *execName )
165 {
166 const char *p = strrchr( execName, '/' );
167 if ( p != NULL )
168 execName = p + 1;
169
170 log_info( "Usage: %s [options] [test_names]\n", execName );
171 log_info( "Options:\n" );
172 log_info( "\n" );
173 log_info( "\tThe following flags specify the types to test. They can be combined; if none are specified, all are tested:\n" );
174 log_info( "\t\tint - Test integer I/O (read_imagei)\n" );
175 log_info( "\t\tuint - Test unsigned integer I/O (read_imageui)\n" );
176 log_info( "\t\tfloat - Test float I/O (read_imagef)\n" );
177 log_info( "\n" );
178 log_info( "You may also use appropriate CL_ channel type and ordering constants.\n" );
179 log_info( "\n" );
180 log_info( "\tThe following modify the types of images tested:\n" );
181 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" );
182 log_info( "\t\tsmall_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes\n" );
183 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" );
184 log_info( "\n" );
185 log_info( "\tdebug_trace - Enables additional debug info logging\n" );
186 log_info( "\tuse_pitches - Enables row and slice pitches\n" );
187 log_info( "\n" );
188 log_info( "Test names:\n" );
189 for( int i = 0; i < test_num; i++ )
190 {
191 log_info( "\t%s\n", test_list[i].name );
192 }
193 }
194