Initial commit

This commit is contained in:
Matthias
2017-04-11 15:49:21 +02:00
commit ec80b339e2
2081 changed files with 968992 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
#pragma once
#include <exception>
#include <memory>
namespace wfr {
// Forward declarations
namespace scheduling {
class SchedulingDecision;
}
namespace execution {
enum class ExecutionHandleState
: int { Unknown,
Pending,
Running,
Finished,
Error };
class ExecutionHandle {
// Invariant properties that can be accessed directly.
public:
std::shared_ptr<wfr::scheduling::SchedulingDecision> schedulingDecision = nullptr;
// Mutable properties that need to be accessed via getter-/setter-functions.
private:
ExecutionHandleState state = ExecutionHandleState::Unknown;
std::exception_ptr errorCause = nullptr;
public:
ExecutionHandle(std::shared_ptr<wfr::scheduling::SchedulingDecision> schedulingDecision) noexcept :
schedulingDecision(schedulingDecision), state(ExecutionHandleState::Pending) {}
std::exception_ptr getErrorCause() const noexcept { return errorCause; }
void setErrorCause(std::exception_ptr errorCause) noexcept { this->errorCause = errorCause; }
ExecutionHandleState getState() const noexcept { return state; }
void setState(ExecutionHandleState state) noexcept { this->state = state; }
};
} /* namespace execution */
} /* namespace wfr */
+59
View File
@@ -0,0 +1,59 @@
#pragma once
#include <mutex>
#include <thread>
#include <utility>
#include <queue>
#include <memory>
#include <map>
#include <atomic>
#include <condition_variable>
namespace wfr {
namespace scheduling {
class SchedulingDecision;
class AbstractScheduler;
class PThreadBackend;
}
namespace execution {
class PThreadBackend;
class CudaBackend;
}
namespace execution {
class ExecutionHandle;
class ExecutionManager {
private:
ExecutionManager();
static ExecutionManager singleton;
std::mutex managerMutex;
PThreadBackend* pThreadBackend = nullptr;
CudaBackend* cudaBackend = nullptr;
std::map<ExecutionHandle*, scheduling::AbstractScheduler*> schedulerHandleMap;
std::queue<ExecutionHandle*> updateQueue;
public:
static void init(int argc, char** argv);
static void finish();
~ExecutionManager();
static ExecutionManager& getInstance() { return singleton; }
bool executeSchedulingDecision(std::shared_ptr<scheduling::SchedulingDecision> sd, scheduling::AbstractScheduler& scheduler);
void notifyExecutionHandleUpdate(ExecutionHandle& handle);
};
} /* namespace execution */
} /* namespace wfr */
+57
View File
@@ -0,0 +1,57 @@
#pragma once
#include <wfr/common/types/WfrTypes.h>
#include <set>
#include <queue>
#include <mutex>
#include <condition_variable>
namespace wfr {
namespace resource {
class Resource;
class ComputingResource;
}
namespace execution {
class ExecutionManager;
class ExecutionHandle;
class PThreadWorker;
class PThreadBackend {
private:
std::mutex objMutex;
std::condition_variable workerCondVar;
ExecutionManager& manager;
std::set<PThreadWorker*> workers;
std::set<PThreadWorker*> idleWorkers;
std::set<resource::ComputingResource*> resources;
std::queue<ExecutionHandle*> taskQueue;
wfr_size_t maxWorkerCount;
wfr_size_t currentTotalWorkerCount = 0;
wfr_size_t currentBusyWorkerCount = 0;
wfr_size_t occupiedSlotCount = 0;
wfr_size_t slotsInQueue = 0;
bool isShutdown = false;
public:
PThreadBackend(ExecutionManager& manager, const std::set<resource::ComputingResource*>& resources);
virtual ~PThreadBackend();
void notifyExecutionHandleUpdate(ExecutionHandle& handle, PThreadWorker& worker);
bool queueTaskExecution(ExecutionHandle& handle);
ExecutionHandle* popTaskExecution(PThreadWorker& worker);
wfr_size_t getBusyWorkerCount() { return currentBusyWorkerCount; }
wfr_size_t getTotalSlotCount() { return maxWorkerCount; }
};
} /* namespace execution */
} /* namespace wfr */
+81
View File
@@ -0,0 +1,81 @@
#pragma once
#include <thread>
#include <mutex>
#include <condition_variable>
#include <atomic>
#include <wfr/common/types/WfsTypes.h>
namespace wfr {
namespace resource {
class Resource;
}
namespace scheduling {
class SchedulingDecision;
}
namespace execution {
class PThreadBackend;
class ExecutionHandle;
class PThreadWorker {
private:
/**
* Static variable holding the next free threadID.
**/
static std::atomic<wfr_id_t> nextThreadID;
/**
* Returns the next free threadID.
*
* @return next free threadID.
*/
static wfr_id_t getNextThreadID();
static void workerFunc(PThreadWorker* threadObj);
private:
wfr_id_t threadID;
bool stopThread;
bool threadRunning;
bool threadBusy;
PThreadBackend& backend;
std::mutex threadMutex;
std::thread* thread;
wfr_size_t usedSlotCount;
wfs::ComputingResourceStatus status;
PThreadWorker(PThreadBackend& backend);
public:
virtual ~PThreadWorker();
wfr_size_t getThreadID() { return threadID; }
bool isBusy() { return threadBusy; }
void setBusy(bool val) {threadBusy = val; }
wfr_size_t getUsedSlotCount() { return usedSlotCount; }
void setUsedSlotCount(wfr_size_t count) { usedSlotCount += count; }
void finishThread();
void join();
wfs::ComputingResourceStatus getStatus() { return status; }
void setStatus(wfs::ComputingResourceStatus status, std::shared_ptr<wfr::scheduling::SchedulingDecision> sd = nullptr);
static PThreadWorker* createNewThread(PThreadBackend& backend);
};
} /* namespace execution */
} /* namespace wfr */