|
SkePU 0.7
|
00001 00005 #ifndef DEVICE_H 00006 #define DEVICE_H 00007 00008 #ifndef SKEPU_NUMGPU 00009 #define SKEPU_NUMGPU 0 00010 #endif 00011 00012 #include <vector> 00013 00014 #ifdef SKEPU_OPENCL 00015 #include "device_cl.h" 00016 #include "device_mem_pointer_cl.h" 00017 #endif 00018 00019 #include <sstream> 00020 00021 #include "skepu/vector.h" 00022 00023 namespace skepu 00024 { 00025 00035 template <typename T> 00036 class EnvironmentDestroyer; 00037 00038 00039 00051 template <typename T> 00052 class Environment 00053 { 00054 00055 public: 00056 00057 00061 enum SkelObjectType { 00062 MAP_UNARY = 0, 00063 MAP_BINARY, 00064 MAP_TERNARY, 00065 MAP_UNARY_MATRIX, 00066 MAP_BINARY_MATRIX, 00067 MAP_TERNARY_MATRIX, 00068 MAPRED_UNARY, 00069 MAPRED_BINARY, 00070 MAPRED_TERNARY, 00071 REDUCE, 00072 MAP_ARRAY, 00073 MAP_ARRAY_MATRIX, 00074 MAP_OVERLAP, 00075 MAP_OVERLAP_MAT_ROW, 00076 MAP_OVERLAP_MAT_COL, 00077 MAP_OVERLAP_MAT_CONVOL, 00078 NUMBER_OF_SkelObjectType 00079 }; 00080 00081 static Environment* getInstance(); 00082 00083 int objCounters[NUMBER_OF_SkelObjectType]; 00084 00085 #ifdef SKEPU_OPENCL 00086 std::vector<Device_CL*> m_devices_CL; 00087 #endif 00088 00089 #ifdef SKEPU_CUDA 00090 // std::vector<Device_CU*> m_devices_CU; // Not used in this translation 00091 #endif 00092 00093 void finishAll(); 00094 00095 protected: 00096 Environment(); 00097 00098 virtual ~Environment(); 00099 00100 friend class EnvironmentDestroyer<T>; // To safely clean resources 00101 00102 00103 00104 private: 00105 00106 static EnvironmentDestroyer<T> _destroyer; 00107 00108 00109 void init(); 00110 00111 private: 00112 static Environment* instance; 00113 struct starpu_conf conf; 00114 00115 00116 public: 00117 unsigned int getNextTagID() 00118 { 00119 int tagId = ++tagCounter; 00120 m_tagIds.push_back(tagId); 00121 return tagId; 00122 } 00123 unsigned int getCurrentTagID() 00124 { 00125 return tagCounter; 00126 } 00127 private: 00128 unsigned int tagCounter; 00129 00130 public: 00131 std::vector<unsigned int> m_tagIds; 00132 bool m_useTagIds; 00133 bool m_isFarmCall; 00134 00135 }; 00136 00137 00138 template <typename T> 00139 EnvironmentDestroyer<T> Environment<T>::_destroyer; 00140 00141 00145 template <typename T> 00146 class EnvironmentDestroyer 00147 { 00148 public: 00149 EnvironmentDestroyer(Environment<T>* = 0); 00150 ~EnvironmentDestroyer(); 00151 00152 void SetEnvironment(Environment<T>* s); 00153 private: 00154 Environment<T>* _singleton; 00155 }; 00156 00157 00158 00159 00160 template <typename T> 00161 EnvironmentDestroyer<T>::EnvironmentDestroyer(Environment<T>* s) { 00162 _singleton = s; 00163 } 00164 00165 template <typename T> 00166 EnvironmentDestroyer<T>::~EnvironmentDestroyer () { 00167 delete _singleton; 00168 } 00169 00170 template <typename T> 00171 void EnvironmentDestroyer<T>::SetEnvironment (Environment<T>* s) { 00172 _singleton = s; 00173 } 00174 00175 } 00176 00177 #include "environment.inl" 00178 00179 #endif 00180
1.7.4