Skip to content

Commit f216df6

Browse files
Adding onetrace_enabled
Example of usage: ``` (dev_dpctl) opavlyk@opavlyk-mobl:~/repos/dpctl$ ~/pti-gpu/tools/onetrace/build/onetrace --conditional-collection -v -t --demangle ipython Device Timeline: start time (CLOCK_MONOTONIC_RAW) [ns] = 207284739877222 Device Timeline: start time (CLOCK_MONOTONIC) [ns] = 207284790110055 Device Timeline: start time (CLOCK_REALTIME) [ns] = 1662686020459161393 Python 3.9.12 (main, Jun 1 2022, 11:38:51) Type 'copyright', 'credits' or 'license' for more information IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: import dpctl.tensor as dpt, dpctl, numpy as np Device Timeline: start time (CLOCK_MONOTONIC_RAW) [ns] = 207294358012969 Device Timeline: start time (CLOCK_MONOTONIC) [ns] = 207294408245381 Device Timeline: start time (CLOCK_REALTIME) [ns] = 1662686030077296715 Device Timeline: start time (CLOCK_MONOTONIC_RAW) [ns] = 207294447416361 Device Timeline: start time (CLOCK_MONOTONIC) [ns] = 207294497648642 Device Timeline: start time (CLOCK_REALTIME) [ns] = 1662686030166699977 Device Timeline: start time (CLOCK_MONOTONIC_RAW) [ns] = 207294522074685 Device Timeline: start time (CLOCK_MONOTONIC) [ns] = 207294572308151 Device Timeline: start time (CLOCK_REALTIME) [ns] = 1662686030241359487 Device Timeline: start time (CLOCK_MONOTONIC_RAW) [ns] = 207294602756763 Device Timeline: start time (CLOCK_MONOTONIC) [ns] = 207294652988740 Device Timeline: start time (CLOCK_REALTIME) [ns] = 1662686030322040075 In [2]: from dpctl.utils import onetrace_enabled In [3]: with onetrace_enabled(): ...: dpt.linspace(0, 1, num=1000, dtype='f4') ...: dpt.arange(0, 20, dtype='i4') ...: Device Timeline (queue: 0x56315e00e720): linear_sequence_affine_kernel<float, float>[SIMD32 {5; 1; 1} {200; 1; 1}]<1.1> [ns] = 49099144803 (append) 49099446053 (submit) 49101192928 (start) 49101202303 (end) Device Timeline (queue: 0x56315e00e720): linear_sequence_step_kernel<int>[SIMD32 {1; 1; 1} {20; 1; 1}]<2.1> [ns] = 49154332484 (append) 49154668024 (submit) 49155196149 (start) 49155213440 (end) In [4]: quit Segmentation fault ``` The segmenation fault at the exit is a known issue with ZE-tracer module.
1 parent a7dde5a commit f216df6

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

dpctl/utils/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
get_execution_queue,
2424
validate_usm_type,
2525
)
26+
from ._onetrace_context import onetrace_enabled
2627

2728
__all__ = [
2829
"get_execution_queue",
2930
"get_coerced_usm_type",
3031
"validate_usm_type",
32+
"onetrace_enabled",
3133
]

dpctl/utils/_onetrace_context.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Data Parallel Control (dpctl)
2+
#
3+
# Copyright 2020-2022 Intel Corporation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import os
18+
from contextlib import contextmanager
19+
20+
21+
@contextmanager
22+
def onetrace_enabled():
23+
""" Enable `onetrace` collection for kernels executed in this context.
24+
25+
N.B.: Proper working of this utility assumes that Python interpreter
26+
has been launched by `onetrace` tool from intel/pti-gpu project.
27+
28+
.. Example:: bash
29+
30+
$ onetrace --conditional-collection -v -t --demangle \
31+
python script.py
32+
33+
.. Example:: bash
34+
35+
import dpctl.tensor as dpt
36+
from dpctl.utils import onetrace_enabled
37+
38+
# onetrace output reporting on execution of the kernel
39+
# should be seen, starting with "Device Timeline"
40+
with onetrace_enabled():
41+
dpt.arange(100, dtype='int16')
42+
43+
"""
44+
_env_var_name = "PTI_ENABLE_COLLECTION"
45+
saved = os.getenv(_env_var_name, None)
46+
try:
47+
os.environ[_env_var_name] = "1"
48+
yield
49+
finally:
50+
if saved is None:
51+
del os.environ[_env_var_name]
52+
else:
53+
os.environ[_env_var_name] = saved

0 commit comments

Comments
 (0)