Skip to content

Commit

Permalink
Add compile time instruction count metric (#133834)
Browse files Browse the repository at this point in the history
Summary:
PYTHONPATH=$(pwd) python benchmarks/update_hint_benchmark.py out
as of this diff, compile_time_instruction_count counts the number of instruction from within
convert_frame.compile_inner
```
update_hint_regression,compile_time_instruction_count,10522459165
```
 will add result from CI once populated.

X-link: pytorch/pytorch#133834
Approved by: https://github.com/aorenste

Reviewed By: ZainRizvi

Differential Revision: D61897875

Pulled By: laithsakka

fbshipit-source-id: 4588bc94c81b1b2df970962231c3ca72aa03a5a0
  • Loading branch information
laithsakka authored and facebook-github-bot committed Aug 28, 2024
1 parent ae902e4 commit d873514
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions userbenchmark/dynamo/dynamobench/_dynamo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
from torch import fx
from torch._C import (
_get_function_stack_at,
_instruction_counter,
_len_torch_function_stack,
_pop_torch_function_stack,
_push_on_torch_function_stack,
Expand Down Expand Up @@ -3203,3 +3204,41 @@ def get_user_object_from_id(obj_id):
def store_user_object_weakref(obj):
obj_id = id(obj)
user_obj_id_to_weakref[obj_id] = weakref.ref(obj)


class CompileTimeInstructionCounter:
_counter: int = 0
_id: int = -1
_depth = 0

@classmethod
def start(cls) -> None:
cls._depth = cls._depth + 1
if cls._depth == 1:
cls._id = _instruction_counter.start()

@classmethod
def end(cls) -> None:
cls._depth = cls._depth - 1
if cls._depth == 0:
cls._counter += _instruction_counter.end(cls._id)
cls._id = -1

@classmethod
def clear(cls) -> None:
cls._counter = 0

@classmethod
def value(cls) -> int:
return cls._counter

@classmethod
@contextmanager
def record(cls):
try:
if config.record_compile_time_instruction_count:
cls.start()
yield
finally:
if config.record_compile_time_instruction_count:
cls.end()

0 comments on commit d873514

Please sign in to comment.