• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (c) 2021 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 COMMON_H
17 #define COMMON_H
18 
19 #include "harness/typeWrappers.h"
20 #include "utility.h"
21 
22 #include <array>
23 #include <string>
24 #include <vector>
25 
26 // Array of thread-specific kernels for each vector size.
27 using KernelMatrix = std::array<std::vector<cl_kernel>, VECTOR_SIZE_COUNT>;
28 
29 // Array of programs for each vector size.
30 using Programs = std::array<clProgramWrapper, VECTOR_SIZE_COUNT>;
31 
32 // Array of buffers for each vector size.
33 using Buffers = std::array<clMemWrapper, VECTOR_SIZE_COUNT>;
34 
35 // Types supported for kernel code generation.
36 enum class ParameterType
37 {
38     Float,
39     Double,
40 };
41 
42 // Return kernel name suffixed with vector size.
43 std::string GetKernelName(int vector_size_index);
44 
45 // Generate kernel code for the given builtin function/operator.
46 std::string GetTernaryKernel(const std::string &kernel_name,
47                              const char *builtin, ParameterType retType,
48                              ParameterType type1, ParameterType type2,
49                              ParameterType type3, int vector_size_index);
50 
51 // Information to generate OpenCL kernels.
52 struct BuildKernelInfo
53 {
54     // Number of kernels to build, one for each thread to avoid data races.
55     cl_uint threadCount;
56 
57     KernelMatrix &kernels;
58 
59     Programs &programs;
60 
61     // Function, macro or symbol tested by the kernel.
62     const char *nameInCode;
63 
64     // Whether to build with -cl-fast-relaxed-math.
65     bool relaxedMode;
66 };
67 
68 #endif /* COMMON_H */
69