1 #include "pybind_common.h"
3 template<typename T>
4 void AllocateMemoryT(const vector<T *>& eos)
5 {
6 // Allocate input and output buffers for each execution object
7 for (auto eo : eos)
8 {
9 size_t in_size = eo->GetInputBufferSizeInBytes();
10 size_t out_size = eo->GetOutputBufferSizeInBytes();
11 void* in_ptr = malloc(in_size);
12 void* out_ptr = malloc(out_size);
13 assert(in_ptr != nullptr && out_ptr != nullptr);
15 ArgInfo in = { ArgInfo(in_ptr, in_size)};
16 ArgInfo out = { ArgInfo(out_ptr, out_size)};
17 eo->SetInputOutputBuffer(in, out);
18 }
19 }
21 // Allocate input and output memory for each EO
22 void AllocateMemory(const vector<ExecutionObject *>& eos)
23 {
24 AllocateMemoryT<ExecutionObject>(eos);
25 }
27 // Allocate input and output memory for each EO
28 void AllocateMemory(const vector<ExecutionObjectPipeline *>& eos)
29 {
30 AllocateMemoryT<ExecutionObjectPipeline>(eos);
31 }
35 // Free the input and output memory associated with each EO
36 template<typename T>
37 void FreeMemoryT(const vector<T *>& eos)
38 {
39 for (auto eo : eos)
40 {
41 free(eo->GetInputBufferPtr());
42 free(eo->GetOutputBufferPtr());
43 }
44 }
46 void FreeMemory(const vector<ExecutionObject *>& eos)
47 {
48 FreeMemoryT<ExecutionObject>(eos);
49 }
52 // Free the input and output memory associated with each EO
53 void FreeMemory(const vector<ExecutionObjectPipeline *>& eos)
54 {
55 FreeMemoryT<ExecutionObjectPipeline>(eos);
56 }