Skip to content

Commit d873514

Browse files
laithsakkafacebook-github-bot
authored andcommitted
Add compile time instruction count metric (#133834)
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
1 parent ae902e4 commit d873514

File tree

1 file changed

+39
-0
lines changed
  • userbenchmark/dynamo/dynamobench/_dynamo

1 file changed

+39
-0
lines changed

userbenchmark/dynamo/dynamobench/_dynamo/utils.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
from torch import fx
6565
from torch._C import (
6666
_get_function_stack_at,
67+
_instruction_counter,
6768
_len_torch_function_stack,
6869
_pop_torch_function_stack,
6970
_push_on_torch_function_stack,
@@ -3203,3 +3204,41 @@ def get_user_object_from_id(obj_id):
32033204
def store_user_object_weakref(obj):
32043205
obj_id = id(obj)
32053206
user_obj_id_to_weakref[obj_id] = weakref.ref(obj)
3207+
3208+
3209+
class CompileTimeInstructionCounter:
3210+
_counter: int = 0
3211+
_id: int = -1
3212+
_depth = 0
3213+
3214+
@classmethod
3215+
def start(cls) -> None:
3216+
cls._depth = cls._depth + 1
3217+
if cls._depth == 1:
3218+
cls._id = _instruction_counter.start()
3219+
3220+
@classmethod
3221+
def end(cls) -> None:
3222+
cls._depth = cls._depth - 1
3223+
if cls._depth == 0:
3224+
cls._counter += _instruction_counter.end(cls._id)
3225+
cls._id = -1
3226+
3227+
@classmethod
3228+
def clear(cls) -> None:
3229+
cls._counter = 0
3230+
3231+
@classmethod
3232+
def value(cls) -> int:
3233+
return cls._counter
3234+
3235+
@classmethod
3236+
@contextmanager
3237+
def record(cls):
3238+
try:
3239+
if config.record_compile_time_instruction_count:
3240+
cls.start()
3241+
yield
3242+
finally:
3243+
if config.record_compile_time_instruction_count:
3244+
cls.end()

0 commit comments

Comments
 (0)