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 &>(),
150 py::arg(
"id"), py::arg(
"fields"))
151 .def_property_readonly(
"fields", &StructType::getFields,
152 py::return_value_policy::reference);
153 py::class_<ArrayType, Type>(m,
"ArrayType")
154 .def(py::init<const Type::ID &, const Type *, uint64_t>(), py::arg(
"id"),
155 py::arg(
"element_type"), py::arg(
"size"))
156 .def_property_readonly(
"element", &ArrayType::getElementType,
157 py::return_value_policy::reference)
158 .def_property_readonly(
"size", &ArrayType::getSize);
160 py::class_<Constant>(m,
"Constant")
161 .def_property_readonly(
"value", [](
Constant &c) {
return c.
value; })
162 .def_property_readonly(
164 py::return_value_policy::reference);
166 py::class_<AppID>(m,
"AppID")
167 .def(py::init<std::string, std::optional<uint32_t>>(), py::arg(
"name"),
168 py::arg(
"idx") = std::nullopt)
169 .def_property_readonly(
"name", [](
AppID &
id) {
return id.name; })
170 .def_property_readonly(
"idx",
171 [](
AppID &
id) -> py::object {
173 return py::cast(
id.idx);
178 std::string ret =
"<" +
id.name;
180 ret = ret +
"[" + std::to_string(*
id.idx) +
"]";
184 .def(
"__eq__", [](
AppID &a,
AppID &b) {
return a == b; })
185 .def(
"__hash__", [](
AppID &
id) {
187 std::hash<uint32_t>{}(
id.idx.value_or(-1)));
191 py::class_<ModuleInfo>(m,
"ModuleInfo")
192 .def_property_readonly(
"name", [](
ModuleInfo &info) {
return info.name; })
193 .def_property_readonly(
"summary",
194 [](
ModuleInfo &info) {
return info.summary; })
195 .def_property_readonly(
"version",
196 [](
ModuleInfo &info) {
return info.version; })
197 .def_property_readonly(
"repo", [](
ModuleInfo &info) {
return info.repo; })
198 .def_property_readonly(
"commit_hash",
199 [](
ModuleInfo &info) {
return info.commitHash; })
200 .def_property_readonly(
"constants",
201 [](
ModuleInfo &info) {
return info.constants; })
205 std::stringstream os(ret);
210 py::enum_<Logger::Level>(m,
"LogLevel")
211 .value(
"Debug", Logger::Level::Debug)
212 .value(
"Info", Logger::Level::Info)
213 .value(
"Warning", Logger::Level::Warning)
214 .value(
"Error", Logger::Level::Error)
216 py::class_<Logger>(m,
"Logger");
218 py::class_<services::Service>(m,
"Service");
220 py::class_<SysInfo, services::Service>(m,
"SysInfo")
224 py::class_<MMIO::RegionDescriptor>(m,
"MMIORegionDescriptor")
225 .def_property_readonly(
"base",
227 .def_property_readonly(
"size",
229 py::class_<services::MMIO, services::Service>(m,
"MMIO")
233 py::return_value_policy::reference);
235 py::class_<services::HostMem::HostMemRegion>(m,
"HostMemRegion")
236 .def_property_readonly(
"ptr",
238 return reinterpret_cast<uintptr_t
>(mem.
getPtr());
240 .def_property_readonly(
"size",
243 py::class_<services::HostMem::Options>(m,
"HostMemOptions")
246 .def_readwrite(
"use_large_pages",
249 std::string ret =
"HostMemOptions(";
253 ret +=
"use_large_pages";
258 py::class_<services::HostMem, services::Service>(m,
"HostMem")
261 py::return_value_policy::take_ownership)
265 return self.
mapMemory(
reinterpret_cast<void *
>(ptr), size, opts);
267 py::arg(
"ptr"), py::arg(
"size"),
271 [](
HostMem &self, uintptr_t ptr) {
272 return self.
unmapMemory(
reinterpret_cast<void *
>(ptr));
277 py::class_<std::future<MessageData>>(m,
"MessageDataFuture")
279 [](std::future<MessageData> &f) {
286 [](std::future<MessageData> &f) {
289 py::gil_scoped_release release{};
292 .def(
"get", [](std::future<MessageData> &f) {
293 std::optional<MessageData> data;
297 py::gil_scoped_release release{};
298 data.emplace(f.get());
300 return py::bytearray((
const char *)data->getBytes(), data->getSize());
303 py::class_<ChannelPort>(m,
"ChannelPort")
305 py::arg(
"buffer_size") = std::nullopt)
308 py::return_value_policy::reference);
310 py::class_<WriteChannelPort, ChannelPort>(m,
"WriteChannelPort")
313 py::buffer_info info(py::buffer(data).request());
314 std::vector<uint8_t> dataVec((uint8_t *)info.ptr,
315 (uint8_t *)info.ptr + info.size);
319 py::buffer_info info(py::buffer(data).request());
320 std::vector<uint8_t> dataVec((uint8_t *)info.ptr,
321 (uint8_t *)info.ptr + info.size);
324 py::class_<ReadChannelPort, ChannelPort>(m,
"ReadChannelPort")
330 return py::bytearray((
const char *)data.getBytes(), data.getSize());
332 "Read data from the channel. Blocking.")
335 py::class_<BundlePort>(m,
"BundlePort")
336 .def_property_readonly(
"id", &BundlePort::getID)
337 .def_property_readonly(
"channels", &BundlePort::getChannels,
338 py::return_value_policy::reference)
339 .def(
"getWrite", &BundlePort::getRawWrite,
340 py::return_value_policy::reference)
341 .def(
"getRead", &BundlePort::getRawRead,
342 py::return_value_policy::reference);
344 py::class_<ServicePort, BundlePort>(m,
"ServicePort");
346 py::class_<MMIO::MMIORegion, ServicePort>(m,
"MMIORegion")
351 py::class_<FuncService::Function, ServicePort>(m,
"Function")
355 py::bytearray msg) -> std::future<MessageData> {
356 py::buffer_info info(py::buffer(msg).request());
357 std::vector<uint8_t> dataVec((uint8_t *)info.ptr,
358 (uint8_t *)info.ptr + info.size);
360 return self.call(data);
362 py::return_value_policy::take_ownership)
365 py::class_<CallService::Callback, ServicePort>(m,
"Callback")
367 std::function<py::object(py::object)> pyCallback) {
372 py::gil_scoped_acquire acquire{};
373 std::vector<uint8_t> arg(req.
getBytes(),
375 py::bytearray argObj((
const char *)arg.data(), arg.size());
376 auto ret = pyCallback(argObj);
379 py::buffer_info info(py::buffer(ret).request());
380 std::vector<uint8_t> dataVec((uint8_t *)info.ptr,
381 (uint8_t *)info.ptr + info.size);
386 py::class_<TelemetryService::Telemetry, ServicePort>(m,
"Telemetry")
393 py::class_<HWModule>(m,
"HWModule")
396 py::return_value_policy::reference)
398 py::return_value_policy::reference);
401 py::class_<Instance, HWModule>(m,
"Instance")
404 py::class_<Accelerator, HWModule>(m,
"Accelerator");
409 py::return_value_policy::reference);
411 auto accConn = py::class_<AcceleratorConnection>(m,
"AcceleratorConnection");
413 py::class_<Context>(m,
"Context")
415 .def(
"connect", &Context::connect)
417 ctxt.setLogger(std::make_unique<StreamLogger>(level));
426 py::return_value_policy::reference)
432 py::return_value_policy::reference)
434 "get_service_hostmem",
438 py::return_value_policy::reference)
440 py::return_value_policy::reference);
442 py::class_<Manifest>(m,
"Manifest")
443 .def(py::init<Context &, std::string>())
444 .def_property_readonly(
"api_version", &Manifest::getApiVersion)
448 auto acc = m.buildAccelerator(conn);
452 py::return_value_policy::reference)
453 .def_property_readonly(
"type_table",
455 std::vector<py::object> ret;
456 std::ranges::transform(m.getTypeTable(),
457 std::back_inserter(ret),
461 .def_property_readonly(
"module_infos", &Manifest::getModuleInfos);