7 #include "spineMLLogging.h" 18 StateVar(
const std::string &stateVarName, std::function<
void*(
const char*,
bool)> getLibrarySymbolFunc)
21 T **hostStateVar =
reinterpret_cast<T**
>(getLibrarySymbolFunc(stateVarName.c_str(),
true));
24 if(hostStateVar ==
nullptr) {
25 m_Access = Access::None;
29 LOGD_SPINEML <<
"\t" << stateVarName;
32 GetCurrentFunc getCurrentFunc =
reinterpret_cast<GetCurrentFunc
>(getLibrarySymbolFunc((
"getCurrent" + stateVarName).c_str(),
true));
35 m_Access = Access::Indirect;
39 m_Indirect.pushFunc =
reinterpret_cast<PushCurrentFunc
>(getLibrarySymbolFunc((
"pushCurrent" + stateVarName +
"ToDevice").c_str(),
false));
40 m_PullFunc =
reinterpret_cast<PullFunc
>(getLibrarySymbolFunc((
"pullCurrent" + stateVarName +
"FromDevice").c_str(),
false));
42 LOGD_SPINEML <<
"\t\tIndirect with get function:" <<
m_Indirect.getFunc <<
", push function:" <<
m_Indirect.pushFunc <<
", pull function:" << m_PullFunc;
47 m_Access = Access::Direct;
50 m_Direct.hostStateVar = *hostStateVar;
51 m_Direct.pushFunc =
reinterpret_cast<PushFunc
>(getLibrarySymbolFunc((
"push" + stateVarName +
"ToDevice").c_str(),
false));
52 m_PullFunc =
reinterpret_cast<PullFunc
>(getLibrarySymbolFunc((
"pull" + stateVarName +
"FromDevice").c_str(),
false));
54 LOGD_SPINEML <<
"\t\tDirect with host pointer:" <<
m_Direct.hostStateVar <<
", push function:" <<
m_Direct.pushFunc <<
", pull function:" << m_PullFunc;
63 if(m_Access == Access::Indirect) {
66 else if(m_Access == Access::Direct) {
70 throw std::runtime_error(
"Unable to push inaccessible variable");
76 if(m_Access == Access::None) {
77 throw std::runtime_error(
"Unable to pull inaccessible variable");
86 if(m_Access == Access::Indirect) {
89 else if(m_Access == Access::Direct) {
93 throw std::runtime_error(
"Unable to get inaccessible variable");
99 if(m_Access == Access::Indirect) {
102 else if(m_Access == Access::Direct) {
106 throw std::runtime_error(
"Unable to get inaccessible variable");
114 typedef T *(*GetCurrentFunc)(void);
115 typedef void (*PushFunc)(bool);
116 typedef void (*PullFunc)(void);
117 typedef void (*PushCurrentFunc)(void);
137 GetCurrentFunc getFunc;
138 PushCurrentFunc pushFunc;
Definition: stateVar.h:15
void pull() const
Definition: stateVar.h:74
Direct m_Direct
Definition: stateVar.h:161
Indirect m_Indirect
Definition: stateVar.h:160
Definition: connectors.h:25
bool isAccessible() const
Definition: stateVar.h:59
StateVar(const std::string &stateVarName, std::function< void *(const char *, bool)> getLibrarySymbolFunc)
Definition: stateVar.h:18
void push() const
Definition: stateVar.h:61