detkit.InstructionsCounter#
- class detkit.InstructionsCounter#
Wrapper for Linux’s Perf tool.
- Parameters:
- inst_per_flopfloat, default=1.0
Instructions per FLOP. This can also be set later using
set_inst_per_flop()
.
Notes
To measure hardware instructions count, the Perf tool needs to be installed and necessary permissions should be granted for it to work. See Perf Tool.
To count FLOPs, multiply hardware instructions counter by flops per hardware instructions, which can be estimated using
detkit.get_instructions_per_flop()
.Examples
>>> import detkit >>> # You may first check Perf tool is installed and supported >>> results = detkit.check_perf_support() >>> print(results) { 'kernel_version': '6.8.0-51-generic', 'perf_event_paranoid': 1, 'perf_installed': True, 'perf_working': True }
Once you made sure Perf tool is installed and working, you can measure hardware instructions count. In the example below, we measure it for the matrix-matrix multiplication.
>>> # Initialize >>> from detkit import InstructionsCounter >>> ic = InstructionsCounter() >>> # Create matrices for testing >>> import numpy >>> n = 1000 >>> A = numpy.random.randn(n, n) >>> B = numpy.random.randn(n, n) >>> # Start counting hardware instructions >>> ic.start() >>> C = A @ B >>> ic.stop() >>> print(is.get_count())
Methods
start
(self)Start counting instructions.
stop
(self)Stop counting instructions.
reset
(self)Reset counts.
get_count
(self)Get the instruction count.
set_inst_per_flop
(self, double inst_per_flop)Set retired instructions per floating-point operations.
get_flop