ROCTx is AMD tools extension library, a cross platform API for annotating code with markers and ranges. The ROCTx API is written in C++.
In certain situations, such as debugging performance issues in large-scale GPU programs, API-level tracing might be too fine-grained to provide a big picture of the program execution.
In such cases, it is helpful to define specific tasks to be traced. To specify the tasks for tracing, enclose the respective source code with the API calls provided by the ROCTx library.
-**Push and Pop:** These can be nested to form a stack. The Pop call is automatically associated with a prior Push call on the same thread.
-**Start and End:** These may overlap with other ranges arbitrarily. The Start call returns a handle that must be passed to the End call. These ranges can start and end on different threads.
-``roctxProfilerPause``: Requests any currently running profiling tool to stop data collection.
-``roctxProfilerResume``: Requests any currently running profiling tool to resume data collection.
-``roctxGetThreadId``: Retrieves the ID for the current thread identical to the ID received using ``rocprofiler_get_thread_id(rocprofiler_thread_id_t*)``.
-``roctxNameOsThread``: Labels the current CPU OS thread in the profiling tool output with the provided name.
-``roctxNameHsaAgent``: Labels the given HSA agent in the profiling tool output with the provided name.
-``roctxNameHipDevice``: Labels the HIP device ID in the profiling tool output with the provided name.
-``roctxNameHipStream``: Labels the given HIP stream in the profiling tool output with the provided name.
hipMemcpy(TransposeMatrix, gpuTransposeMatrix, NUM * sizeof(float), hipMemcpyDeviceToHost);
roctxRangePop(); // for"hipMemcpy"
roctxRangePop(); // for"hipLaunchKernel"
roctxRangeStop(rangeId);
To trace the API calls enclosed within the range, use:
..code-block::bash
rocprofv3 --marker-trace -- <application_path>
Running the preceding command generates a ``marker_api_trace.csv`` file prefixed with the process ID.
..code-block::shell
$ cat 210_marker_api_trace.csv
Here are the contents of ``marker_api_trace.csv`` file:
..csv-table:: Marker api trace
:file:/data/marker_api_trace.csv
:widths:10,10,10,10,10,20,20
:header-rows:1
For the description of the fields in the output file, see :ref:`output-file-fields`.
``roctxProfilerPause`` and ``roctxProfilerResume`` can be used to hide the calls between them. This is useful when you want to hide the calls that are not relevant to your profiling session.
..code-block::bash
#include <rocprofiler-sdk-roctx/roctx.h>
// Memory transfer from host to device
HIP_API_CALL(hipMemcpy(gpuMatrix, Matrix, NUM * sizeof(float), hipMemcpyHostToDevice));
auto tid= roctx_thread_id_t{};
roctxGetThreadId(&tid);
roctxProfilerPause(tid);
// Memory transfer that should be hidden by profiling tool
HIP_API_CALL(
hipMemcpy(gpuTransposeMatrix, gpuMatrix, NUM * sizeof(float), hipMemcpyDeviceToDevice));
The preceding command generates a ``hip_api_trace.csv`` file prefixed with the process ID. The file has only two ``hipMemcpy`` calls with the in-between ``hipMemcpyDeviceToHost`` hidden .
``ROCTx`` provides APIs to rename certain resources in the output generated by the profiling tool. You can pass the desired label for a specific resource in the output as an argument to the API. Note that ROCprofiler-SDK doesn't provide any explicit support for how profiling tools handle this request. Support for this capability is tool-specific.
The following table lists the APIs available for labeling the given resources: