MCPcopy Create free account
hub / github.com/NVIDIA/DALI / ExposeOperator

Function ExposeOperator

dali/python/backend_impl.cc:3031–3069  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3029}
3030
3031void 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
3071auto GetSupportedBackends(OpSchema &schema) {
3072 std::vector<std::string_view> ret;

Callers 1

PYBIND11_MODULEFunction · 0.85

Calls 13

GetOpDisplayNameFunction · 0.85
InstantiateOperatorFunction · 0.85
SetupAndRunFunction · 0.85
ReaderMetaToDictFunction · 0.85
initFunction · 0.50
SetupMethod · 0.45
RunMethod · 0.45
GetReaderMetaMethod · 0.45
SaveStateMethod · 0.45
SerializeCheckpointMethod · 0.45
DeserializeCheckpointMethod · 0.45

Tested by

no test coverage detected