2025-12-18 15:51:54 +08:00
|
|
|
from contextlib import contextmanager
|
|
|
|
|
|
|
|
|
|
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@contextmanager
|
|
|
|
|
def torch_cuda_wrapper():
|
|
|
|
|
try:
|
|
|
|
|
torch.cuda.Event = torch.npu.Event
|
|
|
|
|
torch.cuda.Stream = torch.npu.Stream
|
2025-12-29 15:28:34 +08:00
|
|
|
torch.cuda.stream = torch.npu.stream
|
2025-12-18 15:51:54 +08:00
|
|
|
torch.cuda.default_stream = torch.npu.default_stream
|
|
|
|
|
torch.cuda.current_stream = torch.npu.current_stream
|
|
|
|
|
torch.cuda.graph_pool_handle = torch.npu.graph_pool_handle
|
2025-12-29 15:28:34 +08:00
|
|
|
torch.cuda.CUDAGraph = torch.npu.NPUGraph
|
2025-12-18 15:51:54 +08:00
|
|
|
torch.cuda.graph = torch.npu.graph
|
2025-12-29 15:28:34 +08:00
|
|
|
torch.cuda.synchronize = torch.npu.synchronize
|
2025-12-18 15:51:54 +08:00
|
|
|
yield
|
|
|
|
|
finally:
|
2025-12-29 15:28:34 +08:00
|
|
|
pass
|