|
163 | 163 | # Note the occurrence of ``aten::convolution`` twice with different input shapes.
|
164 | 164 |
|
165 | 165 | ######################################################################
|
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: |
167 | 167 | # Users could switch between cpu, cuda and xpu
|
| 168 | +activities = [ProfilerActivity.CPU] |
168 | 169 | if torch.cuda.is_available():
|
169 | 170 | device = 'cuda'
|
| 171 | + activities += [ProfilerActivity.CUDA] |
170 | 172 | elif torch.xpu.is_available():
|
171 | 173 | device = 'xpu'
|
| 174 | + activities += [ProfilerActivity.XPU] |
172 | 175 | else:
|
173 | 176 | print('Neither CUDA nor XPU devices are available to demonstrate profiling on acceleration devices')
|
174 | 177 | import sys
|
175 | 178 | sys.exit(0)
|
176 | 179 |
|
177 |
| -activities = [ProfilerActivity.CPU, ProfilerActivity.CUDA, ProfilerActivity.XPU] |
178 | 180 | sort_by_keyword = device + "_time_total"
|
179 | 181 |
|
180 | 182 | model = models.resnet18().to(device)
|
|
308 | 310 | # Profiling results can be outputted as a ``.json`` trace file:
|
309 | 311 | # Tracing CUDA or XPU kernels
|
310 | 312 | # 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) |
314 | 324 |
|
315 | 325 | model = models.resnet18().to(device)
|
316 | 326 | inputs = torch.randn(5, 3, 224, 224).to(device)
|
|
0 commit comments