aboutsummaryrefslogtreecommitdiff
path: root/test_conformance/half/cl_utils.h
blob: da6073cf1dc51e6f30a631b75445cfc77c694593 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// Copyright (c) 2017 The Khronos Group Inc.
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef CL_UTILS_H
#define  CL_UTILS_H

#include "harness/testHarness.h"
#include "harness/compat.h"
#include "harness/conversions.h"

#include <stdio.h>

#if !defined(_WIN32)
#include <sys/param.h>
#endif


#ifdef __MINGW32__
#define __mingw_printf printf
#endif
#include "harness/errorHelpers.h"

#include "harness/ThreadPool.h"



#include "test_config.h"

#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/opencl.h>
#endif

extern void *gIn_half;
extern void *gOut_half;
extern void *gOut_half_reference;
extern void *gOut_half_reference_double;
extern void *gIn_single;
extern void *gOut_single;
extern void *gOut_single_reference;
extern void *gIn_double;
// extern void *gOut_double;
// extern void *gOut_double_reference;
extern cl_mem gInBuffer_half;
extern cl_mem gOutBuffer_half;
extern cl_mem gInBuffer_single;
extern cl_mem gOutBuffer_single;
extern cl_mem gInBuffer_double;
// extern cl_mem gOutBuffer_double;

extern cl_context gContext;
extern cl_command_queue gQueue;
extern uint32_t gDeviceFrequency;
extern uint32_t gComputeDevices;
extern size_t gMaxThreadGroupSize;
extern size_t gWorkGroupSize;
extern int gTestDouble;
extern int gReportTimes;
extern bool gHostReset;

// gWimpyMode indicates if we run the test in wimpy mode where we limit the
// size of 32 bit ranges to a much smaller set.  This is meant to be used
// as a smoke test
extern bool gWimpyMode;
extern int gWimpyReductionFactor;

uint64_t ReadTime( void );
double SubtractTime( uint64_t endTime, uint64_t startTime );

cl_uint numVecs(cl_uint count, int vectorSizeIdx, bool aligned);
cl_uint runsOverBy(cl_uint count, int vectorSizeIdx, bool aligned);

void printSource(const char * src[], int len);

extern const char *vector_size_name_extensions[kVectorSizeCount+kStrangeVectorSizeCount];
extern const char *vector_size_strings[kVectorSizeCount+kStrangeVectorSizeCount];
extern const char *align_divisors[kVectorSizeCount+kStrangeVectorSizeCount];
extern const char *align_types[kVectorSizeCount+kStrangeVectorSizeCount];

test_status InitCL( cl_device_id device );
void ReleaseCL( void );
int RunKernel( cl_device_id device, cl_kernel kernel, void *inBuf, void *outBuf, uint32_t blockCount , int extraArg);
cl_program MakeProgram( cl_device_id device, const char *source[], int count );

static inline float as_float(cl_uint u) { union { cl_uint u; float f; }v; v.u = u; return v.f; }
static inline double as_double(cl_ulong u) { union { cl_ulong u; double d; }v; v.u = u; return v.d; }

// used to convert a bucket of bits into a search pattern through double
static inline cl_ulong DoubleFromUInt( cl_uint bits );
static inline cl_ulong DoubleFromUInt( cl_uint bits )
{
    // split 0x89abcdef to 0x89abcd00000000ef
    cl_ulong u = ((cl_ulong)(bits & ~0xffU) << 32) | ((cl_ulong)(bits & 0xffU));

    // sign extend the leading bit of def segment as sign bit so that the middle region consists of either all 1s or 0s
    u -= (cl_ulong)((bits & 0x80U) << 1);

    return u;
}

#endif /* CL_UTILS_H */