From d721624adebb144c9feeb50d8c0b8b296b7d9623 Mon Sep 17 00:00:00 2001 From: "[6~" Date: Mon, 27 Jan 2020 18:49:05 -0600 Subject: [PATCH] Fix PyOpenCL target device comparison semantics --- loopy/target/pyopencl.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/loopy/target/pyopencl.py b/loopy/target/pyopencl.py index c5e8d0a7f..826ba2a8f 100644 --- a/loopy/target/pyopencl.py +++ b/loopy/target/pyopencl.py @@ -299,7 +299,26 @@ class PyOpenCLTarget(OpenCLTarget): self.device = device self.pyopencl_module_name = pyopencl_module_name - comparison_fields = ["device"] + # NB: Not including 'device', as that is handled specially here. + hash_fields = OpenCLTarget.hash_fields + ( + "pyopencl_module_name",) + comparison_fields = OpenCLTarget.comparison_fields + ( + "pyopencl_module_name",) + + def __eq__(self, other): + if not super(PyOpenCLTarget, self).__eq__(other): + return False + + if (self.device is None) != (other.device is None): + return False + + if self.device is not None: + assert other.device is not None + return (self.device.persistent_unique_id + == other.device.persistent_unique_id) + else: + assert other.device is None + return True def update_persistent_hash(self, key_hash, key_builder): super(PyOpenCLTarget, self).update_persistent_hash(key_hash, key_builder) -- GitLab