You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added functionality for profiling of code executed on the native backend SequentialInterpreter.
Native profiling involves several components:
- C++ NativeProfiler class in execution.cpp, which plays the role
of compilation._Profiler
- Calls to update the profiler from SequentialInterpreter.run
- Python wrapper for NativeProfiler in cycgt.pyx (NativeProfilerWrapper)
- A reference to the wrapper is stored as a variable in the cycgt module
(native_profiler)
- In order for us to be consistent in displaying the profiling output on
a per-Op (rather than per-instruction) basis, we need a way to map each
C++ Instruction instance back to the Python Instr instance from which it
derives. In order to make this possible I added a call in
CppInterpreterWrapper__init__ that tells the NativeProfilerWrapper to
store the mappings.
- A C++ Instruction cannot (easily/safely) refer back to the Python
op, but we need the op description to properly display the profile
results; therefore I have passed the op description as a string
op_repr which is stored in the Instruction class and passed back to
Python for display when
From a user perspective the profiling interface should remain unchanged,
i.e. cgt.profile.start, cgt.profile.print_stats... etc, should work as
before but the results will now include native operations. But note
that cgt.profiler.instr2stats will NOT include native calls.
TODO:
- Make this work for ParallelInterpreter.
- Since the Instruction->Instr mapping may be useful outside of profiling
I feel it may be better to refactor and store this information somewhere
else.
out = new LoadArgument(repr(pyinstr), pyinstr.ind, wloc)
367
+
out = new LoadArgument(repr(pyinstr), hash(pyinstr), pyinstr.ind, wloc)
350
368
elif t == compilation.Alloc:
351
-
out = new Alloc(repr(pyinstr), dtype_fromstr(pyinstr.dtype), _tocppmemvec(pyinstr.read_locs), wloc)
369
+
out = new Alloc(repr(pyinstr), hash(pyinstr), dtype_fromstr(pyinstr.dtype), _tocppmemvec(pyinstr.read_locs), wloc)
352
370
elif t == compilation.BuildTup:
353
-
out = new BuildTup(repr(pyinstr), _tocppmemvec(pyinstr.read_locs), wloc)
371
+
out = new BuildTup(repr(pyinstr), hash(pyinstr), _tocppmemvec(pyinstr.read_locs), wloc)
354
372
elif t == compilation.ReturnByRef:
355
-
out = new ReturnByRef(repr(pyinstr), _tocppmemvec(pyinstr.read_locs), wloc, _tocppbyrefcallable(pyinstr.get_callable(), storage), _isquick(pyinstr))
373
+
out = new ReturnByRef(repr(pyinstr), hash(pyinstr), _tocppmemvec(pyinstr.read_locs), wloc, _tocppbyrefcallable(pyinstr.get_callable(), storage), _isquick(pyinstr))
356
374
elif t == compilation.ReturnByVal:
357
-
out = new ReturnByVal(repr(pyinstr), _tocppmemvec(pyinstr.read_locs), wloc, _tocppbyvalcallable(pyinstr.get_callable(), storage), _isquick(pyinstr))
375
+
out = new ReturnByVal(repr(pyinstr), hash(pyinstr), _tocppmemvec(pyinstr.read_locs), wloc, _tocppbyvalcallable(pyinstr.get_callable(), storage), _isquick(pyinstr))
358
376
else:
359
377
raiseRuntimeError("expected instance of type Instruction. got type %s"%t)
360
378
return out
@@ -420,6 +438,7 @@ cdef class CppInterpreterWrapper:
0 commit comments