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 <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19
20 #if !defined (_WIN32)
21 #include <sys/resource.h>
22 #if defined(__APPLE__)
23 #include <sys/sysctl.h>
24 #endif
25 #include <libgen.h>
26 #include <sys/param.h>
27 #endif
28
29 #include "harness/testHarness.h"
30 #include "harness/mingw_compat.h"
31 #include "harness/parseParameters.h"
32 #if defined (__MINGW32__)
33 #include <sys/param.h>
34 #endif
35
36 #include "cl_utils.h"
37 #include "tests.h"
38
39 const char ** argList = NULL;
40 size_t argCount = 0;
41 char appName[64] = "ctest";
42 const char *addressSpaceNames[AS_NumAddressSpaces] = {"global", "private", "local", "constant"};
43
44 #pragma mark -
45 #pragma mark Declarations
46
47
48 static int ParseArgs( int argc, const char **argv );
49 static void PrintUsage( void );
50
51
52 int g_arrVecSizes[kVectorSizeCount+kStrangeVectorSizeCount];
53 int g_arrVecAligns[kLargestVectorSize+1];
54 static int arrStrangeVecSizes[kStrangeVectorSizeCount] = {3};
55
56 test_definition test_list[] = {
57 ADD_TEST( vload_half ),
58 ADD_TEST( vloada_half ),
59 ADD_TEST( vstore_half ),
60 ADD_TEST( vstorea_half ),
61 ADD_TEST( vstore_half_rte ),
62 ADD_TEST( vstorea_half_rte ),
63 ADD_TEST( vstore_half_rtz ),
64 ADD_TEST( vstorea_half_rtz ),
65 ADD_TEST( vstore_half_rtp ),
66 ADD_TEST( vstorea_half_rtp ),
67 ADD_TEST( vstore_half_rtn ),
68 ADD_TEST( vstorea_half_rtn ),
69 ADD_TEST( roundTrip ),
70 };
71
72 const int test_num = ARRAY_SIZE( test_list );
73
main(int argc,const char ** argv)74 int main (int argc, const char **argv )
75 {
76 int error;
77 int i;
78 int alignbound;
79
80 for(i = 0; i < kVectorSizeCount; ++i) {
81 g_arrVecSizes[i] = (1<<i);
82 }
83 for(i = 0; i < kStrangeVectorSizeCount; ++i) {
84 g_arrVecSizes[i+kVectorSizeCount] =
85 arrStrangeVecSizes[i];
86 }
87
88 for(i = 0, alignbound=1; i <= kLargestVectorSize; ++i) {
89 while(alignbound < i) {
90 alignbound = alignbound<<1;
91 }
92 g_arrVecAligns[i] = alignbound;
93 }
94
95 argc = parseCustomParam(argc, argv);
96 if (argc == -1)
97 {
98 return -1;
99 }
100
101 if( (error = ParseArgs( argc, argv )) )
102 goto exit;
103
104 if (gIsEmbedded) {
105 vlog( "\tProfile: Embedded\n" );
106 }else
107 {
108 vlog( "\tProfile: Full\n" );
109 }
110
111 fflush( stdout );
112 error = runTestHarnessWithCheck( argCount, argList, test_num, test_list, true, 0, InitCL );
113
114 exit:
115 if(gQueue)
116 {
117 int flush_error = clFinish(gQueue);
118 if(flush_error)
119 {
120 vlog_error("clFinish failed: %d\n", flush_error);
121 }
122 }
123
124 ReleaseCL();
125 return error;
126 }
127
128 #pragma mark -
129 #pragma mark setup
130
ParseArgs(int argc,const char ** argv)131 static int ParseArgs( int argc, const char **argv )
132 {
133 int i;
134 argList = (const char **)calloc(argc, sizeof(char *));
135 if( NULL == argList )
136 {
137 vlog_error( "Failed to allocate memory for argList.\n" );
138 return 1;
139 }
140
141 argList[0] = argv[0];
142 argCount = 1;
143
144 #if (defined( __APPLE__ ) || defined(__linux__) || defined(__MINGW32__))
145 { // Extract the app name
146 char baseName[ MAXPATHLEN ];
147 strncpy( baseName, argv[0], MAXPATHLEN );
148 char *base = basename( baseName );
149 if( NULL != base )
150 {
151 strncpy( appName, base, sizeof( appName ) );
152 appName[ sizeof( appName ) -1 ] = '\0';
153 }
154 }
155 #elif defined (_WIN32)
156 {
157 char fname[_MAX_FNAME + _MAX_EXT + 1];
158 char ext[_MAX_EXT];
159
160 errno_t err = _splitpath_s( argv[0], NULL, 0, NULL, 0,
161 fname, _MAX_FNAME, ext, _MAX_EXT );
162 if (err == 0) { // no error
163 strcat (fname, ext); //just cat them, size of frame can keep both
164 strncpy (appName, fname, sizeof(appName));
165 appName[ sizeof( appName ) -1 ] = '\0';
166 }
167 }
168 #endif
169
170 vlog( "\n%s", appName );
171 for( i = 1; i < argc; i++ )
172 {
173 const char *arg = argv[i];
174 if( NULL == arg )
175 break;
176
177 vlog( "\t%s", arg );
178 if( arg[0] == '-' )
179 {
180 arg++;
181 while( *arg != '\0' )
182 {
183 switch( *arg )
184 {
185 case 'd':
186 gTestDouble ^= 1;
187 break;
188
189 case 'h':
190 PrintUsage();
191 return -1;
192
193 case 't':
194 gReportTimes ^= 1;
195 break;
196
197 case 'r': gHostReset = true; break;
198
199 case 'w': // Wimpy mode
200 gWimpyMode = true;
201 break;
202 case '[':
203 parseWimpyReductionFactor( arg, gWimpyReductionFactor);
204 break;
205 default:
206 vlog_error( " <-- unknown flag: %c (0x%2.2x)\n)", *arg, *arg );
207 PrintUsage();
208 return -1;
209 }
210 arg++;
211 }
212 }
213 else
214 {
215 argList[ argCount ] = arg;
216 argCount++;
217 }
218 }
219
220 if (getenv("CL_WIMPY_MODE")) {
221 vlog( "\n" );
222 vlog( "*** Detected CL_WIMPY_MODE env ***\n" );
223 gWimpyMode = 1;
224 }
225
226 PrintArch();
227 if( gWimpyMode )
228 {
229 vlog( "\n" );
230 vlog( "*** WARNING: Testing in Wimpy mode! ***\n" );
231 vlog( "*** Wimpy mode is not sufficient to verify correctness. ***\n" );
232 vlog( "*** It gives warm fuzzy feelings and then nevers calls. ***\n\n" );
233 vlog( "*** Wimpy Reduction Factor: %-27u ***\n\n", gWimpyReductionFactor);
234 }
235 return 0;
236 }
237
PrintUsage(void)238 static void PrintUsage( void )
239 {
240 vlog("%s [-dthw]: <optional: test names>\n", appName);
241 vlog("\t\t-d\tToggle double precision testing (default: on if double "
242 "supported)\n");
243 vlog("\t\t-t\tToggle reporting performance data.\n");
244 vlog("\t\t-r\tReset buffers on host instead of on device.\n");
245 vlog("\t\t-w\tRun in wimpy mode\n");
246 vlog("\t\t-[2^n]\tSet wimpy reduction factor, recommended range of n is "
247 "1-12, default factor(%u)\n",
248 gWimpyReductionFactor);
249 vlog("\t\t-h\tHelp\n");
250 for (int i = 0; i < test_num; i++)
251 {
252 vlog("\t\t%s\n", test_list[i].name );
253 }
254 }
255