From 6f8bcdc774e1cb1460bed78752f2b2adf8ff2b50 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk <21087696+oleksandr-pavlyk@users.noreply.github.com> Date: Tue, 1 Jul 2025 14:53:54 -0500 Subject: [PATCH] Fixed correctness of nvbench.State.getStream() method Fix run-time exception: ``` Fail: Unexpected error: RuntimeError: return_value_policy = copy, but type is non-copyable! (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details) ``` caused by attempt to returning move-only `nvbench::cuda_stream` class instance using default `pybind11::return_value_policy::copy`. --- python/src/py_nvbench.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/src/py_nvbench.cpp b/python/src/py_nvbench.cpp index ab15b5a..c940587 100644 --- a/python/src/py_nvbench.cpp +++ b/python/src/py_nvbench.cpp @@ -345,7 +345,10 @@ PYBIND11_MODULE(_nvbench, m) return state.get_benchmark().get_printer().has_value(); }); - pystate_cls.def("getStream", &nvbench::state::get_cuda_stream); + pystate_cls.def( + "getStream", + [](nvbench::state &state) { return std::ref(state.get_cuda_stream()); }, + py::return_value_policy::reference); pystate_cls.def("getInt64", &nvbench::state::get_int64); pystate_cls.def("getInt64", &nvbench::state::get_int64_or_default);