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 #ifndef CL_UTILS_H
17 #define CL_UTILS_H
18
19 #include "harness/testHarness.h"
20 #include "harness/compat.h"
21 #include "harness/conversions.h"
22
23 #include <stdio.h>
24
25 #if !defined(_WIN32)
26 #include <sys/param.h>
27 #endif
28
29
30 #ifdef __MINGW32__
31 #define __mingw_printf printf
32 #endif
33 #include "harness/errorHelpers.h"
34
35 #include "harness/ThreadPool.h"
36
37
38
39 #include "test_config.h"
40
41 #ifdef __APPLE__
42 #include <OpenCL/opencl.h>
43 #else
44 #include <CL/opencl.h>
45 #endif
46
47 extern void *gIn_half;
48 extern void *gOut_half;
49 extern void *gOut_half_reference;
50 extern void *gOut_half_reference_double;
51 extern void *gIn_single;
52 extern void *gOut_single;
53 extern void *gOut_single_reference;
54 extern void *gIn_double;
55 // extern void *gOut_double;
56 // extern void *gOut_double_reference;
57 extern cl_mem gInBuffer_half;
58 extern cl_mem gOutBuffer_half;
59 extern cl_mem gInBuffer_single;
60 extern cl_mem gOutBuffer_single;
61 extern cl_mem gInBuffer_double;
62 // extern cl_mem gOutBuffer_double;
63
64 extern cl_context gContext;
65 extern cl_command_queue gQueue;
66 extern uint32_t gDeviceFrequency;
67 extern uint32_t gComputeDevices;
68 extern size_t gMaxThreadGroupSize;
69 extern size_t gWorkGroupSize;
70 extern int gTestDouble;
71 extern int gReportTimes;
72 extern bool gHostReset;
73
74 // gWimpyMode indicates if we run the test in wimpy mode where we limit the
75 // size of 32 bit ranges to a much smaller set. This is meant to be used
76 // as a smoke test
77 extern bool gWimpyMode;
78 extern int gWimpyReductionFactor;
79
80 uint64_t ReadTime( void );
81 double SubtractTime( uint64_t endTime, uint64_t startTime );
82
83 cl_uint numVecs(cl_uint count, int vectorSizeIdx, bool aligned);
84 cl_uint runsOverBy(cl_uint count, int vectorSizeIdx, bool aligned);
85
86 void printSource(const char * src[], int len);
87
88 extern const char *vector_size_name_extensions[kVectorSizeCount+kStrangeVectorSizeCount];
89 extern const char *vector_size_strings[kVectorSizeCount+kStrangeVectorSizeCount];
90 extern const char *align_divisors[kVectorSizeCount+kStrangeVectorSizeCount];
91 extern const char *align_types[kVectorSizeCount+kStrangeVectorSizeCount];
92
93 test_status InitCL( cl_device_id device );
94 void ReleaseCL( void );
95 int RunKernel( cl_device_id device, cl_kernel kernel, void *inBuf, void *outBuf, uint32_t blockCount , int extraArg);
96 cl_program MakeProgram( cl_device_id device, const char *source[], int count );
97
as_float(cl_uint u)98 static inline float as_float(cl_uint u) { union { cl_uint u; float f; }v; v.u = u; return v.f; }
as_double(cl_ulong u)99 static inline double as_double(cl_ulong u) { union { cl_ulong u; double d; }v; v.u = u; return v.d; }
100
101 // used to convert a bucket of bits into a search pattern through double
102 static inline cl_ulong DoubleFromUInt( cl_uint bits );
DoubleFromUInt(cl_uint bits)103 static inline cl_ulong DoubleFromUInt( cl_uint bits )
104 {
105 // split 0x89abcdef to 0x89abcd00000000ef
106 cl_ulong u = ((cl_ulong)(bits & ~0xffU) << 32) | ((cl_ulong)(bits & 0xffU));
107
108 // sign extend the leading bit of def segment as sign bit so that the middle region consists of either all 1s or 0s
109 u -= (cl_ulong)((bits & 0x80U) << 1);
110
111 return u;
112 }
113
114 #endif /* CL_UTILS_H */
115
116
117
118