Skip to content

Commit

Permalink
Refactor gpuid --> gpu_id to match rest of package.
Browse files Browse the repository at this point in the history
Signed-off by: David Rowenhorst <[email protected]>
  • Loading branch information
drowenhorst-nrl committed May 20, 2024
1 parent 4fbf081 commit 3d15720
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 54 deletions.
34 changes: 17 additions & 17 deletions pyebsdindex/opencl/nlpar_cl.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,29 @@ def loptfunc(lam, d2, tw, dthresh):
return lamopt_values.flatten()


def calcsigma_cl(self,nn=1,saturation_protect=True,automask=True, normalize_d=False, gpuid = None, **kwargs):
def calcsigma_cl(self,nn=1,saturation_protect=True,automask=True, normalize_d=False, gpu_id = None, **kwargs):

if gpuid is None:
if gpu_id is None:
clparams = openclparam.OpenClParam()
clparams.get_gpu()
target_mem = 0
gpuid = 0
gpu_id = 0
count = 0

for gpu in clparams.gpu:
gmem = gpu.max_mem_alloc_size
if target_mem < gmem:
gpuid = count
gpu_id = count
target_mem = gmem
count += 1
else:
clparams = openclparam.OpenClParam()
clparams.get_gpu()
gpuid = min(len(clparams.gpu)-1, gpuid)
gpu_id = min(len(clparams.gpu)-1, gpu_id)


#print(gpuid)
clparams.get_context(gpu_id=gpuid, kfile = 'clnlpar.cl')
#print(gpu_id)
clparams.get_context(gpu_id=gpu_id, kfile = 'clnlpar.cl')
clparams.get_queue()
target_mem = clparams.queue.device.max_mem_alloc_size//2
ctx = clparams.ctx
Expand Down Expand Up @@ -258,9 +258,9 @@ def calcsigma_cl(self,nn=1,saturation_protect=True,automask=True, normalize_d=Fa
self.sigma = sigma
return sigma, dist, countnn

def calcnlpar_cl(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,
gpuid = None, verbose=2, **kwargs):
def calcnlpar_cl(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,
gpu_id = None, verbose=2, **kwargs):

if lam is not None:
self.lam = lam
Expand Down Expand Up @@ -307,7 +307,7 @@ def calcnlpar_cl(self,chunksize=0, searchradius=None, lam = None, dthresh = None
self.sigma = None

if self.sigma is None:
self.sigma = self.calcsigma_cl(nn=1, saturation_protect=saturation_protect, automask=automask, gpuid=gpuid)[0]
self.sigma = self.calcsigma_cl(nn=1, saturation_protect=saturation_protect, automask=automask, gpu_id=gpu_id)[0]

sigma = np.asarray(self.sigma).astype(np.float32)

Expand All @@ -331,27 +331,27 @@ def calcnlpar_cl(self,chunksize=0, searchradius=None, lam = None, dthresh = None



if gpuid is None:
if gpu_id is None:
clparams = openclparam.OpenClParam()
clparams.get_gpu()
target_mem = 0
gpuid = 0
gpu_id = 0
count = 0

for gpu in clparams.gpu:
gmem = gpu.max_mem_alloc_size
if target_mem < gmem:
gpuid = count
gpu_id = count
target_mem = gmem
count += 1
else:
clparams = openclparam.OpenClParam()
clparams.get_gpu()
gpuid = min(len(clparams.gpu)-1, gpuid)
gpu_id = min(len(clparams.gpu) - 1, gpu_id)


#print(gpuid)
clparams.get_context(gpu_id=gpuid, kfile = 'clnlpar.cl')
#print(gpu_id)
clparams.get_context(gpu_id=gpu_id, kfile ='clnlpar.cl')
clparams.get_queue()
target_mem = clparams.queue.device.max_mem_alloc_size//2
ctx = clparams.ctx
Expand Down
79 changes: 42 additions & 37 deletions pyebsdindex/opencl/nlpar_clray.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,45 +42,45 @@ def calcsigma_clsq(self, **kwargs):
return nlpar_cl.NLPAR.calcsigma_cl(self, **kwargs)

def calcsigma_clray(self, nn=1, saturation_protect=True, automask=True, normalize_d=False,
gpuid = None, verbose=2, **kwargs):
gpu_id = None, verbose=2, **kwargs):
self.patternfile = self.getinfileobj()
self.sigmann = nn

if gpuid is None:
if gpu_id is None:
clparams = openclparam.OpenClParam()
clparams.get_gpu()

target_mem = 0
gpuid = 0
gpu_id = 0
count = 0

for gpu in clparams.gpu:
gmem = gpu.max_mem_alloc_size
if target_mem < gmem:
gpuid = count
gpu_id = count
target_mem = gmem
count += 1
else:
clparams = openclparam.OpenClParam()
clparams.get_gpu()
gpuid = min(len(clparams.gpu)-1, gpuid)
gpu_id = min(len(clparams.gpu)-1, gpu_id)

cudavis = ''
for cdgpu in range(len(clparams.gpu)):
cudavis += str(cdgpu) + ','

#print(gpuid)
#print(gpu_id)
ngpuwrker = 6
clparams.get_context(gpu_id=gpuid, kfile = 'clnlpar.cl')
clparams.get_context(gpu_id=gpu_id, kfile = 'clnlpar.cl')
clparams.get_queue()
if clparams.gpu[gpuid].host_unified_memory:
if clparams.gpu[gpu_id].host_unified_memory:
return nlpar_cl.NLPAR.calcsigma_cl(self, nn=nn, saturation_protect=saturation_protect,
automask=automask,
normalize_d=normalize_d,
gpuid=gpuid, **kwargs)
gpu_id=gpu_id, **kwargs)

target_mem = clparams.gpu[gpuid].max_mem_alloc_size // 3
max_mem = clparams.gpu[gpuid].global_mem_size * 0.75
target_mem = clparams.gpu[gpu_id].max_mem_alloc_size // 3
max_mem = clparams.gpu[gpu_id].global_mem_size * 0.75
if target_mem * ngpuwrker > max_mem:
target_mem = max_mem / ngpuwrker

Expand Down Expand Up @@ -129,7 +129,7 @@ def calcsigma_clray(self, nn=1, saturation_protect=True, automask=True, normaliz
[cstartcalc, cendcalc, rstartcalc, rendcalc]))


# wrker = NLPARGPUWorker(actorid=1, gpu_id=gpuid, cudavis=cudavis)
# wrker = NLPARGPUWorker(actorid=1, gpu_id=gpu_id, cudavis=cudavis)
# job = jobqueue[0]
#
# data = wrker.runsigma_chunk(job, nlparobj=self, saturation_protect=saturation_protect)
Expand Down Expand Up @@ -165,7 +165,7 @@ def calcsigma_clray(self, nn=1, saturation_protect=True, automask=True, normaliz

for w in range(ngpuwrker):
idlewrker.append(NLPARGPUWorker.options(num_cpus=float(0.99), num_gpus=ngpu_per_wrker).remote(
actorid=w, gpu_id=gpuid, cudavis=cudavis))
actorid=w, gpu_id=gpu_id, cudavis=cudavis))

njobs = len(jobqueue)
ndone = 0
Expand Down Expand Up @@ -329,7 +329,8 @@ def _sigmachunkcalc_cl(self, data, calclim, clparams=None, saturation_protect=Tr


def calcnlpar_clray(self, searchradius=None, lam = None, dthresh = None, saturation_protect=True, automask=True,
filename=None, fileout=None, reset_sigma=False, backsub = False, rescale = False, gpuid = None, **kwargs):
filename=None, fileout=None, reset_sigma=False, backsub = False, rescale = False,
verbose = 2, gpu_id = None, **kwargs):

if lam is not None:
self.lam = lam
Expand Down Expand Up @@ -376,7 +377,7 @@ def calcnlpar_clray(self, searchradius=None, lam = None, dthresh = None, saturat
self.sigma = None

if self.sigma is None:
self.sigma = self.calcsigma_cl(nn=1, saturation_protect=saturation_protect, automask=automask, gpuid=gpuid)[0]
self.sigma = self.calcsigma_cl(nn=1, saturation_protect=saturation_protect, automask=automask, gpu_id=gpu_id)[0]

sigma = np.asarray(self.sigma).astype(np.float32)

Expand All @@ -400,41 +401,42 @@ def calcnlpar_clray(self, searchradius=None, lam = None, dthresh = None, saturat
ngpuwrker = 6
clparams = openclparam.OpenClParam()
clparams.get_gpu()
if gpuid is None:
if gpu_id is None:
target_mem = 0
gpuid = 0
gpu_id = 0
count = 0

for gpu in clparams.gpu:
gmem = gpu.max_mem_alloc_size
if target_mem < gmem:
gpuid = count
gpu_id = count
target_mem = gmem
count += 1
else:
gpuid = min(len(clparams.gpu)-1, gpuid)
gpu_id = min(len(clparams.gpu)-1, gpu_id)
cudavis = ''
for cdgpu in range(len(clparams.gpu)):
cudavis += str(cdgpu) + ','

# print(gpuid)
clparams.get_context(gpu_id=gpuid, kfile = 'clnlpar.cl')
# print(gpu_id)
clparams.get_context(gpu_id=gpu_id, kfile = 'clnlpar.cl')
clparams.get_queue()
if clparams.gpu[gpuid].host_unified_memory:
if clparams.gpu[gpu_id].host_unified_memory:
return nlpar_cl.NLPAR.calcnlpar_cl(self, saturation_protect=saturation_protect,
automask=automask,
filename=filename,
fileout=fileout,
reset_sigma=reset_sigma,
backsub = backsub,
rescale = rescale,
gpuid = gpuid)

target_mem = clparams.gpu[gpuid].max_mem_alloc_size//3
max_mem = clparams.gpu[gpuid].global_mem_size*0.75
automask=automask,
filename=filename,
fileout=fileout,
reset_sigma=reset_sigma,
backsub = backsub,
rescale = rescale,
gpu_id= gpu_id)

target_mem = clparams.gpu[gpu_id].max_mem_alloc_size//3
max_mem = clparams.gpu[gpu_id].global_mem_size*0.75
if target_mem*ngpuwrker > max_mem:
target_mem = max_mem/ngpuwrker
print(target_mem/1.0e9)
#print(target_mem/1.0e9)

chunks = self._calcchunks([pwidth, pheight], ncols, nrows, target_bytes=target_mem,
col_overlap=sr, row_overlap=sr)

Expand Down Expand Up @@ -465,7 +467,8 @@ def calcnlpar_clray(self, searchradius=None, lam = None, dthresh = None, saturat
[cstartcalc,cendcalc, rstartcalc, rendcalc ]))



if verbose >=1:
print("lambda:", lam, "search radius:", sr, "dthresh:", dthresh)
ngpu_per_wrker = float(1.0/ngpuwrker)
ray.shutdown()

Expand All @@ -487,7 +490,7 @@ def calcnlpar_clray(self, searchradius=None, lam = None, dthresh = None, saturat

for w in range(ngpuwrker):
idlewrker.append(NLPARGPUWorker.options(num_cpus=float(0.99), num_gpus=ngpu_per_wrker).remote(
actorid=w, gpu_id=gpuid, cudavis=cudavis))
actorid=w, gpu_id=gpu_id, cudavis=cudavis))

njobs = len(jobqueue)
ndone = 0
Expand All @@ -509,8 +512,10 @@ def calcnlpar_clray(self, searchradius=None, lam = None, dthresh = None, saturat
idlewrker.append(busywrker.pop(indx))
tasks.remove(tsk)
ndone += 1
print(message, ndone, njobs)

if verbose >= 2:
print("tiles complete: ", ndone, "/", njobs, sep='', end='\r')
if verbose >= 2:
print('\n', end='')
return str(self.patternfileout.filepath)

def _nlparchunkcalc_cl(self, data, calclim, clparams=None):
Expand Down

0 comments on commit 3d15720

Please sign in to comment.