SkePU  1.2
 All Classes Namespaces Files Functions Variables Enumerations Friends Macros Groups Pages
environment.h
Go to the documentation of this file.
1 
5 #ifndef DEVICE_H
6 #define DEVICE_H
7 
8 #include <vector>
9 #include <sstream>
10 
11 #include "../globals.h"
12 
13 #ifdef SKEPU_OPENCL
14 #include "device_cl.h"
15 #include "device_mem_pointer_cl.h"
16 #endif
17 
18 #ifdef SKEPU_CUDA
19 #include "device_cu.h"
20 #include "device_mem_pointer_cu.h"
21 #endif
22 
23 namespace skepu
24 {
25 
26 
34 enum BackEnd
35 {
36  CPU_BACKEND,
37  OMP_BACKEND,
38  CU_BACKEND,
39  CUM_BACKEND,
40  CL_BACKEND,
41  CLM_BACKEND
42 };
43 
44 
45 enum ImplType
46 {
47  IMPL_CPU,
48  IMPL_OMP,
49  IMPL_CUDA,
50  IMPL_OPENCL
51 };
52 
53 
54 
55 enum skepu_container_type
56 {
57  VECTOR=0,
58  MATRIX=1
59 };
60 
61 
66 // Forward declaration
67 template <typename T>
69 
79 template <typename T>
81 {
82 
83 public:
84  static Environment* getInstance();
85 
86 #ifdef SKEPU_OPENCL
87  void finishAll_CL();
88  std::vector<Device_CL*> m_devices_CL;
89 #endif
90 
91  unsigned int m_numDevices;
92 
93 #ifdef SKEPU_CUDA
94  unsigned int bestCUDADevID;
95 
96  int m_peerAccessEnabled;
97  std::vector<std::pair<int, int> > m_peerCopyGpuIDsVector;
98 
99  void finishAll_CU(int lowID=-1, int highID=-1);
100 
101  std::vector<Device_CU*> m_devices_CU;
102 #endif
103 
104  void finishAll();
105 
106  DevTimingStruct bwDataStruct;
107 
108 
109  bool getGroupMapping(int groupId, BackEnd &type)
110  {
111  if(m_cacheGroupResult.first == groupId)
112  {
113  type = m_cacheGroupResult.second;
114  return true;
115  }
116  for(int i=0; i<m_groupMapping.size(); ++i)
117  {
118  if(m_groupMapping[i].first == groupId)
119  {
120  m_cacheGroupResult = m_groupMapping[i];
121  type = m_cacheGroupResult.second;
122  return true;
123  }
124  }
125  return false;
126  }
127 
128 
129  void addGroupMapping(int groupId, BackEnd type)
130  {
131  m_cacheGroupResult = std::make_pair(groupId, type);
132  m_groupMapping.push_back(std::make_pair(groupId, type));
133  }
134 
135  void clearGroupMapping()
136  {
137  m_groupMapping.clear();
138  }
139 
140 protected:
141 
144  std::vector<std::pair<int, BackEnd> > m_groupMapping;
145  std::pair<int, BackEnd> m_cacheGroupResult;
146 
147  Environment();
148 
149  virtual ~Environment();
150 
151  friend class EnvironmentDestroyer<T>; // To safely clean resources
152 
153 
154 
155 public:
156 
157 #ifdef SKEPU_OPENCL
159  std::vector<std::pair<cl_kernel, Device_CL*> > m_transposeKernels_CL;
160 #endif
161 
162 private:
163 
164  static EnvironmentDestroyer<T> _destroyer;
165 
166 
167  void init();
168 
169 #ifdef SKEPU_OPENCL
170  void init_CL();
171 #endif
172 
173 #ifdef SKEPU_CUDA
174  void init_CU();
175 #endif
176 
177 
178 
179 private:
180  static Environment* instance;
181 
182 };
183 
184 template <typename T>
186 
187 
200 template <typename T>
202 {
203 public:
206 
207  void SetEnvironment(Environment<T>* s);
208 private:
209  Environment<T>* _singleton;
210 };
211 
212 
213 
214 
215 template <typename T>
216 EnvironmentDestroyer<T>::EnvironmentDestroyer(Environment<T>* s)
217 {
218  _singleton = s;
219 }
220 
221 template <typename T>
222 EnvironmentDestroyer<T>::~EnvironmentDestroyer ()
223 {
224  delete _singleton;
225 }
226 
227 template <typename T>
228 void EnvironmentDestroyer<T>::SetEnvironment (Environment<T>* s)
229 {
230  _singleton = s;
231 }
232 
233 }
234 
235 #include "environment.inl"
236 
237 #endif
238 
239 
void finishAll_CL()
Definition: environment.inl:562
Contains a class declaration for an object which represents an OpenCL device memory allocation for co...
Contains a class declaration for an object which represents an CUDA device memory allocation for Vect...
virtual ~Environment()
Definition: environment.inl:145
void createOpenCLProgramForMatrixTranspose()
Definition: environment.inl:636
void finishAll()
Definition: environment.inl:575
Contains member function definitions for the Environment class.
BackEnd
Can be used to specify which backend to use.
Definition: environment.h:34
Contains a class declaration for the object that represents an OpenCL device.
A class that is used to properly deallocate singelton object of Environment class.
Definition: environment.h:68
Contains a class declaration for the object that represents a CUDA device.
Environment()
Definition: environment.inl:104
A class representing a execution environment.
Definition: environment.h:80
std::vector< std::pair< int, BackEnd > > m_groupMapping
Definition: environment.h:144
static Environment * getInstance()
Definition: environment.inl:90
std::vector< std::pair< int, int > > m_peerCopyGpuIDsVector
Definition: environment.h:97
void finishAll_CU(int lowID=-1, int highID=-1)
Definition: environment.inl:412