104 py::class_<Type>(m,
"Type")
105 .def_property_readonly(
"id", &Type::getID)
106 .def(
"__repr__", [](
Type &t) {
return "<" + t.
getID() +
">"; });
107 py::class_<ChannelType, Type>(m,
"ChannelType")
108 .def_property_readonly(
"inner", &ChannelType::getInner,
109 py::return_value_policy::reference);
110 py::enum_<BundleType::Direction>(m,
"Direction")
111 .value(
"To", BundleType::Direction::To)
112 .value(
"From", BundleType::Direction::From)
114 py::class_<BundleType, Type>(m,
"BundleType")
115 .def_property_readonly(
"channels", &BundleType::getChannels,
116 py::return_value_policy::reference);
117 py::class_<VoidType, Type>(m,
"VoidType");
118 py::class_<AnyType, Type>(m,
"AnyType");
119 py::class_<BitVectorType, Type>(m,
"BitVectorType")
121 py::class_<BitsType, BitVectorType>(m,
"BitsType");
122 py::class_<IntegerType, BitVectorType>(m,
"IntegerType");
123 py::class_<SIntType, IntegerType>(m,
"SIntType");
124 py::class_<UIntType, IntegerType>(m,
"UIntType");
125 py::class_<StructType, Type>(m,
"StructType")
126 .def_property_readonly(
"fields", &StructType::getFields,
127 py::return_value_policy::reference);
128 py::class_<ArrayType, Type>(m,
"ArrayType")
129 .def_property_readonly(
"element", &ArrayType::getElementType,
130 py::return_value_policy::reference)
131 .def_property_readonly(
"size", &ArrayType::getSize);
133 py::class_<Constant>(m,
"Constant")
134 .def_property_readonly(
"value", [](
Constant &c) {
return c.
value; })
135 .def_property_readonly(
137 py::return_value_policy::reference);
139 py::class_<AppID>(m,
"AppID")
140 .def(py::init<std::string, std::optional<uint32_t>>(), py::arg(
"name"),
141 py::arg(
"idx") = std::nullopt)
142 .def_property_readonly(
"name", [](
AppID &
id) {
return id.name; })
143 .def_property_readonly(
"idx",
144 [](
AppID &
id) -> py::object {
146 return py::cast(
id.idx);
151 std::string ret =
"<" +
id.name;
153 ret = ret +
"[" + std::to_string(*
id.idx) +
"]";
157 .def(
"__eq__", [](
AppID &a,
AppID &b) {
return a == b; })
158 .def(
"__hash__", [](
AppID &
id) {
160 std::hash<uint32_t>{}(
id.idx.value_or(-1)));
164 py::class_<ModuleInfo>(m,
"ModuleInfo")
165 .def_property_readonly(
"name", [](
ModuleInfo &info) {
return info.
name; })
166 .def_property_readonly(
"summary",
168 .def_property_readonly(
"version",
170 .def_property_readonly(
"repo", [](
ModuleInfo &info) {
return info.
repo; })
171 .def_property_readonly(
"commit_hash",
173 .def_property_readonly(
"constants",
178 std::stringstream os(ret);
183 py::enum_<Logger::Level>(m,
"LogLevel")
184 .value(
"Debug", Logger::Level::Debug)
185 .value(
"Info", Logger::Level::Info)
186 .value(
"Warning", Logger::Level::Warning)
187 .value(
"Error", Logger::Level::Error)
189 py::class_<Logger>(m,
"Logger");
191 py::class_<services::Service>(m,
"Service");
193 py::class_<SysInfo, services::Service>(m,
"SysInfo")
197 py::class_<MMIO::RegionDescriptor>(m,
"MMIORegionDescriptor")
198 .def_property_readonly(
"base",
200 .def_property_readonly(
"size",
202 py::class_<services::MMIO, services::Service>(m,
"MMIO")
206 py::return_value_policy::reference);
208 py::class_<services::HostMem::HostMemRegion>(m,
"HostMemRegion")
209 .def_property_readonly(
"ptr",
211 return reinterpret_cast<uintptr_t
>(mem.
getPtr());
213 .def_property_readonly(
"size",
216 py::class_<services::HostMem::Options>(m,
"HostMemOptions")
219 .def_readwrite(
"use_large_pages",
222 std::string ret =
"HostMemOptions(";
226 ret +=
"use_large_pages";
231 py::class_<services::HostMem, services::Service>(m,
"HostMem")
234 py::return_value_policy::take_ownership)
238 return self.
mapMemory(
reinterpret_cast<void *
>(ptr), size, opts);
240 py::arg(
"ptr"), py::arg(
"size"),
244 [](
HostMem &self, uintptr_t ptr) {
245 return self.
unmapMemory(
reinterpret_cast<void *
>(ptr));
250 py::class_<std::future<MessageData>>(m,
"MessageDataFuture")
252 [](std::future<MessageData> &f) {
258 .def(
"wait", &std::future<MessageData>::wait)
259 .def(
"get", [](std::future<MessageData> &f) {
261 return py::bytearray((
const char *)data.getBytes(), data.getSize());
264 py::class_<ChannelPort>(m,
"ChannelPort")
266 py::arg(
"buffer_size") = std::nullopt)
269 py::return_value_policy::reference);
271 py::class_<WriteChannelPort, ChannelPort>(m,
"WriteChannelPort")
274 py::buffer_info info(py::buffer(data).request());
275 std::vector<uint8_t> dataVec((uint8_t *)info.ptr,
276 (uint8_t *)info.ptr + info.size);
280 py::buffer_info info(py::buffer(data).request());
281 std::vector<uint8_t> dataVec((uint8_t *)info.ptr,
282 (uint8_t *)info.ptr + info.size);
285 py::class_<ReadChannelPort, ChannelPort>(m,
"ReadChannelPort")
291 return py::bytearray((
const char *)data.getBytes(), data.getSize());
293 "Read data from the channel. Blocking.")
296 py::class_<BundlePort>(m,
"BundlePort")
297 .def_property_readonly(
"id", &BundlePort::getID)
298 .def_property_readonly(
"channels", &BundlePort::getChannels,
299 py::return_value_policy::reference)
300 .def(
"getWrite", &BundlePort::getRawWrite,
301 py::return_value_policy::reference)
302 .def(
"getRead", &BundlePort::getRawRead,
303 py::return_value_policy::reference);
305 py::class_<ServicePort, BundlePort>(m,
"ServicePort");
307 py::class_<MMIO::MMIORegion, ServicePort>(m,
"MMIORegion")
312 py::class_<FuncService::Function, ServicePort>(m,
"Function")
316 py::bytearray msg) -> std::future<MessageData> {
317 py::buffer_info info(py::buffer(msg).request());
318 std::vector<uint8_t> dataVec((uint8_t *)info.ptr,
319 (uint8_t *)info.ptr + info.size);
321 return self.call(data);
323 py::return_value_policy::take_ownership)
329 py::class_<HWModule>(m,
"HWModule")
332 py::return_value_policy::reference)
334 py::return_value_policy::reference);
337 py::class_<Instance, HWModule>(m,
"Instance")
340 py::class_<Accelerator, HWModule>(m,
"Accelerator");
345 py::return_value_policy::reference);
347 auto accConn = py::class_<AcceleratorConnection>(m,
"AcceleratorConnection");
349 py::class_<Context>(m,
"Context")
353 ctxt.setLogger(std::make_unique<StreamLogger>(level));
362 py::return_value_policy::reference)
368 py::return_value_policy::reference)
370 "get_service_hostmem",
374 py::return_value_policy::reference);
376 py::class_<Manifest>(m,
"Manifest")
377 .def(py::init<Context &, std::string>())
378 .def_property_readonly(
"api_version", &Manifest::getApiVersion)
382 auto acc = m.buildAccelerator(conn);
386 py::return_value_policy::reference)
387 .def_property_readonly(
"type_table",
389 std::vector<py::object> ret;
390 std::ranges::transform(m.getTypeTable(),
391 std::back_inserter(ret),
395 .def_property_readonly(
"module_infos", &Manifest::getModuleInfos);
AcceleratorConnections, Accelerators, and Manifests must all share a context.
std::unique_ptr< AcceleratorConnection > connect(std::string backend, std::string connection)
Connect to an accelerator backend.