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