| 3029 | } |
| 3030 | |
| 3031 | void ExposeOperator(py::module &m) { |
| 3032 | py::class_<OperatorBase, py::smart_holder>(m, "_Operator") |
| 3033 | .def(py::init([](const OpSpec &spec) { |
| 3034 | DomainTimeRange tr("Instantiate " + GetOpDisplayName(spec, true), kDynamicDefaultColor); |
| 3035 | return dali::InstantiateOperator(spec); |
| 3036 | })) |
| 3037 | .def("Setup", [](OperatorBase &self, std::vector<dali::OutputDesc> &out_descs, Workspace &ws) { |
| 3038 | py::gil_scoped_release interpreter_unlock{}; |
| 3039 | DomainTimeRange tr("Setup " + GetOpDisplayName(self.GetSpec(), true), kDynamicDefaultColor); |
| 3040 | return self.Setup(out_descs, ws); |
| 3041 | }) |
| 3042 | .def("Run", [](OperatorBase &self, Workspace &ws) { |
| 3043 | py::gil_scoped_release interpreter_unlock{}; |
| 3044 | DomainTimeRange tr("Run " + GetOpDisplayName(self.GetSpec(), true), kDynamicDefaultColor); |
| 3045 | self.Run(ws); |
| 3046 | } ) |
| 3047 | .def("SetupAndRun", [](OperatorBase &self, PyWorkspace &ws, std::optional<int> batch_size) { |
| 3048 | py::gil_scoped_release interpreter_unlock{}; |
| 3049 | SetupAndRun(self, ws, batch_size); |
| 3050 | }, "ws"_a, "batch_size"_a = py::none()) |
| 3051 | .def("GetReaderMeta", [](OperatorBase &self) { |
| 3052 | return ReaderMetaToDict(self.GetReaderMeta()); |
| 3053 | }) |
| 3054 | .def("SaveCheckpoint", [](OperatorBase &self, py::object stream) -> py::bytes { |
| 3055 | // Saves the operator state, serializes it and returns the serialized representation. |
| 3056 | // Used by the dynamic API to expose stateful operator checkpointing to Python. |
| 3057 | // The returned blob may contain arbitrary bytes (e.g. protobuf-serialized loader |
| 3058 | // state), so it is returned as `py::bytes` to avoid UTF-8 conversion. |
| 3059 | OpCheckpoint cpt(self.GetSpec().SchemaName()); |
| 3060 | self.SaveState(cpt, AccessOrderFromPythonStreamObj(stream)); |
| 3061 | return py::bytes(self.SerializeCheckpoint(cpt)); |
| 3062 | }, "stream"_a = py::none()) |
| 3063 | .def("RestoreCheckpoint", [](OperatorBase &self, const std::string &data) { |
| 3064 | // Deserializes the operator state from a string/bytes blob and restores it. |
| 3065 | OpCheckpoint cpt(self.GetSpec().SchemaName()); |
| 3066 | self.DeserializeCheckpoint(cpt, data); |
| 3067 | self.RestoreState(cpt); |
| 3068 | }, "data"_a); |
| 3069 | } |
| 3070 | |
| 3071 | auto GetSupportedBackends(OpSchema &schema) { |
| 3072 | std::vector<std::string_view> ret; |
no test coverage detected