110 py::class_<Type>(m,
"Type")
111 .def(py::init<const Type::ID &>(), py::arg(
"id"))
112 .def_property_readonly(
"id", &Type::getID)
113 .def(
"__repr__", [](
Type &t) {
return "<" + t.
getID() +
">"; });
114 py::class_<ChannelType, Type>(m,
"ChannelType")
115 .def(py::init<const Type::ID &, const Type *>(), py::arg(
"id"),
117 .def_property_readonly(
"inner", &ChannelType::getInner,
118 py::return_value_policy::reference);
119 py::enum_<BundleType::Direction>(m,
"Direction")
120 .value(
"To", BundleType::Direction::To)
121 .value(
"From", BundleType::Direction::From)
123 py::class_<BundleType, Type>(m,
"BundleType")
124 .def(py::init<const Type::ID &, const BundleType::ChannelVector &>(),
125 py::arg(
"id"), py::arg(
"channels"))
126 .def_property_readonly(
"channels", &BundleType::getChannels,
127 py::return_value_policy::reference);
128 py::class_<VoidType, Type>(m,
"VoidType")
129 .def(py::init<const Type::ID &>(), py::arg(
"id"));
130 py::class_<AnyType, Type>(m,
"AnyType")
131 .def(py::init<const Type::ID &>(), py::arg(
"id"));
132 py::class_<BitVectorType, Type>(m,
"BitVectorType")
133 .def(py::init<const Type::ID &, uint64_t>(), py::arg(
"id"),
136 py::class_<BitsType, BitVectorType>(m,
"BitsType")
137 .def(py::init<const Type::ID &, uint64_t>(), py::arg(
"id"),
139 py::class_<IntegerType, BitVectorType>(m,
"IntegerType")
140 .def(py::init<const Type::ID &, uint64_t>(), py::arg(
"id"),
142 py::class_<SIntType, IntegerType>(m,
"SIntType")
143 .def(py::init<const Type::ID &, uint64_t>(), py::arg(
"id"),
145 py::class_<UIntType, IntegerType>(m,
"UIntType")
146 .def(py::init<const Type::ID &, uint64_t>(), py::arg(
"id"),
148 py::class_<StructType, Type>(m,
"StructType")
149 .def(py::init<const Type::ID &, const StructType::FieldVector &, bool>(),
150 py::arg(
"id"), py::arg(
"fields"), py::arg(
"reverse") =
true)
151 .def_property_readonly(
"fields", &StructType::getFields,
152 py::return_value_policy::reference)
153 .def_property_readonly(
"reverse", &StructType::isReverse);
154 py::class_<ArrayType, Type>(m,
"ArrayType")
155 .def(py::init<const Type::ID &, const Type *, uint64_t>(), py::arg(
"id"),
156 py::arg(
"element_type"), py::arg(
"size"))
157 .def_property_readonly(
"element", &ArrayType::getElementType,
158 py::return_value_policy::reference)
159 .def_property_readonly(
"size", &ArrayType::getSize);
161 py::class_<Constant>(m,
"Constant")
162 .def_property_readonly(
"value", [](
Constant &c) {
return c.
value; })
163 .def_property_readonly(
165 py::return_value_policy::reference);
167 py::class_<AppID>(m,
"AppID")
168 .def(py::init<std::string, std::optional<uint32_t>>(), py::arg(
"name"),
169 py::arg(
"idx") = std::nullopt)
170 .def_property_readonly(
"name", [](
AppID &
id) {
return id.name; })
171 .def_property_readonly(
"idx",
172 [](
AppID &
id) -> py::object {
174 return py::cast(
id.idx);
179 std::string ret =
"<" +
id.name;
181 ret = ret +
"[" + std::to_string(*
id.idx) +
"]";
185 .def(
"__eq__", [](
AppID &a,
AppID &b) {
return a == b; })
186 .def(
"__hash__", [](
AppID &
id) {
188 std::hash<uint32_t>{}(
id.idx.value_or(-1)));
192 py::class_<ModuleInfo>(m,
"ModuleInfo")
193 .def_property_readonly(
"name", [](
ModuleInfo &info) {
return info.name; })
194 .def_property_readonly(
"summary",
195 [](
ModuleInfo &info) {
return info.summary; })
196 .def_property_readonly(
"version",
197 [](
ModuleInfo &info) {
return info.version; })
198 .def_property_readonly(
"repo", [](
ModuleInfo &info) {
return info.repo; })
199 .def_property_readonly(
"commit_hash",
200 [](
ModuleInfo &info) {
return info.commitHash; })
201 .def_property_readonly(
"constants",
202 [](
ModuleInfo &info) {
return info.constants; })
206 std::stringstream os(ret);
211 py::enum_<Logger::Level>(m,
"LogLevel")
212 .value(
"Debug", Logger::Level::Debug)
213 .value(
"Info", Logger::Level::Info)
214 .value(
"Warning", Logger::Level::Warning)
215 .value(
"Error", Logger::Level::Error)
217 py::class_<Logger>(m,
"Logger");
219 py::class_<services::Service>(m,
"Service");
221 py::class_<SysInfo, services::Service>(m,
"SysInfo")
225 py::class_<MMIO::RegionDescriptor>(m,
"MMIORegionDescriptor")
226 .def_property_readonly(
"base",
228 .def_property_readonly(
"size",
230 py::class_<services::MMIO, services::Service>(m,
"MMIO")
234 py::return_value_policy::reference);
236 py::class_<services::HostMem::HostMemRegion>(m,
"HostMemRegion")
237 .def_property_readonly(
"ptr",
239 return reinterpret_cast<uintptr_t
>(mem.
getPtr());
241 .def_property_readonly(
"size",
244 py::class_<services::HostMem::Options>(m,
"HostMemOptions")
247 .def_readwrite(
"use_large_pages",
250 std::string ret =
"HostMemOptions(";
254 ret +=
"use_large_pages";
259 py::class_<services::HostMem, services::Service>(m,
"HostMem")
262 py::return_value_policy::take_ownership)
266 return self.
mapMemory(
reinterpret_cast<void *
>(ptr), size, opts);
268 py::arg(
"ptr"), py::arg(
"size"),
272 [](
HostMem &self, uintptr_t ptr) {
273 return self.
unmapMemory(
reinterpret_cast<void *
>(ptr));
278 py::class_<std::future<MessageData>>(m,
"MessageDataFuture")
280 [](std::future<MessageData> &f) {
287 [](std::future<MessageData> &f) {
290 py::gil_scoped_release release{};
293 .def(
"get", [](std::future<MessageData> &f) {
294 std::optional<MessageData> data;
298 py::gil_scoped_release release{};
299 data.emplace(f.get());
301 return py::bytearray((
const char *)data->getBytes(), data->getSize());
304 py::class_<ChannelPort>(m,
"ChannelPort")
306 py::arg(
"buffer_size") = std::nullopt)
309 py::return_value_policy::reference);
311 py::class_<WriteChannelPort, ChannelPort>(m,
"WriteChannelPort")
314 py::buffer_info info(py::buffer(data).request());
315 std::vector<uint8_t> dataVec((uint8_t *)info.ptr,
316 (uint8_t *)info.ptr + info.size);
320 py::buffer_info info(py::buffer(data).request());
321 std::vector<uint8_t> dataVec((uint8_t *)info.ptr,
322 (uint8_t *)info.ptr + info.size);
325 py::class_<ReadChannelPort, ChannelPort>(m,
"ReadChannelPort")
331 return py::bytearray((
const char *)data.getBytes(), data.getSize());
333 "Read data from the channel. Blocking.")
336 py::class_<BundlePort>(m,
"BundlePort")
337 .def_property_readonly(
"id", &BundlePort::getID)
338 .def_property_readonly(
"channels", &BundlePort::getChannels,
339 py::return_value_policy::reference)
340 .def(
"getWrite", &BundlePort::getRawWrite,
341 py::return_value_policy::reference)
342 .def(
"getRead", &BundlePort::getRawRead,
343 py::return_value_policy::reference);
345 py::class_<ServicePort, BundlePort>(m,
"ServicePort");
347 py::class_<MMIO::MMIORegion, ServicePort>(m,
"MMIORegion")
352 py::class_<FuncService::Function, ServicePort>(m,
"Function")
356 py::bytearray msg) -> std::future<MessageData> {
357 py::buffer_info info(py::buffer(msg).request());
358 std::vector<uint8_t> dataVec((uint8_t *)info.ptr,
359 (uint8_t *)info.ptr + info.size);
361 return self.call(data);
363 py::return_value_policy::take_ownership)
366 py::class_<CallService::Callback, ServicePort>(m,
"Callback")
368 std::function<py::object(py::object)> pyCallback) {
373 py::gil_scoped_acquire acquire{};
374 std::vector<uint8_t> arg(req.
getBytes(),
376 py::bytearray argObj((
const char *)arg.data(), arg.size());
377 auto ret = pyCallback(argObj);
380 py::buffer_info info(py::buffer(ret).request());
381 std::vector<uint8_t> dataVec((uint8_t *)info.ptr,
382 (uint8_t *)info.ptr + info.size);
387 py::class_<TelemetryService::Telemetry, ServicePort>(m,
"Telemetry")
394 py::class_<HWModule>(m,
"HWModule")
397 py::return_value_policy::reference)
399 py::return_value_policy::reference);
402 py::class_<Instance, HWModule>(m,
"Instance")
405 py::class_<Accelerator, HWModule>(m,
"Accelerator");
410 py::return_value_policy::reference);
412 auto accConn = py::class_<AcceleratorConnection>(m,
"AcceleratorConnection");
414 py::class_<Context>(m,
"Context")
416 .def(
"connect", &Context::connect)
418 ctxt.setLogger(std::make_unique<StreamLogger>(level));
427 py::return_value_policy::reference)
433 py::return_value_policy::reference)
435 "get_service_hostmem",
439 py::return_value_policy::reference)
441 py::return_value_policy::reference);
443 py::class_<Manifest>(m,
"Manifest")
444 .def(py::init<Context &, std::string>())
445 .def_property_readonly(
"api_version", &Manifest::getApiVersion)
449 auto acc = m.buildAccelerator(conn);
453 py::return_value_policy::reference)
454 .def_property_readonly(
"type_table",
456 std::vector<py::object> ret;
457 std::ranges::transform(m.getTypeTable(),
458 std::back_inserter(ret),
462 .def_property_readonly(
"module_infos", &Manifest::getModuleInfos);