4 #include "kalmar_runtime.h" 5 #include "kalmar_exception.h" 12 class FunctorBufferWalker {
14 virtual void Append(
size_t sz,
const void* s) {}
15 virtual void AppendPtr(
size_t sz,
const void* s) {}
16 virtual void visit_buffer(
struct rw_info* rw,
bool modify,
bool isArray) = 0;
21 FunctorBufferWalker* vis;
23 Serialize(FunctorBufferWalker* vis) : vis(vis) {}
24 void Append(
size_t sz,
const void* s) { vis->Append(sz, s); }
25 void AppendPtr(
size_t sz,
const void* s) { vis->AppendPtr(sz, s); }
26 void visit_buffer(
struct rw_info* rw,
bool modify,
bool isArray) {
27 vis->visit_buffer(rw, modify, isArray);
33 class CPUVisitor :
public FunctorBufferWalker
35 std::shared_ptr<KalmarQueue> pQueue;
36 std::set<struct rw_info*> bufs;
38 CPUVisitor(std::shared_ptr<KalmarQueue> pQueue) : pQueue(pQueue) {}
39 void visit_buffer(
struct rw_info* rw,
bool modify,
bool isArray)
override {
41 auto curr = pQueue->getDev()->get_path();
42 auto path = rw->master->getDev()->get_path();
44 auto asoc = rw->stage->getDev()->get_path();
45 if (asoc == L
"cpu" || path != curr)
46 throw runtime_exception(__errorMsg_UnsupportedAccelerator, E_FAIL);
49 rw->sync(pQueue, modify,
false);
50 if (bufs.find(rw) == std::end(bufs)) {
51 void*& device = rw->devs[pQueue->getDev()].data;
52 void*& data = rw->data;
54 std::swap(device, data);
60 class BufferArgumentsAppender :
public FunctorBufferWalker
62 std::shared_ptr<KalmarQueue> pQueue;
66 BufferArgumentsAppender(std::shared_ptr<KalmarQueue> pQueue,
void* k)
67 : pQueue(pQueue), k_(k), current_idx_(0) {}
68 void Append(
size_t sz,
const void *s)
override {
69 CLAMP::PushArg(k_, current_idx_++, sz, s);
71 void AppendPtr(
size_t sz,
const void *s)
override {
72 CLAMP::PushArgPtr(k_, current_idx_++, sz, s);
74 void visit_buffer(
struct rw_info* rw,
bool modify,
bool isArray)
override {
76 auto curr = pQueue->getDev()->get_path();
77 auto path = rw->master->getDev()->get_path();
79 auto asoc = rw->stage->getDev()->get_path();
80 if (asoc == L
"cpu" || path != curr)
81 throw runtime_exception(__errorMsg_UnsupportedAccelerator, E_FAIL);
84 rw->sync(pQueue, modify,
false);
85 pQueue->Push(k_, current_idx_++, rw->devs[pQueue->getDev()].data, modify);
95 class QueueSearcher :
public FunctorBufferWalker
97 std::shared_ptr<KalmarQueue> pQueue;
99 QueueSearcher() =
default;
100 void visit_buffer(
struct rw_info* rw,
bool modify,
bool isArray)
override {
101 if (isArray && !pQueue) {
102 if (rw->master->getDev()->get_path() != L
"cpu")
104 else if (rw->stage->getDev()->get_path() != L
"cpu")
108 std::shared_ptr<KalmarQueue> get_que()
const {
return pQueue; }
namespace for internal classes of Kalmar compiler / runtime
Definition: hc.hpp:42