classCudaProfilerWrapper:def__init__(self)->None:self._profiler_running=False# Note: lazy import to avoid dependency issues if CUDA is not available.importtorch.cuda.profilerascuda_profilerself._cuda_profiler=cuda_profilerdefstart(self)->None:try:self._cuda_profiler.start()self._profiler_running=Truelogger.info_once("Started CUDA profiler")exceptExceptionase:logger.warning_once("Failed to start CUDA profiler: %s",e)defstop(self)->None:ifself._profiler_running:try:self._cuda_profiler.stop()logger.info_once("Stopped CUDA profiler")exceptExceptionase:logger.warning_once("Failed to stop CUDA profiler: %s",e)finally:self._profiler_running=Falsedefshutdown(self)->None:"""Ensure profiler is stopped when shutting down."""self.stop()
def__init__(self)->None:self._profiler_running=False# Note: lazy import to avoid dependency issues if CUDA is not available.importtorch.cuda.profilerascuda_profilerself._cuda_profiler=cuda_profiler
defstart(self)->None:try:self._cuda_profiler.start()self._profiler_running=Truelogger.info_once("Started CUDA profiler")exceptExceptionase:logger.warning_once("Failed to start CUDA profiler: %s",e)
defstop(self)->None:ifself._profiler_running:try:self._cuda_profiler.stop()logger.info_once("Stopped CUDA profiler")exceptExceptionase:logger.warning_once("Failed to stop CUDA profiler: %s",e)finally:self._profiler_running=False