Skip to content

Commit cccce6b

Browse files
jingxu10svekars
andauthored
remove unnecessary term XPUs from profiler (#3394)
* remove unnecessary term XPUs from profiler * fine tune ProfilerActivity usage --------- Co-authored-by: Svetlana Karslioglu <[email protected]>
1 parent 5f17335 commit cccce6b

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

recipes_source/recipes/profiler_recipe.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,20 @@
163163
# Note the occurrence of ``aten::convolution`` twice with different input shapes.
164164

165165
######################################################################
166-
# Profiler can also be used to analyze performance of models executed on GPUs and XPUs:
166+
# Profiler can also be used to analyze performance of models executed on GPUs:
167167
# Users could switch between cpu, cuda and xpu
168+
activities = [ProfilerActivity.CPU]
168169
if torch.cuda.is_available():
169170
device = 'cuda'
171+
activities += [ProfilerActivity.CUDA]
170172
elif torch.xpu.is_available():
171173
device = 'xpu'
174+
activities += [ProfilerActivity.XPU]
172175
else:
173176
print('Neither CUDA nor XPU devices are available to demonstrate profiling on acceleration devices')
174177
import sys
175178
sys.exit(0)
176179

177-
activities = [ProfilerActivity.CPU, ProfilerActivity.CUDA, ProfilerActivity.XPU]
178180
sort_by_keyword = device + "_time_total"
179181

180182
model = models.resnet18().to(device)
@@ -308,9 +310,17 @@
308310
# Profiling results can be outputted as a ``.json`` trace file:
309311
# Tracing CUDA or XPU kernels
310312
# Users could switch between cpu, cuda and xpu
311-
device = 'cuda'
312-
313-
activities = [ProfilerActivity.CPU, ProfilerActivity.CUDA, ProfilerActivity.XPU]
313+
activities = [ProfilerActivity.CPU]
314+
if torch.cuda.is_available():
315+
device = 'cuda'
316+
activities += [ProfilerActivity.CUDA]
317+
elif torch.xpu.is_available():
318+
device = 'xpu'
319+
activities += [ProfilerActivity.XPU]
320+
else:
321+
print('Neither CUDA nor XPU devices are available to demonstrate profiling on acceleration devices')
322+
import sys
323+
sys.exit(0)
314324

315325
model = models.resnet18().to(device)
316326
inputs = torch.randn(5, 3, 224, 224).to(device)

0 commit comments

Comments
 (0)