From c834d9042981d1dff633520e7550183566a9c6a8 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Thu, 8 Aug 2024 16:02:51 +0000 Subject: [PATCH 1/2] Enable string-based UID for GPU selection --- .../core/src/bindings/BindingsCudaUtils.hpp | 10 +++++++++- .../core/src/utils/cuda_utils/DevicePool.hpp | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pennylane_lightning/core/src/bindings/BindingsCudaUtils.hpp b/pennylane_lightning/core/src/bindings/BindingsCudaUtils.hpp index 2a04ad4d63..c482e40511 100644 --- a/pennylane_lightning/core/src/bindings/BindingsCudaUtils.hpp +++ b/pennylane_lightning/core/src/bindings/BindingsCudaUtils.hpp @@ -65,7 +65,15 @@ void registerCudaUtils(py::module_ &m) { .def("syncDevice", &DevicePool::syncDevice) .def("refresh", &DevicePool::refresh) .def_static("getTotalDevices", &DevicePool::getTotalDevices) - .def_static("getDeviceUIDs", &DevicePool::getDeviceUIDs) + .def_static("getDeviceUIDs", [](){ + auto data = DevicePool::getDeviceUIDs(); + std::vector data_conv; + data_conv.reserve(data.size()); + for(auto d : data){ + data_conv.push_back(py::bytes(std::move(d))); + } + return data_conv; + }) .def_static("setDeviceID", &DevicePool::setDeviceIdx) .def(py::pickle( []([[maybe_unused]] const DevicePool &self) { // __getstate__ diff --git a/pennylane_lightning/core/src/utils/cuda_utils/DevicePool.hpp b/pennylane_lightning/core/src/utils/cuda_utils/DevicePool.hpp index 7ef3e25268..27a99ffadf 100644 --- a/pennylane_lightning/core/src/utils/cuda_utils/DevicePool.hpp +++ b/pennylane_lightning/core/src/utils/cuda_utils/DevicePool.hpp @@ -131,11 +131,11 @@ template class DevicePool { int deviceCount; cudaGetDeviceCount(&deviceCount); int device; - std::vector dev_uid(deviceCount); + std::vector dev_uid(deviceCount); for (device = 0; device < deviceCount; device++) { cudaDeviceProp deviceProp; cudaGetDeviceProperties(&deviceProp, device); - dev_uid[device] = deviceProp.uuid; + dev_uid[device] = std::string(deviceProp.uuid.bytes); } return dev_uid; } From 6822e0874d93250d4e2d619144fce584fd6cec7a Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Thu, 8 Aug 2024 16:13:48 +0000 Subject: [PATCH 2/2] Fix return type of UID func --- pennylane_lightning/core/src/utils/cuda_utils/DevicePool.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/src/utils/cuda_utils/DevicePool.hpp b/pennylane_lightning/core/src/utils/cuda_utils/DevicePool.hpp index 27a99ffadf..5bd1985680 100644 --- a/pennylane_lightning/core/src/utils/cuda_utils/DevicePool.hpp +++ b/pennylane_lightning/core/src/utils/cuda_utils/DevicePool.hpp @@ -127,7 +127,7 @@ template class DevicePool { * * @return std::vector */ - static std::vector getDeviceUIDs() { + static std::vector getDeviceUIDs() { int deviceCount; cudaGetDeviceCount(&deviceCount); int device;