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