Skip to content

Commit

Permalink
Got profiling working again
Browse files Browse the repository at this point in the history
  • Loading branch information
hunse committed Sep 30, 2015
1 parent dc094b8 commit 9d4ff91
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
56 changes: 31 additions & 25 deletions nengo_ocl/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ def __init__(self, name="", tag="",
# -- bandwidth requirement per call
self.bw_per_call = bw_per_call

def __str__(self):
return '%s{%s %s}' % (
def __repr__(self):
return '%s{%s%s}' % (
self.__class__.__name__,
self.name,
self.tag,
": %s" % self.tag if self.tag else "",
)

def update_profiling(self):
pass


class PythonPlan(BasePlan):

Expand Down Expand Up @@ -64,40 +67,39 @@ def __init__(self, queue, kern, gsize, lsize, **kwargs):
self.kern = kern
self.gsize = gsize
self.lsize = lsize
self._evs = []
self._events_to_profile = []

def __call__(self, profiling=False):
def __call__(self):
ev = self.enqueue()
ev.wait()

def update_from_enqueued_events(self, profiling):
if profiling:
for ev in self._evs:
self.atimes.append(
1e-9 * (ev.profile.submit - ev.profile.queued))
self.btimes.append(
1e-9 * (ev.profile.start - ev.profile.submit))
self.ctimes.append(
1e-9 * (ev.profile.end - ev.profile.start))
self.n_calls += 1
self._evs[:] = []
def update_profiling(self):
for ev in self._events_to_profile:
self.atimes.append(
1e-9 * (ev.profile.submit - ev.profile.queued))
self.btimes.append(
1e-9 * (ev.profile.start - ev.profile.submit))
self.ctimes.append(
1e-9 * (ev.profile.end - ev.profile.start))
self.n_calls += 1

self._events_to_profile[:] = []

def enqueue(self, wait_for=None):
ev = cl.enqueue_nd_range_kernel(
self.queue, self.kern, self.gsize, self.lsize,
wait_for=wait_for)
self._evs.append(ev)
self._events_to_profile.append(ev)
return ev

def __str__(self):
return '%s{%s, %s, %s, %s, tag=%s, name=%s}' % (
def __repr__(self):
return '%s{%s%s %s %s}' % (
self.__class__.__name__,
self.queue,
self.kern,
self.name,
": %s" % self.tag if self.tag else "",
self.gsize,
self.lsize,
self.tag,
self.name)
)


class Marker(Plan):
Expand All @@ -113,8 +115,8 @@ def __init__(self, queue):
class Plans(object):

def __init__(self, planlist, profiling):
assert not profiling, "Not yet implemented"
self.plans = planlist
self.profiling = profiling

def __call__(self):
return self.call_n_times(1)
Expand All @@ -124,6 +126,10 @@ def call_n_times(self, n):
if last_event is not None:
last_event.wait()

if self.profiling:
for p in self.plans:
p.update_profiling()

def enqueue_n_times(self, n):
for _ in range(n):
last_event = None
Expand Down Expand Up @@ -170,7 +176,7 @@ def call_n_times(self, n):
last_ev.wait()
if self.profiling:
for p in self.order:
p.update_from_enqueued_events(self.profiling)
p.update_profiling()
else:
for ii in range(n):
for p in self.order:
Expand Down
4 changes: 2 additions & 2 deletions nengo_ocl/sim_ocl.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def plan_probes(self):
[np.zeros((n_prealloc, self.model.sig[p]['in'].size))
for p in probes])

cl_plan = plan_probes(self.queue, periods, X, Y, tag="probes")
cl_plan = plan_probes(self.queue, periods, X, Y)
self._max_steps_between_probes = n_prealloc * min(periods)

cl_plan.Y = Y
Expand Down Expand Up @@ -409,7 +409,7 @@ def print_profiling(self, sort=None):
# make and sort table
table = []
unknowns = []
for p in self._dag.order:
for p in self._plans.plans:
gflops_per_sec = 0
gbytes_per_sec = 0
if isinstance(p, BasePlan):
Expand Down

0 comments on commit 9d4ff91

Please sign in to comment.