From c3fa34e66dbf19a737ed6660c204d6869c056984 Mon Sep 17 00:00:00 2001 From: TPP-G6 Date: Wed, 28 Jan 2026 10:23:00 +0800 Subject: [PATCH] fix hhd d_gpu bug if cuda=false --- src/orisys/HHD.py | 16 ++++++++++------ src/orisys/sensor.py | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/orisys/HHD.py b/src/orisys/HHD.py index ca326ea..f3c301b 100644 --- a/src/orisys/HHD.py +++ b/src/orisys/HHD.py @@ -75,7 +75,14 @@ except ImportError: class nHHD(object): # constructor - def __init__(self, **kwargs): + def __init__(self, cuda=True, **kwargs): + self.cuda = cuda + if self.cuda and CUPY_AVAILABLE: + self.stream1 = cp.cuda.Stream() + self.stream2 = cp.cuda.Stream() + else: + self.stream1 = None + self.stream2 = None args = kwargs.keys() @@ -104,9 +111,6 @@ class nHHD(object): raise ValueError("nHHD Solver works only for 2 and 3 dimensions") self.psolver.prepare(False) - if CUPY_AVAILABLE: - self.stream1 = cp.cuda.Stream() - self.stream2 = cp.cuda.Stream() # create the 3-component decomposition def decompose(self, vfield, verbose=0): @@ -447,12 +451,12 @@ class nHHD(object): cp.get_default_memory_pool().free_all_blocks() def get_shear(self): - if not CUPY_AVAILABLE: + if not self.cuda or not CUPY_AVAILABLE: return self.h return cp.asnumpy(self._h_gpu) def get_normal(self): - if not CUPY_AVAILABLE: + if not self.cuda or not CUPY_AVAILABLE: return self.d return cp.asnumpy(self._d_gpu) diff --git a/src/orisys/sensor.py b/src/orisys/sensor.py index a05fc7d..998c6d9 100644 --- a/src/orisys/sensor.py +++ b/src/orisys/sensor.py @@ -228,7 +228,7 @@ class Sensor: # Initialize HHD solver if self.__hhd is None: - self.__hhd = nHHD(grid=flow.shape[:2], spacings=(18, 18)) + self.__hhd = nHHD(cuda=self.cuda, Qgrid=flow.shape[:2], spacings=(18, 18)) # Force computation if self.cuda and self.CUPY_AVAILABLE: