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

Function ExposePhilox

dali/python/backend_impl.cc:2721–2773  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2719}
2720
2721void ExposePhilox(py::module &m) {
2722 // Declare, but do not populate it yet; we need to define the nested class first.
2723 py::class_<Philox4x32_10> philox(m, "_Philox4x32_10");
2724
2725 py::class_<Philox4x32_10::State>(philox, "State")
2726 .def(py::init([](uint64_t key, uint64_t sequence, uint64_t offset) {
2727 return Philox4x32_10::State(key, sequence, offset);
2728 }), "key"_a, "sequence"_a, "offset"_a)
2729 .def(py::init([](uint64_t key, uint64_t ctr_hi, uint64_t ctr_lo, unsigned phase) {
2730 if (phase > 3)
2731 throw py::value_error("phase must be in [0, 3]");
2732 return Philox4x32_10::State(key, ctr_hi, ctr_lo, phase);
2733 }), "key"_a, "ctr_hi"_a, "ctr_lo"_a, "phase"_a)
2734 .def(py::init([](std::string_view str) {
2735 Philox4x32_10::State s;
2736 Philox4x32_10::state_from_string(s, str);
2737 return s;
2738 }), "str"_a)
2739 .def("__str__", [](const Philox4x32_10::State &s) {
2740 return Philox4x32_10::state_to_string(s);
2741 })
2742 .def("__repr__", [](const Philox4x32_10::State &s) {
2743 return make_string("Philox4x32_10.State('", Philox4x32_10::state_to_string(s), "')");
2744 })
2745 .def_static("parse", [](std::string_view str) {
2746 Philox4x32_10::State s;
2747 Philox4x32_10::state_from_string(s, str);
2748 return s;
2749 }, "str"_a);
2750
2751 philox
2752 .def(py::init([](uint64_t key, uint64_t sequence, uint64_t offset) {
2753 auto p = std::make_unique<Philox4x32_10>();
2754 p->init(key, sequence, offset);
2755 return p;
2756 }), "key"_a, "sequence"_a, "offset"_a)
2757 .def(py::init([](const Philox4x32_10::State &state) {
2758 return std::make_unique<Philox4x32_10>(state);
2759 }), "state"_a)
2760 .def(py::init([](std::string_view state_str) {
2761 Philox4x32_10::State state;
2762 Philox4x32_10::state_from_string(state, state_str);
2763 return std::make_unique<Philox4x32_10>(state);
2764 }), "state"_a)
2765 .def("next", &Philox4x32_10::next)
2766 .def("skipahead", &Philox4x32_10::skipahead, "n"_a)
2767 .def("skipahead_sequence", &Philox4x32_10::skipahead_sequence, "n"_a)
2768 .def("get_state", &Philox4x32_10::get_state)
2769 .def("set_state", &Philox4x32_10::set_state, "state"_a)
2770 .def("set_state", [](Philox4x32_10 &self, std::string_view state) {
2771 self.state_from_string(state);
2772 }, "state"_a);
2773}
2774
2775void ExposeStream(py::module &m) {
2776 py::class_<dali::CUDAStreamLease>(m, "Stream")

Callers 1

PYBIND11_MODULEFunction · 0.85

Calls 5

initFunction · 0.50
StateClass · 0.50
make_stringFunction · 0.50
initMethod · 0.45
state_from_stringMethod · 0.45

Tested by

no test coverage detected