mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
This is the result of applying the ruff `UP035` check. `Callable` is imported from `collections.abc` instead of `typing`. `TypeAlias` is also imported from `typing`. This PR is the follow-up of #163947. Pull Request resolved: https://github.com/pytorch/pytorch/pull/164054 Approved by: https://github.com/ezyang, https://github.com/Skylion007
70 lines
2.3 KiB
Python
70 lines
2.3 KiB
Python
from collections.abc import Callable
|
|
|
|
from torch._utils import CallbackRegistry
|
|
|
|
|
|
EventCreationCallbacks: "CallbackRegistry[int]" = CallbackRegistry("XPU event creation")
|
|
EventDeletionCallbacks: "CallbackRegistry[int]" = CallbackRegistry("XPU event deletion")
|
|
EventRecordCallbacks: "CallbackRegistry[int, int]" = CallbackRegistry(
|
|
"XPU event record"
|
|
)
|
|
EventWaitCallbacks: "CallbackRegistry[int, int]" = CallbackRegistry("XPU event wait")
|
|
MemoryAllocationCallbacks: "CallbackRegistry[int]" = CallbackRegistry(
|
|
"XPU memory allocation"
|
|
)
|
|
MemoryDeallocationCallbacks: "CallbackRegistry[int]" = CallbackRegistry(
|
|
"XPU memory deallocation"
|
|
)
|
|
StreamCreationCallbacks: "CallbackRegistry[int]" = CallbackRegistry(
|
|
"XPU stream creation"
|
|
)
|
|
DeviceSynchronizationCallbacks: "CallbackRegistry[[]]" = CallbackRegistry(
|
|
"XPU device synchronization"
|
|
)
|
|
StreamSynchronizationCallbacks: "CallbackRegistry[int]" = CallbackRegistry(
|
|
"XPU stream synchronization"
|
|
)
|
|
EventSynchronizationCallbacks: "CallbackRegistry[int]" = CallbackRegistry(
|
|
"XPU event synchronization"
|
|
)
|
|
|
|
|
|
def register_callback_for_event_creation(cb: Callable[[int], None]) -> None:
|
|
EventCreationCallbacks.add_callback(cb)
|
|
|
|
|
|
def register_callback_for_event_deletion(cb: Callable[[int], None]) -> None:
|
|
EventDeletionCallbacks.add_callback(cb)
|
|
|
|
|
|
def register_callback_for_event_record(cb: Callable[[int, int], None]) -> None:
|
|
EventRecordCallbacks.add_callback(cb)
|
|
|
|
|
|
def register_callback_for_event_wait(cb: Callable[[int, int], None]) -> None:
|
|
EventWaitCallbacks.add_callback(cb)
|
|
|
|
|
|
def register_callback_for_memory_allocation(cb: Callable[[int], None]) -> None:
|
|
MemoryAllocationCallbacks.add_callback(cb)
|
|
|
|
|
|
def register_callback_for_memory_deallocation(cb: Callable[[int], None]) -> None:
|
|
MemoryDeallocationCallbacks.add_callback(cb)
|
|
|
|
|
|
def register_callback_for_stream_creation(cb: Callable[[int], None]) -> None:
|
|
StreamCreationCallbacks.add_callback(cb)
|
|
|
|
|
|
def register_callback_for_device_synchronization(cb: Callable[[], None]) -> None:
|
|
DeviceSynchronizationCallbacks.add_callback(cb)
|
|
|
|
|
|
def register_callback_for_stream_synchronization(cb: Callable[[int], None]) -> None:
|
|
StreamSynchronizationCallbacks.add_callback(cb)
|
|
|
|
|
|
def register_callback_for_event_synchronization(cb: Callable[[int], None]) -> None:
|
|
EventSynchronizationCallbacks.add_callback(cb)
|