Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor objective.Function out of Search #23

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions orio/main/tuner/search/exhaustive/exhaustive.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, params):
orio.main.tuner.search.search.Search.__init__(self, params)

self.start_coord = None

# read all algorithm-specific arguments
self.__readAlgoArgs()

Expand All @@ -29,15 +29,15 @@ def __init__(self, params):
if self.total_runs > 1:
err('orio.main.tuner.search.exhaustive: the total number of %s search runs must be one (or can be undefined)' %
self.__class__.__name__, doexit=True)


#-----------------------------------------------------
# Method required by the search interface
def searchBestCoord(self, startCoord=None):
'''
Explore the search space and return the coordinate that yields the best performance
(i.e. minimum performance cost).

@param startCoord: Starting coordinate (optional)
@return: A list of coordinates
'''
Expand All @@ -49,46 +49,46 @@ def searchBestCoord(self, startCoord=None):
if self.use_parallel_search:
coord_count = self.num_procs
top_perf={}

# record the best coordinate and its best performance cost
best_coord = None
top_coords = {}
best_perf_cost = self.MAXFLOAT
corr_transfer = self.MAXFLOAT

# start the timer
start_time = time.time()

if startCoord:
if len(startCoord) != self.total_dims:
if len(startCoord) != self.pb.total_dims:
warn("orio.main.tuner.search.exhaustive: " +
"Invalid starting coordinate %s specified," +
" expected %d elements, but was given %d"
% (startCoord, self.total_dims, len(startCoord)))
% (startCoord, self.pb.total_dims, len(startCoord)))
startCoord = None
else:
coord = startCoord

if not startCoord:
# start from the origin coordinate (i.e. [0,0,...])
coord = [0] * self.total_dims
coord = [0] * self.pb.total_dims

coords = [coord]
while len(coords) < coord_count:
coord = self.__getNextCoord(coord)
if coord:
coords.append(coord)
else:
break

recFlag = True

# evaluate every coordinate in the search space
while True:

# determine the performance cost of all chosen coordinates
perf_costs = self.getPerfCosts(coords)
perf_costs = self.pb.getPerfCosts(coords)

# compare to the best result
pcost_items = perf_costs.items()
pcost_items.sort(lambda x,y: cmp(eval(x[0]),eval(y[0])))
Expand Down Expand Up @@ -126,13 +126,13 @@ def searchBestCoord(self, startCoord=None):
json.dump(Globals().metadata, outfile)
except Exception, e:
err('orio.search.Exhaustive: failed to execute meta export: "%s"\n --> %s: %s' % (Globals().meta,e.__class__.__name__, e),doexit = False)

if mean_perf_cost < best_perf_cost and perf_cost > 0.0:
best_coord = coord_val
best_perf_cost = mean_perf_cost
corr_transfer = mean_transfer
info('>>>> best coordinate found: %s, average cost: %e, average transfer time: %s' % (coord_val, mean_perf_cost, mean_transfer))

# record time elapsed vs best perf cost found so far in a format that could be read in by matlab/octave
#progress = 'init' if recFlag else 'continue'
#recFlag = False
Expand Down Expand Up @@ -163,25 +163,25 @@ def searchBestCoord(self, startCoord=None):
search_time = time.time() - start_time

info('----- end exhaustive search -----')

# record time elapsed vs best perf cost found so far in a format that could be read in by matlab/octave
#Globals().stats.record(time.time()-start_time, best_perf_cost, best_coord, 'done')

# return the best coordinate
return best_coord,(best_perf_cost,corr_transfer),search_time,len(coords)

# Private methods
#--------------------------------------------------

def __readAlgoArgs(self):
'''To read all algorithm-specific arguments'''

for vname, rhs in self.search_opts.iteritems():
if vname == 'start_coord':
if not isinstance(rhs,list):
err('%s argument "%s" must be a list of coordinate indices' % (self.__class__.__name__,'start_coord'))
elif len(rhs) != self.total_dims:
err('%s dimension of start_coord must be %d, but was instead %d' % (self.__class__.__name__, self.total_dims, len(rhs)))
elif len(rhs) != self.pb.total_dims:
err('%s dimension of start_coord must be %d, but was instead %d' % (self.__class__.__name__, self.pb.total_dims, len(rhs)))
self.start_coord = rhs
else:
err('orio.main.tuner.search.exhaustive: unrecognized %s algorithm-specific argument: "%s"' %
Expand All @@ -193,19 +193,19 @@ def __getNextCoord(self, coord):
'''
Return the next neighboring coordinate to be considered in the search space.
Return None if all coordinates in the search space have been visited.

@return: the next coordinate
'''
next_coord = coord[:]
for i in range(0, self.total_dims):
for i in range(0, self.pb.total_dims):
ipoint = next_coord[i]
iuplimit = self.dim_uplimits[i]
iuplimit = self.pb.dim_uplimits[i]
if ipoint < iuplimit-1:
next_coord[i] += 1
break
else:
next_coord[i] = 0
if i == self.total_dims - 1:
if i == self.pb.total_dims - 1:
return None
return next_coord

Loading