From 87939d59e12459376e2b341f4fef168438d6def7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20=C5=81opaciuk?= Date: Mon, 17 Jun 2024 14:38:03 +0200 Subject: [PATCH] Select correct devices when tests run with XOBJECTS_TEST_CONTEXTS --- xobjects/context_cupy.py | 3 +++ xobjects/context_pyopencl.py | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/xobjects/context_cupy.py b/xobjects/context_cupy.py index ba3c427..186907d 100644 --- a/xobjects/context_cupy.py +++ b/xobjects/context_cupy.py @@ -473,6 +473,9 @@ def build_kernels( return out_kernels + def __str__(self): + return f"{type(self).__name__}:{cupy.cuda.get_device_id()}" + def nparray_to_context_array(self, arr): """ Copies a numpy array to the device memory. diff --git a/xobjects/context_pyopencl.py b/xobjects/context_pyopencl.py index 45b5a83..c5277e3 100644 --- a/xobjects/context_pyopencl.py +++ b/xobjects/context_pyopencl.py @@ -219,7 +219,7 @@ def build_kernels( fid.write(specialized_source) prg = cl.Program(self.context, specialized_source).build( - options="-cl-std=CL2.0" + options="-cl-std=CL2.0", ) out_kernels = {} @@ -238,6 +238,11 @@ def build_kernels( return out_kernels + def __str__(self): + platform_id = cl.get_platforms().index(self.platform) + device_id = self.platform.get_devices().index(self.device) + return f"{type(self).__name__}:{platform_id}.{device_id}" + def nparray_to_context_array(self, arr): """ Copies a numpy array to the device memory.