From e91547a0da844e392fa50c9fa91ce3d5c37ed380 Mon Sep 17 00:00:00 2001 From: Jing Xu Date: Fri, 13 Jun 2025 06:11:05 +0900 Subject: [PATCH 1/2] remove unnecessary term XPUs from profiler --- recipes_source/recipes/profiler_recipe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes_source/recipes/profiler_recipe.py b/recipes_source/recipes/profiler_recipe.py index 4d43726e71f..2cfcf2ae550 100644 --- a/recipes_source/recipes/profiler_recipe.py +++ b/recipes_source/recipes/profiler_recipe.py @@ -161,7 +161,7 @@ # Note the occurrence of ``aten::convolution`` twice with different input shapes. ###################################################################### -# Profiler can also be used to analyze performance of models executed on GPUs and XPUs: +# Profiler can also be used to analyze performance of models executed on GPUs: # Users could switch between cpu, cuda and xpu if torch.cuda.is_available(): device = 'cuda' From 48199a33d23072d70a6045eb2da8dee4de61f9bd Mon Sep 17 00:00:00 2001 From: Jing Xu Date: Mon, 16 Jun 2025 17:10:43 +0900 Subject: [PATCH 2/2] fine tune ProfilerActivity usage --- recipes_source/recipes/profiler_recipe.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/recipes_source/recipes/profiler_recipe.py b/recipes_source/recipes/profiler_recipe.py index e80f63adc29..602ab1a7a80 100644 --- a/recipes_source/recipes/profiler_recipe.py +++ b/recipes_source/recipes/profiler_recipe.py @@ -165,16 +165,18 @@ ###################################################################### # Profiler can also be used to analyze performance of models executed on GPUs: # Users could switch between cpu, cuda and xpu +activities = [ProfilerActivity.CPU] if torch.cuda.is_available(): device = 'cuda' + activities += [ProfilerActivity.CUDA] elif torch.xpu.is_available(): device = 'xpu' + activities += [ProfilerActivity.XPU] else: print('Neither CUDA nor XPU devices are available to demonstrate profiling on acceleration devices') import sys sys.exit(0) -activities = [ProfilerActivity.CPU, ProfilerActivity.CUDA, ProfilerActivity.XPU] sort_by_keyword = device + "_time_total" model = models.resnet18().to(device) @@ -308,9 +310,17 @@ # Profiling results can be outputted as a ``.json`` trace file: # Tracing CUDA or XPU kernels # Users could switch between cpu, cuda and xpu -device = 'cuda' - -activities = [ProfilerActivity.CPU, ProfilerActivity.CUDA, ProfilerActivity.XPU] +activities = [ProfilerActivity.CPU] +if torch.cuda.is_available(): + device = 'cuda' + activities += [ProfilerActivity.CUDA] +elif torch.xpu.is_available(): + device = 'xpu' + activities += [ProfilerActivity.XPU] +else: + print('Neither CUDA nor XPU devices are available to demonstrate profiling on acceleration devices') + import sys + sys.exit(0) model = models.resnet18().to(device) inputs = torch.randn(5, 3, 224, 224).to(device)