|
SkePU 0.7
|
00001 00005 #ifndef EXEC_PLAN_H 00006 #define EXEC_PLAN_H 00007 00008 #include <map> 00009 00010 00011 00012 namespace skepu 00013 { 00014 00015 enum BackEnd 00016 { 00017 CPU_BACKEND, 00018 OMP_BACKEND, 00019 CU_BACKEND, 00020 CUM_BACKEND, 00021 CL_BACKEND, 00022 CLM_BACKEND 00023 }; 00024 00025 00026 struct BackEndParams 00027 { 00028 BackEndParams(): backend(CPU_BACKEND), maxThreads(32), maxBlocks(2048), numOmpThreads(1) {} 00029 BackEnd backend; 00030 int maxThreads; 00031 int maxBlocks; 00032 int numOmpThreads; 00033 }; 00034 00035 00056 class ExecPlan 00057 { 00058 public: 00059 00060 void add(int lowBound, int highBound, BackEnd backend, unsigned gs, unsigned bs) 00061 { 00062 BackEndParams bp; 00063 bp.backend=backend; 00064 bp.maxThreads=bs; 00065 bp.maxBlocks = gs; 00066 sizePlan.insert(std::make_pair(std::make_pair(lowBound, highBound),bp)); 00067 } 00068 00069 void add(int lowBound, int highBound, BackEnd backend, unsigned numOmpThreads) 00070 { 00071 BackEndParams bp; 00072 bp.backend=backend; 00073 bp.numOmpThreads = numOmpThreads; 00074 sizePlan.insert(std::make_pair(std::make_pair(lowBound, highBound),bp)); 00075 } 00076 00077 void add(int lowBound, int highBound, BackEndParams params) 00078 { 00079 sizePlan.insert(std::make_pair(std::make_pair(lowBound, highBound),params)); 00080 } 00081 00082 void add(int lowBound, int highBound, BackEnd backend) 00083 { 00084 BackEndParams bp; 00085 bp.backend=backend; 00086 sizePlan.insert(std::make_pair(std::make_pair(lowBound, highBound),bp)); 00087 } 00088 00089 void setMaxThreads(int size, int maxthreads) 00090 { 00091 std::map< std::pair<int, int>, BackEndParams >::iterator it; 00092 for(it = sizePlan.begin(); it != sizePlan.end(); ++it) 00093 { 00094 if(size >= it->first.first && size <= it->first.second) 00095 { 00096 it->second.maxThreads=maxthreads; 00097 return; 00098 } 00099 } 00100 00101 (--it)->second.maxThreads= maxthreads; 00102 } 00103 00104 void setMaxBlocks(int size, int maxBlocks) 00105 { 00106 std::map< std::pair<int, int>, BackEndParams >::iterator it; 00107 for(it = sizePlan.begin(); it != sizePlan.end(); ++it) 00108 { 00109 if(size >= it->first.first && size <= it->first.second) 00110 { 00111 it->second.maxBlocks=maxBlocks; 00112 return; 00113 } 00114 } 00115 00116 (--it)->second.maxBlocks= maxBlocks; 00117 } 00118 00119 void setNumOmpThreads(int size, int ompThreads) 00120 { 00121 std::map< std::pair<int, int>, BackEndParams >::iterator it; 00122 for(it = sizePlan.begin(); it != sizePlan.end(); ++it) 00123 { 00124 if(size >= it->first.first && size <= it->first.second) 00125 { 00126 it->second.numOmpThreads = ompThreads; 00127 return; 00128 } 00129 } 00130 00131 (--it)->second.numOmpThreads = ompThreads; 00132 } 00133 00134 int numOmpThreads(int size) 00135 { 00136 if(sizePlan.empty()) 00137 return 1; 00138 00139 std::map< std::pair<int, int>, BackEndParams >::iterator it; 00140 for(it = sizePlan.begin(); it != sizePlan.end(); ++it) 00141 { 00142 if(size >= it->first.first && size <= it->first.second) 00143 { 00144 return it->second.numOmpThreads; 00145 } 00146 } 00147 00148 return (--it)->second.numOmpThreads; 00149 } 00150 00151 int maxThreads(int size) 00152 { 00153 if(sizePlan.empty()) 00154 return 32; 00155 00156 std::map< std::pair<int, int>, BackEndParams >::iterator it; 00157 for(it = sizePlan.begin(); it != sizePlan.end(); ++it) 00158 { 00159 if(size >= it->first.first && size <= it->first.second) 00160 { 00161 return it->second.maxThreads; 00162 } 00163 } 00164 00165 return (--it)->second.maxThreads; 00166 } 00167 00168 BackEnd find(int size) 00169 { 00170 if(sizePlan.empty()) 00171 return CPU_BACKEND; 00172 00173 std::map< std::pair<int, int>, BackEndParams >::iterator it; 00174 for(it = sizePlan.begin(); it != sizePlan.end(); ++it) 00175 { 00176 if(size >= it->first.first && size <= it->first.second) 00177 { 00178 return it->second.backend; 00179 } 00180 } 00181 00182 return (--it)->second.backend; 00183 } 00184 00185 BackEndParams find_(int size) 00186 { 00187 if(sizePlan.empty()) 00188 return BackEndParams(); 00189 00190 std::map< std::pair<int, int>, BackEndParams >::iterator it; 00191 for(it = sizePlan.begin(); it != sizePlan.end(); ++it) 00192 { 00193 if(size >= it->first.first && size <= it->first.second) 00194 { 00195 return it->second; 00196 } 00197 } 00198 00199 return (--it)->second; 00200 } 00201 00202 void clear() 00203 { 00204 sizePlan.clear(); 00205 } 00206 00207 private: 00208 std::map< std::pair<int, int>, BackEndParams > sizePlan; 00209 }; 00210 00211 } 00212 00213 #endif 00214
1.7.4