Skip to content

Commit

Permalink
NLPAR GPU (#57)
Browse files Browse the repository at this point in the history
* Improved NLPAR CPU reporting.
* Attempt to fix package test

Signed-off by: David Rowenhorst <[email protected]>
  • Loading branch information
drowenhorst-nrl authored May 23, 2024
1 parent 88136e6 commit 82ebcbb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
31 changes: 24 additions & 7 deletions pyebsdindex/nlpar_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -285,17 +289,23 @@ 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:
self.sigma = 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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
10 changes: 8 additions & 2 deletions pyebsdindex/tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 82ebcbb

Please sign in to comment.