• 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 #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 
73 // gWimpyMode indicates if we run the test in wimpy mode where we limit the
74 // size of 32 bit ranges to a much smaller set.  This is meant to be used
75 // as a smoke test
76 extern bool            gWimpyMode;
77 extern int             gWimpyReductionFactor;
78 
79 uint64_t ReadTime( void );
80 double SubtractTime( uint64_t endTime, uint64_t startTime );
81 
82 cl_uint numVecs(cl_uint count, int vectorSizeIdx, bool aligned);
83 cl_uint runsOverBy(cl_uint count, int vectorSizeIdx, bool aligned);
84 
85 void printSource(const char * src[], int len);
86 
87 extern const char *vector_size_name_extensions[kVectorSizeCount+kStrangeVectorSizeCount];
88 extern const char *vector_size_strings[kVectorSizeCount+kStrangeVectorSizeCount];
89 extern const char *align_divisors[kVectorSizeCount+kStrangeVectorSizeCount];
90 extern const char *align_types[kVectorSizeCount+kStrangeVectorSizeCount];
91 
92 test_status InitCL( cl_device_id device );
93 void ReleaseCL( void );
94 int RunKernel( cl_device_id device, cl_kernel kernel, void *inBuf, void *outBuf, uint32_t blockCount , int extraArg);
95 cl_program MakeProgram( cl_device_id device, const char *source[], int count );
96 
as_float(cl_uint u)97 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)98 static inline double as_double(cl_ulong u) { union { cl_ulong u; double d; }v; v.u = u; return v.d; }
99 
100 // used to convert a bucket of bits into a search pattern through double
101 static inline cl_ulong DoubleFromUInt( cl_uint bits );
DoubleFromUInt(cl_uint bits)102 static inline cl_ulong DoubleFromUInt( cl_uint bits )
103 {
104     // split 0x89abcdef to 0x89abcd00000000ef
105     cl_ulong u = ((cl_ulong)(bits & ~0xffU) << 32) | ((cl_ulong)(bits & 0xffU));
106 
107     // sign extend the leading bit of def segment as sign bit so that the middle region consists of either all 1s or 0s
108     u -= (cl_ulong)((bits & 0x80U) << 1);
109 
110     return u;
111 }
112 
113 #endif /* CL_UTILS_H */
114 
115 
116 
117