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 _TESTNONUNIFORMWORKGROUP_H 17 #define _TESTNONUNIFORMWORKGROUP_H 18 19 #include "procs.h" 20 #include <vector> 21 #include "tools.h" 22 #include <algorithm> 23 24 #define MAX_SIZE_OF_ALLOCATED_MEMORY (400*1024*1024) 25 26 #define NUMBER_OF_REGIONS 8 27 28 #define BUILD_CL_STD_2_0 "-cl-std=CL2.0" 29 30 #define MAX_DIMS 3 31 32 // This structure reflects data received from kernel. 33 typedef struct _DataContainerAttrib 34 { 35 cl_ulong get_global_size[MAX_DIMS]; 36 cl_ulong get_global_offset[MAX_DIMS]; 37 cl_ulong get_local_size[MAX_DIMS]; 38 cl_ulong get_enqueued_local_size[MAX_DIMS]; 39 cl_ulong get_global_id[MAX_DIMS]; 40 cl_ulong get_local_id[MAX_DIMS]; 41 cl_ulong get_group_id[MAX_DIMS]; 42 cl_ulong get_num_groups[MAX_DIMS]; 43 cl_ulong get_work_dim; 44 cl_ushort test_local_barrier_result_bool; 45 cl_ushort test_global_barrier_result_bool; 46 cl_ushort test_local_atomic_result_value; 47 }DataContainerAttrib; 48 49 // Describes range of testing. 50 namespace Range { 51 enum RangeEnum { 52 BASIC = (1 << 0), 53 BARRIERS = (1 << 1), 54 ATOMICS = (1 << 2), 55 56 ALL = Range::BASIC | Range::BARRIERS | Range::ATOMICS 57 }; 58 } 59 60 std::string showArray (const size_t *arr, cl_uint dims); 61 62 // Main class responsible for testing 63 class TestNonUniformWorkGroup { 64 public: 65 66 TestNonUniformWorkGroup (const cl_device_id &device, const cl_context &context, 67 const cl_command_queue &queue, const cl_uint dims, const size_t *globalSize, 68 const size_t *localSize, const size_t *buffersSize, const size_t *globalWorkOffset, 69 const size_t *reqdWorkGroupSize=NULL); 70 71 ~TestNonUniformWorkGroup (); 72 73 static size_t getMaxLocalWorkgroupSize (const cl_device_id &device); setMaxLocalWorkgroupSize(size_t workGroupSize)74 static void setMaxLocalWorkgroupSize (size_t workGroupSize) { 75 TestNonUniformWorkGroup::_maxLocalWorkgroupSize = workGroupSize; 76 } 77 static void enableStrictMode (bool state); 78 setTestRange(int range)79 void setTestRange (int range) {_testRange = range;} 80 int prepareDevice (); 81 int verifyResults (); 82 int runKernel (); 83 84 private: 85 size_t _globalSize[MAX_DIMS]; 86 size_t _localSize[MAX_DIMS]; 87 size_t _globalWorkOffset[MAX_DIMS]; 88 bool _globalWorkOffset_IsNull; 89 size_t _enqueuedLocalSize[MAX_DIMS]; 90 bool _localSize_IsNull; 91 size_t _reqdWorkGroupSize[MAX_DIMS]; 92 static size_t _maxLocalWorkgroupSize; 93 size_t _maxWorkItemSizes[MAX_DIMS]; 94 size_t _numOfGlobalWorkItems; // in global work group 95 const cl_device_id _device; 96 const cl_context _context; 97 const cl_command_queue _queue; 98 const cl_uint _dims; 99 100 int _testRange; 101 102 std::vector<DataContainerAttrib> _resultsRegionArray; 103 std::vector<DataContainerAttrib> _referenceRegionArray; 104 cl_uint _globalAtomicTestValue; 105 106 clProgramWrapper _program; 107 clKernelWrapper _testKernel; 108 109 Error::ErrorClass _err; 110 111 TestNonUniformWorkGroup (); 112 113 static bool _strictMode; 114 void setLocalWorkgroupSize (const size_t *globalSize, const size_t *localSize); 115 void setGlobalWorkgroupSize (const size_t *globalSize); 116 void verifyData (DataContainerAttrib * reference, DataContainerAttrib * results, short regionNumber); 117 void calculateExpectedValues (); 118 void showTestInfo (); 119 size_t adjustLocalArraySize(size_t localArraySize); 120 size_t adjustGlobalBufferSize(size_t globalBufferSize); 121 }; 122 123 // Class responsible for running subtest scenarios in test function 124 class SubTestExecutor { 125 public: SubTestExecutor(const cl_device_id & device,const cl_context & context,const cl_command_queue & queue)126 SubTestExecutor(const cl_device_id &device, const cl_context &context, const cl_command_queue &queue) 127 : _device (device), _context (context), _queue (queue), _failCounter (0), _overallCounter (0) {} 128 129 void runTestNonUniformWorkGroup (const cl_uint dims, const size_t *globalSize, 130 const size_t *localSize, int range); 131 132 void runTestNonUniformWorkGroup (const cl_uint dims, const size_t *globalSize, 133 const size_t *localSize, const size_t *globalWorkOffset, 134 const size_t *reqdWorkGroupSize, int range); 135 136 int calculateWorkGroupSize(size_t &maxWgSize, int testRange); 137 int status(); 138 139 private: 140 SubTestExecutor(); 141 const cl_device_id _device; 142 const cl_context _context; 143 const cl_command_queue _queue; 144 unsigned int _failCounter; 145 unsigned int _overallCounter; 146 }; 147 148 #endif // _TESTNONUNIFORMWORKGROUP_H 149 150