Line data Source code
1 : /////////////////////////////////////////////////////////////////////////// 2 : // Spetabaru - Berenger Bramas MPCDF - 2017 3 : // Under LGPL Licence, please you must read the LICENCE file. 4 : /////////////////////////////////////////////////////////////////////////// 5 : #ifndef SPRUNTIME_HPP 6 : #define SPRUNTIME_HPP 7 : 8 : #include "Speculation/SpSpeculativeModel.hpp" 9 : #include "TaskGraph/SpTaskGraph.hpp" 10 : #include "Compute/SpComputeEngine.hpp" 11 : #include "Utils/SpUtils.hpp" 12 : #include "Compute/SpWorker.hpp" 13 : 14 : //! The runtime is the main component of spetabaru. 15 : template <SpSpeculativeModel SpecModel = SpSpeculativeModel::SP_MODEL_1> 16 : class SpRuntime { 17 : 18 : //=====----------------------------===== 19 : // Private API - members 20 : //=====----------------------------===== 21 : private: 22 : SpTaskGraph<SpecModel> tg; 23 : SpComputeEngine ce; 24 : 25 : //=====--------------------===== 26 : // Public API 27 : //=====--------------------===== 28 : public: 29 : /////////////////////////////////////////////////////////////////////////// 30 : /// Constructor 31 : /////////////////////////////////////////////////////////////////////////// 32 : 33 49 : explicit SpRuntime(const int inNumThreads = SpUtils::DefaultNumThreads()) : tg(), ce(SpWorker::createATeamOfNCpuWorkers(inNumThreads)) { 34 49 : tg.computeOn(ce); 35 49 : } 36 : 37 : /////////////////////////////////////////////////////////////////////////// 38 : /// Destructor 39 : /////////////////////////////////////////////////////////////////////////// 40 49 : ~SpRuntime() { 41 49 : tg.waitAllTasks(); 42 49 : ce.stopIfNotAlreadyStopped(); 43 49 : } 44 : 45 : // No copy and no move 46 : SpRuntime(const SpRuntime&) = delete; 47 : SpRuntime(SpRuntime&&) = delete; 48 : SpRuntime& operator=(const SpRuntime&) = delete; 49 : SpRuntime& operator=(SpRuntime&&) = delete; 50 : 51 : /////////////////////////////////////////////////////////////////////////// 52 : /// Task creation method 53 : /////////////////////////////////////////////////////////////////////////// 54 : 55 : template <class... ParamsTy> 56 353 : auto task(ParamsTy&&...params) { 57 353 : return tg.task(std::forward<ParamsTy>(params)...); 58 : } 59 : 60 : /////////////////////////////////////////////////////////////////////////// 61 : /// Getters/actions 62 : /////////////////////////////////////////////////////////////////////////// 63 : 64 31 : void setSpeculationTest(std::function<bool(int,const SpProbability&)> inFormula){ 65 31 : tg.setSpeculationTest(std::move(inFormula)); 66 31 : } 67 : 68 59 : void waitAllTasks(){ 69 59 : tg.waitAllTasks(); 70 59 : } 71 : 72 167 : void waitRemain(const long int windowSize){ 73 167 : tg.waitRemain(windowSize); 74 167 : } 75 : 76 39 : void stopAllThreads(){ 77 39 : ce.stopIfNotAlreadyStopped(); 78 39 : } 79 : 80 75 : int getNbThreads() const { 81 75 : return static_cast<int>(ce.getCurrentNbOfWorkers()); 82 : } 83 : 84 : /////////////////////////////////////////////////////////////////////////// 85 : /// Output 86 : /////////////////////////////////////////////////////////////////////////// 87 : 88 21 : void generateDot(const std::string& outputFilename, bool printAccesses=false) const { 89 21 : tg.generateDot(outputFilename, printAccesses); 90 21 : } 91 : 92 12 : void generateTrace(const std::string& outputFilename, const bool showDependences = true) const { 93 12 : tg.generateTrace(outputFilename, showDependences); 94 12 : } 95 : }; 96 : #endif