ROCm / rocprofiler

ROC profiler library. Profiling with perf-counters and derived metrics.
https://rocm.docs.amd.com/projects/rocprofiler/en/latest/
Other
115 stars 43 forks source link

ROCm Profiling Tools

DISCLAIMER

The information presented in this document is for informational purposes only and may contain technical inaccuracies, omissions, and typographical errors. The information contained herein is subject to change and may be rendered inaccurate for many reasons, including but not limited to product and roadmap changes, component and motherboard version changes, new model and/or product releases, product differences between differing manufacturers, software changes, BIOS flashes, firmware upgrades, or the like. Any computer system has risks of security vulnerabilities that cannot be completely prevented or mitigated. AMD assumes no obligation to update or otherwise correct or revise this information. However, AMD reserves the right to revise this information and to make changes from time to time to the content hereof without obligation of AMD to notify any person of such revisions or changes.THIS INFORMATION IS PROVIDED ‘AS IS.” AMD MAKES NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE CONTENTS HEREOF AND ASSUMES NO RESPONSIBILITY FOR ANY INACCURACIES, ERRORS, OR OMISSIONS THAT MAY APPEAR IN THIS INFORMATION. AMD SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT WILL AMD BE LIABLE TO ANY PERSON FOR ANY RELIANCE, DIRECT, INDIRECT, SPECIAL, OR OTHER CONSEQUENTIAL DAMAGES ARISING FROM THE USE OF ANY INFORMATION CONTAINED HEREIN, EVEN IF AMD IS EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. AMD, the AMD Arrow logo, and combinations thereof are trademarks of Advanced Micro Devices, Inc. Other product names used in this publication are for identification purposes only and may be trademarks of their respective companies.

© 2022 Advanced Micro Devices, Inc. All Rights Reserved.

Build Status

Introduction

ROCProfiler is AMD’s tooling infrastructure that provides a hardware specific low level performance analysis interface for the profiling and the tracing of GPU compute applications.

ROCProfiler V1

Profiling with metrics and traces based on perfcounters (PMC) and traces (SPM). Implementation is based on AqlProfile HSA extension. The last API library version for ROCProfiler v1 is 8.0.0

The library source tree:

Build environment

Roctracer & Rocprofiler need to be installed in the same directory.

export CMAKE_PREFIX_PATH=<path_to_hsa-runtime_includes>:<path_to_hsa-runtime_library>
export CMAKE_BUILD_TYPE=<debug|release> # release by default
export CMAKE_DEBUG_TRACE=1 # 1 to enable debug tracing

To build with the current installed ROCM:

cd .../rocprofiler
./build.sh ## (for clean build use `-cb`)

To run the test:

cd .../rocprofiler/build
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH # paths to ROC profiler and oher libraries
export HSA_TOOLS_LIB=librocprofiler64.so.1 # ROC profiler library loaded by HSA runtime
export ROCP_TOOL_LIB=test/librocprof-tool.so # tool library loaded by ROC profiler
export ROCP_METRICS=metrics.xml # ROC profiler metrics config file
export ROCP_INPUT=input.xml # input file for the tool library
export ROCP_OUTPUT_DIR=./ # output directory for the tool library, for metrics results file 'results.txt' and trace files
./<your_test>

Internal 'simple_convolution' test run script:

cd .../rocprofiler/build
./run.sh
export ROCPROFILER_LOG=1
export ROCPROFILER_TRACE=1

Supported AMD GPU Architectures (V1)

The following AMD GPU architectures are supported with ROCprofiler V1:


Note: ROCProfiler V1 tool usage documentation is available at Click Here


ROCProfiler V2

The first API library version for ROCProfiler v2 is 9.0.0


Note: ROCProfilerV2 is currently considered a beta version and is subject to change in future releases


ROCProfilerV2 Modules

Getting started

Requirements

Build

The user has two options for building:

Install

Features & Usage

rocsys

A command line utility to control a session (launch/start/stop/exit), with the required application to be traced or profiled in a rocprofv2 context. Usage:

ROCProf Versioning Support

Currently, rocprof can support both versions, rocprof and rocprofv2, that can be done using --tool-version

rocprof --tool-version <VERSION_REQUIRED> <rocprof/v2_options> <app_relative_path>

To know what version you are using right now, along with more information about the rocm version, use the following:

rocprof --version

Counters and Metric Collection

HW counters and derived metrics can be collected using following option:

rocprofv2 -i samples/input.txt <app_relative_path>

input.txt content Example (Details of what is needed inside input.txt will be mentioned with every feature):

pmc: SQ_WAVES GRBM_COUNT GRBM_GUI_ACTIVE SQ_INSTS_VALU

Application Trace Support

Different trace options are available while profiling an app:

Plugin Support

We have a template for adding new plugins. New plugins can be written on top of rocprofv2 to support the desired output format using include/rocprofiler/v2/rocprofiler_plugins.h header file. These plugins are modular in nature and can easily be decoupled from the code based on need. Installation files:

rocprofiler-plugins_2.0.0-local_amd64.deb
rocprofiler-plugins-2.0.0-local.x86_64.rpm

Plugins may have multiple versions, the user can specify which version of the plugin to use by running the following command:

rocprofv2 --plugin <plugin_name> --plugin-version <plugin_version_required> <rocprofv2_options> <app_relative_path>

Flush Interval

Flush interval can be used to control the interval time in milliseconds between the buffers flush for the tool. However, if the buffers are full the flush will be called on its own. This can be used as in the next example:

rocprofv2 --flush-interval <TIME_INTERVAL_IN_MILLISECONDS> <rest_of_rocprofv2_arguments> <app_relative_path>

Trace Period

Trace period can be used to control when the profiling or tracing is enabled using two arguments, the first one is the delay time, which is the time spent idle without tracing or profiling. The second argument is the profiling or the tracing time, which is the active time where the profiling and tracing are working, so basically, the session will work in the following timeline:

<DELAY_TIME> => <PROFILING_OR_TRACING_SESSION_START> => <ACTIVE_PROFILING_OR_TRACING_TIME> => <PROFILING_OR_TRACING_SESSION_STOP>

This feature can be used using the following command:

rocprofv2 --trace-period <delay>:<active_time>:<interval> <rest_of_rocprofv2_arguments> <app_relative_path>

Device Profiling

A device profiling session allows the user to profile the GPU device for counters irrespective of the running applications on the GPU. This is different from application profiling. device profiling session doesn't care about the host running processes and threads. It directly provides low level profiling information.

Session Support

A session is a unique identifier for a profiling/tracing/pc-sampling task. A ROCProfilerV2 Session has enough information about what needs to be collected or traced and it allows the user to start/stop profiling/tracing whenever required. More details on the API can be found in the API specification documentation that can be installed using rocprofiler-doc package. Samples also can be found for how to use the API in samples directory.

Tests

We make use of the GoogleTest (Gtest) framework to automatically find and add test cases to the CMAKE testing environment. ROCProfilerV2 testing is categorized as following:

installation: rocprofiler-tests_9.0.0-local_amd64.deb rocprofiler-tests-9.0.0-local.x86_64.rpm

List and Run tests

Run unit tests on the commandline

./build/tests/unittests/runUnitTests

Run profilerfeaturetests on the commandline

./build/tests/featuretests/profiler/runFeatureTests

Run tracer featuretests on the commandline

./build/tests/featuretests/tracer/runTracerFeatureTests

Run all tests

rocprofv2 -t

OR

ctest

Guidelines for adding new tests

Logging

To enable error messages logging to '/tmp/rocprofiler_log.txt':

export ROCPROFILER_LOG=1

Kernel Name Truncation

By default kernel names are not truncated. To enable truncation for readability:

export ROCPROFILER_TRUNCATE_KERNEL_PATH=1

Documentation

We make use of doxygen to automatically generate API documentation. Generated document can be found in the following path:

ROCM_PATH by default is /opt/rocm It can be set by the user in different location if needed.

/share/doc/rocprofv2 installation: ```string rocprofiler-docs_9.0.0-local_amd64.deb rocprofiler-docs-9.0.0-local.x86_64.rpm ``` ## Samples - Profiling: Profiling Samples depending on replay mode - Tracing: Tracing Samples installation: ```string rocprofiler-samples_9.0.0-local_amd64.deb rocprofiler-samples-9.0.0-local.x86_64.rpm ``` usage: samples can be run as independent executables once installed ## Project Structure - bin: ROCProf scripts along with V1 post processing scripts - doc: Documentation settings for doxygen, V1 API Specifications pdf document. - include: - rocprofiler.h: V1 API Header File - v2: - rocprofiler.h: V2 API Header File - rocprofiler_plugin.h: V2 Tool Plugins API - plugin - file: File Plugin - perfetto: Perfetto Plugin - att: Adavced thread tracer Plugin - ctf: CTF Plugin - samples: Samples of how to use the API, and also input.txt input file samples for counter collection and ATT. - script: Scripts needed for tracing - src: Source files of the project - api: API implementation for rocprofv2 - core: Core source files needed for the V1/V2 API - counters: Basic and Derived Counters - hardware: Hardware support - hsa: Provides support for profiler and tracer to communicate with HSA - queues: Intercepting HSA Queues - packets: Packets Preparation for profiling - memory: Memory Pool used in buffers that saves the output data - session: Session Logic - filter: Type of profiling or tracing and its properties - tracer: Tracing support of the session - profiler: Profiling support of the session - spm: SPM support of the session - att: ATT support of the session - tools: Tools needed to run profiling and tracing - rocsys: Controlling Session from another CLI - utils: Utilities needed by the project - tests: Tests folder - CMakeLists.txt: Handles cmake list for the whole project - build.sh: To easily build and compile rocprofiler - CHANGELOG.md: Changes that are happening per release ## Support Please report in the Github Issues. ## Limitations - Navi3x requires a stable power state for counter collection. Currently, this state needs to be set by the user. To do so, set "power_dpm_force_performance_level" to be writeable for non-root users, then set performance level to profile_standard: ```bash sudo chmod 777 /sys/class/drm/card0/device/power_dpm_force_performance_level echo profile_standard >> /sys/class/drm/card0/device/power_dpm_force_performance_level ``` Recommended: "profile_standard" for counter collection and "auto" for all other profiling. Use rocm-smi to verify the current power state. For multiGPU systems (includes integrated graphics), replace "card0" by the desired card. - Timestamps may be incorrect with HIP_OPS when the system has been in sleep state. - HIP_OPS are mutually exclusive with HSA_OPS. - JSON Plugin as of now doesn't have an automated way to merge for multiple processes, a file will be generated per process (rank). ## Supported AMD GPU Architectures (V2) The following AMD GPU architectures are supported with ROCprofiler V2: - gfx900 (AMD Vega 10) - gfx906 (AMD Vega 7nm also referred to as AMD Vega 20) - gfx908 (AMD Instinct™ MI100 accelerator) - gfx90a (AMD Instinct™ MI200) - gfx94x (AMD Instinct™ MI300) - gfx10xx ([Navi2x] AMD Radeon(TM) Graphics) - gfx11xx ([Navi3x] AMD Radeon(TM) Graphics) > [!WARNING] > The latest mainline version of AQLprofile can be found at [https://repo.radeon.com/rocm/misc/aqlprofile/](https://repo.radeon.com/rocm/misc/aqlprofile/). However, it's important to note that updates to the public AQLProfile may not occur as frequently as updates to the rocprofiler. This discrepancy could lead to a potential mismatch between the AQLprofile binary and the rocprofiler source.