clBLAS  2.11
 All Functions Typedefs Enumerations Enumerator Groups Pages
step.h
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 
18 #ifndef KTEST_PATTERN_H__
19 #define KTEST_PATTERN_H__
20 
21 #ifdef __APPLE__
22 #include <OpenCL/cl.h>
23 #else
24 #include <CL/cl.h>
25 #endif
26 #include <list>
27 #include <map>
28 #include <string>
29 
30 #include <clblas-internal.h>
31 #include <blas_funcs.h>
32 #include <granulation.h>
33 #include <kernel_extra.h>
34 #include <solution_seq.h>
35 #include <mempat.h>
36 #include <list.h>
37 #include "var.h"
38 
39 namespace clMath {
40 
41 // This structure reflects CLBlasKargs structure, declared in clblas-internal.h
42 typedef struct StepKargs {
43  // kernType
44  // dtype
45  // order
46  // side
47  // uplo
48  // transA
49  // transB
50  // diag
51  Variable *M;
52  Variable *N;
53  Variable *K;
54  Variable *alpha;
55  Variable *A;
56  Variable *lda;
57  Variable *B;
58  Variable *ldb;
59  Variable *beta;
60  Variable *C;
61  Variable *ldc;
62  // addrBits
63  Variable *offsetM;
64  Variable *offsetN;
65  Variable *offsetK;
66  Variable *scimage0;
67  Variable *scimage1;
68  Variable *offA;
69  Variable *offBX;
70  Variable *offCY;
71 } Kargs;
72 
73 typedef std::list<Variable*> VarList;
74 typedef std::list<ArrayVariableInterface*> ArrayVarList;
75 typedef std::map<unsigned int, const Variable*> KArgMap;
76 
90 class Step {
91 private:
92  CLBLASKernExtra kextra_;
93  cl_platform_id platform_;
94 
95  VarList vars_;
96  ArrayVarList arrays_;
97  VarList buffers_;
105  KArgMap kargMap_;
106 
107  std::string dumpMemoryPattern();
108  std::string dumpSubdim(const SubproblemDim *subdim);
109  std::string dumpPgran();
110  std::string dumpKextra();
111 
112  cl_device_id device() { return step_.device.id; };
113  void setKernelArg(unsigned int index, const Variable *var);
114 
115 protected:
120  SolutionStep step_;
125  MemoryPattern* pattern_;
133  std::string naiveCall_;
141  std::string compareCall_;
149  std::string postRandomCall_;
154  std::string kernelName_;
155 
156 
163  Variable* addVar(const std::string& name, const std::string& type,
164  const std::string& defaultValue = "");
171  Variable* addVar(const std::string& name, const std::string& type,
172  size_t value);
179  Variable* addVar(const std::string& name, const std::string& type,
180  int value);
187  Variable* addConst(const std::string& name, const std::string& type,
188  const std::string& defaultValue);
195  Variable* addConst(const std::string& name, const std::string& type,
196  size_t value);
203  Variable* addConst(const std::string& name, const std::string& type,
204  int value);
209  MatrixVariable* addMatrix(const std::string& name, const std::string& type,
210  Variable *rows, Variable *columns, Variable *ld, Variable *off = NULL);
215  VectorVariable* addVector(const std::string& name, const std::string& type,
216  Variable *N, Variable *inc, Variable *off = NULL);
221  Variable* addBuffer(BufferID bufID, const std::string& name,
222  const std::string& type, cl_mem_flags flags,
223  ArrayVariableInterface* hostPtr);
224 
233  void assignKargs(const Kargs& kargs);
234 
239  static std::string deviceVendor(cl_device_id device);
240 
241 public:
253  Step(BlasFunctionID funcID, cl_device_id device);
265  Step(ListNode *node);
270  virtual ~Step();
271 
276  const VarList& vars() const { return vars_; };
281  const ArrayVarList& arrays() const { return arrays_; };
286  const VarList& buffers() const { return buffers_; };
287 
292  virtual void fixLD() = 0;
304  virtual void declareVars(Step *masterStep) = 0;
315  Variable* getBuffer(BufferID bufID);
316 
324  void completeDecompositionSingle();
335  void makeSolutionSequence(ListHead *seq, cl_platform_id platform);
344  void freeSolutionSequence(ListHead *seq);
351  std::string generate();
358  std::string globalWorkSize();
359 
365  BlasFunctionID blasFunctionID() const { return step_.funcID; };
371  const CLBlasKargs& kargs() const { return step_.args; };
377  const PGranularity& pgran() const { return step_.pgran; };
386  const std::string& naiveCall() const { return naiveCall_; };
395  const std::string& compareCall() const { return compareCall_; };
404  const std::string& postRandomCall() const { return postRandomCall_; };
410  const std::string& kernelName() const { return kernelName_; };
417  const char* getBlasFunctionName();
418 
424  const std::map<unsigned int, const Variable*>& kargMap() const { return kargMap_; }
430  void setKargs(const CLBlasKargs& kargs);
436  void setDecomposition(const SubproblemDim *subdims);
442  void setKernelName(std::string name);
449  std::string matrixSize(MatrixVariable *var);
456  std::string vectorSize(VectorVariable *vector);
457 
466  static std::string multiplierToString(DataType dtype, ArgMultiplier arg);
473  static std::string dtypeToString(DataType dtype);
480  static BlasFunctionID getStepNodeFuncID(ListNode *node);
481 };
482 
483 } // namespace clMath
484 
485 #endif // KTEST_PATTERN_H__