Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify SonicCore and redesign SonicTriton
- Loading branch information
Showing
26 changed files
with
887 additions
and
562 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef HeterogeneousCore_SonicCore_SonicClient | ||
#define HeterogeneousCore_SonicCore_SonicClient | ||
|
||
#include "HeterogeneousCore/SonicCore/interface/SonicClientBase.h" | ||
#include "HeterogeneousCore/SonicCore/interface/SonicClientTypes.h" | ||
|
||
//convenience definition for multiple inheritance (base and types) | ||
template <typename InputT, typename OutputT = InputT> | ||
class SonicClient : public SonicClientBase, public SonicClientTypes<InputT, OutputT> { | ||
public: | ||
//constructor | ||
SonicClient(const edm::ParameterSet& params) : SonicClientBase(params), SonicClientTypes<InputT, OutputT>() {} | ||
|
||
//do nothing by default | ||
void reset() override {} | ||
}; | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,60 @@ | ||
#ifndef HeterogeneousCore_SonicCore_SonicClientBase | ||
#define HeterogeneousCore_SonicCore_SonicClientBase | ||
|
||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" | ||
#include "FWCore/Concurrency/interface/WaitingTaskWithArenaHolder.h" | ||
#include "FWCore/MessageLogger/interface/MessageLogger.h" | ||
#include "HeterogeneousCore/SonicCore/interface/SonicDispatcher.h" | ||
#include "HeterogeneousCore/SonicCore/interface/SonicDispatcherPseudoAsync.h" | ||
|
||
#include <string> | ||
#include <chrono> | ||
#include <exception> | ||
#include <memory> | ||
|
||
enum class SonicMode { Sync = 1, Async = 2, PseudoAsync = 3 }; | ||
|
||
class SonicClientBase { | ||
public: | ||
//constructor | ||
SonicClientBase() : tries_(0) {} | ||
SonicClientBase(const edm::ParameterSet& params); | ||
|
||
//destructor | ||
virtual ~SonicClientBase() = default; | ||
|
||
void setDebugName(const std::string& debugName) { | ||
debugName_ = debugName; | ||
fullDebugName_ = debugName_; | ||
if (!clientName_.empty()) | ||
fullDebugName_ += ":" + clientName_; | ||
} | ||
void setDebugName(const std::string& debugName); | ||
const std::string& debugName() const { return debugName_; } | ||
const std::string& clientName() const { return clientName_; } | ||
|
||
//main operation | ||
virtual void dispatch(edm::WaitingTaskWithArenaHolder holder) = 0; | ||
virtual void dispatch(edm::WaitingTaskWithArenaHolder holder) { dispatcher_->dispatch(std::move(holder)); } | ||
|
||
//helper | ||
virtual void reset() = 0; | ||
|
||
//provide base params | ||
static edm::ParameterSetDescription basePSetDescription(bool allowRetry = true); | ||
|
||
protected: | ||
virtual void evaluate() = 0; | ||
|
||
//this should be overridden by clients that allow retries | ||
virtual unsigned allowedTries() const { return 0; } | ||
|
||
void setStartTime() { | ||
tries_ = 0; | ||
if (debugName_.empty()) | ||
return; | ||
t0_ = std::chrono::high_resolution_clock::now(); | ||
} | ||
|
||
void finish(bool success, std::exception_ptr eptr = std::exception_ptr{}) { | ||
//retries are only allowed if no exception was raised | ||
if (!success and !eptr) { | ||
++tries_; | ||
//if max retries has not been exceeded, call evaluate again | ||
if (tries_ < allowedTries()) { | ||
evaluate(); | ||
//avoid calling doneWaiting() twice | ||
return; | ||
} | ||
//prepare an exception if exceeded | ||
else { | ||
cms::Exception ex("SonicCallFailed"); | ||
ex << "call failed after max " << tries_ << " tries"; | ||
eptr = make_exception_ptr(ex); | ||
} | ||
} | ||
if (!debugName_.empty()) { | ||
auto t1 = std::chrono::high_resolution_clock::now(); | ||
edm::LogInfo(fullDebugName_) << "Client time: " | ||
<< std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0_).count(); | ||
} | ||
holder_.doneWaiting(eptr); | ||
} | ||
void start(edm::WaitingTaskWithArenaHolder holder); | ||
|
||
void finish(bool success, std::exception_ptr eptr = std::exception_ptr{}); | ||
|
||
//members | ||
unsigned tries_; | ||
SonicMode mode_; | ||
std::unique_ptr<SonicDispatcher> dispatcher_; | ||
unsigned allowedTries_, tries_; | ||
edm::WaitingTaskWithArenaHolder holder_; | ||
|
||
//for logging/debugging | ||
std::string clientName_, debugName_, fullDebugName_; | ||
std::chrono::time_point<std::chrono::high_resolution_clock> t0_; | ||
|
||
friend class SonicDispatcher; | ||
friend class SonicDispatcherPseudoAsync; | ||
}; | ||
|
||
#endif |
76 changes: 0 additions & 76 deletions
76
HeterogeneousCore/SonicCore/interface/SonicClientPseudoAsync.h
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef HeterogeneousCore_SonicCore_SonicDispatcher | ||
#define HeterogeneousCore_SonicCore_SonicDispatcher | ||
|
||
#include "FWCore/Concurrency/interface/WaitingTaskWithArenaHolder.h" | ||
|
||
class SonicClientBase; | ||
|
||
class SonicDispatcher { | ||
public: | ||
//constructor | ||
SonicDispatcher(SonicClientBase* client) : client_(client) {} | ||
|
||
//destructor | ||
virtual ~SonicDispatcher() = default; | ||
|
||
//main operation | ||
virtual void dispatch(edm::WaitingTaskWithArenaHolder holder); | ||
|
||
protected: | ||
SonicClientBase* client_; | ||
}; | ||
|
||
#endif |
38 changes: 38 additions & 0 deletions
38
HeterogeneousCore/SonicCore/interface/SonicDispatcherPseudoAsync.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef HeterogeneousCore_SonicCore_SonicDispatcherPseudoAsync | ||
#define HeterogeneousCore_SonicCore_SonicDispatcherPseudoAsync | ||
|
||
#include "HeterogeneousCore/SonicCore/interface/SonicDispatcher.h" | ||
|
||
#include <memory> | ||
#include <condition_variable> | ||
#include <mutex> | ||
#include <thread> | ||
#include <atomic> | ||
#include <exception> | ||
|
||
class SonicClientBase; | ||
|
||
//pretend to be async + non-blocking by waiting for blocking calls to return in separate std::thread | ||
class SonicDispatcherPseudoAsync : public SonicDispatcher { | ||
public: | ||
//constructor | ||
SonicDispatcherPseudoAsync(SonicClientBase* client); | ||
|
||
//destructor | ||
~SonicDispatcherPseudoAsync() override; | ||
|
||
//main operation | ||
void dispatch(edm::WaitingTaskWithArenaHolder holder) override; | ||
|
||
private: | ||
void waitForNext(); | ||
|
||
//members | ||
bool hasCall_; | ||
std::mutex mutex_; | ||
std::condition_variable cond_; | ||
std::atomic<bool> stop_; | ||
std::unique_ptr<std::thread> thread_; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.