23#include <pybind11/complex.h>
26inline void register_DeviceBuffer(py::module &m,
const char *class_name) {
29 py::class_<sham::DeviceBuffer<T>>(m, class_name)
31 return std::make_unique<sham::DeviceBuffer<T>>(
37 return self.get_size();
47 return self.get_val_at_idx(idx);
52 self.set_val_at_idx(idx, val);
62 self.copy_from_stdvec(v);
65 return self.copy_to_stdvec();
70 auto &m = root_module;
72 py::module shambackends_module = m.def_submodule(
"backends",
"backend library");
74 register_DeviceBuffer<u8>(shambackends_module,
"DeviceBuffer_u8");
75 register_DeviceBuffer<u32>(shambackends_module,
"DeviceBuffer_u32");
76 register_DeviceBuffer<f32>(shambackends_module,
"DeviceBuffer_f32");
77 register_DeviceBuffer<f64>(shambackends_module,
"DeviceBuffer_f64");
78 register_DeviceBuffer<f64_2>(shambackends_module,
"DeviceBuffer_f64_2");
79 register_DeviceBuffer<f64_3>(shambackends_module,
"DeviceBuffer_f64_3");
81 shambackends_module.def(
"reset_mem_info_max", []() {
85 py::class_<sham::MemPerfInfos>(shambackends_module,
"MemPerfInfos")
92 py::return_value_policy::reference_internal)
96 py::return_value_policy::reference_internal)
100 py::return_value_policy::reference_internal)
104 py::return_value_policy::reference_internal)
108 py::return_value_policy::reference_internal)
112 py::return_value_policy::reference_internal)
114 "allocated_byte_host",
116 py::return_value_policy::reference_internal)
118 "allocated_byte_device",
120 py::return_value_policy::reference_internal)
122 "allocated_byte_shared",
124 py::return_value_policy::reference_internal)
126 "max_allocated_byte_host",
128 py::return_value_policy::reference_internal)
130 "max_allocated_byte_device",
132 py::return_value_policy::reference_internal)
134 "max_allocated_byte_shared",
136 py::return_value_policy::reference_internal)
140 return shambase::format(
142 " time_alloc_host=\"{0:}\",\n"
143 " time_alloc_device=\"{1:}\",\n"
144 " time_alloc_shared=\"{2:}\",\n"
145 " time_free_host=\"{3:}\",\n"
146 " time_free_device=\"{4:}\",\n"
147 " time_free_shared=\"{5:}\",\n"
148 " allocated_byte_host=\"{6:}\",\n"
149 " allocated_byte_device=\"{7:}\",\n"
150 " allocated_byte_shared=\"{8:}\",\n"
151 " max_allocated_byte_host=\"{9:}\",\n"
152 " max_allocated_byte_device=\"{10:}\",\n"
153 " max_allocated_byte_shared=\"{11:}\")",
168 return shambase::format(
170 " time_alloc_host=\"{0:}\",\n"
171 " time_alloc_device=\"{1:}\",\n"
172 " time_alloc_shared=\"{2:}\",\n"
173 " time_free_host=\"{3:}\",\n"
174 " time_free_device=\"{4:}\",\n"
175 " time_free_shared=\"{5:}\",\n"
176 " allocated_byte_host=\"{6:}\",\n"
177 " allocated_byte_device=\"{7:}\",\n"
178 " allocated_byte_shared=\"{8:}\",\n"
179 " max_allocated_byte_host=\"{9:}\",\n"
180 " max_allocated_byte_device=\"{10:}\",\n"
181 " max_allocated_byte_shared=\"{11:}\")",
196 shambackends_module.def(
"get_mem_perf_info", []() {
Header file describing a Node Instance.
std::uint32_t u32
32 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory).
MemPerfInfos get_mem_perf_info()
Retrieve the memory performance information.
void reset_mem_info_max()
Reset the memory information for the maximum allocated bytes.
Pybind11 include and definitions.
#define ON_PYTHON_INIT
Register a Python module init function using static initialization.
void debug_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
Structure to store the performance informations about memory allocation and deallocation.
f64 time_alloc_host
Time spent allocating memory on the host.
size_t max_allocated_byte_host
max bytes allocated on the host
size_t allocated_byte_shared
Bytes allocated in shared memory.
f64 time_free_device
Time spent deallocating memory on the device.
f64 time_free_shared
Time spent deallocating memory in shared memory.
size_t max_allocated_byte_device
max bytes allocated on the device
f64 time_alloc_device
Time spent allocating memory on the device.
size_t allocated_byte_device
Bytes allocated on the device.
size_t allocated_byte_host
Bytes allocated on the host.
f64 time_free_host
Time spent deallocating memory on the host.
f64 time_alloc_shared
Time spent allocating memory in shared memory.
size_t max_allocated_byte_shared
max bytes allocated in shared memory