From 82ebcbbb16b0798572661809200e45b7a26c17f0 Mon Sep 17 00:00:00 2001 From: Dave Rowenhorst <45666721+drowenhorst-nrl@users.noreply.github.com> Date: Thu, 23 May 2024 11:02:46 -0400 Subject: [PATCH] NLPAR GPU (#57) * Improved NLPAR CPU reporting. * Attempt to fix package test Signed-off by: David Rowenhorst --- pyebsdindex/nlpar_cpu.py | 31 ++++++++++++++++++++++++------- pyebsdindex/tests/test_package.py | 10 ++++++++-- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/pyebsdindex/nlpar_cpu.py b/pyebsdindex/nlpar_cpu.py index 129968a..28e5a55 100644 --- a/pyebsdindex/nlpar_cpu.py +++ b/pyebsdindex/nlpar_cpu.py @@ -189,7 +189,7 @@ def getoutfileobj(self): return None def opt_lambda(self,chunksize=0,saturation_protect=True,automask=True, backsub = False, - target_weights=[0.5, 0.34, 0.25], dthresh=0.0, autoupdate=True, **kwargs): + target_weights=(0.5, 0.34, 0.25), dthresh=0.0, autoupdate=True, verbose = 2, **kwargs): target_weights = np.asarray(target_weights) @@ -250,7 +250,11 @@ def d2norm(d2, n2, dij, sigma): lamopt_values = [] for j in range(0,nrows,chunksize): - print('Block',j) + + if verbose >= 2: + print("begin row: ", j, "/", nrows, sep='', end='\r') + #print('Block',j) + #rowstartread = np.int64(max(0,j - nn)) rowstartread = np.int64(j) rowend = min(j + chunksize + nn,nrows) @@ -285,9 +289,14 @@ def d2norm(d2, n2, dij, sigma): lamopt_values.append(lamopt_values_chnk) + + if verbose >= 2: + print('', end='') lamopt_values = np.asarray(lamopt_values) - print("Range of lambda values: ", np.mean(lamopt_values, axis = 0).flatten()) - print("Optimal Choice: ", np.median(np.mean(lamopt_values, axis = 0))) + if verbose >=1: + print("Range of lambda values: ", np.mean(lamopt_values, axis = 0).flatten()) + print("Optimal Choice: ", np.median(np.mean(lamopt_values, axis = 0))) + if autoupdate == True: self.lam = np.median(np.mean(lamopt_values, axis = 0)) if self.sigma is None: @@ -295,7 +304,8 @@ def d2norm(d2, n2, dij, sigma): return np.mean(lamopt_values, axis = 0).flatten() def calcnlpar(self, chunksize=0, searchradius=None, lam = None, dthresh = None, saturation_protect=True, automask=True, - filename=None, fileout=None, reset_sigma=False, backsub = False, rescale = False, **kwargs): + filename=None, fileout=None, reset_sigma=False, backsub = False, rescale = False,verbose=2, + **kwargs): if lam is not None: self.lam = lam @@ -381,10 +391,13 @@ def calcnlpar(self, chunksize=0, searchradius=None, lam = None, dthresh = None, nthreadpos = numba.get_num_threads() #numba.set_num_threads(36) colstartcount = np.asarray([0,ncols],dtype=np.int64) - print(lam, sr, dthresh) + if verbose >= 1: + print("lambda:", self.lam, "search radius:", self.searchradius, "dthresh:", self.dthresh) for j in range(0,nrows,chunksize): - print('Row start', j) + #print('Row start', j) + if verbose >= 2: + print("begin row: ", j, "/", nrows, sep='', end='\r') rowstartread = np.int64(max(0, j-sr)) rowend = min(j + chunksize+sr,nrows) @@ -436,6 +449,10 @@ def calcnlpar(self, chunksize=0, searchradius=None, lam = None, dthresh = None, #sigma[j:j+rowstartcount[1],:] += \ # sigchunk[rowstartcount[0]:rowstartcount[0]+rowstartcount[1],:] + + if verbose >= 2: + print('', end='') + numba.set_num_threads(nthreadpos) return str(patternfileout.filepath) diff --git a/pyebsdindex/tests/test_package.py b/pyebsdindex/tests/test_package.py index 2d2706b..f046ff3 100644 --- a/pyebsdindex/tests/test_package.py +++ b/pyebsdindex/tests/test_package.py @@ -39,9 +39,15 @@ def test_available_functionality_without_pyopencl(): @pytest.mark.skipif(_pyopencl_installed, reason="pyopencl is installed") def test_unavailable_functionality_without_pyopencl(): with pytest.raises(ImportError): - raise ImportError() - #from pyebsdindex.opencl.band_detect_cl import BandDetect + from pyebsdindex.opencl import openclparam + try: + clparam = openclparam.OpenClParam() + gpu = clparam.get_gpu() + if len(gpu) < 1: + raise ImportError('') + except: + raise ImportError('') @pytest.mark.skipif(not _ray_installed, reason="ray is not installed") def test_available_functionality_with_ray():