mstxRangeStartA¶
| Product | Supported |
|---|---|
| Ascend 910_95 AI Processors | √ |
| Atlas A3 training products/Atlas A3 inference products | √ |
| Atlas A2 training products/Atlas A2 inference products | √ |
| Atlas 200I/500 A2 inference products | √ |
| Atlas inference products | √ |
| Atlas training products | √ |
Marks the start position of the mstx range capability.
C/C++:
Python:
Table 1 Parameter description
| Parameter | Input/Output | Description |
|---|---|---|
| message | Input | message is a text marker that carries trace information. Data type in C/C++: const char *. In Python, message is a string. Defaults to None. Length requirement for the input message string: MSPTI scenario: cannot exceed 255 bytes. Non-MSPTI scenario (for example, msprof command line, Ascend PyTorch Profiler): cannot exceed 156 bytes. message cannot be a null pointer. |
| stream | Input | stream indicates the thread that uses the mark. Data type in C/C++: aclrtStream. In Python, stream is an aclrtStream object. Defaults to None. When set to nullptr, only the instantaneous event on the Host side is marked. When set to a valid stream, the instantaneous events on the Host side and the corresponding Device side are marked. |
If 0 is returned, it indicates failure.
-
Through the Python API interface, implement the relevant interface content in C/C++ language and compile it to generate an so file. The relevant so file can be directly referenced by Python in PYTHONPATH.
import mstx mstx.range_start("aaa") print(1) mstx.range_end(1) import torch import torch_npu a = torch.Tensor([1,2,3,4]).npu() b = torch.Tensor([1,2,3,4]).npu() hi_str = "hi" hello_str = "hello" hi_id = mstx.range_start(hi_str, None) c = a + b hello_id = mstx.range_start(hello_str, stream=None) d = a - b mstx.range_end(hi_id) e = a * b mstx.range_end(hello_id) -
Python Calling Method 2:
Directly use Python for development, reference the original mstx .so file via ctypes.CDLL("libms_tools_ext.so"), and use the APIs provided within it.
import mstx import torch import torch_npu import acl import sys import ctypes lib = ctypes.CDLL("libms_tools_ext.so") # Define the parameter types and return type of the function lib.mstxRangeStartA.argtypes = [ctypes.c_char_p, ctypes.c_void_p] lib.mstxRangeStartA.restype = ctypes.c_uint64 lib.mstxRangeEnd.argtypes = [ctypes.c_uint64] lib.mstxRangeEnd.restype = None a = torch.Tensor([1,2,3,4]).npu() b = torch.Tensor([1,2,3,4]).npu() # Create a ctypes.c_char_p pointer hi_str = b"hi" hi_ptr = ctypes.c_char_p(hi_str) hi_id = ctypes.c_uint64() # Create a ctypes.c_char_p pointer hello_str = b"hello" hello_ptr = ctypes.c_char_p(hello_str) hello_id = ctypes.c_uint64() # Call the function hi_id.value = lib.mstxRangeStartA(hi_ptr, None) c = a + b hello_id.value = lib.mstxRangeStartA(hello_ptr, None) d = a - b lib.mstxRangeEnd(hi_id) e = a * b lib.mstxRangeEnd(hello_id)