diff --git a/projects/rocprofiler/CHANGELOG.md b/projects/rocprofiler/CHANGELOG.md index f1b67daef7..857a1b92f3 100644 --- a/projects/rocprofiler/CHANGELOG.md +++ b/projects/rocprofiler/CHANGELOG.md @@ -3,7 +3,210 @@ Full documentation for ROCprofiler is available at [docs.amd.com](https://docs.amd.com/bundle/ROCm-Profiling-Tools-User-Guide-v5.3) +As of ROCm 5.5, the ROCm Profiler will not use terminologies like `rocmtools` or +`rocsight` to describe `rocrofiler` as was done in ROCm 5.4. To identify the +separation of the two versions of `rocprofiler`, the terms `rocprofilerV1` and +`rocprofilerV2` will be used. The `rocprofilerV2` API is currently considered a +beta release and subject to changes in future releases. + +## ROCprofiler for rocm 5.4.4 + +In ROCm 5.4 the naming of the ROCm Profiler related files is: + + | ROCm 5.4 | rocprofilerv1 | rocmtools | + |-----------------|-------------------------------------|---------------------------------| + | **Tool script** | `bin/rocprof` | `bin/rocsight` | + | **API include** | `include/rocprofiler/rocprofiler.h` | `include/rocmtools/rocmtools.h` | + | **API library** | `lib/librocprofiler64.so.1` | `lib/librocmtools.so.1` | + +The ROCm Profiler Tool that uses `rocprofilerV1` can be invoked using the +following command: + +```sh +$ rocprof … +``` + +To write a custom tool based on the `rocprofilerV1` API do the following: + +```C +main.c: +#include // Use the rocprofilerV1 API +int main() { + // Use the rocprofilerV1 API + return 0; +} +``` + +This can be built in the following manner: + +```sh +$ gcc main.c -I/opt/rocm-5.4.4/include -L/opt/rocm-5.4.4/lib -lrocprofiler64 +``` + +The resulting `a.out` will depend on +`/opt/rocm-5.4.4/lib/librocprofiler64.so.1`. + +The ROCm Profiler that uses `rocprofilerV2` API can be invoked using the +following command: + +```sh +$ rocsight … +``` + +To write a custom tool based on the `rocmtools` API do the following: + +```C +main.c: +#include // Use the rocmtools API +int main() { + // Use the rocmtools API + return 0; +} +``` + +This can be built in the following manner: + +```sh +$ gcc main.c -I/opt/rocm-5.4.4/include -L/opt/rocm-5.4.4/lib -lrocmtools +``` + +The resulting `a.out` will depend on `/opt/rocm-5.4.4/lib/librocmtools.so.1`. + +## ROCprofiler for rocm 5.5.0 + +In ROCm 5.5 the `rocprofilerv1` and `rocprofilerv2` include and library files +are merged into single files. The `rocmtools` available in ROCm 5.4 is also +available in ROCm 5.5 but is deprecated and will be removed in a future release. + + | ROCm 5.5 | rocprofilerv1 | rocprofilerv2 | rocmtools *(deprecated)* | + |-----------------|-------------------------------------|-------------------------------------|---------------------------------| + | **Tool script** | `bin/rocprof` | `bin/rocprofv2` | `bin/rocsight` | + | **API include** | `include/rocprofiler/rocprofiler.h` | `include/rocprofiler/rocprofiler.h` | `include/rocmtools/rocmtools.h` | + | **API library** | `lib/librocprofiler64.so.1` | `lib/librocprofiler64.so.1` | `lib/librocmtools.so.1` | + + +The ROCm Profiler Tool that uses `rocprofilerV1` can be invoked using the +following command: + +```sh +$ rocprof … +``` + +To write a custom tool based on the `rocprofilerV1` API it is necessary to +define the macro `ROCPROFILER_V1`: + +```C +main.c: +#define ROCPROFILER_V1 +#include +int main() { + // Use the rocprofilerV1 API + return 0; +} +``` + +This can be built in the following manner: + +```sh +$ gcc main.c -I/opt/rocm-5.5.0/include -L/opt/rocm-5.5.0/lib -lrocprofiler64 +``` + +The resulting `a.out` will depend on +`/opt/rocm-5.5.0/lib/librocprofiler64.so.1`. + +The ROCm Profiler that uses `rocprofilerV2` API can be invoked using the +following command: + +```sh +$ rocprofv2 … +``` + +To write a custom tool based on the `rocprofilerV2` API do the following: + +```C +main.c: +#include +int main() { + // Use the rocprofilerV2 API + return 0; +} +``` + +This can be built in the following manner: + +```sh +$ gcc main.c -I/opt/rocm-5.5.0/include -L/opt/rocm-5.5.0/lib -lrocprofiler64 +``` + +The resulting `a.out` will depend on +`/opt/rocm-5.5.0/lib/librocprofiler64.so.1`. + ## ROCprofiler for rocm 5.6.0 + +In ROCm 5.6 the `rocprofilerv1` and `rocprofilerv2` include and library files of +ROCm 5.5 are split into separate files. The `rocmtools` files that were +deprecated in ROCm 5.5 have been removed. + + | ROCm 5.6 | rocprofilerv1 | rocprofilerv2 | + |-----------------|-------------------------------------|----------------------------------------| + | **Tool script** | `bin/rocprof` | `bin/rocprofv2` | + | **API include** | `include/rocprofiler/rocprofiler.h` | `include/rocprofiler/v2/rocprofiler.h` | + | **API library** | `lib/librocprofiler.so.1` | `lib/librocprofiler.so.2` | + +The ROCm Profiler Tool that uses `rocprofilerV1` can be invoked using the +following command: + +```sh +$ rocprof … +``` + +To write a custom tool based on the `rocprofilerV1` API do the following: + +```C +main.c: +#include // Use the rocprofilerV1 API +int main() { + // Use the rocprofilerV1 API + return 0; +} +``` + +This can be built in the following manner: + +```sh +$ gcc main.c -I/opt/rocm-5.6.0/include -L/opt/rocm-5.6.0/lib -lrocprofiler64 +``` + +The resulting `a.out` will depend on +`/opt/rocm-5.6.0/lib/librocprofiler64.so.1`. + +The ROCm Profiler that uses `rocprofilerV2` API can be invoked using the +following command: + +```sh +$ rocprofv2 … +``` + +To write a custom tool based on the `rocprofilerV2` API do the following: + +```C +main.c: +#include // Use the rocprofilerV2 API +int main() { + // Use the rocprofilerV2 API + return 0; +} +``` + +This can be built in the following manner: + +```sh +$ gcc main.c -I/opt/rocm-5.6.0/include -L/opt/rocm-5.6.0/lib -lrocprofiler64-v2 +``` + +The resulting `a.out` will depend on +`/opt/rocm-5.6.0/lib/librocprofiler64.so.2`. + ### Optimized - Improved Test Suite ### Added diff --git a/projects/rocprofiler/CMakeLists.txt b/projects/rocprofiler/CMakeLists.txt index 09b1f72ab8..7b0dfaf3d4 100644 --- a/projects/rocprofiler/CMakeLists.txt +++ b/projects/rocprofiler/CMakeLists.txt @@ -516,8 +516,8 @@ if(DOXYGEN_FOUND) COMMAND make -C ${CMAKE_CURRENT_BINARY_DIR}/doc/latex pdf MAIN_DEPENDENCY ${DOXYGEN_OUT} ${DOXYGEN_IN} - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/inc/rocprofiler.h - ${CMAKE_CURRENT_SOURCE_DIR}/inc/rocprofiler_plugin.h + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/include/rocprofiler/v2/rocprofiler_plugin.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/rocprofiler/v2/rocprofiler.h COMMENT "Generating documentation") add_custom_target( diff --git a/projects/rocprofiler/README.md b/projects/rocprofiler/README.md index b570b64262..d63c01e66c 100644 --- a/projects/rocprofiler/README.md +++ b/projects/rocprofiler/README.md @@ -13,7 +13,9 @@ Library supports GFX8/GFX9. The library source tree: - doc - Documentation - - inc/rocprofiler.h - Library public API + - include/rocprofiler/rocprofiler.h - Library public API + - include/rocprofiler/v2/rocprofiler.h - V2 Beta Library public API + - include/rocprofiler/v2/rocprofiler_plugins.h - V2 Beta Tool's Plugins Library public API - src - Library sources - core - Library API sources - util - Library utils sources diff --git a/projects/rocprofiler/bin/rpl_run.sh b/projects/rocprofiler/bin/rpl_run.sh index f0290e0ac1..ae9bfcb9b1 100755 --- a/projects/rocprofiler/bin/rpl_run.sh +++ b/projects/rocprofiler/bin/rpl_run.sh @@ -61,7 +61,7 @@ unset ROCPROFILER_SESS # Profiler environment # Loading of profiler library by HSA runtime -MY_HSA_TOOLS_LIB="$RPL_PATH/librocprofiler64.so" +MY_HSA_TOOLS_LIB="$RPL_PATH/librocprofiler64.so.1" # Loading of the test tool by ROC Profiler export ROCP_TOOL_LIB=$TLIB_PATH/librocprof-tool.so # Enabling HSA dispatches intercepting by ROC PRofiler @@ -272,16 +272,16 @@ run() { if [ "$HSA_TRACE" = 1 ] ; then export ROCTRACER_DOMAIN=$API_TRACE":hsa" - MY_HSA_TOOLS_LIB="$MY_HSA_TOOLS_LIB $ROCM_LIB_PATH/libroctracer64.so $TTLIB_PATH/libroctracer_tool.so" + MY_HSA_TOOLS_LIB="$MY_HSA_TOOLS_LIB $ROCM_LIB_PATH/libroctracer64.so.4 $TTLIB_PATH/libroctracer_tool.so" elif [ -n "$API_TRACE" ] ; then export ROCTRACER_DOMAIN=$API_TRACE OUTPUT_LIST="$ROCP_OUTPUT_DIR/" - MY_HSA_TOOLS_LIB="$ROCM_LIB_PATH/libroctracer64.so $TTLIB_PATH/libroctracer_tool.so" + MY_HSA_TOOLS_LIB="$ROCM_LIB_PATH/libroctracer64.so.4 $TTLIB_PATH/libroctracer_tool.so" fi if [ "$ROCP_STATS_OPT" = 1 ] ; then if [ "$ROCTRACER_DOMAIN" = ":hip" ] ; then - MY_HSA_TOOLS_LIB="$ROCM_LIB_PATH/libroctracer64.so $TTLIB_PATH/libhip_stats.so" + MY_HSA_TOOLS_LIB="$ROCM_LIB_PATH/libroctracer64.so.4 $TTLIB_PATH/libhip_stats.so" else error_message="ROCP_STATS_OPT is only available with --hip-trace option" echo $error_message diff --git a/projects/rocprofiler/doc/Doxyfile.in b/projects/rocprofiler/doc/Doxyfile.in index a34c460c43..684b13156a 100644 --- a/projects/rocprofiler/doc/Doxyfile.in +++ b/projects/rocprofiler/doc/Doxyfile.in @@ -791,7 +791,7 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = @CMAKE_CURRENT_SOURCE_DIR@/inc/rocprofiler.h @CMAKE_CURRENT_SOURCE_DIR@/inc/rocprofiler_plugin.h +INPUT = @CMAKE_CURRENT_SOURCE_DIR@/include/rocprofiler/v2/rocprofiler.h @CMAKE_CURRENT_SOURCE_DIR@/include/rocprofiler/v2/rocprofiler_plugin.h # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses diff --git a/projects/rocprofiler/doc/ROCProfiler_V1_API_spec.md b/projects/rocprofiler/doc/ROCProfiler_V1_API_spec.md new file mode 100644 index 0000000000..975d58ca56 --- /dev/null +++ b/projects/rocprofiler/doc/ROCProfiler_V1_API_spec.md @@ -0,0 +1,837 @@ +# ROC Profiler Library Specification +ROC Profiler API version 7 + +## 1. High level overview +``` +The goal of the implementation is to provide a HW specific low-level performance analysis +interface for profiling of GPU compute applications. The profiling includes HW performance +counters with complex performance metrics and HW traces. The implementation distinguishes +two profiling features, metrics and traces. HW performance counters are treated as the basic +metrics and the formulas can be defined for derived complex metrics. +The library can be loaded by HSA runtime as a tool plugin and it can be loaded by higher +level HW independent performance analysis API like PAPI. +The library has C API and is based on AQLprofile AMD specific HSA extension. + + 1. The library provides methods to query the list of supported HW features. + 2. The library provides profiling APIs to start, stop, read metrics results and tracing + data. + 3. The library provides a intercepting API for collecting per-kernel profiling data for + the kernels + dispatched to HSA AQL queues. + 4. The library provides mechanism to load profiling tool library plugin by env variable + ROCP_TOOL_LIB. + 5. The library is responsible for allocation of the buffers for profiling and notifying + about output data buffer overflow for traces. + 6. The library is implemented based on AMD specific AQLprofile HSA extension. + 7. The library implementation is abstracted from the specific GFXIP. + 8. The library implementation is extensible: + - Easy adding of counters and metrics + - Counters enumeration + - Counters and metrics can be dynamically configured using XML configuration files with + counters and metrics tables: + o Counters table entry, basic metric: counter name, block name, event id + o Complex metrics table entry: metric name, an expression for calculation the metric + from the counters + +Metrics XML file example: + + + + . . . + + + + . . . + + + + + +``` +## 2. Environment +``` +* HSA_TOOLS_LIB - required to be set to the name of rocprofiler library to be loaded by +HSA runtime +* ROCP_METRICS - path to the metrics XML file +* ROCP_TOOL_LIB - path to profiling tool library loaded by ROC Profiler +* ROCP_HSA_INTERCEPT - if set then HSA dispatches intercepting is enabled +``` +## 3. General API +### 3.1. Description +``` +The library supports method for getting the error number and error string of the last +failed library API call. +To check the conformance of used library APi header and the library binary the version +macros and API methods can be used. + +Returning the error and error string methods: +- rocprofiler_error_string - method for returning the error string + +Library version: +- ROCPROFILER_VERSION_MAJOR - API major version macro +- ROCPROFILER_VERSION_MINOR - API minor version macro +- rocprofiler_version_major - library major version +- rocprofiler_version_minor - library minor version +``` +### 3.2. Returning the error and error string methods +``` +const char* rocprofiler_error_string(); +``` +### 3.3. Library version +``` +The library provides back compatibility if the library major version is less or equal +then the API major version macro. + +API version macros defined in the library API header 'rocprofiler.h': + +ROCPROFILER_VERSION_MAJOR +ROCPROFILER_VERSION_MINOR + +Methods to check library major and minor venison: + +uint32_t rocprofiler_major_version(); +uint32_t rocprofiler_minor_version(); +``` +## 4. Backend API +### 4.1. Description +``` +The library provides the methods to open/close profiling context, to start, stop and read +HW performance counters and traces, to intercept kernel dispatches to collect per-kernel +profiling data. Also the library provides methods to calculate complex performance metrics +and to query the list of available metrics. The library distinguishes two profiling features, +metrics and traces, where HW performance counters are treated as the basic metrics. To check +if there was an error the library methods return HSA standard status code. +For a given context the profiling can be started/stopped and counters sampled in standalone +mode or profiling can be initiated by intercepting the kernel dispatches with registering +a dispatch callback. +For counters sampling, which is the usage model of higher level APIs like PAPI, +the start/stop/read APIs should be used. +For collecting per-kernel data for the submitted to HSA queues kernels the dispatch callback +API should be used. +The library provides back compatibility if the library major version is less or equal. + +Returned API status: +- hsa_status_t - HSA status codes are used from hsa.h header + +Loading and Configuring, loadable plugin on-load/unload methods: +- rocprofiler_settings_t – global properties +- OnLoadTool +- OnLoadToolProp +- OnUnloadTool + +Info API: +- rocprofiler_info_kind_t - profiling info kind +- rocprofiler_info_query_t - profiling info query +- rocprofiler_info_data_t - profiling info data +- rocprofiler_get_info - return the info for a given info kind +- rocprofiler_iterote_inf_ - iterate over the info for a given info kind +- rocprofiler_query_info - iterate over the info for a given info query + +Context API: +- rocprofiler_t - profiling context handle +- rocprofiler_feature_kind_t - profiling feature kind +- rocprofiler_feature_parameter_t - profiling feature parameter +- rocprofiler_data_kind_t - profiling data kind +- rocprofiler_data_t - profiling data +- rocprofiler_feature_t - profiling feature +- rocprofiler_mode_t - profiling modes +- rocprofiler_properties_t - profiler properties +- rocprofiler_open - open new profiling context +- rocprofiler_close - close profiling context and release all allocated resources +- rocprofiler_group_count - return profiling groups count +- rocprofiler_get_group - return profiling group for a given index +- rocprofiler_get_metrics - method for calculating the metrics data +- rocprofiler_iterate_trace_data - method for iterating output trace data instances +- rocprofiler_time_id_t - supported time value ID enumeration +- rocprofiler_get_time – return time for a given time ID and profiling timestamp value + +Sampling API: +- rocprofiler_start - start profiling +- rocprofiler_stop - stop profiling +- rocprofiler_read - read profiling data to the profiling features objects +- rocprofiler_get_data - wait for profiling data + Group versions of start/stop/read/get_data methods: + o rocprofiler_group_start + o rocprofiler_group_stop + o rocprofiler_group_read + o rocprofiler_group_get_data + +Intercepting API: +- rocprofiler_callback_t - profiling callback type +- rocprofiler_callback_data_t - profiling callback data type +- rocprofiler_dispatch_record_t – dispatch record +- rocprofiler_queue_callbacks_t – queue callbacks, dispatch/destroy +- rocprofiler_set_queue_callbacks - set queue kernel dispatch and queue destroy callbacks +- rocprofiler_remove_queue_callbacks - remove queue callbacks + +Context pool API: +- rocprofiler_pool_t – context pool handle +- rocprofiler_pool_entry_t – context pool entry +- rocprofiler_pool_properties_t – context pool properties +- rocprofiler_pool_handler_t – context pool completion handler +- rocprofiler_pool_open - context pool open +- rocprofiler_pool_close - context pool close +- rocprofiler_pool_fetch – fetch and empty context entry to pool +- rocprofiler_pool_release – release a context entry +- rocprofiler_pool_iterate – iterated fetched context entries +- rocprofiler_pool_flush – flush completed context entries +``` +### 4.2. Loading and Configuring +``` +Loading and Configuring +The profiling properties can be set by profiler plugin on loading by ROC runtime. +The profiler library plugin can be set by ROCP_TOOL_LIB env var. + +Global properties: + +typedef struct { + uint32_t intercept_mode; + uint64_t timeout; + uint32_t timestamp_on; +} rocprofiler_settings_t; + +On load/unload methods defined in profiling tool library loaded by ROCP_TOOL_LIB env var: +extern "C" void OnLoadTool(); +extern "C" void OnLoadToolProp(rocprofiler_settings_t* settings); +extern "C" void OnUnloadTool(); + +``` +### 4.3. Info API +``` +The profiling metrics are defined by name and the traces are defined by name and parameters. +All supported features can be iterated using 'iterate_info/query_info' methods. The counter +names are defined in counters table configuration file, each counter has a unique name and +defined by block name and event id. The traces and trace parameters names are same as in +the hardware documentation and the parameters codes are rocprofiler_feature_parameter_t values, +see below in the "Context API" section. + +Profiling info kind: + +typedef enum { + ROCPROFILER_INFO_KIND_METRIC = 0, // metric info + ROCPROFILER_INFO_KIND_METRIC_COUNT = 1, // metrics count + ROCPROFILER_INFO_KIND_TRACE = 2, // trace info + ROCPROFILER_INFO_KIND_TRACE_COUNT = 3, // traces count +} rocprofiler_info_kind_t; + +Profiling info data: + +typedef struct { + rocprofiler_info_kind_t kind; // info data kind + union { + struct { + const char* name; // metric name + uint32_t instances; // instances number + const char* expr; // metric expression, NULL for basic counters + const char* description; // metric description + const char* block_name; // block name + uint32_t block_counters; // number of block counters + } metric; + struct { + const char* name; // trace name + const char* description; // trace description + uint32_t parameter_count; // supported by the trace number + // parameters + } trace; + }; +} rocprofiler_info_data_t; + +Return info for a given info kind: + +has_status_t rocprofiler_get_info( + const hsa_agent_t* agent, // [in] GPU handle, NULL for all + // GPU agents + rocprofiler info_kind_t kind, // kind of iterated info + void *data); // data passed to callback + +Iterate over the info for a given info kind, and invoke an application-defined callback on +every iteration: + +has_status_t rocprofiler_iterate_info( + const hsa_agent_t* agent, // [in] GPU handle, NULL for all + // GPU agents + rocprofiler info_kind_t kind, // kind of iterated info + hsa_status_t (*callback)(const rocprofiler_info_data_t info, void *data), // callback + void *data); + +Iterate over the info for a given info query, and invoke an application-defined callback on +every iteration. The query +fields set to NULL define the query wildcard: + +has_status_t rocprofiler_query_info( + const hsa_agent_t* agent, // [in] GPU handle, NULL for all + // GPU agents + rocprofiler info_kind_t kind, // kind of iterated info + rocprofiler_info_data_t query, // info query + hsa_status_t (*callback)(const rocprofiler_info_data_t info, void *data), // callback + void *data); // data passed to callback +``` +### 4.4. Context API +``` +Profiling context is accumulating all profiling information including profiling features +which carry profiling data, required buffers for profiling command packets and output data. +The context can be created and deleted by the library open/close methods. By deleting +the context all accumulated by the library resources associated with this context will be +released. If it is required more than one run to collect all requested counters data then +data for all profiling groups should be collected and then the metrics can be calculated by +loading the saved groups' data to the profiling context. Saving and loading of the groups +data is responsibility of the tool. The groups are automatically identified on the profiling +context open and there is API to access them, see the "Profiling groups" section below. + +Profiling context handle: + +typename rocprofiler_t; + +Profiling feature kind: + +typedef enum { + ROCPROFILER_FEATURE_KIND_METRIC = 0, // metric + ROCPROFILER_FEATURE_KIND_TRACE = 1 // trace +} rocprofiler_feature_kind_t; + +Profiling feature parameter: + +typedef hsa_ven_amd_aqlprofile_parameter_t rocprofiler_feature_parameter_t; + +Profiling data kind: + +typedef enum { + ROCPROFILER_DATA_KIND_UNINIT = 0, // data uninitialized + ROCPROFILER_DATA_KIND_INT32 = 1, // 32bit integer + ROCPROFILER_DATA_KIND_INT64 = 2, // 64bit integer + ROCPROFILER_DATA_KIND_FLOAT = 3, // float single-precision result + ROCPROFILER_DATA_KIND_DOUBLE = 4, // float double-precision result + ROCPROFILER_DATA_KIND_BYTES = 5 // trace output as a bytes array +} rocprofiler_data_kind_t; + + +Profiling data: + +typedef struct { + rocprofiler_data_kind_t kind; // result kind + union { + uint32_t result_int32; // 32bit integer result + uint64_t result_int64; // 64bit integer result + float result_float; // float single-precision result + double result_double; // float double-precision result + typedef struct { + void* ptr; // pointer + uint32_t size; // byte size + uint32_t instances; // number of trace instances + } result_bytes; // data by ptr and byte size + }; +} rocprofiler_data_t; + +Profiling feature: + +typedef struct { + rocprofiler_feature_kind_t type; // feature type + const char* name; // feature name + const rocprofiler_feature_parameter_t* parameters; // feature parameters + uint32_t parameter_count; // feature parameter count + rocprofiler_data_t* data; // profiling data +} rocprofiler_feature_t; + +Profiling mode masks: +There are several modes which can be specified for the profiling context. +STANDALONE mode can be used for the counters sampling in another then application context +to support statistical system wide profiling. In this mode the profiling context supports +its own queue which can be created on the context open if the CREATEQUEUE mode also specified. +See also "Profiler properties" section below for the standalone mode queue properties. +The profiler supports several profiling groups for collecting profiling data in several +runs and 'SINGLEGROUP' mode allows only one group and the context open will fail if more +groups are needed. + +typedef enum { + ROCPROFILER_MODE_STANDALONE = 1, // standalone mode when ROC profiler + // supports own AQL queue + ROCPROFILER_MODE_CREATEQUEUE = 2, // profiler creates queue in STANDALONE mode + ROCPROFILER_MODE_SINGLEGROUP = 4 // profiler allows one group only and fails + // if more groups are needed +} rocprofiler_mode_t; + +Context data readiness callback: + +typedef void (*rocprofiler_context_callback_t)( + rocprofiler_group_t* group, // profiling group + void* arg); // callback arg + +Profiler properties: +There are several properties which can be specified for the context. A callback can be +registered which will be called when the context data is ready. In standalone profiling mode +'ROCPROFILER_MODE_STANDALONE' the context supports its own queue and the queue can be set by +the property 'queue' or a queue will be created with the specified depth 'queue_depth' if mode +'ROCPROFILER_MODE_CREATEQUEUE' also specified. + +typedef struct { + rocprofiler_context_callback_t callback; // callback on the context data readiness + void* callback_arg; // callback arg + has_queue_t* queue; // HSA queue for standalone mode + uint32_t queue_depth; // created queue depth,for create-queue mode +} rocprofiler_properties_t; + +Open/close profiling context: + +hsa_status_t rocprofiler_open( + hsa_agent_t agent, // GPU handle + rocprofiler_feature_t* features, // [in/out] profiling feature array + uint32_t feature_count, // profiling feature count + rocprofiler_t** context, // [out] profiling context handle + uint32_t mode, // profiling mode mask + rocprofiler_properties_t* properties); // profiler properties + +hsa_status_t rocprofiler_close( + rocprofiler_t* context); // [in] profiling context + +Profiling groups: +The profiler on the context open automatically identifies a required number of the application +runs to collect all data needed for all specified metrics and creates a metric group per each +run. Data for all profiling groups should be collected and then the metrics can be calculated +by loading the saved groups' data to the profiling context. Saving and loading of he groups +data is responsibility of the tool. + +typedef struct { + uint32_t index; // profiling group index + rocprofiler_feature_t** features; // profiling features array + uint32_t feature_count; // profiling feature count + rocprofiler_t* context; // profiling context handle +} rocprofiler_group_t; + +Return profiling groups count: + +hsa_status_t rocprofiler_group_count( + rocprofiler_t* context); // [in/out] profiling context + uint32* count); // [out] profiling groups count + +Return the profiling group for a given index: + +hsa_status_t rocprofiler_get_group( + rocprofiler_t* context, // [in/out] profiling context, + // will be returned as + // a part of the group structure + uint32_t index, // [in] group index + rocprofiler_group_t* group); // [out] profiling group + +Calculate metrics data. The data will be stored to the registered profiling features data fields: +After all profiling context data is ready the registered metrics can be calculated. The context +data readiness can be checked by 'get_data' API or using the context callback. + +hsa_status_t rocprofiler_get_metrics( + rocprofiler_t* context); // [in/out] profiling context + +Method for iterating trace data instances: +Trace data can have several instance, for example, one instance per Shader Engine. + +hsa_status_t rocprofiler_iterate_trace_data( + const rocprofiler_t* contex, // [in] context object + hsa_ven_amd_aqlprofile_data_callback_t callback, // [in] callback to iterate + // the output data + void* callback_data); // [in/out] passed to callback data + +Converting of profiling timestamp to time value for suported time ID. +Supported time value ID enumeration: +typedef enum { + ROCPROFILER_TIME_ID_CLOCK_REALTIME = 0, // Linux realtime clock time + ROCPROFILER_TIME_ID_CLOCK_MONOTONIC = 1, // Linux monotonic clock time +} rocprofiler_time_id_t; + +Method for converting of profiling timestamp to time value for a given time ID: +hsa_status_t rocprofiler_get_time( + rocprofiler_time_id_t time_id, // identifier of the particular + // time to convert the timestamp + uint64_t timestamp, // profiling timestamp + uint64_t* value_ns); // [out] returned time ‘ns’ value +``` +### 4.5. Sampling API +``` +The API supports the counters sampling usage model with start/read/stop methods and also lets +to wait for the profiling data in the intercepting usage model with get_data method. + +Start/stop/read methods: + +hsa_status_t rocprofiler_start( + rocprofiler_t* context, // [in/out] profiling context + uint32_t group_index = 0); // group index + +hsa_status_t rocprofiler_stop( + rocprofiler_t* context, // [in/out] profiling context + uint32_t group_index = 0); // group index + +hsa_status_t rocprofiler_read( + rocprofiler_t* context, // [in/out] profiling context + uint32_t group_index = 0); // group index + +Wait for profiling data: + +hsa_status_t rocprofiler_get_data( + rocprofiler_t* context, // [in/out] profiling context + uint32_t group_index = 0); // group index + +Group versions of the above start/stop/read/get_data methods: + +hsa_status_t rocprofiler_group_start( + rocprofiler_group_t* group); // [in/out] profiling group + +hsa_status_t rocprofiler_group_stop( + rocprofiler_group_t* group); // [in/out] profiling group + + +hsa_status_t rocprofiler_group_read( + rocprofiler_group_t* group); // [in/out] profiling group + + +hsa_status_t rocprofiler_group_get_data( + rocprofiler_group_t* group); // [in/out] profiling group +``` +### 4.6. Intercepting API +``` +The library provides a callback API for enabling profiling for the kernels dispatched to +HSA AQL queues. The API enables per-kernel profiling data collection. +Currently implemented the option with serializing the kernels execution. + +ROC profiler callback type: + +hsa_status_t (*rocprofiler_callback_t)( + const rocprofiler_callback_data_t* callback_data, // callback data passed by HSA runtime + void* user_data, // [in/out] user data passed + // to the callback + rocprofiler_group** group); // [out] returned profiling group + +Profiling callback data: + +typedef struct { + uint64_t dispatch; // dispatch timestamp + uint64_t begin; // begin timestamp + uint64_t end; // end timestamp + uint64_t complete; // completion signal timestamp +} rocprofiler_dispatch_record_t; + +typedef struct { + hsa_agent_t agent; // GPU agent handle + uint32_t agent_index; // GPU index + const hsa_queue_t* queue; // HSA queue + uint64_t queue_index; // Index in the queue + const hsa_kernel_dispatch_packet_t* packet; // HSA dispatch packet + const char* kernel_name; // Kernel name + const rocprofiler_dispatch_record_t* record; // Dispatch record +} rocprofiler_callback_data_t; + +Queue callbacks: + +typedef struct { + rocprofiler_callback_t dispatch; // kernel dispatch callback + hsa_status_t (*destroy)(hsa_queue_t* queue, void* data); // queue destroy callback +} rocprofiler_queue_callbacks_t; + +Adding/removing kernel dispatch and queue destroy callbacks + +hsa_status_t rocprofiler_set_intercepting( + rocprofiler_intercepting_t callbacks, // intercepting callbacks + void* data); // [in/out] passed callbacks data + +hsa_status_t rocprofiler_remove_intercepting(); +``` +### 4.7. Profiling Context Pools +``` +The API provide capability to create a context pool for a given agent and a set of features, to fetch/release a context entry, to register a callback for pool’s contexts completion. +Profiling pool handle: +typename rocprofiler_pool_t; +Profiling pool entry: +typedef struct { + rocprofiler_t* context; // context object + void* payload; // payload data object +} rocprofiler_pool_entry_t; + +Profiling handler, calling on profiling completion: +typedef bool (*rocprofiler_pool_handler_t)(const rocprofiler_pool_entry_t* entry, void* arg); + +Profiling properties: +typedef struct { + uint32_t num_entries; // pool size entries + uint32_t payload_bytes; // payload size bytes + rocprofiler_pool_handler_t handler; // handler on context completion + void* handler_arg; // the handler arg +} rocprofiler_pool_properties_t; + +Open profiling pool: +hsa_status_t rocprofiler_pool_open( + hsa_agent_t agent, // GPU handle + rocprofiler_feature_t* features, // [in] profiling features array + uint32_t feature_count, // profiling info count + rocprofiler_pool_t** pool, // [out] context object + uint32_t mode, // profiling mode mask + rocprofiler_pool_properties_t*); // pool properties + +Close profiling pool: +hsa_status_t rocprofiler_pool_close( + rocprofiler_pool_t* pool); // profiling pool handle + +Fetch profiling pool entry: +hsa_status_t rocprofiler_pool_fetch( + rocprofiler_pool_t* pool, // profiling pool handle + rocprofiler_pool_entry_t* entry); // [out] empty profiling pool entry + +Release profiling pool entry: +hsa_status_t rocprofiler_pool_release( + rocprofiler_pool_entry_t* entry); // released profiling pool entry + +Iterate fetched profiling pool entries: +hsa_status_t rocprofiler_pool_iterate( + rocprofiler_pool_t* pool, // profiling pool handle + hsa_status_t (*callback)(rocprofiler_pool_entry_t* entry, void* data), + // callback + void *data); // [in/out] data passed to callback + +Flush completed entries in profiling pool: +hsa_status_t rocprofiler_pool_flush( + rocprofiler_pool_t* pool); // profiling pool handle +``` +## 5. Application code examples +### 5.1. Querying available metrics +``` +Info data callback: + + hsa_status_t info_data_callback(const rocprofiler_info_data_t info, void *data) { + switch (info.kind) { + case ROCPROFILER_INFO_KIND_METRIC: { + if (info.metric.expr != NULL) { + fprintf(stdout, "Derived counter: gpu-agent%d : %s : %s\n", + info.agent_index, info.metric.name, info.metric.description); + fprintf(stdout, " %s = %s\n", info.metric.name, info.metric.expr); + } else { + fprintf(stdout, "Basic counter: gpu-agent%d : %s", + info.agent_index, info.metric.name); + if (info.metric.instances > 1) { + fprintf(stdout, "[0-%u]", info.metric.instances - 1); + } + fprintf(stdout, " : %s\n", info.metric.description); + fprintf(stdout, " block %s has %u counters\n", + info.metric.block_name, info.metric.block_counters); + } + fflush(stdout); + break; + } + default: + printf("wrong info kind %u\n", kind); + return HSA_STATUS_ERROR; + } + return HSA_STATUS_SUCCESS; + } + +Printing all available metrics: + + hsa_status_t status = rocprofiler_iterate_info( + agent, + ROCPROFILER_INFO_KIND_METRIC, + info_data_callback, + NULL); + +``` +### 5.2. Profiling code example +``` +Profiling of L1 miss ratio, average memory bandwidth. +In the example below rocprofiler_group_get_data group APIs are used for the purpose of a usage +example but in SINGLEGROUP mode when only one group is allowed the context handle itself can be +saved and then direct context method rocprofiler_get_data with default group index equal to 0 +can be used. + +hsa_status_t dispatch_callback( + const rocprofiler_callback_data_t* callback_data, + void* user_data, + rocprofiler_group_t* group) +{ + hsa_status_t status = HSA_STATUS_SUCCESS; + // Profiling context + rocprofiler_t* context; + // Profiling info objects + rocprofiler_feature_t features* = new rocprofiler_feature_t[2]; + // Tracing parameters + rocprofiler_feature_parameter_t* parameters = new rocprofiler_feature_parameter_t[2]; + + // Setting profiling features + features[0].type = ROCPROFILER_METRIC; + features[0].name = "L1_MISS_RATIO"; + features[1].type = ROCPROFILER_METRIC; + features[1].name = "DRAM_BANDWIDTH"; + + // Creating profiling context + status = rocprofiler_open(callback_data->dispatch.agent, features, 2, &context, + ROCPROFILER_MODE_SINGLEGROUP, NULL); + + + // Get the profiling group + // For general case with many groups there is rocprofiler_group_count() API + const uint32_t group_index = 0 + status = rocprofiler_get_group(context, group_index, group); + + + // In SINGLEGROUP mode the context handle itself can be saved, because there is just one group + + + return status; +} + +Profiling tool constructor is adding the dispatch callback: + +void profiling_libary_constructor() { + // Defining callback data, no data in this simple example + void* callback_data = NULL; + + // Adding observers + hsa_sttaus_t status = rocprofiler_add_dispatch_callback(dispatch_callback, callback_data); + + + // Dispatching profiled kernel + +} + +void profiling_libary_destructor() { + > { + // In SINGLEGROUP mode the rocprofiler_get_group() method with default zero group + // index can be used, if context handle would be saved + status = rocprofiler_group_get_data(entry->group); + + status = rocprofiler_get_metrics(entry->group->context); + + status = rocprofiler_close(entry->group->context); + + + dispatch_data, entry->features, entry->features_count)>; + } +} +``` +### 5.3. Option to use completion callback +``` +Creating profiling context with completion callback: + . . . + rocprofiler_properties_t properties = {}; + properties.callback = completion_callback; + properties.callback_arg = NULL; // no args defined + status = rocprofiler_open(agent, features, 3, &context, + ROCPROFILER_MODE_SINGLEGROUP, properties); + + . . . + +Definition of completion callback: + +void completion_callback(profiler_group_t group, void* arg) { + + hsa_status_t status = rocprofiler_close(group.context); + +} +``` +### 5.4. Option to Use Context Pool +``` +Code example of context pool usage. +Creating profiling contexts pool: + . . . + rocprofiler_pool_properties_t properties{}; + properties.num_entries = 100; + properties.payload_bytes = sizeof(context_entry_t); + properties.handler = context_handler; + properties.handler_arg = handler_arg; + status = rocprofiler_pool_open(agent, features, 3, &context, + ROCPROFILER_MODE_SINGLEGROUP, properties); + + . . . + +Fetching a context entry: + rocprofiler_pool_entry_t pool_entry{}; + status = rocprofiler_pool_fetch(pool, &pool_entry); + + // Profiling context entry + rocprofiler_t* context = pool_entry.context; + context_entry_t* entry = reinterpret_cast + (pool_entry.payload); +``` +### 5.5. Standalone Sampling Usage Code Example +``` +The profiling metrics are being read from separate standalone queue other than the application kernels are submitted to. +To enable the sampling mode, the profiling mode in all user queues should be enabled. It can be done by loading ROC-profiler +library to HSA runtime using the environment variable HSA_TOOLS_LIB for all shell sessions. + // Sampling rate + uint32_t sampling_rate = ; + // Sampling count + uint32_t sampling_count = ; + // HSA status + hsa_status_t status = HSA_STATUS_ERROR; + // HSA agent + hsa_agent_t agent; + // Profiling context + rocprofiler_t* context = NULL; + // Profiling properties + rocprofiler_properties_t properties; + + // Getting HSA agent + + + // Profiling feature objects + const unsigned feature_count = 2; + rocprofiler_feature_t feature[feature_count]; + + // Counters and metrics + feature[0].kind = ROCPROFILER_FEATURE_KIND_METRIC; + feature[0].name = "GPUBusy"; + feature[1].kind = ROCPROFILER_FEATURE_KIND_METRIC; + feature[1].name = "SQ_WAVES"; + + // Creating profiling context with standalone queue + properties = {}; + properties.queue_depth = 128; + status = rocprofiler_open(agent, feature, feature_count, &context, + ROCPROFILER_MODE_STANDALONE| ROCPROFILER_MODE_CREATEQUEUE| + ROCPROFILER_MODE_SINGLEGROUP, &properties); + + + // Start counters and sample them in the loop with the sampling rate + status = rocprofiler_start(context, 0); + + + for (unsigned ind = 0; ind < sampling_count; ++ind) { + sleep(sampling_rate); + status = rocprofiler_read(context, 0); + + status = rocprofiler_get_data(context, 0); + + status = rocprofiler_get_metrics(context); + + print_results(feature, feature_count); + } + + // Stop counters + status = rocprofiler_stop(context, group_n); + + + // Finishing cleanup + // Deleting profiling context will delete all allocated resources + status = rocprofiler_close(context); + +``` +### 5.6. Printing Out Profiling Results +``` +Below is a code example for printing out the profiling results from profiling features array: +void print_results(rocprofiler_feature_t* feature, uint32_t feature_count) { + for (rocprofiler_feature_t* p = feature; p < feature + feature_count; ++p) + { + std::cout << (p - feature) << ": " << p->name; + switch (p->data.kind) { + case ROCPROFILER_DATA_KIND_INT64: + std::cout << " result_int64 (" << p->data.result_int64 << ")" + << std::endl; + break; + + case ROCPROFILER_DATA_KIND_BYTES: { + std::cout << " result_bytes ptr(" << p->data.result_bytes.ptr << + ") " << " size(" << p->data.result_bytes.size << ")" + << " instance_count(" << p->data.result_bytes.instance_count + << ")"; + break; + } + default: + std::cout << "bad result kind (" << p->data.kind << ")" + << std::endl; + + } + } +} +``` diff --git a/projects/rocprofiler/doc/ROC_profiler_API.pptx b/projects/rocprofiler/doc/ROC_profiler_V1_API.pptx similarity index 100% rename from projects/rocprofiler/doc/ROC_profiler_API.pptx rename to projects/rocprofiler/doc/ROC_profiler_V1_API.pptx diff --git a/projects/rocprofiler/doc/Rocprofiler_Documentation.pdf b/projects/rocprofiler/doc/Rocprofiler_V1_Usage_Documentation.pdf similarity index 100% rename from projects/rocprofiler/doc/Rocprofiler_Documentation.pdf rename to projects/rocprofiler/doc/Rocprofiler_V1_Usage_Documentation.pdf diff --git a/projects/rocprofiler/doc/rocprof_tool.md b/projects/rocprofiler/doc/rocprof_tool.md new file mode 100644 index 0000000000..7746d1ff2c --- /dev/null +++ b/projects/rocprofiler/doc/rocprof_tool.md @@ -0,0 +1,393 @@ +# rocprof +## 1. Overview +The rocProf is a command line tool implemented on the top of rocProfiler and rocTracer APIs. Source code for rocProf may be found here: +GitHub: https://github.com/ROCm-Developer-Tools/rocprofiler/blob/amd-master/bin/rocprof +This command line tool is implemented as a script which is setting up the environment for attaching the profiler and then run the provided application command line. The tool uses two profiling plugins loaded by ROC runtime and based on rocProfiler and rocTracer for collecting metrics/counters, HW traces and runtime API/activity traces. The tool consumes an input XML or text file with counters list or trace parameters and provides output profiling data and statistics in various formats as text, CSV and JSON traces. Google Chrome tracing can be used to visualize the JSON traces with runtime API/activity timelines and per kernel counters data. +## 2. Profiling Modes +‘rocprof’ can be used for GPU profiling using HW counters and application tracing +### 2.1. GPU profiling +GPU profiling is controlled with input file which defines a list of metrics/counters and a profiling scope. An input file is provided using option ‘-i ’. Output CSV file with a line per submitted kernel is generated. Each line has kernel name, kernel parameters and counter values. By option ‘—stats’ the kernel execution stats can be generated in CSV format. Currently profiling has limitation of serializing submitted kernels. +An example of input file: +``` + # Perf counters group 1 + pmc : Wavefronts VALUInsts SALUInsts SFetchInsts + # Perf counters group 2 + pmc : TCC_HIT[0], TCC_MISS[0] + # Filter by dispatches range, GPU index and kernel names + # supported range formats: "3:9", "3:", "3" + range: 1 : 4 + gpu: 0 1 2 3 + kernel: simple Pass1 simpleConvolutionPass2 +``` +An example of profiling command line for ‘MatrixTranspose’ application +``` +$ rocprof -i input.txt MatrixTranspose +RPL: on '191018_011134' from '/…./rocprofiler_pkg' in '/…./MatrixTranspose' +RPL: profiling '"./MatrixTranspose"' +RPL: input file 'input.txt' +RPL: output dir '/tmp/rpl_data_191018_011134_9695' +RPL: result dir '/tmp/rpl_data_191018_011134_9695/input0_results_191018_011134' +ROCProfiler: rc-file '/…./rpl_rc.xml' +ROCProfiler: input from "/tmp/rpl_data_191018_011134_9695/input0.xml" + gpu_index = + kernel = + range = + 4 metrics + L2CacheHit, VFetchInsts, VWriteInsts, MemUnitStalled + 0 traces +Device name Ellesmere [Radeon RX 470/480/570/570X/580/580X] +PASSED! + +ROCPRofiler: 1 contexts collected, output directory /tmp/rpl_data_191018_011134_9695/input0_results_191018_011134 +RPL: '/…./MatrixTranspose/input.csv' is generated +``` +#### 2.1.1. Counters and metrics +There are two profiling features, metrics and traces. Hardware performance counters are treated as the basic metrics and the formulas can be defined for derived metrics. +Counters and metrics can be dynamically configured using XML configuration files with counters and metrics tables: + - Counters table entry, basic metric: counter name, block name, event id + - Derived metrics table entry: metric name, an expression for calculation the metric from the counters + +Metrics XML File Example: +``` + + + + . . . + + + + . . . + + + + + +``` +##### 2.1.1.1. Metrics query +Available counters and metrics can be queried by options ‘—list-basic’ for counters and ‘—list-derived’ for derived metrics. The output for counters indicates number of block instances and number of block counter registers. The output for derived metrics prints the metrics expressions. +Examples: +``` +$ rocprof --list-basic +RPL: on '191018_014450' from '/opt/rocm/rocprofiler' in '/…./MatrixTranspose' +ROCProfiler: rc-file '/…./rpl_rc.xml' +Basic HW counters: + gpu-agent0 : GRBM_COUNT : Tie High - Count Number of Clocks + block GRBM has 2 counters + gpu-agent0 : GRBM_GUI_ACTIVE : The GUI is Active + block GRBM has 2 counters + . . . + gpu-agent0 : TCC_HIT[0-15] : Number of cache hits. + block TCC has 4 counters + gpu-agent0 : TCC_MISS[0-15] : Number of cache misses. UC reads count as misses. + block TCC has 4 counters + . . . + +$ rocprof --list-derived +RPL: on '191018_015911' from '/opt/rocm/rocprofiler' in '/home/evgeny/work/BUILD/0_MatrixTranspose' +ROCProfiler: rc-file '/home/evgeny/rpl_rc.xml' +Derived metrics: + gpu-agent0 : TCC_HIT_sum : Number of cache hits. Sum over TCC instances. + TCC_HIT_sum = sum(TCC_HIT,16) + gpu-agent0 : TCC_MISS_sum : Number of cache misses. Sum over TCC instances. + TCC_MISS_sum = sum(TCC_MISS,16) + gpu-agent0 : TCC_MC_RDREQ_sum : Number of 32-byte reads. Sum over TCC instaces. + TCC_MC_RDREQ_sum = sum(TCC_MC_RDREQ,16) + . . . +``` +##### 2.1.1.2. Metrics collecting +Counters and metrics accumulated per kernel can be collected using input file with a list of metrics, see an example in 2.1. +Currently profiling has limitation of serializing submitted kernels. +The number of counters which can be dumped by one run is limited by GPU HW by number of counter registers per block. The number of counters can be different for different blocks and can be queried, see 2.1.1.1. +###### 2.1.1.2.1. Blocks instancing +GPU blocks are implemented as several identical instances. To dump counters of specific instance square brackets can be used, see an example in 2.1. +The number of block instances can be queried, see 2.1.1.1. +###### 2.1.1.2.2. HW limitations +The number of counters which can be dumped by one run is limited by GPU HW by number of counter registers per block. The number of counters can be different for different blocks and can be queried, see 2.1.1.1. + - Metrics groups + +To dump a list of metrics exceeding HW limitations the metrics list can be split on groups. +The tool supports automatic splitting on optimal metric groups: +``` +$ rocprof -i input.txt ./MatrixTranspose +RPL: on '191018_032645' from '/opt/rocm/rocprofiler' in '/…./MatrixTranspose' +RPL: profiling './MatrixTranspose' +RPL: input file 'input.txt' +RPL: output dir '/tmp/rpl_data_191018_032645_12106' +RPL: result dir '/tmp/rpl_data_191018_032645_12106/input0_results_191018_032645' +ROCProfiler: rc-file '/…./rpl_rc.xml' +ROCProfiler: input from "/tmp/rpl_data_191018_032645_12106/input0.xml" + gpu_index = + kernel = + range = + 20 metrics + Wavefronts, VALUInsts, SALUInsts, SFetchInsts, FlatVMemInsts, LDSInsts, FlatLDSInsts, GDSInsts, VALUUtilization, FetchSize, WriteSize, L2CacheHit, VWriteInsts, GPUBusy, VALUBusy, SALUBusy, MemUnitStalled, WriteUnitStalled, LDSBankConflict, MemUnitBusy + 0 traces +Device name Ellesmere [Radeon RX 470/480/570/570X/580/580X] + +Input metrics out of HW limit. Proposed metrics group set: + group1: L2CacheHit VWriteInsts MemUnitStalled WriteUnitStalled MemUnitBusy FetchSize FlatVMemInsts LDSInsts VALUInsts SALUInsts SFetchInsts FlatLDSInsts GPUBusy Wavefronts + group2: WriteSize GDSInsts VALUUtilization VALUBusy SALUBusy LDSBankConflict + +ERROR: rocprofiler_open(), Construct(), Metrics list exceeds HW limits + +Aborted (core dumped) +Error found, profiling aborted. +``` + - Collecting with multiple runs + +To collect several metric groups a full application replay is used by defining several ‘pmc:’ lines in the input file, see 2.1. + +### 2.2. Application tracing +Supported application tracing includes runtime API and GPU activity tracing’ +Supported runtimes are: ROCr (HSA API) and HIP +Supported GPU activity: kernel execution, async memory copy, barrier packets. +The trace is generated in JSON format compatible with Chrome tracing. +The trace consists of several sections with timelines for API trace per thread and GPU activity. The timelines events show event name and parameters. +Supported options: ‘—hsa-trace’, ‘—hip-trace’, ‘—sys-trace’, where ‘sys trace’ is for HIP and HSA combined trace. +#### 2.2.1. HIP runtime trace +The trace is generated by option ‘—hip-trace’ and includes HIP API timelines and GPU activity at the runtime level. +#### 2.2.2. ROCr runtime trace +The trace is generated by option ‘—hsa-trace’ and includes ROCr API timelines and GPU activity at AQL queue level. Also, can provide counters per kernel. +#### 2.2.3. KFD driver trace +The trace is generated by option ‘—kfd-trace’ and includes KFD Thunk API timeline. +It is planned to add memory allocations/migration tracing. +#### 2.2.4. Code annotation +Support for application code annotation. +Start/stop API is supported to programmatically control the profiling. +A ‘roctx’ library provides annotation API. Annotation is visualized in JSON trace as a separate "Markers and Ranges" timeline section. +##### 2.2.4.1. Start/stop API +``` +// Tracing start API +void roctracer_start(); + +// Tracing stop API +void roctracer_stop(); +``` +##### 2.2.4.2. rocTX basic markers API +``` +// A marker created by given ASCII massage +void roctxMark(const char* message); + +// Returns the 0 based level of a nested range being started by given message associated to this range. +// A negative value is returned on the error. +int roctxRangePush(const char* message); + +// Marks the end of a nested range. +// Returns the 0 based level the range. +// A negative value is returned on the error. +int roctxRangePop(); +``` +### 2.3. Multiple GPUs profiling +The profiler supports multiple GPU’s profiling and provide GPI id for counters and kernels data in CSV output file. Also, GPU id is indicating for respective GPU activity timeline in JSON trace. +## 3. Profiling control +Profiling can be controlled by specifying a profiling scope, by filtering trace events and specifying interesting time intervals. +### 3.1. Profiling scope +Counters profiling scope can be specified by GPU id list, kernel name substrings list and dispatch range. +Supported range formats examples: "3:9", "3:", "3". You can see an example of input file in 2.1. +#### 3.2. Tracing control +Tracing can be filtered by events names using profiler input file and by enabling interesting time intervals by command line option. +#### 3.2.1. Filtering traced APIs +A list of traced API names can be specified in profiler input file. +An example of input file line for ROCr runtime trace (HAS API): +``` +hsa: hsa_queue_create hsa_amd_memory_pool_allocate +``` +#### 3.2.2. Tracing time period +Trace can be dumped periodically with initial delay, dumping period length and rate: +``` +--trace-period +``` +### 3.3. Concurrent kernels +Currently concurrent kernels profiling is not supported which is a planned feature. Kernels are serialized. +### 3.4. Multi-processes profiling +Multi-processes profiling is not currently supported. +### 3.5. Errors logging +Profiler errors are logged to global logs: +``` +/tmp/aql_profile_log.txt +/tmp/rocprofiler_log.txt +/tmp/roctracer_log.txt +``` +## 4. 3rd party visualization tools +‘rocprof’ is producing JSON trace compatible with Chrome Tracing, which is an internal trace visualization tool in Google Chrome. +### 4.1. Chrome tracing +Good review can be found by the link: https://aras-p.info/blog/2017/01/23/Chrome-Tracing-as-Profiler-Frontend/ +## 5. Command line options +The command line options can be printed with option ‘-h’: +``` +$ rocprof -h +RPL: on '191018_023018' from '/opt/rocm/rocprofiler' in '/…./MatrixTranspose' +ROCm Profiling Library (RPL) run script, a part of ROCprofiler library package. +Full path: /opt/rocm/rocprofiler/bin/rocprof +Metrics definition: /opt/rocm/rocprofiler/lib/metrics.xml + +Usage: + rocprof [-h] [--list-basic] [--list-derived] [-i ] [-o ] + +Options: + -h - this help + --verbose - verbose mode, dumping all base counters used in the input metrics + --list-basic - to print the list of basic HW counters + --list-derived - to print the list of derived metrics with formulas + --cmd-qts - quoting profiled cmd-line [on] + + -i <.txt|.xml file> - input file + Input file .txt format, automatically rerun application for every pmc line: + + # Perf counters group 1 + pmc : Wavefronts VALUInsts SALUInsts SFetchInsts FlatVMemInsts LDSInsts FlatLDSInsts GDSInsts VALUUtilization FetchSize + # Perf counters group 2 + pmc : WriteSize L2CacheHit + # Filter by dispatches range, GPU index and kernel names + # supported range formats: "3:9", "3:", "3" + range: 1 : 4 + gpu: 0 1 2 3 + kernel: simple Pass1 simpleConvolutionPass2 + + Input file .xml format, for single profiling run: + + # Metrics list definition, also the form ":" can be used + # All defined metrics can be found in the 'metrics.xml' + # There are basic metrics for raw HW counters and high-level metrics for derived counters + + + # Filter by dispatches range, GPU index and kernel names + + + -o - output CSV file [.csv] + -d - directory where profiler store profiling data including traces [/tmp] + The data directory is renoving autonatically if the directory is matching the temporary one, which is the default. + -t - to change the temporary directory [/tmp] + By changing the temporary directory you can prevent removing the profiling data from /tmp or enable removing from not '/tmp' directory. + + --basenames - to turn on/off truncating of the kernel full function names till the base ones [off] + --timestamp - to turn on/off the kernel disoatches timestamps, dispatch/begin/end/complete [off] + --ctx-wait - to wait for outstanding contexts on profiler exit [on] + --ctx-limit - maximum number of outstanding contexts [0 - unlimited] + --heartbeat - to print progress heartbeats [0 - disabled] + --obj-tracking - to turn on/off kernels code objects tracking [off] + + --stats - generating kernel execution stats, file .stats.csv + + --roctx-trace - to enable rocTX application code annotation trace, "Markers and Ranges" JSON trace section. + --sys-trace - to trace HIP/HSA APIs and GPU activity, generates stats and JSON trace chrome-tracing compatible + --hip-trace - to trace HIP, generates API execution stats and JSON file chrome-tracing compatible + --hsa-trace - to trace HSA, generates API execution stats and JSON file chrome-tracing compatible + --kfd-trace - to trace KFD, generates API execution stats and JSON file chrome-tracing compatible + Generated files: ._stats.txt .json + Traced API list can be set by input .txt or .xml files. + Input .txt: + hsa: hsa_queue_create hsa_amd_memory_pool_allocate + Input .xml: + + + + + + --trace-start - to enable tracing on start [on] + --trace-period - to enable trace with initial delay, with periodic sample length and rate + Supported time formats: + +Configuration file: + You can set your parameters defaults preferences in the configuration file 'rpl_rc.xml'. The search path sequence: .:/home/evgeny: + First the configuration file is looking in the current directory, then in your home, and then in the package directory. + Configurable options: 'basenames', 'timestamp', 'ctx-limit', 'heartbeat', 'obj-tracking'. + An example of 'rpl_rc.xml': + +``` +## 6. Publicly available counters and metrics +The following counters are publicly available for commercially available VEGA10/20 GPUs. + +Counters: +``` +• GRBM_COUNT : Tie High - Count Number of Clocks +• GRBM_GUI_ACTIVE : The GUI is Active +• SQ_WAVES : Count number of waves sent to SQs. (per-simd, emulated, global) +• SQ_INSTS_VALU : Number of VALU instructions issued. (per-simd, emulated) +• SQ_INSTS_VMEM_WR : Number of VMEM write instructions issued (including FLAT). (per-simd, emulated) +• SQ_INSTS_VMEM_RD : Number of VMEM read instructions issued (including FLAT). (per-simd, emulated) +• SQ_INSTS_SALU : Number of SALU instructions issued. (per-simd, emulated) +• SQ_INSTS_SMEM : Number of SMEM instructions issued. (per-simd, emulated) +• SQ_INSTS_FLAT : Number of FLAT instructions issued. (per-simd, emulated) +• SQ_INSTS_FLAT_LDS_ONLY : Number of FLAT instructions issued that read/wrote only from/to LDS (only works if EARLY_TA_DONE is enabled). (per-simd, emulated) +• SQ_INSTS_LDS : Number of LDS instructions issued (including FLAT). (per-simd, emulated) +• SQ_INSTS_GDS : Number of GDS instructions issued. (per-simd, emulated) +• SQ_WAIT_INST_LDS : Number of wave-cycles spent waiting for LDS instruction issue. In units of 4 cycles. (per-simd, nondeterministic) +• SQ_ACTIVE_INST_VALU : regspec 71? Number of cycles the SQ instruction arbiter is working on a VALU instruction. (per-simd, nondeterministic) +• SQ_INST_CYCLES_SALU : Number of cycles needed to execute non-memory read scalar operations. (per-simd, emulated) +• SQ_THREAD_CYCLES_VALU : Number of thread-cycles used to execute VALU operations (similar to INST_CYCLES_VALU but multiplied by # of active threads). (per-simd) +• SQ_LDS_BANK_CONFLICT : Number of cycles LDS is stalled by bank conflicts. (emulated) +• TA_TA_BUSY[0-15] : TA block is busy. Perf_Windowing not supported for this counter. +• TA_FLAT_READ_WAVEFRONTS[0-15] : Number of flat opcode reads processed by the TA. +• TA_FLAT_WRITE_WAVEFRONTS[0-15] : Number of flat opcode writes processed by the TA. +• TCC_HIT[0-15] : Number of cache hits. +• TCC_MISS[0-15] : Number of cache misses. UC reads count as misses. +• TCC_EA_WRREQ[0-15] : Number of transactions (either 32-byte or 64-byte) going over the TC_EA_wrreq interface. Atomics may travel over the same interface and are generally classified as write requests. This does not include probe commands. +• TCC_EA_WRREQ_64B[0-15] : Number of 64-byte transactions going (64-byte write or CMPSWAP) over the TC_EA_wrreq interface. +• TCC_EA_WRREQ_STALL[0-15] : Number of cycles a write request was stalled. +• TCC_EA_RDREQ[0-15] : Number of TCC/EA read requests (either 32-byte or 64-byte) +• TCC_EA_RDREQ_32B[0-15] : Number of 32-byte TCC/EA read requests +• TCP_TCP_TA_DATA_STALL_CYCLES[0-15] : TCP stalls TA data interface. Now Windowed. +``` + +The following derived metrics have been defined and the profiler metrics XML specification can be found at: https://github.com/ROCm-Developer-Tools/rocprofiler/blob/amd-master/test/tool/metrics.xml. + +Metrics: +``` +• TA_BUSY_avr : TA block is busy. Average over TA instances. +• TA_BUSY_max : TA block is busy. Max over TA instances. +• TA_BUSY_min : TA block is busy. Min over TA instances. +• TA_FLAT_READ_WAVEFRONTS_sum : Number of flat opcode reads processed by the TA. Sum over TA instances. +• TA_FLAT_WRITE_WAVEFRONTS_sum : Number of flat opcode writes processed by the TA. Sum over TA instances. +• TCC_HIT_sum : Number of cache hits. Sum over TCC instances. +• TCC_MISS_sum : Number of cache misses. Sum over TCC instances. +• TCC_EA_RDREQ_32B_sum : Number of 32-byte TCC/EA read requests. Sum over TCC instances. +• TCC_EA_RDREQ_sum : Number of TCC/EA read requests (either 32-byte or 64-byte). Sum over TCC instances. +• TCC_EA_WRREQ_sum : Number of transactions (either 32-byte or 64-byte) going over the TC_EA_wrreq interface. Sum over TCC instances. +• TCC_EA_WRREQ_64B_sum : Number of 64-byte transactions going (64-byte write or CMPSWAP) over the TC_EA_wrreq interface. Sum over TCC instances. +• TCC_WRREQ_STALL_max : Number of cycles a write request was stalled. Max over TCC instances. +• TCC_MC_WRREQ_sum : Number of 32-byte effective writes. Sum over TCC instaces. +• FETCH_SIZE : The total kilobytes fetched from the video memory. This is measured with all extra fetches and any cache or memory effects taken into account. +• WRITE_SIZE : The total kilobytes written to the video memory. This is measured with all extra fetches and any cache or memory effects taken into account. +• GPUBusy : The percentage of time GPU was busy. +• Wavefronts : Total wavefronts. +• VALUInsts : The average number of vector ALU instructions executed per work-item (affected by flow control). +• SALUInsts : The average number of scalar ALU instructions executed per work-item (affected by flow control). +• VFetchInsts : The average number of vector fetch instructions from the video memory executed per work-item (affected by flow control). Excludes FLAT instructions that fetch from video memory. +• SFetchInsts : The average number of scalar fetch instructions from the video memory executed per work-item (affected by flow control). +• VWriteInsts : The average number of vector write instructions to the video memory executed per work-item (affected by flow control). Excludes FLAT instructions that write to video memory. +• FlatVMemInsts : The average number of FLAT instructions that read from or write to the video memory executed per work item (affected by flow control). Includes FLAT instructions that read from or write to scratch. +• LDSInsts : The average number of LDS read or LDS write instructions executed per work item (affected by flow control). Excludes FLAT instructions that read from or write to LDS. +• FlatLDSInsts : The average number of FLAT instructions that read or write to LDS executed per work item (affected by flow control). +• GDSInsts : The average number of GDS read or GDS write instructions executed per work item (affected by flow control). +• VALUUtilization : The percentage of active vector ALU threads in a wave. A lower number can mean either more thread divergence in a wave or that the work-group size is not a multiple of 64. Value range: 0% (bad), 100% (ideal - no thread divergence). +• VALUBusy : The percentage of GPUTime vector ALU instructions are processed. Value range: 0% (bad) to 100% (optimal). +• SALUBusy : The percentage of GPUTime scalar ALU instructions are processed. Value range: 0% (bad) to 100% (optimal). +• Mem32Bwrites : +• FetchSize : The total kilobytes fetched from the video memory. This is measured with all extra fetches and any cache or memory effects taken into account. +• WriteSize : The total kilobytes written to the video memory. This is measured with all extra fetches and any cache or memory effects taken into account. +• L2CacheHit : The percentage of fetch, write, atomic, and other instructions that hit the data in L2 cache. Value range: 0% (no hit) to 100% (optimal). +• MemUnitBusy : The percentage of GPUTime the memory unit is active. The result includes the stall time (MemUnitStalled). This is measured with all extra fetches and writes and any cache or memory effects taken into account. Value range: 0% to 100% (fetch-bound). +• MemUnitStalled : The percentage of GPUTime the memory unit is stalled. Try reducing the number or size of fetches and writes if possible. Value range: 0% (optimal) to 100% (bad). +• WriteUnitStalled : The percentage of GPUTime the Write unit is stalled. Value range: 0% to 100% (bad). +• ALUStalledByLDS : The percentage of GPUTime ALU units are stalled by the LDS input queue being full or the output queue being not ready. If there are LDS bank conflicts, reduce them. Otherwise, try reducing the number of LDS accesses if possible. Value range: 0% (optimal) to 100% (bad). +• LDSBankConflict : The percentage of GPUTime LDS is stalled by bank conflicts. Value range: 0% (optimal) to 100% (bad). +``` diff --git a/projects/rocprofiler/include/rocprofiler/rocprofiler.h b/projects/rocprofiler/include/rocprofiler/rocprofiler.h new file mode 100644 index 0000000000..7d9a02ef40 --- /dev/null +++ b/projects/rocprofiler/include/rocprofiler/rocprofiler.h @@ -0,0 +1,600 @@ +/****************************************************************************** +Copyright (c) 2018 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*******************************************************************************/ + +//////////////////////////////////////////////////////////////////////////////// +// +// ROC Profiler API +// +// The goal of the implementation is to provide a HW specific low-level +// performance analysis interface for profiling of GPU compute applications. +// The profiling includes HW performance counters (PMC) with complex +// performance metrics and traces. +// +// The library can be used by a tool library loaded by HSA runtime or by +// higher level HW independent performance analysis API like PAPI. +// +// The library is written on C and will be based on AQLprofile AMD specific +// HSA extension. The library implementation requires HSA API intercepting and +// a profiling queue supporting a submit callback interface. +// +// + +#ifndef INC_ROCPROFILER_H_ +#define INC_ROCPROFILER_H_ + +/* Placeholder for calling convention and import/export macros */ +#if !defined(ROCPROFILER_CALL) +#define ROCPROFILER_CALL +#endif /* !defined (ROCPROFILER_CALL) */ + +#if !defined(ROCPROFILER_EXPORT_DECORATOR) +#if defined(__GNUC__) +#define ROCPROFILER_EXPORT_DECORATOR __attribute__((visibility("default"))) +#elif defined(_MSC_VER) +#define ROCPROFILER_EXPORT_DECORATOR __declspec(dllexport) +#endif /* defined (_MSC_VER) */ +#endif /* !defined (ROCPROFILER_EXPORT_DECORATOR) */ + +#if !defined(ROCPROFILER_IMPORT_DECORATOR) +#if defined(__GNUC__) +#define ROCPROFILER_IMPORT_DECORATOR +#elif defined(_MSC_VER) +#define ROCPROFILER_IMPORT_DECORATOR __declspec(dllimport) +#endif /* defined (_MSC_VER) */ +#endif /* !defined (ROCPROFILER_IMPORT_DECORATOR) */ + +#define ROCPROFILER_EXPORT ROCPROFILER_EXPORT_DECORATOR ROCPROFILER_CALL +#define ROCPROFILER_IMPORT ROCPROFILER_IMPORT_DECORATOR ROCPROFILER_CALL + +#if !defined(ROCPROFILER) +#if defined(ROCPROFILER_EXPORTS) +#define ROCPROFILER_API ROCPROFILER_EXPORT +#else /* !defined (ROCPROFILER_EXPORTS) */ +#define ROCPROFILER_API ROCPROFILER_IMPORT +#endif /* !defined (ROCPROFILER_EXPORTS) */ +#endif /* !defined (ROCPROFILER) */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include +#include +#include +#include + + +#define ROCPROFILER_VERSION_MAJOR 8 +#define ROCPROFILER_VERSION_MINOR 0 + +//////////////////////////////////////////////////////////////////////////////// +// Returning library version +uint32_t rocprofiler_version_major(); +uint32_t rocprofiler_version_minor(); + +//////////////////////////////////////////////////////////////////////////////// +// Global properties structure + +typedef struct { + uint32_t intercept_mode; + uint32_t code_obj_tracking; + uint32_t memcopy_tracking; + uint32_t trace_size; + uint32_t trace_local; + uint64_t timeout; + uint32_t timestamp_on; + uint32_t hsa_intercepting; + uint32_t k_concurrent; + uint32_t opt_mode; + uint32_t obj_dumping; +} rocprofiler_settings_t; + +//////////////////////////////////////////////////////////////////////////////// +// Returning the error string method + +hsa_status_t rocprofiler_error_string( + const char** str); // [out] the API error string pointer returning + +//////////////////////////////////////////////////////////////////////////////// +// Profiling features and data +// +// Profiling features objects have profiling feature info, type, parameters and data +// Also profiling data samplaes can be iterated using a callback + +// Profiling feature kind +typedef enum { + ROCPROFILER_FEATURE_KIND_METRIC = 0, + ROCPROFILER_FEATURE_KIND_TRACE = 1, + ROCPROFILER_FEATURE_KIND_SPM_MOD = 2, + ROCPROFILER_FEATURE_KIND_PCSMP_MOD = 4 +} rocprofiler_feature_kind_t; + +// Profiling feture parameter +typedef hsa_ven_amd_aqlprofile_parameter_t rocprofiler_parameter_t; + +// Profiling data kind +typedef enum { + ROCPROFILER_DATA_KIND_UNINIT = 0, + ROCPROFILER_DATA_KIND_INT32 = 1, + ROCPROFILER_DATA_KIND_INT64 = 2, + ROCPROFILER_DATA_KIND_FLOAT = 3, + ROCPROFILER_DATA_KIND_DOUBLE = 4, + ROCPROFILER_DATA_KIND_BYTES = 5 +} rocprofiler_data_kind_t; + +// Profiling data type +typedef struct { + rocprofiler_data_kind_t kind; // result kind + union { + uint32_t result_int32; // 32bit integer result + uint64_t result_int64; // 64bit integer result + float result_float; // float single-precision result + double result_double; // float double-precision result + struct { + void* ptr; + uint32_t size; + uint32_t instance_count; + bool copy; + } result_bytes; // data by ptr and byte size + }; +} rocprofiler_data_t; + +// Profiling feature type +typedef struct { + rocprofiler_feature_kind_t kind; // feature kind + union { + const char* name; // feature name + struct { + const char* block; // counter block name + uint32_t event; // counter event id + } counter; + }; + const rocprofiler_parameter_t* parameters; // feature parameters array + uint32_t parameter_count; // feature parameters count + rocprofiler_data_t data; // profiling data +} rocprofiler_feature_t; + +// Profiling features set type +typedef void rocprofiler_feature_set_t; + +//////////////////////////////////////////////////////////////////////////////// +// Profiling context +// +// Profiling context object accumuate all profiling information + +// Profiling context object +typedef void rocprofiler_t; + +// Profiling group object +typedef struct { + unsigned index; // group index + rocprofiler_feature_t** features; // profiling info array + uint32_t feature_count; // profiling info count + rocprofiler_t* context; // context object +} rocprofiler_group_t; + +// Profiling mode mask +typedef enum { + ROCPROFILER_MODE_STANDALONE = 1, // standalone mode when ROC profiler supports a queue + ROCPROFILER_MODE_CREATEQUEUE = 2, // ROC profiler creates queue in standalone mode + ROCPROFILER_MODE_SINGLEGROUP = 4 // only one group is allowed, failed otherwise +} rocprofiler_mode_t; + +// Profiling handler, calling on profiling completion +typedef bool (*rocprofiler_handler_t)(rocprofiler_group_t group, void* arg); + +// Profiling preperties +typedef struct { + hsa_queue_t* queue; // queue for STANDALONE mode + // the queue is created and returned in CREATEQUEUE mode + uint32_t queue_depth; // created queue depth + rocprofiler_handler_t handler; // handler on completion + void* handler_arg; // the handler arg +} rocprofiler_properties_t; + +// Create new profiling context +hsa_status_t rocprofiler_open(hsa_agent_t agent, // GPU handle + rocprofiler_feature_t* features, // [in] profiling features array + uint32_t feature_count, // profiling info count + rocprofiler_t** context, // [out] context object + uint32_t mode, // profiling mode mask + rocprofiler_properties_t* properties); // profiling properties + +// Add feature to a features set +hsa_status_t rocprofiler_add_feature(const rocprofiler_feature_t* feature, // [in] + rocprofiler_feature_set_t* features_set); // [in/out] profiling features set + +// Create new profiling context +hsa_status_t rocprofiler_features_set_open(hsa_agent_t agent, // GPU handle + rocprofiler_feature_set_t* features_set, // [in] profiling features set + rocprofiler_t** context, // [out] context object + uint32_t mode, // profiling mode mask + rocprofiler_properties_t* properties); // profiling properties + +// Delete profiling info +hsa_status_t rocprofiler_close(rocprofiler_t* context); // [in] profiling context + +// Context reset before reusing +hsa_status_t rocprofiler_reset(rocprofiler_t* context, // [in] profiling context + uint32_t group_index); // group index + +// Return context agent +hsa_status_t rocprofiler_get_agent(rocprofiler_t* context, // [in] profiling context + hsa_agent_t* agent); // [out] GPU handle + +// Supported time value ID +typedef enum { + ROCPROFILER_TIME_ID_CLOCK_REALTIME = 0, // Linux realtime clock time + ROCPROFILER_TIME_ID_CLOCK_REALTIME_COARSE = 1, // Linux realtime-coarse clock time + ROCPROFILER_TIME_ID_CLOCK_MONOTONIC = 2, // Linux monotonic clock time + ROCPROFILER_TIME_ID_CLOCK_MONOTONIC_COARSE = 3, // Linux monotonic-coarse clock time + ROCPROFILER_TIME_ID_CLOCK_MONOTONIC_RAW = 4, // Linux monotonic-raw clock time +} rocprofiler_time_id_t; + +// Return time value for a given time ID and profiling timestamp +hsa_status_t rocprofiler_get_time( + rocprofiler_time_id_t time_id, // identifier of the particular time to convert the timesatmp + uint64_t timestamp, // profiling timestamp + uint64_t* value_ns, // [out] returned time 'ns' value, ignored if NULL + uint64_t* error_ns); // [out] returned time error 'ns' value, ignored if NULL + +//////////////////////////////////////////////////////////////////////////////// +// Queue callbacks +// +// Queue callbacks for initiating profiling per kernel dispatch and to wait +// the profiling data on the queue destroy. + +// Dispatch record +typedef struct { + uint64_t dispatch; // dispatch timestamp, ns + uint64_t begin; // kernel begin timestamp, ns + uint64_t end; // kernel end timestamp, ns + uint64_t complete; // completion signal timestamp, ns +} rocprofiler_dispatch_record_t; + +// Profiling callback data +typedef struct { + hsa_agent_t agent; // GPU agent handle + uint32_t agent_index; // GPU index (GPU Driver Node ID as reported in the sysfs topology) + const hsa_queue_t* queue; // HSA queue + uint64_t queue_index; // Index in the queue + uint32_t queue_id; // Queue id + hsa_signal_t completion_signal; // Completion signal + const hsa_kernel_dispatch_packet_t* packet; // HSA dispatch packet + const char* kernel_name; // Kernel name + uint64_t kernel_object; // Kernel object address + const amd_kernel_code_t* kernel_code; // Kernel code pointer + uint32_t thread_id; // Thread id + const rocprofiler_dispatch_record_t* record; // Dispatch record +} rocprofiler_callback_data_t; + +// Profiling callback type +typedef hsa_status_t (*rocprofiler_callback_t)( + const rocprofiler_callback_data_t* callback_data, // [in] callback data + void* user_data, // [in/out] user data passed to the callback + rocprofiler_group_t* group); // [out] returned profiling group + +// Queue callbacks +typedef struct { + rocprofiler_callback_t dispatch; // dispatch callback + hsa_status_t (*create)(hsa_queue_t* queue, void* data); // create callback + hsa_status_t (*destroy)(hsa_queue_t* queue, void* data); // destroy callback +} rocprofiler_queue_callbacks_t; + +// Set queue callbacks +hsa_status_t rocprofiler_set_queue_callbacks( + rocprofiler_queue_callbacks_t callbacks, // callbacks + void* data); // [in/out] passed callbacks data + +// Remove queue callbacks +hsa_status_t rocprofiler_remove_queue_callbacks(); + +// Start/stop queue callbacks +hsa_status_t rocprofiler_start_queue_callbacks(); +hsa_status_t rocprofiler_stop_queue_callbacks(); + +//////////////////////////////////////////////////////////////////////////////// +// Start/stop profiling +// +// Start/stop the context profiling invocation, have to be as many as +// contect.invocations' to collect all profiling data + +// Start profiling +hsa_status_t rocprofiler_start(rocprofiler_t* context, // [in/out] profiling context + uint32_t group_index); // group index + +// Stop profiling +hsa_status_t rocprofiler_stop(rocprofiler_t* context, // [in/out] profiling context + uint32_t group_index); // group index + +// Read profiling +hsa_status_t rocprofiler_read(rocprofiler_t* context, // [in/out] profiling context + uint32_t group_index); // group index + +// Read profiling data +hsa_status_t rocprofiler_get_data(rocprofiler_t* context, // [in/out] profiling context + uint32_t group_index); // group index + +// Get profiling groups count +hsa_status_t rocprofiler_group_count(const rocprofiler_t* context, // [in] profiling context + uint32_t* group_count); // [out] profiling groups count + +// Get profiling group for a given index +hsa_status_t rocprofiler_get_group(rocprofiler_t* context, // [in] profiling context + uint32_t group_index, // profiling group index + rocprofiler_group_t* group); // [out] profiling group + +// Start profiling +hsa_status_t rocprofiler_group_start(rocprofiler_group_t* group); // [in/out] profiling group + +// Stop profiling +hsa_status_t rocprofiler_group_stop(rocprofiler_group_t* group); // [in/out] profiling group + +// Read profiling +hsa_status_t rocprofiler_group_read(rocprofiler_group_t* group); // [in/out] profiling group + +// Get profiling data +hsa_status_t rocprofiler_group_get_data(rocprofiler_group_t* group); // [in/out] profiling group + +// Get metrics data +hsa_status_t rocprofiler_get_metrics(const rocprofiler_t* context); // [in/out] profiling context + +// Definition of output data iterator callback +typedef hsa_ven_amd_aqlprofile_data_callback_t rocprofiler_trace_data_callback_t; + +// Method for iterating the events output data +hsa_status_t rocprofiler_iterate_trace_data( + rocprofiler_t* context, // [in] profiling context + rocprofiler_trace_data_callback_t callback, // callback to iterate the output data + void* data); // [in/out] callback data + +//////////////////////////////////////////////////////////////////////////////// +// Profiling features and data +// +// Profiling features objects have profiling feature info, type, parameters and data +// Also profiling data samplaes can be iterated using a callback + +// Profiling info kind +typedef enum { + ROCPROFILER_INFO_KIND_METRIC = 0, // metric info + ROCPROFILER_INFO_KIND_METRIC_COUNT = 1, // metric features count, int32 + ROCPROFILER_INFO_KIND_TRACE = 2, // trace info + ROCPROFILER_INFO_KIND_TRACE_COUNT = 3, // trace features count, int32 + ROCPROFILER_INFO_KIND_TRACE_PARAMETER = 4, // trace parameter info + ROCPROFILER_INFO_KIND_TRACE_PARAMETER_COUNT = 5 // trace parameter count, int32 +} rocprofiler_info_kind_t; + +// Profiling info query +typedef union { + rocprofiler_info_kind_t info_kind; // queried profiling info kind + struct { + const char* trace_name; // queried info trace name + } trace_parameter; +} rocprofiler_info_query_t; + +// Profiling info data +typedef struct { + uint32_t agent_index; // GPU HSA agent index (GPU Driver Node ID as reported in the sysfs topology) + rocprofiler_info_kind_t kind; // info data kind + union { + struct { + const char* name; // metric name + uint32_t instances; // instances number + const char* expr; // metric expression, NULL for basic counters + const char* description; // metric description + const char* block_name; // block name + uint32_t block_counters; // number of block counters + } metric; + struct { + const char* name; // trace name + const char* description; // trace description + uint32_t parameter_count; // supported by the trace number parameters + } trace; + struct { + uint32_t code; // parameter code + const char* trace_name; // trace name + const char* parameter_name; // parameter name + const char* description; // trace parameter description + } trace_parameter; + }; +} rocprofiler_info_data_t; + +// Return the info for a given info kind +hsa_status_t rocprofiler_get_info( + const hsa_agent_t* agent, // [in] GFXIP handle + rocprofiler_info_kind_t kind, // kind of iterated info + void *data); // [in/out] returned data + +// Iterate over the info for a given info kind, and invoke an application-defined callback on every iteration +hsa_status_t rocprofiler_iterate_info( + const hsa_agent_t* agent, // [in] GFXIP handle + rocprofiler_info_kind_t kind, // kind of iterated info + hsa_status_t (*callback)(const rocprofiler_info_data_t info, void *data), // callback + void *data); // [in/out] data passed to callback + +// Iterate over the info for a given info query, and invoke an application-defined callback on every iteration +hsa_status_t rocprofiler_query_info( + const hsa_agent_t *agent, // [in] GFXIP handle + rocprofiler_info_query_t query, // iterated info query + hsa_status_t (*callback)(const rocprofiler_info_data_t info, void *data), // callback + void *data); // [in/out] data passed to callback + +// Create a profiled queue. All dispatches on this queue will be profiled +hsa_status_t rocprofiler_queue_create_profiled( + hsa_agent_t agent_handle,uint32_t size, hsa_queue_type32_t type, + void (*callback)(hsa_status_t status, hsa_queue_t* source, void* data), + void* data, uint32_t private_segment_size, uint32_t group_segment_size, + hsa_queue_t** queue); + +//////////////////////////////////////////////////////////////////////////////// +// Profiling pool +// +// Support for profiling contexts pool +// The API provide capability to create a contexts pool for a given agent and a set of features, +// to fetch/relase a context entry, to register a callback for the contexts completion. + +// Profiling pool handle +typedef void rocprofiler_pool_t; + +// Profiling pool entry +typedef struct { + rocprofiler_t* context; // context object + void* payload; // payload data object +} rocprofiler_pool_entry_t; + +// Profiling handler, calling on profiling completion +typedef bool (*rocprofiler_pool_handler_t)(const rocprofiler_pool_entry_t* entry, void* arg); + +// Profiling preperties +typedef struct { + uint32_t num_entries; // pool size entries + uint32_t payload_bytes; // payload size bytes + rocprofiler_pool_handler_t handler; // handler on context completion + void* handler_arg; // the handler arg +} rocprofiler_pool_properties_t; + +// Open profiling pool +hsa_status_t rocprofiler_pool_open( + hsa_agent_t agent, // GPU handle + rocprofiler_feature_t* features, // [in] profiling features array + uint32_t feature_count, // profiling info count + rocprofiler_pool_t** pool, // [out] context object + uint32_t mode, // profiling mode mask + rocprofiler_pool_properties_t*); // pool properties + +// Close profiling pool +hsa_status_t rocprofiler_pool_close( + rocprofiler_pool_t* pool); // profiling pool handle + +// Fetch profiling pool entry +hsa_status_t rocprofiler_pool_fetch( + rocprofiler_pool_t* pool, // profiling pool handle + rocprofiler_pool_entry_t* entry); // [out] empty profiling pool entry + +// Release profiling pool entry +hsa_status_t rocprofiler_pool_release( + rocprofiler_pool_entry_t* entry); // released profiling pool entry + +// Iterate fetched profiling pool entries +hsa_status_t rocprofiler_pool_iterate( + rocprofiler_pool_t* pool, // profiling pool handle + hsa_status_t (*callback)(rocprofiler_pool_entry_t* entry, void* data), // callback + void *data); // [in/out] data passed to callback + +// Flush completed entries in profiling pool +hsa_status_t rocprofiler_pool_flush( + rocprofiler_pool_t* pool); // profiling pool handle + +//////////////////////////////////////////////////////////////////////////////// +// HSA intercepting API + +// HSA callbacks ID enumeration +typedef enum { + ROCPROFILER_HSA_CB_ID_ALLOCATE = 0, // Memory allocate callback + ROCPROFILER_HSA_CB_ID_DEVICE = 1, // Device assign callback + ROCPROFILER_HSA_CB_ID_MEMCOPY = 2, // Memcopy callback + ROCPROFILER_HSA_CB_ID_SUBMIT = 3, // Packet submit callback + ROCPROFILER_HSA_CB_ID_KSYMBOL = 4, // Loading/unloading of kernel symbol + ROCPROFILER_HSA_CB_ID_CODEOBJ = 5 // Loading/unloading of kernel symbol +} rocprofiler_hsa_cb_id_t; + +// HSA callback data type +typedef struct { + union { + struct { + const void* ptr; // allocated area ptr + size_t size; // allocated area size, zero size means 'free' callback + hsa_amd_segment_t segment; // allocated area's memory segment type + hsa_amd_memory_pool_global_flag_t global_flag; // allocated area's memory global flag + int is_code; // equal to 1 if code is allocated + } allocate; + struct { + hsa_device_type_t type; // type of assigned device + uint32_t id; // id of assigned device + hsa_agent_t agent; // device HSA agent handle + const void* ptr; // ptr the device is assigned to + } device; + struct { + const void* dst; // memcopy dst ptr + const void* src; // memcopy src ptr + size_t size; // memcopy size bytes + } memcopy; + struct { + const void* packet; // submitted to GPU packet + const char* kernel_name; // kernel name, not NULL if dispatch + hsa_queue_t* queue; // HSA queue the kernel was submitted to + uint32_t device_type; // type of device the packed is submitted to + uint32_t device_id; // id of device the packed is submitted to + } submit; + struct { + uint64_t object; // kernel symbol object + const char* name; // kernel symbol name + uint32_t name_length; // kernel symbol name length + int unload; // symbol executable destroy + } ksymbol; + struct { + uint32_t storage_type; // code object storage type + int storage_file; // origin file descriptor + uint64_t memory_base; // origin memory base + uint64_t memory_size; // origin memory size + uint64_t load_base; // codeobj load base + uint64_t load_size; // codeobj load size + uint64_t load_delta; // codeobj load size + uint32_t uri_length; // URI string length + char* uri; // URI string + int unload; // unload flag + } codeobj; + }; +} rocprofiler_hsa_callback_data_t; + +// HSA callback function type +typedef hsa_status_t (*rocprofiler_hsa_callback_fun_t)( + rocprofiler_hsa_cb_id_t id, // callback id + const rocprofiler_hsa_callback_data_t* data, // [in] callback data + void* arg); // [in/out] user passed data + +// HSA callbacks structure +typedef struct { + rocprofiler_hsa_callback_fun_t allocate; // memory allocate callback + rocprofiler_hsa_callback_fun_t device; // agent assign callback + rocprofiler_hsa_callback_fun_t memcopy; // memory copy callback + rocprofiler_hsa_callback_fun_t submit; // packet submit callback + rocprofiler_hsa_callback_fun_t ksymbol; // kernel symbol callback + rocprofiler_hsa_callback_fun_t codeobj; // codeobject load/unload callback +} rocprofiler_hsa_callbacks_t; + +// Set callbacks. If the callback is NULL then it is disabled. +// If callback returns a value that is not HSA_STATUS_SUCCESS the callback +// will be unregistered. +hsa_status_t rocprofiler_set_hsa_callbacks( + const rocprofiler_hsa_callbacks_t callbacks, // HSA callback function + void* arg); // callback user data + +#ifdef __cplusplus +} // extern "C" block +#endif // __cplusplus + +#endif // INC_ROCPROFILER_H_ diff --git a/projects/rocprofiler/inc/rocprofiler.h b/projects/rocprofiler/include/rocprofiler/v2/rocprofiler.h similarity index 78% rename from projects/rocprofiler/inc/rocprofiler.h rename to projects/rocprofiler/include/rocprofiler/v2/rocprofiler.h index dfde58b21c..da8643b059 100644 --- a/projects/rocprofiler/inc/rocprofiler.h +++ b/projects/rocprofiler/include/rocprofiler/v2/rocprofiler.h @@ -190,8 +190,6 @@ ROCPROFILER_API uint32_t rocprofiler_version_minor(); /** @} */ -#ifndef ROCPROFILER_V1 - // TODO(aelwazir): Fix them to use the new Error codes /** \defgroup status_codes_group Status Codes * @@ -2439,520 +2437,8 @@ rocprofiler_device_profiling_session_destroy(rocprofiler_session_id_t session_id /** @} */ -#endif - -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -// Old ROCProfiler -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// - -#include -#include -#include -#include -#include - -//////////////////////////////////////////////////////////////////////////////// -// Global properties structure - -typedef struct { - uint32_t intercept_mode; - uint32_t code_obj_tracking; - uint32_t memcopy_tracking; - uint32_t trace_size; - uint32_t trace_local; - uint64_t timeout; - uint32_t timestamp_on; - uint32_t hsa_intercepting; - uint32_t k_concurrent; - uint32_t opt_mode; - uint32_t obj_dumping; -} rocprofiler_settings_t; - -//////////////////////////////////////////////////////////////////////////////// -// Returning the error string method - -hsa_status_t rocprofiler_error_string( - const char** str); // [out] the API error string pointer returning - -//////////////////////////////////////////////////////////////////////////////// -// Profiling features and data -// -// Profiling features objects have profiling feature info, type, parameters and data -// Also profiling data samplaes can be iterated using a callback - -// Profiling feature kind -typedef enum { - ROCPROFILER_FEATURE_KIND_METRIC = 0, - ROCPROFILER_FEATURE_KIND_TRACE = 1, - ROCPROFILER_FEATURE_KIND_SPM_MOD = 2, - ROCPROFILER_FEATURE_KIND_PCSMP_MOD = 4 -} rocprofiler_feature_kind_t; - -// Profiling feture parameter -typedef hsa_ven_amd_aqlprofile_parameter_t rocprofiler_parameter_t; - -// Profiling data kind -typedef enum { - ROCPROFILER_DATA_KIND_UNINIT = 0, - ROCPROFILER_DATA_KIND_INT32 = 1, - ROCPROFILER_DATA_KIND_INT64 = 2, - ROCPROFILER_DATA_KIND_FLOAT = 3, - ROCPROFILER_DATA_KIND_DOUBLE = 4, - ROCPROFILER_DATA_KIND_BYTES = 5 -} rocprofiler_data_kind_t; - -// Profiling data type -typedef struct { - rocprofiler_data_kind_t kind; // result kind - union { - uint32_t result_int32; // 32bit integer result - uint64_t result_int64; // 64bit integer result - float result_float; // float single-precision result - double result_double; // float double-precision result - struct { - void* ptr; - uint32_t size; - uint32_t instance_count; - bool copy; - } result_bytes; // data by ptr and byte size - }; -} rocprofiler_data_t; - -// Profiling feature type -typedef struct { - rocprofiler_feature_kind_t kind; // feature kind - union { - const char* name; // feature name - struct { - const char* block; // counter block name - uint32_t event; // counter event id - } counter; - }; - const rocprofiler_parameter_t* parameters; // feature parameters array - uint32_t parameter_count; // feature parameters count - rocprofiler_data_t data; // profiling data -} rocprofiler_feature_t; - -// Profiling features set type -typedef void rocprofiler_feature_set_t; - -//////////////////////////////////////////////////////////////////////////////// -// Profiling context -// -// Profiling context object accumuate all profiling information - -// Profiling context object -typedef void rocprofiler_t; - -// Profiling group object -typedef struct { - unsigned index; // group index - rocprofiler_feature_t** features; // profiling info array - uint32_t feature_count; // profiling info count - rocprofiler_t* context; // context object -} rocprofiler_group_t; - -// Profiling mode mask -typedef enum { - ROCPROFILER_MODE_STANDALONE = 1, // standalone mode when ROC profiler supports a queue - ROCPROFILER_MODE_CREATEQUEUE = 2, // ROC profiler creates queue in standalone mode - ROCPROFILER_MODE_SINGLEGROUP = 4 // only one group is allowed, failed otherwise -} rocprofiler_mode_t; - -// Profiling handler, calling on profiling completion -typedef bool (*rocprofiler_handler_t)(rocprofiler_group_t group, void* arg); - -// Profiling preperties -typedef struct { - hsa_queue_t* queue; // queue for STANDALONE mode - // the queue is created and returned in CREATEQUEUE mode - uint32_t queue_depth; // created queue depth - rocprofiler_handler_t handler; // handler on completion - void* handler_arg; // the handler arg -} rocprofiler_properties_t; - -// Create new profiling context -hsa_status_t rocprofiler_open(hsa_agent_t agent, // GPU handle - rocprofiler_feature_t* features, // [in] profiling features array - uint32_t feature_count, // profiling info count - rocprofiler_t** context, // [out] context object - uint32_t mode, // profiling mode mask - rocprofiler_properties_t* properties); // profiling properties - -// Add feature to a features set -hsa_status_t rocprofiler_add_feature(const rocprofiler_feature_t* feature, // [in] - rocprofiler_feature_set_t* features_set); // [in/out] profiling features set - -// Create new profiling context -hsa_status_t rocprofiler_features_set_open(hsa_agent_t agent, // GPU handle - rocprofiler_feature_set_t* features_set, // [in] profiling features set - rocprofiler_t** context, // [out] context object - uint32_t mode, // profiling mode mask - rocprofiler_properties_t* properties); // profiling properties - -// Delete profiling info -hsa_status_t rocprofiler_close(rocprofiler_t* context); // [in] profiling context - -// Context reset before reusing -hsa_status_t rocprofiler_reset(rocprofiler_t* context, // [in] profiling context - uint32_t group_index); // group index - -// Return context agent -hsa_status_t rocprofiler_get_agent(rocprofiler_t* context, // [in] profiling context - hsa_agent_t* agent); // [out] GPU handle - -// Supported time value ID -typedef enum { - ROCPROFILER_TIME_ID_CLOCK_REALTIME = 0, // Linux realtime clock time - ROCPROFILER_TIME_ID_CLOCK_REALTIME_COARSE = 1, // Linux realtime-coarse clock time - ROCPROFILER_TIME_ID_CLOCK_MONOTONIC = 2, // Linux monotonic clock time - ROCPROFILER_TIME_ID_CLOCK_MONOTONIC_COARSE = 3, // Linux monotonic-coarse clock time - ROCPROFILER_TIME_ID_CLOCK_MONOTONIC_RAW = 4, // Linux monotonic-raw clock time -} rocprofiler_time_id_t; - -// Return time value for a given time ID and profiling timestamp -hsa_status_t rocprofiler_get_time( - rocprofiler_time_id_t time_id, // identifier of the particular time to convert the timesatmp - uint64_t timestamp, // profiling timestamp - uint64_t* value_ns, // [out] returned time 'ns' value, ignored if NULL - uint64_t* error_ns); // [out] returned time error 'ns' value, ignored if NULL - -//////////////////////////////////////////////////////////////////////////////// -// Queue callbacks -// -// Queue callbacks for initiating profiling per kernel dispatch and to wait -// the profiling data on the queue destroy. - -// Dispatch record -typedef struct { - uint64_t dispatch; // dispatch timestamp, ns - uint64_t begin; // kernel begin timestamp, ns - uint64_t end; // kernel end timestamp, ns - uint64_t complete; // completion signal timestamp, ns -} rocprofiler_dispatch_record_t; - -// Profiling callback data -typedef struct { - hsa_agent_t agent; // GPU agent handle - uint32_t agent_index; // GPU index (GPU Driver Node ID as reported in the sysfs topology) - const hsa_queue_t* queue; // HSA queue - uint64_t queue_index; // Index in the queue - uint32_t queue_id; // Queue id - hsa_signal_t completion_signal; // Completion signal - const hsa_kernel_dispatch_packet_t* packet; // HSA dispatch packet - const char* kernel_name; // Kernel name - uint64_t kernel_object; // Kernel object address - const amd_kernel_code_t* kernel_code; // Kernel code pointer - uint32_t thread_id; // Thread id - const rocprofiler_dispatch_record_t* record; // Dispatch record -} rocprofiler_callback_data_t; - -// Profiling callback type -typedef hsa_status_t (*rocprofiler_callback_t)( - const rocprofiler_callback_data_t* callback_data, // [in] callback data - void* user_data, // [in/out] user data passed to the callback - rocprofiler_group_t* group); // [out] returned profiling group - -// Queue callbacks -typedef struct { - rocprofiler_callback_t dispatch; // dispatch callback - hsa_status_t (*create)(hsa_queue_t* queue, void* data); // create callback - hsa_status_t (*destroy)(hsa_queue_t* queue, void* data); // destroy callback -} rocprofiler_queue_callbacks_t; - -// Set queue callbacks -hsa_status_t rocprofiler_set_queue_callbacks( - rocprofiler_queue_callbacks_t callbacks, // callbacks - void* data); // [in/out] passed callbacks data - -// Remove queue callbacks -hsa_status_t rocprofiler_remove_queue_callbacks(); - -// Start/stop queue callbacks -hsa_status_t rocprofiler_start_queue_callbacks(); -hsa_status_t rocprofiler_stop_queue_callbacks(); - -//////////////////////////////////////////////////////////////////////////////// -// Start/stop profiling -// -// Start/stop the context profiling invocation, have to be as many as -// contect.invocations' to collect all profiling data - -// Start profiling -hsa_status_t rocprofiler_start(rocprofiler_t* context, // [in/out] profiling context - uint32_t group_index); // group index - -// Stop profiling -hsa_status_t rocprofiler_stop(rocprofiler_t* context, // [in/out] profiling context - uint32_t group_index); // group index - -// Read profiling -hsa_status_t rocprofiler_read(rocprofiler_t* context, // [in/out] profiling context - uint32_t group_index); // group index - -// Read profiling data -hsa_status_t rocprofiler_get_data(rocprofiler_t* context, // [in/out] profiling context - uint32_t group_index); // group index - -// Get profiling groups count -hsa_status_t rocprofiler_group_count(const rocprofiler_t* context, // [in] profiling context - uint32_t* group_count); // [out] profiling groups count - -// Get profiling group for a given index -hsa_status_t rocprofiler_get_group(rocprofiler_t* context, // [in] profiling context - uint32_t group_index, // profiling group index - rocprofiler_group_t* group); // [out] profiling group - -// Start profiling -hsa_status_t rocprofiler_group_start(rocprofiler_group_t* group); // [in/out] profiling group - -// Stop profiling -hsa_status_t rocprofiler_group_stop(rocprofiler_group_t* group); // [in/out] profiling group - -// Read profiling -hsa_status_t rocprofiler_group_read(rocprofiler_group_t* group); // [in/out] profiling group - -// Get profiling data -hsa_status_t rocprofiler_group_get_data(rocprofiler_group_t* group); // [in/out] profiling group - -// Get metrics data -hsa_status_t rocprofiler_get_metrics(const rocprofiler_t* context); // [in/out] profiling context - -// Definition of output data iterator callback -typedef hsa_ven_amd_aqlprofile_data_callback_t rocprofiler_trace_data_callback_t; - -// Method for iterating the events output data -hsa_status_t rocprofiler_iterate_trace_data( - rocprofiler_t* context, // [in] profiling context - rocprofiler_trace_data_callback_t callback, // callback to iterate the output data - void* data); // [in/out] callback data - -//////////////////////////////////////////////////////////////////////////////// -// Profiling features and data -// -// Profiling features objects have profiling feature info, type, parameters and data -// Also profiling data samplaes can be iterated using a callback - -// Profiling info kind -typedef enum { - ROCPROFILER_INFO_KIND_METRIC = 0, // metric info - ROCPROFILER_INFO_KIND_METRIC_COUNT = 1, // metric features count, int32 - ROCPROFILER_INFO_KIND_TRACE = 2, // trace info - ROCPROFILER_INFO_KIND_TRACE_COUNT = 3, // trace features count, int32 - ROCPROFILER_INFO_KIND_TRACE_PARAMETER = 4, // trace parameter info - ROCPROFILER_INFO_KIND_TRACE_PARAMETER_COUNT = 5 // trace parameter count, int32 -} rocprofiler_info_kind_t; - -// Profiling info query -typedef union { - rocprofiler_info_kind_t info_kind; // queried profiling info kind - struct { - const char* trace_name; // queried info trace name - } trace_parameter; -} rocprofiler_info_query_t; - -// Profiling info data -typedef struct { - uint32_t agent_index; // GPU HSA agent index (GPU Driver Node ID as reported in the sysfs topology) - rocprofiler_info_kind_t kind; // info data kind - union { - struct { - const char* name; // metric name - uint32_t instances; // instances number - const char* expr; // metric expression, NULL for basic counters - const char* description; // metric description - const char* block_name; // block name - uint32_t block_counters; // number of block counters - } metric; - struct { - const char* name; // trace name - const char* description; // trace description - uint32_t parameter_count; // supported by the trace number parameters - } trace; - struct { - uint32_t code; // parameter code - const char* trace_name; // trace name - const char* parameter_name; // parameter name - const char* description; // trace parameter description - } trace_parameter; - }; -} rocprofiler_info_data_t; - -// Return the info for a given info kind -hsa_status_t rocprofiler_get_info( - const hsa_agent_t* agent, // [in] GFXIP handle - rocprofiler_info_kind_t kind, // kind of iterated info - void *data); // [in/out] returned data - -// Iterate over the info for a given info kind, and invoke an application-defined callback on every iteration -hsa_status_t rocprofiler_iterate_info( - const hsa_agent_t* agent, // [in] GFXIP handle - rocprofiler_info_kind_t kind, // kind of iterated info - hsa_status_t (*callback)(const rocprofiler_info_data_t info, void *data), // callback - void *data); // [in/out] data passed to callback - -// Iterate over the info for a given info query, and invoke an application-defined callback on every iteration -hsa_status_t rocprofiler_query_info( - const hsa_agent_t *agent, // [in] GFXIP handle - rocprofiler_info_query_t query, // iterated info query - hsa_status_t (*callback)(const rocprofiler_info_data_t info, void *data), // callback - void *data); // [in/out] data passed to callback - -// Create a profiled queue. All dispatches on this queue will be profiled -hsa_status_t rocprofiler_queue_create_profiled( - hsa_agent_t agent_handle,uint32_t size, hsa_queue_type32_t type, - void (*callback)(hsa_status_t status, hsa_queue_t* source, void* data), - void* data, uint32_t private_segment_size, uint32_t group_segment_size, - hsa_queue_t** queue); - -//////////////////////////////////////////////////////////////////////////////// -// Profiling pool -// -// Support for profiling contexts pool -// The API provide capability to create a contexts pool for a given agent and a set of features, -// to fetch/relase a context entry, to register a callback for the contexts completion. - -// Profiling pool handle -typedef void rocprofiler_pool_t; - -// Profiling pool entry -typedef struct { - rocprofiler_t* context; // context object - void* payload; // payload data object -} rocprofiler_pool_entry_t; - -// Profiling handler, calling on profiling completion -typedef bool (*rocprofiler_pool_handler_t)(const rocprofiler_pool_entry_t* entry, void* arg); - -// Profiling preperties -typedef struct { - uint32_t num_entries; // pool size entries - uint32_t payload_bytes; // payload size bytes - rocprofiler_pool_handler_t handler; // handler on context completion - void* handler_arg; // the handler arg -} rocprofiler_pool_properties_t; - -// Open profiling pool -hsa_status_t rocprofiler_pool_open( - hsa_agent_t agent, // GPU handle - rocprofiler_feature_t* features, // [in] profiling features array - uint32_t feature_count, // profiling info count - rocprofiler_pool_t** pool, // [out] context object - uint32_t mode, // profiling mode mask - rocprofiler_pool_properties_t*); // pool properties - -// Close profiling pool -hsa_status_t rocprofiler_pool_close( - rocprofiler_pool_t* pool); // profiling pool handle - -// Fetch profiling pool entry -hsa_status_t rocprofiler_pool_fetch( - rocprofiler_pool_t* pool, // profiling pool handle - rocprofiler_pool_entry_t* entry); // [out] empty profiling pool entry - -// Release profiling pool entry -hsa_status_t rocprofiler_pool_release( - rocprofiler_pool_entry_t* entry); // released profiling pool entry - -// Iterate fetched profiling pool entries -hsa_status_t rocprofiler_pool_iterate( - rocprofiler_pool_t* pool, // profiling pool handle - hsa_status_t (*callback)(rocprofiler_pool_entry_t* entry, void* data), // callback - void *data); // [in/out] data passed to callback - -// Flush completed entries in profiling pool -hsa_status_t rocprofiler_pool_flush( - rocprofiler_pool_t* pool); // profiling pool handle - -//////////////////////////////////////////////////////////////////////////////// -// HSA intercepting API - -// HSA callbacks ID enumeration -typedef enum { - ROCPROFILER_HSA_CB_ID_ALLOCATE = 0, // Memory allocate callback - ROCPROFILER_HSA_CB_ID_DEVICE = 1, // Device assign callback - ROCPROFILER_HSA_CB_ID_MEMCOPY = 2, // Memcopy callback - ROCPROFILER_HSA_CB_ID_SUBMIT = 3, // Packet submit callback - ROCPROFILER_HSA_CB_ID_KSYMBOL = 4, // Loading/unloading of kernel symbol - ROCPROFILER_HSA_CB_ID_CODEOBJ = 5 // Loading/unloading of kernel symbol -} rocprofiler_hsa_cb_id_t; - -// HSA callback data type -typedef struct { - union { - struct { - const void* ptr; // allocated area ptr - size_t size; // allocated area size, zero size means 'free' callback - hsa_amd_segment_t segment; // allocated area's memory segment type - hsa_amd_memory_pool_global_flag_t global_flag; // allocated area's memory global flag - int is_code; // equal to 1 if code is allocated - } allocate; - struct { - hsa_device_type_t type; // type of assigned device - uint32_t id; // id of assigned device - hsa_agent_t agent; // device HSA agent handle - const void* ptr; // ptr the device is assigned to - } device; - struct { - const void* dst; // memcopy dst ptr - const void* src; // memcopy src ptr - size_t size; // memcopy size bytes - } memcopy; - struct { - const void* packet; // submitted to GPU packet - const char* kernel_name; // kernel name, not NULL if dispatch - hsa_queue_t* queue; // HSA queue the kernel was submitted to - uint32_t device_type; // type of device the packed is submitted to - uint32_t device_id; // id of device the packed is submitted to - } submit; - struct { - uint64_t object; // kernel symbol object - const char* name; // kernel symbol name - uint32_t name_length; // kernel symbol name length - int unload; // symbol executable destroy - } ksymbol; - struct { - uint32_t storage_type; // code object storage type - int storage_file; // origin file descriptor - uint64_t memory_base; // origin memory base - uint64_t memory_size; // origin memory size - uint64_t load_base; // codeobj load base - uint64_t load_size; // codeobj load size - uint64_t load_delta; // codeobj load size - uint32_t uri_length; // URI string length - char* uri; // URI string - int unload; // unload flag - } codeobj; - }; -} rocprofiler_hsa_callback_data_t; - -// HSA callback function type -typedef hsa_status_t (*rocprofiler_hsa_callback_fun_t)( - rocprofiler_hsa_cb_id_t id, // callback id - const rocprofiler_hsa_callback_data_t* data, // [in] callback data - void* arg); // [in/out] user passed data - -// HSA callbacks structure -typedef struct { - rocprofiler_hsa_callback_fun_t allocate; // memory allocate callback - rocprofiler_hsa_callback_fun_t device; // agent assign callback - rocprofiler_hsa_callback_fun_t memcopy; // memory copy callback - rocprofiler_hsa_callback_fun_t submit; // packet submit callback - rocprofiler_hsa_callback_fun_t ksymbol; // kernel symbol callback - rocprofiler_hsa_callback_fun_t codeobj; // codeobject load/unload callback -} rocprofiler_hsa_callbacks_t; - -// Set callbacks. If the callback is NULL then it is disabled. -// If callback returns a value that is not HSA_STATUS_SUCCESS the callback -// will be unregistered. -hsa_status_t rocprofiler_set_hsa_callbacks( - const rocprofiler_hsa_callbacks_t callbacks, // HSA callback function - void* arg); // callback user data - #ifdef __cplusplus } // extern "C" block #endif // __cplusplus -#endif // INC_ROCPROFILER_H_ +#endif // INC_ROCPROFILER_H_ \ No newline at end of file diff --git a/projects/rocprofiler/inc/rocprofiler_plugin.h b/projects/rocprofiler/include/rocprofiler/v2/rocprofiler_plugin.h similarity index 100% rename from projects/rocprofiler/inc/rocprofiler_plugin.h rename to projects/rocprofiler/include/rocprofiler/v2/rocprofiler_plugin.h diff --git a/projects/rocprofiler/plugin/att/CMakeLists.txt b/projects/rocprofiler/plugin/att/CMakeLists.txt index 021f27dfdf..5ae4c86c8d 100644 --- a/projects/rocprofiler/plugin/att/CMakeLists.txt +++ b/projects/rocprofiler/plugin/att/CMakeLists.txt @@ -39,13 +39,13 @@ target_compile_definitions(att_plugin PRIVATE HIP_PROF_HIP_API_STRING=1 __HIP_PLATFORM_HCC__=1) target_include_directories( - att_plugin PRIVATE ${PROJECT_SOURCE_DIR}/inc ${PROJECT_SOURCE_DIR} + att_plugin PRIVATE ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) target_link_options( att_plugin PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exportmap -Wl,--no-undefined) -target_link_libraries(att_plugin PRIVATE ${ROCPROFILER_TARGET} +target_link_libraries(att_plugin PRIVATE rocprofiler-v2 hsa-runtime64::hsa-runtime64 stdc++fs) install(TARGETS att_plugin diff --git a/projects/rocprofiler/plugin/ctf/CMakeLists.txt b/projects/rocprofiler/plugin/ctf/CMakeLists.txt index 8b0d7e0fa2..10a214d388 100644 --- a/projects/rocprofiler/plugin/ctf/CMakeLists.txt +++ b/projects/rocprofiler/plugin/ctf/CMakeLists.txt @@ -38,7 +38,6 @@ target_compile_definitions(ctf_plugin PRIVATE __HIP_PLATFORM_HCC__=1 CTF_PLUGIN_METADATA_FILE_PATH="${CMAKE_INSTALL_PREFIX}/${METADATA_STREAM_FILE_DIR}/metadata") target_include_directories(ctf_plugin PRIVATE - "${PROJECT_SOURCE_DIR}/inc" "${PROJECT_SOURCE_DIR}" "${CMAKE_BINARY_DIR}/src/api" "${CMAKE_CURRENT_BINARY_DIR}") @@ -46,7 +45,7 @@ target_link_options(ctf_plugin PRIVATE "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exportmap" -Wl,--no-undefined) target_link_libraries(ctf_plugin PRIVATE - ${ROCPROFILER_TARGET} + rocprofiler-v2 hsa-runtime64::hsa-runtime64 stdc++fs dl) diff --git a/projects/rocprofiler/plugin/file/CMakeLists.txt b/projects/rocprofiler/plugin/file/CMakeLists.txt index 9939ede3ad..d9b162b8d2 100644 --- a/projects/rocprofiler/plugin/file/CMakeLists.txt +++ b/projects/rocprofiler/plugin/file/CMakeLists.txt @@ -33,11 +33,11 @@ set_target_properties(file_plugin PROPERTIES target_compile_definitions(file_plugin PRIVATE HIP_PROF_HIP_API_STRING=1 __HIP_PLATFORM_HCC__=1) -target_include_directories(file_plugin PRIVATE ${PROJECT_SOURCE_DIR}/inc ${PROJECT_SOURCE_DIR}) +target_include_directories(file_plugin PRIVATE ${PROJECT_SOURCE_DIR}) target_link_options(file_plugin PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exportmap -Wl,--no-undefined) -target_link_libraries(file_plugin PRIVATE ${ROCPROFILER_TARGET} hsa-runtime64::hsa-runtime64 stdc++fs amd_comgr dl) +target_link_libraries(file_plugin PRIVATE rocprofiler-v2 hsa-runtime64::hsa-runtime64 stdc++fs amd_comgr dl) install(TARGETS file_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} diff --git a/projects/rocprofiler/plugin/perfetto/CMakeLists.txt b/projects/rocprofiler/plugin/perfetto/CMakeLists.txt index 4664205a09..c942aa7a45 100644 --- a/projects/rocprofiler/plugin/perfetto/CMakeLists.txt +++ b/projects/rocprofiler/plugin/perfetto/CMakeLists.txt @@ -14,13 +14,13 @@ target_compile_definitions(perfetto_plugin __HIP_PLATFORM_HCC__=1) target_include_directories(perfetto_plugin - PRIVATE ${PROJECT_SOURCE_DIR}/inc ${PROJECT_SOURCE_DIR} + PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/plugin/perfetto/perfetto_sdk/sdk) target_link_options(perfetto_plugin PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exportmap -Wl,--no-undefined) -target_link_libraries(perfetto_plugin PRIVATE ${ROCPROFILER_TARGET} Threads::Threads stdc++fs amd_comgr) +target_link_libraries(perfetto_plugin PRIVATE rocprofiler-v2 Threads::Threads stdc++fs amd_comgr) install(TARGETS perfetto_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} diff --git a/projects/rocprofiler/rocprofiler-backward-compat.cmake b/projects/rocprofiler/rocprofiler-backward-compat.cmake index 658aab0d6b..f624efb9aa 100644 --- a/projects/rocprofiler/rocprofiler-backward-compat.cmake +++ b/projects/rocprofiler/rocprofiler-backward-compat.cmake @@ -73,7 +73,7 @@ endfunction() function(generate_wrapper_header) file(MAKE_DIRECTORY ${ROCPROF_WRAPPER_INC_DIR}) #find all header files from inc - file(GLOB include_files ${CMAKE_CURRENT_SOURCE_DIR}/inc/*.h) + file(GLOB include_files ${CMAKE_CURRENT_SOURCE_DIR}/include/rocprofiler/*.h) #Convert the list of files into #includes foreach(header_file ${include_files}) #set include guard diff --git a/projects/rocprofiler/samples/CMakeLists.txt b/projects/rocprofiler/samples/CMakeLists.txt index a0c12b6b29..38af39706b 100644 --- a/projects/rocprofiler/samples/CMakeLists.txt +++ b/projects/rocprofiler/samples/CMakeLists.txt @@ -32,7 +32,7 @@ find_package(LibDw REQUIRED) ## Add a custom targets to build and run all the tests add_custom_target(samples) -add_dependencies(samples ${ROCPROFILER_TARGET}) +add_dependencies(samples rocprofiler-v2) add_custom_target(run-samples COMMAND ${PROJECT_BINARY_DIR}/samples/run_samples.sh DEPENDS samples) file(GLOB ROCPROFILER_UTIL_SRC_FILES ${PROJECT_SOURCE_DIR}/src/utils/helper.cpp) @@ -51,8 +51,8 @@ file(GLOB ROCPROFILER_UTIL_SRC_FILES ${PROJECT_SOURCE_DIR}/src/utils/helper.cpp) ## Build Application Replay Sample set_source_files_properties(profiler/application_replay_sample.cpp PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1) hip_add_executable(profiler_application_replay profiler/application_replay_sample.cpp ${ROCPROFILER_UTIL_SRC_FILES}) -target_include_directories(profiler_application_replay PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/inc ${CMAKE_CURRENT_SOURCE_DIR}/common) -target_link_libraries(profiler_application_replay PRIVATE ${ROCPROFILER_TARGET} amd_comgr) +target_include_directories(profiler_application_replay PRIVATE ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/common) +target_link_libraries(profiler_application_replay PRIVATE rocprofiler-v2 amd_comgr) target_link_options(profiler_application_replay PRIVATE "-Wl,--build-id=md5") add_dependencies(samples profiler_application_replay) install(TARGETS profiler_application_replay RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/samples COMPONENT samples) @@ -60,8 +60,8 @@ install(TARGETS profiler_application_replay RUNTIME DESTINATION ${CMAKE_INSTALL_ ## Build Kernel Replay Sample set_source_files_properties(profiler/kernel_replay_sample.cpp PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1) hip_add_executable(profiler_kernel_replay profiler/kernel_replay_sample.cpp ${ROCPROFILER_UTIL_SRC_FILES}) -target_include_directories(profiler_kernel_replay PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/inc ${CMAKE_CURRENT_SOURCE_DIR}/common) -target_link_libraries(profiler_kernel_replay PRIVATE ${ROCPROFILER_TARGET} amd_comgr) +target_include_directories(profiler_kernel_replay PRIVATE ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/common) +target_link_libraries(profiler_kernel_replay PRIVATE rocprofiler-v2 amd_comgr) target_link_options(profiler_kernel_replay PRIVATE "-Wl,--build-id=md5") add_dependencies(samples profiler_kernel_replay) install(TARGETS profiler_kernel_replay RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/samples COMPONENT samples) @@ -69,17 +69,17 @@ install(TARGETS profiler_kernel_replay RUNTIME DESTINATION ${CMAKE_INSTALL_DATAR ## Build User Replay Sample set_source_files_properties(profiler/user_replay_sample.cpp PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1) hip_add_executable(profiler_user_replay profiler/user_replay_sample.cpp ${ROCPROFILER_UTIL_SRC_FILES}) -target_include_directories(profiler_user_replay PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/inc ${CMAKE_CURRENT_SOURCE_DIR}/common) +target_include_directories(profiler_user_replay PRIVATE ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/common) target_link_options(profiler_user_replay PRIVATE "-Wl,--build-id=md5") -target_link_libraries(profiler_user_replay PRIVATE ${ROCPROFILER_TARGET} amd_comgr) +target_link_libraries(profiler_user_replay PRIVATE rocprofiler-v2 amd_comgr) add_dependencies(samples profiler_user_replay) install(TARGETS profiler_user_replay RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/samples COMPONENT samples) ## Build Device Profiling Sample set_source_files_properties(profiler/device_profiling_sample.cpp PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1) hip_add_executable(profiler_device_profiling profiler/device_profiling_sample.cpp ${ROCPROFILER_UTIL_SRC_FILES}) -target_include_directories(profiler_device_profiling PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/inc ${CMAKE_CURRENT_SOURCE_DIR}/common) -target_link_libraries(profiler_device_profiling PRIVATE ${ROCPROFILER_TARGET} amd_comgr) +target_include_directories(profiler_device_profiling PRIVATE ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/common) +target_link_libraries(profiler_device_profiling PRIVATE rocprofiler-v2 amd_comgr) target_link_options(profiler_device_profiling PRIVATE "-Wl,--build-id=md5") add_dependencies(samples profiler_device_profiling) install(TARGETS profiler_device_profiling RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/samples COMPONENT samples) @@ -87,8 +87,8 @@ install(TARGETS profiler_device_profiling RUNTIME DESTINATION ${CMAKE_INSTALL_DA ## Build Counters Sampling example set_source_files_properties(counters_sampler/pcie_counters_example.cpp PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1) hip_add_executable(pcie_counters_sampler counters_sampler/pcie_counters_example.cpp ${ROCPROFILER_UTIL_SRC_FILES}) -target_include_directories(pcie_counters_sampler PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/inc ${CMAKE_CURRENT_SOURCE_DIR}/common) -target_link_libraries(pcie_counters_sampler PRIVATE ${ROCPROFILER_TARGET} systemd amd_comgr) +target_include_directories(pcie_counters_sampler PRIVATE ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/common) +target_link_libraries(pcie_counters_sampler PRIVATE rocprofiler-v2 systemd amd_comgr) target_link_options(pcie_counters_sampler PRIVATE "-Wl,--build-id=md5") add_dependencies(samples pcie_counters_sampler) install(TARGETS pcie_counters_sampler RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/samples COMPONENT samples) @@ -96,8 +96,8 @@ install(TARGETS pcie_counters_sampler RUNTIME DESTINATION ${CMAKE_INSTALL_DATARO ## Build XGMI Counters Sampling example set_source_files_properties(counters_sampler/xgmi_counters_sampler_example.cpp PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1) hip_add_executable(xgmi_counters_sampler counters_sampler/xgmi_counters_sampler_example.cpp ${ROCPROFILER_UTIL_SRC_FILES}) -target_include_directories(xgmi_counters_sampler PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/inc ${CMAKE_CURRENT_SOURCE_DIR}/common) -target_link_libraries(xgmi_counters_sampler PRIVATE ${ROCPROFILER_TARGET} systemd amd_comgr) +target_include_directories(xgmi_counters_sampler PRIVATE ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/common) +target_link_libraries(xgmi_counters_sampler PRIVATE rocprofiler-v2 systemd amd_comgr) target_link_options(xgmi_counters_sampler PRIVATE "-Wl,--build-id=md5") add_dependencies(samples xgmi_counters_sampler) install(TARGETS xgmi_counters_sampler RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/samples COMPONENT samples) @@ -111,8 +111,8 @@ install(TARGETS xgmi_counters_sampler RUNTIME DESTINATION ${CMAKE_INSTALL_DATARO ## Build HIP/HSA Trace Sample set_source_files_properties(tracer/sample.cpp PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1) hip_add_executable(tracer_hip_hsa tracer/sample.cpp ${ROCPROFILER_UTIL_SRC_FILES}) -target_include_directories(tracer_hip_hsa PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/inc ${CMAKE_CURRENT_SOURCE_DIR}/common) -target_link_libraries(tracer_hip_hsa PRIVATE ${ROCPROFILER_TARGET} amd_comgr) +target_include_directories(tracer_hip_hsa PRIVATE ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/common) +target_link_libraries(tracer_hip_hsa PRIVATE rocprofiler-v2 amd_comgr) target_link_options(tracer_hip_hsa PRIVATE "-Wl,--build-id=md5") add_dependencies(samples tracer_hip_hsa) install(TARGETS tracer_hip_hsa RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/samples COMPONENT samples) @@ -120,8 +120,8 @@ install(TARGETS tracer_hip_hsa RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/ ## Build HIP/HSA Trace with async output api trace data Sample set_source_files_properties(tracer/sample_async.cpp PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1) hip_add_executable(tracer_hip_hsa_async tracer/sample_async.cpp ${ROCPROFILER_UTIL_SRC_FILES}) -target_include_directories(tracer_hip_hsa_async PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/inc ${CMAKE_CURRENT_SOURCE_DIR}/common) -target_link_libraries(tracer_hip_hsa_async PRIVATE ${ROCPROFILER_TARGET} amd_comgr) +target_include_directories(tracer_hip_hsa_async PRIVATE ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/common) +target_link_libraries(tracer_hip_hsa_async PRIVATE rocprofiler-v2 amd_comgr) target_link_options(tracer_hip_hsa_async PRIVATE "-Wl,--build-id=md5") add_dependencies(samples tracer_hip_hsa_async) install(TARGETS tracer_hip_hsa_async RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/samples COMPONENT samples) @@ -150,7 +150,7 @@ check_c_source_compiles(" target_link_libraries(pc_sampling_code_printing PRIVATE - ${ROCPROFILER_TARGET} + rocprofiler-v2 rocm-dbgapi ${LIBELF_LIBRARIES} ${LIBDW_LIBRARIES} diff --git a/projects/rocprofiler/samples/common/common.h b/projects/rocprofiler/samples/common/common.h index 50fd4ed722..0695572895 100644 --- a/projects/rocprofiler/samples/common/common.h +++ b/projects/rocprofiler/samples/common/common.h @@ -1,5 +1,5 @@ #include -#include +#include #include #include diff --git a/projects/rocprofiler/samples/pcsampler/code_printing_sample/disassembly.cpp b/projects/rocprofiler/samples/pcsampler/code_printing_sample/disassembly.cpp index 9760e90430..d48b539dae 100644 --- a/projects/rocprofiler/samples/pcsampler/code_printing_sample/disassembly.cpp +++ b/projects/rocprofiler/samples/pcsampler/code_printing_sample/disassembly.cpp @@ -41,7 +41,7 @@ #include #include -#include "rocprofiler.h" +#include #include "code_printing.hpp" #include "program.hpp" diff --git a/projects/rocprofiler/samples/pcsampler/code_printing_sample/main.cpp b/projects/rocprofiler/samples/pcsampler/code_printing_sample/main.cpp index b6abc91cf3..ed4374c517 100644 --- a/projects/rocprofiler/samples/pcsampler/code_printing_sample/main.cpp +++ b/projects/rocprofiler/samples/pcsampler/code_printing_sample/main.cpp @@ -33,7 +33,7 @@ #include #include -#include +#include #include "program.hpp" #include "program_options.hpp" diff --git a/projects/rocprofiler/samples/profiler/device_profiling_sample.cpp b/projects/rocprofiler/samples/profiler/device_profiling_sample.cpp index 7effab1ad2..307b303f64 100644 --- a/projects/rocprofiler/samples/profiler/device_profiling_sample.cpp +++ b/projects/rocprofiler/samples/profiler/device_profiling_sample.cpp @@ -3,7 +3,7 @@ #include #include -#include "rocprofiler.h" +#include int main(int argc, char** argv) { int poll_duration = 5; diff --git a/projects/rocprofiler/src/api/CMakeLists.txt b/projects/rocprofiler/src/api/CMakeLists.txt index 566b9340d4..22adc12cd7 100644 --- a/projects/rocprofiler/src/api/CMakeLists.txt +++ b/projects/rocprofiler/src/api/CMakeLists.txt @@ -134,16 +134,18 @@ set(GENERATED_SOURCES find_path(PCIACCESS_INCLUDE_DIR pciaccess.h REQUIRED) find_library(PCIACCESS_LIBRARIES pciaccess REQUIRED) -set(PUBLIC_HEADERS - rocprofiler_plugin.h - rocprofiler.h) +set(PUBLIC_HEADERS rocprofiler.h) foreach(header ${PUBLIC_HEADERS}) - install(FILES ${PROJECT_SOURCE_DIR}/inc/${header} + install(FILES ${PROJECT_SOURCE_DIR}/include/rocprofiler/${header} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} COMPONENT dev) endforeach() +install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/rocprofiler/v2 + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} + COMPONENT dev) + # Getting Source files for ROCProfiler, Hardware, HSA, Memory, Session, Counters, Utils file(GLOB ROCPROFILER_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) @@ -187,8 +189,31 @@ file(GLOB CORE_UTILS_SRC_FILES ${CORE_UTILS_DIR}/*.cpp) set(CORE_PC_SAMPLING_DIR ${PROJECT_SOURCE_DIR}/src/pcsampler) file(GLOB CORE_PC_SAMPLING_FILES ${CORE_PC_SAMPLING_DIR}/core/*.cpp ${CORE_PC_SAMPLING_DIR}/gfxip/*.cpp ${CORE_PC_SAMPLING_DIR}/session/*.cpp) + +#### V1 Library +# Compiling/Installing ROCProfiler API V1 +add_library(${ROCPROFILER_TARGET} SHARED ${OLD_LIB_SRC}) +set_target_properties(${ROCPROFILER_TARGET} PROPERTIES + CXX_VISIBILITY_PRESET hidden + VERSION 1.0.0 + SOVERSION 1) +# As ROCR hsa_api_trace header file is not usable unless AMD_INTERNAL_BUILD is defined +target_compile_definitions(${ROCPROFILER_TARGET} PUBLIC AMD_INTERNAL_BUILD) +target_include_directories(${ROCPROFILER_TARGET} + PUBLIC + $ + PRIVATE + ${LIB_DIR} ${ROOT_DIR} + ${PROJECT_SOURCE_DIR}/include/rocprofiler) +target_link_libraries(${ROCPROFILER_TARGET} PRIVATE ${AQLPROFILE_LIB} hsa-runtime64::hsa-runtime64 c stdc++) +## Install libraries: Non versioned lib file in dev package +# install ( TARGETS ${ROCPROFILER_TARGET} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dev NAMELINK_COMPONENT runtime) +install ( TARGETS ${ROCPROFILER_TARGET} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime NAMELINK_SKIP) +# install ( TARGETS ${ROCPROFILER_TARGET} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT asan) + +#### V2 Library # Compiling/Installing ROCProfiler API -add_library(${ROCPROFILER_TARGET} SHARED +add_library(rocprofiler-v2 SHARED ${ROCPROFILER_SRC_FILES} ${ROCPROFILER_CLASS_SRC_FILES} ${ROCPROFILER_PROFILER_SRC_FILES} @@ -211,47 +236,54 @@ add_library(${ROCPROFILER_TARGET} SHARED ${ROCPROFILER_ROCTRACER_SRC_FILES} ${GENERATED_SOURCES} ${CORE_COUNTERS_SRC_FILES} - ${CORE_PC_SAMPLING_FILES} - ${OLD_LIB_SRC}) - -set_target_properties(${ROCPROFILER_TARGET} PROPERTIES + ${CORE_PC_SAMPLING_FILES}) +set_target_properties(rocprofiler-v2 PROPERTIES CXX_VISIBILITY_PRESET hidden DEFINE_SYMBOL "ROCPROFILER_EXPORTS" LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/exportmap + OUTPUT_NAME rocprofiler64 + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/v2 VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}) - -target_compile_definitions(${ROCPROFILER_TARGET} - PUBLIC AMD_INTERNAL_BUILD - PRIVATE PROF_API_IMPL HIP_PROF_HIP_API_STRING=1 __HIP_PLATFORM_AMD__=1) - -target_include_directories(${ROCPROFILER_TARGET} +target_compile_definitions(rocprofiler-v2 + # As ROCR hsa_api_trace header file is not usable unless AMD_INTERNAL_BUILD is defined + PRIVATE AMD_INTERNAL_BUILD + PROF_API_IMPL HIP_PROF_HIP_API_STRING=1 __HIP_PLATFORM_AMD__=1) +target_include_directories(rocprofiler-v2 PUBLIC - ${ROCM_PATH}/include ${HIP_INCLUDE_DIRECTORIES} ${HSA_RUNTIME_INCLUDE_DIRECTORIES} $ - $ - $ + $ + $ PRIVATE ${LIB_DIR} ${ROOT_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${PROJECT_SOURCE_DIR} - ${PROJECT_SOURCE_DIR}/tools - ${PROJECT_SOURCE_DIR}/inc) - + ${PROJECT_SOURCE_DIR}/tools) if(ASAN) - target_compile_options(${ROCPROFILER_TARGET} PRIVATE -fsanitize=address) - target_link_options(${ROCPROFILER_TARGET} PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exportmap -Wl,--no-undefined,-fsanitize=address) - target_link_libraries(${ROCPROFILER_TARGET} PRIVATE ${AQLPROFILE_LIB} hsa-runtime64::hsa-runtime64 Threads::Threads atomic asan dl c stdc++ stdc++fs amd_comgr ${PCIACCESS_LIBRARIES}) + target_compile_options(rocprofiler-v2 PRIVATE -fsanitize=address) + target_link_options(rocprofiler-v2 PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exportmap -Wl,--no-undefined,-fsanitize=address) + target_link_libraries(rocprofiler-v2 PRIVATE ${AQLPROFILE_LIB} hsa-runtime64::hsa-runtime64 Threads::Threads atomic asan dl c stdc++ stdc++fs amd_comgr ${PCIACCESS_LIBRARIES}) else() - target_link_options(${ROCPROFILER_TARGET} PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exportmap -Wl,--no-undefined) - target_link_libraries(${ROCPROFILER_TARGET} PRIVATE ${AQLPROFILE_LIB} hsa-runtime64::hsa-runtime64 Threads::Threads atomic dl c stdc++ stdc++fs amd_comgr ${PCIACCESS_LIBRARIES}) + target_link_options(rocprofiler-v2 PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exportmap -Wl,--no-undefined) + target_link_libraries(rocprofiler-v2 PRIVATE ${AQLPROFILE_LIB} hsa-runtime64::hsa-runtime64 Threads::Threads atomic dl c stdc++ stdc++fs amd_comgr ${PCIACCESS_LIBRARIES}) endif() - ## Install libraries: Non versioned lib file in dev package -install ( TARGETS ${ROCPROFILER_TARGET} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dev NAMELINK_ONLY ) -install ( TARGETS ${ROCPROFILER_TARGET} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime NAMELINK_SKIP ) -install ( TARGETS ${ROCPROFILER_TARGET} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT asan ) +# install(TARGETS rocprofiler-v2 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dev) +install(TARGETS rocprofiler-v2 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime NAMELINK_SKIP) +# install(TARGETS rocprofiler-v2 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT asan) + +file(CONFIGURE OUTPUT ${CMAKE_BINARY_DIR}/librocprofiler64.so + CONTENT "OUTPUT_FORMAT(elf64-x86-64)\nINPUT(librocprofiler64.so.1)") +install(FILES ${CMAKE_BINARY_DIR}/librocprofiler64.so DESTINATION ${CMAKE_INSTALL_LIBDIR} + PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE + COMPONENT runtime) + +file(CONFIGURE OUTPUT ${CMAKE_BINARY_DIR}/librocprofiler64v2.so + CONTENT "OUTPUT_FORMAT(elf64-x86-64)\nINPUT(librocprofiler64.so.${PROJECT_VERSION_MAJOR})") +install(FILES ${CMAKE_BINARY_DIR}/librocprofiler64v2.so DESTINATION ${CMAKE_INSTALL_LIBDIR} + PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE + COMPONENT runtime) configure_file(${PROJECT_SOURCE_DIR}/src/core/counters/metrics/basic_counters.xml ${PROJECT_BINARY_DIR}/counters/basic_counters.xml COPYONLY) configure_file(${PROJECT_SOURCE_DIR}/src/core/counters/metrics/derived_counters.xml ${PROJECT_BINARY_DIR}/counters/derived_counters.xml COPYONLY) diff --git a/projects/rocprofiler/src/api/exportmap b/projects/rocprofiler/src/api/exportmap index 013534e6c1..ab110ed177 100644 --- a/projects/rocprofiler/src/api/exportmap +++ b/projects/rocprofiler/src/api/exportmap @@ -1,48 +1,9 @@ -ROCPROFILER_8.0 { +ROCPROFILER_9.0 { global: OnLoad; OnUnload; rocprofiler_version_major; rocprofiler_version_minor; - rocprofiler_error_string; - rocprofiler_open; - rocprofiler_add_feature; - rocprofiler_features_set_open; - rocprofiler_close; - rocprofiler_reset; - rocprofiler_get_agent; - rocprofiler_get_time; - rocprofiler_set_queue_callbacks; - rocprofiler_remove_queue_callbacks; - rocprofiler_start_queue_callbacks; - rocprofiler_stop_queue_callbacks; - rocprofiler_start; - rocprofiler_stop; - rocprofiler_read; - rocprofiler_get_data; - rocprofiler_group_count; - rocprofiler_get_group; - rocprofiler_group_start; - rocprofiler_group_stop; - rocprofiler_group_read; - rocprofiler_group_get_data; - rocprofiler_get_metrics; - rocprofiler_iterate_trace_data; - rocprofiler_get_info; - rocprofiler_iterate_info; - rocprofiler_query_info; - rocprofiler_queue_create_profiled; - rocprofiler_pool_open; - rocprofiler_pool_close; - rocprofiler_pool_fetch; - rocprofiler_pool_release; - rocprofiler_pool_iterate; - rocprofiler_pool_flush; - rocprofiler_set_hsa_callbacks; -local: *; -}; - -ROCPROFILER_9.0 { -global: HSA_AMD_TOOL_PRIORITY; + HSA_AMD_TOOL_PRIORITY; rocprofiler_error_str; rocprofiler_initialize; rocprofiler_finalize; @@ -85,4 +46,5 @@ global: HSA_AMD_TOOL_PRIORITY; rocprofiler_device_profiling_session_poll; rocprofiler_device_profiling_session_stop; rocprofiler_device_profiling_session_destroy; -} ROCPROFILER_8.0; \ No newline at end of file +local: *; +}; \ No newline at end of file diff --git a/projects/rocprofiler/src/api/rocmtools.cpp b/projects/rocprofiler/src/api/rocmtools.cpp index 014ad84d56..7b4dfcf0a3 100644 --- a/projects/rocprofiler/src/api/rocmtools.cpp +++ b/projects/rocprofiler/src/api/rocmtools.cpp @@ -720,7 +720,7 @@ rocprofiler_device_profiling_session_destroy(rocprofiler_session_id_t session_id } -// static bool started{false}; +static bool started{false}; extern "C" { @@ -729,27 +729,28 @@ extern "C" { // The HSA_AMD_TOOL_PRIORITY variable must be a constant value type // initialized by the loader itself, not by code during _init. 'extern const' // seems do that although that is not a guarantee. -// ROCPROFILER_EXPORT extern const uint32_t HSA_AMD_TOOL_PRIORITY = 25; +ROCPROFILER_EXPORT extern const uint32_t HSA_AMD_TOOL_PRIORITY = 25; /** * @brief Callback function called upon loading the HSA. * The function updates the core api table function pointers to point to the * interceptor functions in this file. */ -// ROCPROFILER_EXPORT bool OnLoad(HsaApiTable* table, uint64_t runtime_version, -// uint64_t failed_tool_count, const char* const* failed_tool_names) { -// if (started) rocmtools::fatal("HSA Tool started already!"); -// started = true; -// rocmtools::hsa_support::Initialize(table); -// return true; -// } +ROCPROFILER_EXPORT bool OnLoad(HsaApiTable* table, uint64_t runtime_version, + uint64_t failed_tool_count, const char* const* failed_tool_names) { + if (started) rocmtools::fatal("HSA Tool started already!"); + started = true; + rocmtools::hsa_support::Initialize(table); + return true; +} /** * @brief Callback function upon unloading the HSA. */ -// ROCPROFILER_EXPORT void OnUnload() { -// if (!started) rocmtools::fatal("HSA Tool hasn't started yet!"); -// rocmtools::hsa_support::Finalize(); -// } +ROCPROFILER_EXPORT void OnUnload() { + if (!started) rocmtools::fatal("HSA Tool hasn't started yet!"); + rocmtools::hsa_support::Finalize(); + started=false; +} } // extern "C" diff --git a/projects/rocprofiler/src/core/activity.cpp b/projects/rocprofiler/src/core/activity.cpp index a4cdb90ad8..308625223b 100644 --- a/projects/rocprofiler/src/core/activity.cpp +++ b/projects/rocprofiler/src/core/activity.cpp @@ -20,7 +20,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *******************************************************************************/ -#define ROCP_INTERNAL_BUILD #include "activity.h" #include diff --git a/projects/rocprofiler/src/core/activity.h b/projects/rocprofiler/src/core/activity.h index a7d773802c..f82f47731b 100644 --- a/projects/rocprofiler/src/core/activity.h +++ b/projects/rocprofiler/src/core/activity.h @@ -1,13 +1,7 @@ #ifndef _SRC_CORE_ACTIVITY_H #define _SRC_CORE_ACTIVITY_H -#define ROCPROFILER_V1 - -#ifdef ROCP_INTERNAL_BUILD -#include "inc/rocprofiler.h" -#else -#include -#endif +#include "rocprofiler.h" #include diff --git a/projects/rocprofiler/src/core/context.h b/projects/rocprofiler/src/core/context.h index b66b1584a6..4b999b84de 100644 --- a/projects/rocprofiler/src/core/context.h +++ b/projects/rocprofiler/src/core/context.h @@ -23,7 +23,7 @@ THE SOFTWARE. #ifndef SRC_CORE_CONTEXT_H_ #define SRC_CORE_CONTEXT_H_ -#include "inc/rocprofiler.h" +#include "rocprofiler.h" #include #include diff --git a/projects/rocprofiler/src/core/context_pool.h b/projects/rocprofiler/src/core/context_pool.h index c5c45cc556..68eafb3981 100644 --- a/projects/rocprofiler/src/core/context_pool.h +++ b/projects/rocprofiler/src/core/context_pool.h @@ -23,7 +23,7 @@ THE SOFTWARE. #ifndef SRC_CORE_CONTEXT_POOL_H_ #define SRC_CORE_CONTEXT_POOL_H_ -#include "inc/rocprofiler.h" +#include "rocprofiler.h" #include diff --git a/projects/rocprofiler/src/core/counters/mmio/perfmon.h b/projects/rocprofiler/src/core/counters/mmio/perfmon.h index 9c90c2347e..f7ad8c8d89 100644 --- a/projects/rocprofiler/src/core/counters/mmio/perfmon.h +++ b/projects/rocprofiler/src/core/counters/mmio/perfmon.h @@ -21,7 +21,7 @@ #ifndef SRC_CORE_COUNTERS_PERFMON_H #define SRC_CORE_COUNTERS_PERFMON_H -#include "inc/rocprofiler.h" +#include "rocprofiler.h" #include "mmio.h" #include diff --git a/projects/rocprofiler/src/core/hsa/packets/packets_generator.h b/projects/rocprofiler/src/core/hsa/packets/packets_generator.h index 05c92dcd70..29a562b281 100644 --- a/projects/rocprofiler/src/core/hsa/packets/packets_generator.h +++ b/projects/rocprofiler/src/core/hsa/packets/packets_generator.h @@ -20,7 +20,7 @@ #ifndef SRC_CORE_HSA_PACKETS_PACKETS_GENERATOR_H_ #define SRC_CORE_HSA_PACKETS_PACKETS_GENERATOR_H_ -#include "inc/rocprofiler.h" +#include "rocprofiler.h" #include #include diff --git a/projects/rocprofiler/src/core/hsa/queues/queue.cpp b/projects/rocprofiler/src/core/hsa/queues/queue.cpp index 62774be5ba..5dd01c4ad4 100644 --- a/projects/rocprofiler/src/core/hsa/queues/queue.cpp +++ b/projects/rocprofiler/src/core/hsa/queues/queue.cpp @@ -27,7 +27,6 @@ #include #include -#include "rocprofiler.h" #include "src/api/rocmtool.h" #include "src/core/hsa/packets/packets_generator.h" #include "src/core/hsa/hsa_support.h" diff --git a/projects/rocprofiler/src/core/hsa/queues/queue.h b/projects/rocprofiler/src/core/hsa/queues/queue.h index 5ed0ae798b..1b1ee121a0 100644 --- a/projects/rocprofiler/src/core/hsa/queues/queue.h +++ b/projects/rocprofiler/src/core/hsa/queues/queue.h @@ -21,7 +21,7 @@ #ifndef SRC_CORE_HSA_QUEUES_QUEUE_H_ #define SRC_CORE_HSA_QUEUES_QUEUE_H_ -#include "inc/rocprofiler.h" +#include "rocprofiler.h" #include #include diff --git a/projects/rocprofiler/src/core/hsa_interceptor.h b/projects/rocprofiler/src/core/hsa_interceptor.h index abad9b94d8..151fec6433 100644 --- a/projects/rocprofiler/src/core/hsa_interceptor.h +++ b/projects/rocprofiler/src/core/hsa_interceptor.h @@ -33,7 +33,7 @@ SOFTWARE. #include #include -#include "inc/rocprofiler.h" +#include "rocprofiler.h" #include "util/exception.h" #include "util/hsa_rsrc_factory.h" diff --git a/projects/rocprofiler/src/core/intercept_queue.h b/projects/rocprofiler/src/core/intercept_queue.h index 103d5c391d..f97c810439 100644 --- a/projects/rocprofiler/src/core/intercept_queue.h +++ b/projects/rocprofiler/src/core/intercept_queue.h @@ -36,7 +36,7 @@ THE SOFTWARE. #include "core/proxy_queue.h" #include "core/tracker.h" #include "core/types.h" -#include "inc/rocprofiler.h" +#include "rocprofiler.h" #include "util/hsa_rsrc_factory.h" namespace rocprofiler { diff --git a/projects/rocprofiler/src/core/memory/generic_buffer.h b/projects/rocprofiler/src/core/memory/generic_buffer.h index 65c0f827e0..c8dedb0e1a 100644 --- a/projects/rocprofiler/src/core/memory/generic_buffer.h +++ b/projects/rocprofiler/src/core/memory/generic_buffer.h @@ -20,7 +20,7 @@ #ifndef SRC_CORE_MEMORY_GENERIC_BUFFER_H_ #define SRC_CORE_MEMORY_GENERIC_BUFFER_H_ -#include "inc/rocprofiler.h" +#include "rocprofiler.h" #include #include diff --git a/projects/rocprofiler/src/core/profile.h b/projects/rocprofiler/src/core/profile.h index 904e309570..90d29c535c 100644 --- a/projects/rocprofiler/src/core/profile.h +++ b/projects/rocprofiler/src/core/profile.h @@ -23,7 +23,7 @@ THE SOFTWARE. #ifndef SRC_CORE_PROFILE_H_ #define SRC_CORE_PROFILE_H_ -#include "inc/rocprofiler.h" +#include "rocprofiler.h" #include #include diff --git a/projects/rocprofiler/src/core/rocprofiler.cpp b/projects/rocprofiler/src/core/rocprofiler.cpp index 5908212943..3ec4115931 100644 --- a/projects/rocprofiler/src/core/rocprofiler.cpp +++ b/projects/rocprofiler/src/core/rocprofiler.cpp @@ -20,7 +20,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *******************************************************************************/ -#include "inc/rocprofiler.h" +#include "rocprofiler.h" #include #include @@ -39,8 +39,6 @@ THE SOFTWARE. #include "util/exception.h" #include "util/hsa_rsrc_factory.h" #include "util/logger.h" -#include "src/core/hsa/hsa_support.h" -#include "src/utils/helper.h" #define PUBLIC_API __attribute__((visibility("default"))) #define CONSTRUCTOR_API __attribute__((constructor)) @@ -380,9 +378,6 @@ std::atomic util::Logger::instance_{}; CONTEXT_INSTANTIATE(); -static bool started{false}; -// #include "src/core/hsa/hsa_support.h" - /////////////////////////////////////////////////////////////////////////////////////////////////// // Public library methods // @@ -398,11 +393,6 @@ ROCPROFILER_EXPORT extern const uint32_t HSA_AMD_TOOL_PRIORITY = 25; PUBLIC_API bool OnLoad(HsaApiTable* table, uint64_t runtime_version, uint64_t failed_tool_count, const char* const* failed_tool_names) { ONLOAD_TRACE_BEG(); - if (started) rocmtools::fatal("HSA Tool started already!"); - started = true; - if (!getenv("ROCP_TOOL_LIB") && !getenv("ROCP_HSA_INTERCEPT")) { - rocmtools::hsa_support::Initialize(table); - } else { rocprofiler::SaveHsaApi(table); rocprofiler::ProxyQueue::InitFactory(); @@ -469,20 +459,14 @@ PUBLIC_API bool OnLoad(HsaApiTable* table, uint64_t runtime_version, uint64_t fa ONLOAD_TRACE("end intercept_mode(" << std::hex << intercept_env_value << ")" << " intercept_mode_mask(" << std::hex << intercept_mode_mask << ")" << std::dec); - } return true; } // HSA-runtime tool on-unload method PUBLIC_API void OnUnload() { ONLOAD_TRACE_BEG(); - if (!started) rocmtools::fatal("HSA Tool hasn't started yet!"); - if (!getenv("ROCP_TOOL_LIB") && !getenv("ROCP_HSA_INTERCEPT")) { - rocmtools::hsa_support::Finalize(); - } else { rocprofiler::UnloadTool(); rocprofiler::RestoreHsaApi(); - } ONLOAD_TRACE_END(); } diff --git a/projects/rocprofiler/src/core/session/att/att.h b/projects/rocprofiler/src/core/session/att/att.h index 85360db7b4..2db2553210 100644 --- a/projects/rocprofiler/src/core/session/att/att.h +++ b/projects/rocprofiler/src/core/session/att/att.h @@ -28,7 +28,7 @@ #include #include -#include "inc/rocprofiler.h" +#include "rocprofiler.h" namespace rocmtools { diff --git a/projects/rocprofiler/src/core/session/device_profiling.h b/projects/rocprofiler/src/core/session/device_profiling.h index 658c453898..056631b92e 100644 --- a/projects/rocprofiler/src/core/session/device_profiling.h +++ b/projects/rocprofiler/src/core/session/device_profiling.h @@ -21,7 +21,7 @@ #ifndef SRC_CORE_SESSION_DEVICE_PROFILING_H_ #define SRC_CORE_SESSION_DEVICE_PROFILING_H_ -#include +#include "rocprofiler.h" #include "src/core/hsa/packets/packets_generator.h" #include // #include "src/core/counters/rdc/rdc_metrics.h" diff --git a/projects/rocprofiler/src/core/session/filter.h b/projects/rocprofiler/src/core/session/filter.h index dd36d03ae2..a39f6fe023 100644 --- a/projects/rocprofiler/src/core/session/filter.h +++ b/projects/rocprofiler/src/core/session/filter.h @@ -25,7 +25,7 @@ #include #include -#include "inc/rocprofiler.h" +#include "rocprofiler.h" #define ASSERTM(exp, msg) assert(((void)msg, exp)) diff --git a/projects/rocprofiler/src/core/session/profiler/profiler.h b/projects/rocprofiler/src/core/session/profiler/profiler.h index cbac757c04..1fc1ee69af 100644 --- a/projects/rocprofiler/src/core/session/profiler/profiler.h +++ b/projects/rocprofiler/src/core/session/profiler/profiler.h @@ -31,7 +31,7 @@ #include #include -#include "inc/rocprofiler.h" +#include "rocprofiler.h" #include "src/core/counters/basic/basic_counter.h" #include "src/core/counters/metrics/eval_metrics.h" diff --git a/projects/rocprofiler/src/core/session/session.h b/projects/rocprofiler/src/core/session/session.h index dcba49b3c8..a0da53ce17 100644 --- a/projects/rocprofiler/src/core/session/session.h +++ b/projects/rocprofiler/src/core/session/session.h @@ -32,7 +32,7 @@ #include #include -#include "inc/rocprofiler.h" +#include "rocprofiler.h" #include "src/core/memory/generic_buffer.h" #include "src/core/session/filter.h" #include "profiler/profiler.h" diff --git a/projects/rocprofiler/src/core/session/spm/spm.h b/projects/rocprofiler/src/core/session/spm/spm.h index d25f7217e9..e1cb93655c 100644 --- a/projects/rocprofiler/src/core/session/spm/spm.h +++ b/projects/rocprofiler/src/core/session/spm/spm.h @@ -10,7 +10,7 @@ #include "hsa/hsa_ext_amd.h" #include "src/core/hsa/packets/packets_generator.h" #include "src/utils/exception.h" -#include "inc/rocprofiler.h" +#include "rocprofiler.h" namespace rocmtools { diff --git a/projects/rocprofiler/src/core/session/tracer/src/roctracer.h b/projects/rocprofiler/src/core/session/tracer/src/roctracer.h index 8bf6b893d4..90a9585edd 100644 --- a/projects/rocprofiler/src/core/session/tracer/src/roctracer.h +++ b/projects/rocprofiler/src/core/session/tracer/src/roctracer.h @@ -33,7 +33,7 @@ #include "hip_ostream_ops.h" #include "hsa_ostream_ops.h" #include "hsa_prof_str.h" -#include "inc/rocprofiler.h" +#include "rocprofiler.h" #include "src/core/memory/generic_buffer.h" typedef struct { diff --git a/projects/rocprofiler/src/core/session/tracer/tracer.h b/projects/rocprofiler/src/core/session/tracer/tracer.h index fe63b7b412..7fab2bef2d 100644 --- a/projects/rocprofiler/src/core/session/tracer/tracer.h +++ b/projects/rocprofiler/src/core/session/tracer/tracer.h @@ -27,7 +27,7 @@ #include #include -#include "inc/rocprofiler.h" +#include "rocprofiler.h" #include "src/roctracer.h" typedef bool is_filtered_domain_t; diff --git a/projects/rocprofiler/src/core/tracker.h b/projects/rocprofiler/src/core/tracker.h index 8d9c29f928..7c1fdd3530 100644 --- a/projects/rocprofiler/src/core/tracker.h +++ b/projects/rocprofiler/src/core/tracker.h @@ -33,7 +33,7 @@ THE SOFTWARE. #include #include "util/hsa_rsrc_factory.h" -#include "inc/rocprofiler.h" +#include "rocprofiler.h" #include "util/exception.h" #include "util/logger.h" diff --git a/projects/rocprofiler/src/pcsampler/gfxip/gfxip.cpp b/projects/rocprofiler/src/pcsampler/gfxip/gfxip.cpp index 6fe291eda5..e43f78c18c 100644 --- a/projects/rocprofiler/src/pcsampler/gfxip/gfxip.cpp +++ b/projects/rocprofiler/src/pcsampler/gfxip/gfxip.cpp @@ -29,6 +29,8 @@ #include +#include "rocprofiler.h" + #include "gfxip.h" #include "src/utils/helper.h" diff --git a/projects/rocprofiler/src/tools/CMakeLists.txt b/projects/rocprofiler/src/tools/CMakeLists.txt index 4d1a723619..df9aa71c0e 100644 --- a/projects/rocprofiler/src/tools/CMakeLists.txt +++ b/projects/rocprofiler/src/tools/CMakeLists.txt @@ -18,7 +18,6 @@ set_target_properties(rocprofiler_tool PROPERTIES target_include_directories(rocprofiler_tool PRIVATE ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} - ${PROJECT_SOURCE_DIR}/inc ${PROJECT_SOURCE_DIR}/src) target_compile_definitions(rocprofiler_tool @@ -26,10 +25,10 @@ target_compile_definitions(rocprofiler_tool if(ASAN) target_compile_options(rocprofiler_tool PRIVATE -fsanitize=address) - target_link_libraries(rocprofiler_tool ${ROCPROFILER_TARGET} hsa-runtime64::hsa-runtime64 Threads::Threads atomic asan dl rt stdc++fs amd_comgr) + target_link_libraries(rocprofiler_tool rocprofiler-v2 hsa-runtime64::hsa-runtime64 Threads::Threads atomic asan dl rt stdc++fs amd_comgr) target_link_options(rocprofiler_tool PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exportmap -Wl,--no-undefined,-fsanitize=address) else() - target_link_libraries(rocprofiler_tool ${ROCPROFILER_TARGET} hsa-runtime64::hsa-runtime64 Threads::Threads atomic dl rt stdc++fs amd_comgr) + target_link_libraries(rocprofiler_tool rocprofiler-v2 hsa-runtime64::hsa-runtime64 Threads::Threads atomic dl rt stdc++fs amd_comgr) target_link_options(rocprofiler_tool PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exportmap -Wl,--no-undefined) endif() @@ -44,9 +43,8 @@ add_subdirectory(amdsys) add_subdirectory(rocprofv2) add_executable(ctrl ctrl.cpp) -target_include_directories(ctrl PRIVATE ${PROJECT_SOURCE_DIR}/inc) target_link_options(rocprofiler_tool PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exportmap -Wl,--no-undefined) -target_link_libraries(ctrl PRIVATE ${ROCPROFILER_TARGET} hsa-runtime64::hsa-runtime64) +target_link_libraries(ctrl PRIVATE rocprofiler-v2 hsa-runtime64::hsa-runtime64) install(TARGETS ctrl RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/rocprofiler COMPONENT runtime) diff --git a/projects/rocprofiler/src/tools/ctrl.cpp b/projects/rocprofiler/src/tools/ctrl.cpp index 3b58e206da..a9c133028e 100644 --- a/projects/rocprofiler/src/tools/ctrl.cpp +++ b/projects/rocprofiler/src/tools/ctrl.cpp @@ -1,5 +1,5 @@ #include -#include +#include "rocprofiler.h" #include diff --git a/projects/rocprofiler/src/tools/tool.cpp b/projects/rocprofiler/src/tools/tool.cpp index 3a53a05918..ff2a882b96 100644 --- a/projects/rocprofiler/src/tools/tool.cpp +++ b/projects/rocprofiler/src/tools/tool.cpp @@ -18,15 +18,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#define ROCPROFILER_V2 - #include #include #include #include -#include -#include -#include +#include "rocprofiler.h" +#include "rocprofiler_plugin.h" #include #include #include @@ -54,7 +51,6 @@ #include #include -#include "rocprofiler.h" #include "utils/helper.h" namespace fs = std::experimental::filesystem; @@ -415,7 +411,7 @@ ROCPROFILER_EXPORT extern const uint32_t HSA_AMD_TOOL_PRIORITY = 1025; The function updates the core api table function pointers to point to the interceptor functions in this file. */ -ROCPROFILER_EXPORT bool OnLoad(HsaApiTable* table, uint64_t runtime_version, +ROCPROFILER_EXPORT bool OnLoad(void* table, uint64_t runtime_version, uint64_t failed_tool_count, const char* const* failed_tool_names) { if (rocprofiler_version_major() != ROCPROFILER_VERSION_MAJOR || rocprofiler_version_minor() < ROCPROFILER_VERSION_MINOR) { diff --git a/projects/rocprofiler/src/utils/exception.h b/projects/rocprofiler/src/utils/exception.h index 14e105f900..df739eb83e 100644 --- a/projects/rocprofiler/src/utils/exception.h +++ b/projects/rocprofiler/src/utils/exception.h @@ -26,7 +26,7 @@ #include #include "helper.h" -#include "inc/rocprofiler.h" +#include "rocprofiler.h" // TODO(aelwazir): namespace rocmtool namespace rocmtools { diff --git a/projects/rocprofiler/test/CMakeLists.txt b/projects/rocprofiler/test/CMakeLists.txt index 625dcd7cf7..fd99d3fbcc 100644 --- a/projects/rocprofiler/test/CMakeLists.txt +++ b/projects/rocprofiler/test/CMakeLists.txt @@ -47,7 +47,7 @@ include_directories(${HSA_RUNTIME_INC_PATH}) ## C test add_executable ( "c_test" ${TEST_DIR}/app/c_test.c ) -target_include_directories ( "c_test" PRIVATE ${ROOT_DIR} $ ) +target_include_directories ( "c_test" PRIVATE ${ROOT_DIR} ${PROJECT_SOURCE_DIR}/include $ ) ## Util sources file( GLOB UTIL_SRC "${TEST_DIR}/util/*.cpp" ) @@ -93,22 +93,22 @@ add_custom_target( mytest ## Building standalone test executable add_executable ( ${ST_EXE_NAME} ${ST_TST_SRC} ${UTIL_SRC} ${KERN_SRC} ) -target_include_directories ( ${ST_EXE_NAME} PRIVATE ${TEST_DIR} ${ROOT_DIR} ) +target_include_directories ( ${ST_EXE_NAME} PRIVATE ${TEST_DIR} ${ROOT_DIR} ${PROJECT_SOURCE_DIR}/include ) target_link_libraries ( ${ST_EXE_NAME} ${ROCPROFILER_TARGET} hsa-runtime64::hsa-runtime64 hsakmt::hsakmt Threads::Threads dl ) ## Building standalone intercept test executable add_executable ( ${STIN_EXE_NAME} ${STIN_TST_SRC} ${UTIL_SRC} ${KERN_SRC} ) -target_include_directories ( ${STIN_EXE_NAME} PRIVATE ${TEST_DIR} ${ROOT_DIR} ) +target_include_directories ( ${STIN_EXE_NAME} PRIVATE ${TEST_DIR} ${ROOT_DIR} ${PROJECT_SOURCE_DIR}/include ) target_link_libraries ( ${STIN_EXE_NAME} ${ROCPROFILER_TARGET} hsa-runtime64::hsa-runtime64 hsakmt::hsakmt Threads::Threads dl ) ## Building intercept test executable add_library ( ${IN_EXE_NAME} SHARED ${IN_TST_SRC} ${UTIL_SRC} ${KERN_SRC} ) -target_include_directories ( ${IN_EXE_NAME} PRIVATE ${TEST_DIR} ${ROOT_DIR} ) +target_include_directories ( ${IN_EXE_NAME} PRIVATE ${TEST_DIR} ${ROOT_DIR} ${PROJECT_SOURCE_DIR}/include ) target_link_libraries ( ${IN_EXE_NAME} ${ROCPROFILER_TARGET} hsa-runtime64::hsa-runtime64 hsakmt::hsakmt Threads::Threads dl ) ## Building ctrl test executable add_executable ( ${EXE_NAME} ${CTRL_SRC} ${UTIL_SRC} ${KERN_SRC} ) -target_include_directories ( ${EXE_NAME} PRIVATE ${TEST_DIR} ${ROOT_DIR} ) +target_include_directories ( ${EXE_NAME} PRIVATE ${TEST_DIR} ${ROOT_DIR} ${PROJECT_SOURCE_DIR}/include ) target_link_libraries ( ${EXE_NAME} hsa-runtime64::hsa-runtime64 hsakmt::hsakmt Threads::Threads dl ) execute_process ( COMMAND sh -xc "cp ${TEST_DIR}/run.sh ${PROJECT_BINARY_DIR}" ) execute_process ( COMMAND sh -xc "cp ${TEST_DIR}/tool/*.xml ${PROJECT_BINARY_DIR}" ) @@ -118,7 +118,7 @@ execute_process ( COMMAND sh -xc "mkdir -p ${PROJECT_BINARY_DIR}/RESULTS" ) set ( TEST_LIB "rocprof-tool" ) set ( TEST_LIB_SRC ${TEST_DIR}/tool/tool.cpp ${UTIL_SRC} ) add_library ( ${TEST_LIB} SHARED ${TEST_LIB_SRC} ) -target_include_directories ( ${TEST_LIB} PRIVATE ${TEST_DIR} ${ROOT_DIR} ) +target_include_directories ( ${TEST_LIB} PRIVATE ${TEST_DIR} ${ROOT_DIR} ${PROJECT_SOURCE_DIR}/include ) target_link_libraries ( ${TEST_LIB} ${ROCPROFILER_TARGET} hsa-runtime64::hsa-runtime64 Threads::Threads dl ) ## Build memory test bench diff --git a/projects/rocprofiler/test/app/c_test.c b/projects/rocprofiler/test/app/c_test.c index 3d0b5d5370..ec0ba39f9f 100644 --- a/projects/rocprofiler/test/app/c_test.c +++ b/projects/rocprofiler/test/app/c_test.c @@ -19,7 +19,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *******************************************************************************/ -#define ROCPROFILER_V1 -#include "inc/rocprofiler.h" +#include "rocprofiler/rocprofiler.h" const int ret = 0; int main() { return ret; } diff --git a/projects/rocprofiler/test/app/intercept_test.cpp b/projects/rocprofiler/test/app/intercept_test.cpp index 9226b4af50..5ad9649987 100644 --- a/projects/rocprofiler/test/app/intercept_test.cpp +++ b/projects/rocprofiler/test/app/intercept_test.cpp @@ -30,7 +30,7 @@ THE SOFTWARE. #include #include -#include "inc/rocprofiler.h" +#include "rocprofiler/rocprofiler.h" #include "util/hsa_rsrc_factory.h" #define PUBLIC_API __attribute__((visibility("default"))) diff --git a/projects/rocprofiler/test/app/stand_intercept_test.cpp b/projects/rocprofiler/test/app/stand_intercept_test.cpp index 32d7e6ed43..0a4b92f469 100644 --- a/projects/rocprofiler/test/app/stand_intercept_test.cpp +++ b/projects/rocprofiler/test/app/stand_intercept_test.cpp @@ -30,7 +30,7 @@ THE SOFTWARE. #include "ctrl/run_kernel.h" #include "ctrl/test_aql.h" #include "ctrl/test_hsa.h" -#include "inc/rocprofiler.h" +#include "rocprofiler/rocprofiler.h" #include "dummy_kernel/dummy_kernel.h" #include "simple_convolution/simple_convolution.h" #include "util/test_assert.h" diff --git a/projects/rocprofiler/test/app/standalone_test.cpp b/projects/rocprofiler/test/app/standalone_test.cpp index 7986c2a34b..707430e257 100644 --- a/projects/rocprofiler/test/app/standalone_test.cpp +++ b/projects/rocprofiler/test/app/standalone_test.cpp @@ -28,7 +28,7 @@ THE SOFTWARE. #include "ctrl/run_kernel.h" #include "ctrl/test_aql.h" #include "ctrl/test_hsa.h" -#include "inc/rocprofiler.h" +#include "rocprofiler/rocprofiler.h" #include "dummy_kernel/dummy_kernel.h" #include "simple_convolution/simple_convolution.h" #include "util/hsa_rsrc_factory.h" diff --git a/projects/rocprofiler/test/tool/tool.cpp b/projects/rocprofiler/test/tool/tool.cpp index 5bd7412df6..1466f83a45 100644 --- a/projects/rocprofiler/test/tool/tool.cpp +++ b/projects/rocprofiler/test/tool/tool.cpp @@ -51,7 +51,7 @@ THE SOFTWARE. #include #include -#include "inc/rocprofiler.h" +#include "rocprofiler/rocprofiler.h" #include "util/hsa_rsrc_factory.h" #include "util/xml.h" @@ -1169,7 +1169,7 @@ extern "C" PUBLIC_API void OnLoadToolProp(rocprofiler_settings_t* settings) // Getting GPU indexes gpu_index_vec = new std::vector; get_xml_array(xml, "top.metric", "gpu_index", ",", gpu_index_vec, " "); - + // Skipping cpu count to get to correct gpu index const uint32_t cpu_count = HsaRsrcFactory::Instance().GetCountOfCpuAgents(); std::transform(gpu_index_vec->begin(), gpu_index_vec->end(), diff --git a/projects/rocprofiler/test/util/hsa_rsrc_factory.h b/projects/rocprofiler/test/util/hsa_rsrc_factory.h index cc5db82956..1c557c5f40 100644 --- a/projects/rocprofiler/test/util/hsa_rsrc_factory.h +++ b/projects/rocprofiler/test/util/hsa_rsrc_factory.h @@ -25,8 +25,6 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TEST_UTIL_HSA_RSRC_FACTORY_H_ #define TEST_UTIL_HSA_RSRC_FACTORY_H_ -// #define AMD_INTERNAL_BUILD - #include #include #include diff --git a/projects/rocprofiler/tests/featuretests/profiler/CMakeLists.txt b/projects/rocprofiler/tests/featuretests/profiler/CMakeLists.txt index 22d8e94961..6dd1d5e290 100644 --- a/projects/rocprofiler/tests/featuretests/profiler/CMakeLists.txt +++ b/projects/rocprofiler/tests/featuretests/profiler/CMakeLists.txt @@ -55,7 +55,6 @@ set_target_properties(hip_helloworld PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJ target_link_options(hip_helloworld PRIVATE "-Wl,--build-id=md5") install(TARGETS hip_helloworld RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/tests/featuretests/profiler/apps COMPONENT tests) - #hip_vectoradd set_source_files_properties(apps/vector_add_hip.cpp PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1) hip_add_executable(hip_vectoradd apps/vector_add_hip.cpp) @@ -149,9 +148,9 @@ endforeach(target_id) add_custom_target(hsaco_targets DEPENDS ${HSACO_TARGET_LIST}) add_executable(multiqueue_testapp apps/multiqueue_testapp.cpp) - target_include_directories(multiqueue_testapp PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/inc ${PROJECT_SOURCE_DIR}/tests/featuretests/profiler) + target_include_directories(multiqueue_testapp PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/tests/featuretests/profiler) # Link test executable against gtest & gtest_main - target_link_libraries(multiqueue_testapp PRIVATE ${ROCPROFILER_TARGET} hsa-runtime64::hsa-runtime64 GTest::gtest GTest::gtest_main stdc++fs Threads::Threads amd_comgr dl) + target_link_libraries(multiqueue_testapp PRIVATE rocprofiler-v2 hsa-runtime64::hsa-runtime64 GTest::gtest GTest::gtest_main stdc++fs Threads::Threads amd_comgr dl) add_dependencies(multiqueue_testapp hsaco_targets) add_dependencies(tests multiqueue_testapp ) set_target_properties(multiqueue_testapp PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/tests/featuretests/profiler/apps") @@ -179,7 +178,7 @@ target_include_directories(runFeatureTests PRIVATE ${TEST_DIR} ${PROJECT_SOURCE_DIR}/tests/featuretests/profiler) # Link test executable against gtest & gtest_main -target_link_libraries(runFeatureTests PRIVATE ${ROCPROFILER_TARGET} ${ROCPROFILER_TARGET} hsa-runtime64::hsa-runtime64 +target_link_libraries(runFeatureTests PRIVATE rocprofiler-v2 hsa-runtime64::hsa-runtime64 GTest::gtest GTest::gtest_main Threads::Threads dl stdc++fs amd_comgr) add_dependencies(tests runFeatureTests) diff --git a/projects/rocprofiler/tests/featuretests/profiler/profiler_gtest.cpp b/projects/rocprofiler/tests/featuretests/profiler/profiler_gtest.cpp index ee91aee107..8a033c8d82 100644 --- a/projects/rocprofiler/tests/featuretests/profiler/profiler_gtest.cpp +++ b/projects/rocprofiler/tests/featuretests/profiler/profiler_gtest.cpp @@ -25,7 +25,7 @@ THE SOFTWARE. #include #include #include -#include +#include "rocprofiler.h" #include #include #include diff --git a/projects/rocprofiler/tests/featuretests/tracer/apps/goldentraces/hip_helloworld_golden_traces.txt b/projects/rocprofiler/tests/featuretests/tracer/apps/goldentraces/hip_helloworld_golden_traces.txt index c92d6ba2c3..5568e4b13f 100755 --- a/projects/rocprofiler/tests/featuretests/tracer/apps/goldentraces/hip_helloworld_golden_traces.txt +++ b/projects/rocprofiler/tests/featuretests/tracer/apps/goldentraces/hip_helloworld_golden_traces.txt @@ -2,23 +2,23 @@ 0x2fcc70 agent gpu 9598333364898937 Enabling API Tracing -Record(1), Domain(HIP_API_DOMAIN), Function(hipGetDeviceProperties), Begin(2159039058113892), Correlation_ID(1) -Record(2), Domain(HIP_API_DOMAIN), Function(hipGetDeviceProperties), End(2159039058121252), Correlation_ID(1) -Record(4), Domain(HIP_API_DOMAIN), Function(hipMalloc), Begin(2159039058128392), Correlation_ID(2) -Record(5), Domain(HIP_API_DOMAIN), Function(hipMalloc), End(2159039058176762), Correlation_ID(2) -Record(7), Domain(HIP_API_DOMAIN), Function(hipMalloc), Begin(2159039058180502), Correlation_ID(3) -Record(8), Domain(HIP_API_DOMAIN), Function(hipMalloc), End(2159039058189602), Correlation_ID(3) -Record(10), Domain(HIP_API_DOMAIN), Function(hipMemcpy), Begin(2159039058196672), Correlation_ID(4) -Record(11), Domain(HIP_API_DOMAIN), Function(hipMemcpy), End(2159039277693090), Correlation_ID(4) -Record(13), Domain(HIP_API_DOMAIN), Function(__hipPushCallConfiguration), Begin(2159039277704830), Correlation_ID(5) -Record(14), Domain(HIP_API_DOMAIN), Function(__hipPushCallConfiguration), End(2159039277707780), Correlation_ID(5) -Record(16), Domain(HIP_API_DOMAIN), Function(__hipPopCallConfiguration), Begin(2159039277711180), Correlation_ID(6) -Record(17), Domain(HIP_API_DOMAIN), Function(__hipPopCallConfiguration), End(2159039277713880), Correlation_ID(6) -Record(19), Domain(HIP_API_DOMAIN), Function(hipLaunchKernel), Kernel_Name(helloworld(char*, char*)), Begin(2159039277746730), Correlation_ID(7) -Record(20), Domain(HIP_API_DOMAIN), Function(hipLaunchKernel), Kernel_Name(helloworld(char*, char*)), End(2159039278037481), Correlation_ID(7) -Record(22), Domain(HIP_API_DOMAIN), Function(hipMemcpy), Begin(2159039278045081), Correlation_ID(8) -Record(23), Domain(HIP_API_DOMAIN), Function(hipMemcpy), End(2159039278471722), Correlation_ID(8) -Record(25), Domain(HIP_API_DOMAIN), Function(hipFree), Begin(2159039278478022), Correlation_ID(9) -Record(26), Domain(HIP_API_DOMAIN), Function(hipFree), End(2159039278489413), Correlation_ID(9) -Record(28), Domain(HIP_API_DOMAIN), Function(hipFree), Begin(2159039278493343), Correlation_ID(10) -Record(29), Domain(HIP_API_DOMAIN), Function(hipFree), End(2159039278497233), Correlation_ID(10) +Record(1), Domain(HIP_API_DOMAIN), Function(hipGetDeviceProperties), Begin(2995593944218577), Correlation_ID(1) +Record(2), Domain(HIP_API_DOMAIN), Function(hipGetDeviceProperties), End(2995593944228886), Correlation_ID(1) +Record(4), Domain(HIP_API_DOMAIN), Function(hipMalloc), Begin(2995593944238565), Correlation_ID(2) +Record(5), Domain(HIP_API_DOMAIN), Function(hipMalloc), End(2995593944266920), Correlation_ID(2) +Record(7), Domain(HIP_API_DOMAIN), Function(hipMalloc), Begin(2995593944271769), Correlation_ID(3) +Record(8), Domain(HIP_API_DOMAIN), Function(hipMalloc), End(2995593944277100), Correlation_ID(3) +Record(10), Domain(HIP_API_DOMAIN), Function(hipMemcpy), Begin(2995593944284394), Correlation_ID(4) +Record(11), Domain(HIP_API_DOMAIN), Function(hipMemcpy), End(2995594191690241), Correlation_ID(4) +Record(13), Domain(HIP_API_DOMAIN), Function(__hipPushCallConfiguration), Begin(2995594191704198), Correlation_ID(5) +Record(14), Domain(HIP_API_DOMAIN), Function(__hipPushCallConfiguration), End(2995594191707104), Correlation_ID(5) +Record(16), Domain(HIP_API_DOMAIN), Function(__hipPopCallConfiguration), Begin(2995594191710731), Correlation_ID(6) +Record(17), Domain(HIP_API_DOMAIN), Function(__hipPopCallConfiguration), End(2995594191713486), Correlation_ID(6) +Record(19), Domain(HIP_API_DOMAIN), Function(hipLaunchKernel), Kernel_Name(helloworld(char*, char*)), Begin(2995594191738064), Correlation_ID(7) +Record(21), Domain(HIP_API_DOMAIN), Function(hipLaunchKernel), Kernel_Name(helloworld(char*, char*)), End(2995594192197542), Correlation_ID(7) +Record(23), Domain(HIP_API_DOMAIN), Function(hipMemcpy), Begin(2995594192204856), Correlation_ID(8) +Record(24), Domain(HIP_API_DOMAIN), Function(hipMemcpy), End(2995594192228011), Correlation_ID(8) +Record(26), Domain(HIP_API_DOMAIN), Function(hipFree), Begin(2995594192237078), Correlation_ID(9) +Record(27), Domain(HIP_API_DOMAIN), Function(hipFree), End(2995594192256085), Correlation_ID(9) +Record(29), Domain(HIP_API_DOMAIN), Function(hipFree), Begin(2995594192259622), Correlation_ID(10) +Record(30), Domain(HIP_API_DOMAIN), Function(hipFree), End(2995594192264101), Correlation_ID(10)