1 /* ************************************************************************
2  * Copyright 2013 Advanced Micro Devices, 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 
17 #ifndef SUBDIM_H__
18 #define SUBDIM_H__
19 
20 //#define TEST_LOG
21 
22 typedef struct SubDimItem
23 {
24     int curId;
25     int maxId;
26     int* data;
27 }SubDimItem;
28 
29 int get(SubDimItem * sdi);
30 
31 ///////////////////////////////////////////////////////////////////////////////
32 enum
33 {
34     V_NONE = -1,
35 };
36 typedef enum SubDimVariable
37 {
38     V_L0_X,
39     V_L0_Y,
40     V_L0_BW,
41     V_L1_X,
42     V_L1_Y,
43     V_L1_BW,
44     V_COUNT,
45 }SubDimVariable;
46 
47 typedef struct IgnoreItem
48 {
49     int var[V_COUNT];
50     struct IgnoreItem* next;
51 }IgnoreItem;
52 
53 typedef struct GroupStatInfo
54 {
55     int var[V_COUNT];
56     int pg;
57 
58     double minTime;
59     double allTime;
60     int count;
61     int allCount;
62 }GroupStatInfo;
63 
64 typedef struct Variant
65 {
66     //
67     int var[V_COUNT];
68     int pg;
69     // Estimated time performance
70     double minTime;      // lower bound
71     double probableTime; //
72     double maxTime;      // upper bound
73 
74     double weight;
75     double time;
76 }Variant;
77 
78 ///////////////////////////////////////////////////////////////////////////////
79 
80 typedef struct SubDimInfo
81 {
82     // dynamic array for statistics
83     GroupStatInfo * info;
84     int infoCount;
85     int infoMaxCount;
86 
87     Variant* allVariant;
88 
89     SubDimItem var[V_COUNT];
90 
91     PGranularity    pgran;
92     SubproblemDim   sdim[MAX_SUBDIMS];
93 
94     MemoryPattern * pattern;
95     bool valid;
96 
97     DataType            dtype;
98     KernelExtraFlags    flag;
99 
100     unsigned int func;
101     unsigned int patt;
102 
103     bool is2D;
104 
105     int  blasLevel;
106     int  nrLevel;
107     bool isSquareBlock;
108     unsigned long ldsSize;
109     size_t workGroupSizes;
110 
111     //
112     IgnoreItem * first;
113 
114     int count;
115     double sumTime;
116 
117     Variant* curVar;
118     int curVarID;
119     int varCount;
120     float minTime;
121 
122     void (*init)(struct SubDimInfo* sdi);
123     bool (*isValid)(struct SubDimInfo* sdi);
124 
125 //#ifdef TEST_LOG
126     bool returnAll;
127 //#endif
128 
129 }SubDimInfo;
130 
131 void setVariable(struct SubDimInfo* sdi, SubDimVariable var, int dcount, int* dim);
132 void setInvalid (struct SubDimInfo* sdi, int l0x, int l0y, int l0w,
133         int l1x, int l1y, int l1w);
134 
135 bool nextSubdim(SubDimInfo* sd, int maxParam, double time);
136 void resetSubdim(SubDimInfo* sd);
137 void initSubDimInfo(SubDimInfo* sd, MemoryPattern* mempatt,
138                DeviceInfo* devinfo, unsigned int func, unsigned int patt,
139                DataType dtype, KernelExtraFlags flag);
140 
141 void destroySubdim(SubDimInfo* sd);
142 void convKExtraFlagToArg(KernelExtraFlags flags, CLBlasKargs* args);
143 #endif /* SUBDIM_H__ */
144