• 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 _TOOLS_H
17 #define _TOOLS_H
18 
19 #include "procs.h"
20 #include <vector>
21 #include <map>
22 #include <string>
23 
24 typedef std::vector<unsigned int> PrimeNumbersCollection;
25 
26 
27 
28 // Class responsible for distributing prime numbers
29 class PrimeNumbers {
30 
31 public:
32   struct Result1d{
33         size_t Val1;
34   };
35 
36   struct Result2d{
37         size_t Val1;
38         size_t Val2;
39   };
40 
41   struct Result3d{
42         size_t Val1;
43         size_t Val2;
44         size_t Val3;
45   };
46 
47   static void generatePrimeNumbers (unsigned int maxValue);
48   static int getPrimeNumberInRange (size_t lowerValue, size_t higherValue);
49   static int getNextLowerPrimeNumber (size_t upperValue);
50   static Result1d fitMaxPrime1d(size_t Val1, size_t productMax);
51   // Return val1 and Val2 which are largest prime numbers who's product is <= productMax
52   static Result2d fitMaxPrime2d(size_t Val1, size_t Val2, size_t productMax);
53   // Return val1, val2 and val3, which are largest prime numbers who's product is <= productMax
54   static Result3d fitMaxPrime3d(size_t Val1, size_t Val2,  size_t Val3, size_t productMax);
55 private:
56   static PrimeNumbersCollection primeNumbers;
57   PrimeNumbers();
58 };
59 
60 // Stores information about errors
61 namespace Error {
62 #define MAX_NUMBER_OF_PRINTED_ERRORS 10
63   enum Type{
64     ERR_GLOBAL_SIZE=0,
65     ERR_GLOBAL_WORK_OFFSET,
66     ERR_LOCAL_SIZE,
67     ERR_GLOBAL_ID,
68     ERR_LOCAL_ID,
69     ERR_ENQUEUED_LOCAL_SIZE,
70     ERR_NUM_GROUPS,
71     ERR_GROUP_ID,
72     ERR_WORK_DIM,
73     ERR_GLOBAL_BARRIER,
74     ERR_LOCAL_BARRIER,
75     ERR_GLOBAL_ATOMIC,
76     ERR_LOCAL_ATOMIC,
77 
78     ERR_STRICT_MODE,
79     ERR_BUILD_STATUS,
80 
81     ERR_UNKNOWN,
82     ERR_DIFFERENT,
83     _LAST_ELEM
84   };
85 
86   typedef std::map<Type, std::string> ErrorMap;
87   typedef std::map<Type, unsigned int> ErrorStats;
88 
89   class ErrorClass {
90   public:
91     ErrorClass();
92     void show(Type whatErr, std::string where="", std::string additionalInfo="");
93     void show(Type whatErr, std::string where, cl_ulong valueIs, cl_ulong valueExpected);
94     void show(std::string description);
95     bool checkError();
96     void showStats();
97     void synchronizeStatsMap();
errorArrayCounter()98     cl_uint * errorArrayCounter() {return _errorArrayCounter;};
errorArrayCounterSize()99     size_t errorArrayCounterSize() {return sizeof(_errorArrayCounter);};
100   private:
101     cl_uint _errorArrayCounter[Error::_LAST_ELEM]; // this buffer is passed to kernel
102     int _overallNumberOfErrors;
103     ErrorStats _stats;
104     void printError(std::string errString);
105 
106   };
107 
108 }
109 #endif // _TOOLS_H
110