Files
rocm-systems/source/include/rocprofiler-sdk/counters.h
T
Welton, Benjamin 4cd121e27b [SDK] Release 1.0 Public API Modifications (#277)
* Make sure all structs/enums can be forward declared

* Updates to counter collection

- consistency updates and cleanup

* Conversion of dimension information to info struct

* Added deprecated folder

* Testing changes

* merge changes

* Fix shadowed variable

* Source code formatting

* Fix shadowed variable

* Update rocprofiler_counter_info_v1_t member names

* Split version.h into version.h and ext_version.h

- ext_version.h contains external version info, e.g. ROCPROFILER_HSA_API_TABLE_MAJOR_VERSION, ROCPROFILER_HSA_RUNTIME_VERSION
- this reduces amount of recompilation after a commit since version.h gets updated with the git revision

* profile_config -> counter_config

* EOF new line

* [Samples] Reduce header includes + reorg counter collection samples

* Misc compilation fixes

- shadowed variables
- use of [[deprecated("...")]] in C code
- unused variables

* Minor misc modifications

- use common:: instead of rocprofiler::common:: when inside rocprofiler namespace
- counters.cpp
  - move local anon namespace functions into rocprofiler::counters:: anon namespace
  - use std::string_view for get_static_string
  - const ref for get_static_ptr
  - misc namespace shortening

* [Public API] rocprofiler_get_version_triplet + rocprofiler_version_triplet_t

- struct rocprofiler_version_triplet_t containing fields for the major, minor, and patch version
- public API function: rocprofiler_get_version_triplet
- define C++ operators for rocprofiler_version_triplet_t
- C++ function compute_version_triplet

* [Tests] Improve async-copy-testing test

- relax constraints
- improve logging

* Update counter_config.h doxygen docs

* ROCPROFILER_SDK_BETA_COMPAT

- ppdef which helps with renaming when set to 1

* Remove spurious include

* Fix includes for cxx/version.hpp

* Doxygen fixes for rocprofiler_get_version and rocprofiler_get_version_triplet

* Public API Experimental Designation

- ROCPROFILER_SDK_EXPERIMENTAL added to experimental function
- "(experimental)" added to doxygen @brief entries

* Fix use of assert instead of static_assert in hip/stream.cpp

* Use typedef instead of define for rocprofiler_profile_config_id_t

* Use inline rocprofiler_{create,destroy}_profile_config instead of ppdef

- added <rocprofiler-sdk/deprecated/profile_config.h>

* Doxygen for rocprofiler_{create,destroy}_profile_config

* ROCPROFILER_SDK_DEPRECATED_WARNINGS

* Temporarily comment out ROCPROFILER_SDK_DEPRECATED_WARNINGS=1

* cmake formatting

* Misc variable renaming in samples and tests

* Fix declarations of types

* Fix hip stream tracing service struct name

- rocprofiler_callback_tracing_stream_handle_data_t renamed to rocprofiler_callback_tracing_hip_stream_api_data_t

* Rename "HIP_STREAM_API" to "HIP_STREAM"

---------

Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>
Co-authored-by: Benjamin Welton <bewelton@amd.com>
2025-03-24 12:07:33 +05:30

198 wiersze
9.3 KiB
C

// MIT License
//
// Copyright (c) 2023-2025 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.
#pragma once
#include <rocprofiler-sdk/agent.h>
#include <rocprofiler-sdk/defines.h>
#include <rocprofiler-sdk/fwd.h>
#include <rocprofiler-sdk/deprecated/counters.h>
ROCPROFILER_EXTERN_C_INIT
/**
* @defgroup COUNTERS Hardware counters Information
* @brief Query functions related to hardware counters
* @{
*/
/**
* @brief (experimental) Counter info struct version 0
*/
typedef struct ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_counter_info_v0_t
{
rocprofiler_counter_id_t id; ///< Id of this counter
const char* name; ///< Name of the counter
const char* description; ///< Description of the counter
const char* block; ///< Block of the counter (non-derived only)
const char* expression; ///< Counter expression (derived counters only)
uint8_t is_constant : 1; ///< If this counter is HW constant
uint8_t is_derived : 1; ///< If this counter is a derived counter
} rocprofiler_counter_info_v0_t;
/**
* @brief (experimental) Counter info struct version 1. Combines information from
* ::rocprofiler_counter_info_v0_t with the dimension information.
*/
typedef struct ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_counter_info_v1_t
{
rocprofiler_counter_id_t id; ///< Id of this counter
const char* name; ///< Name of the counter
const char* description; ///< Description of the counter
const char* block; ///< Block of the counter (non-derived only)
const char* expression; ///< Counter expression (derived counters only)
uint8_t is_constant : 1; ///< If this counter is HW constant
uint8_t is_derived : 1; ///< If this counter is a derived counter
uint64_t dimensions_count;
const rocprofiler_counter_record_dimension_info_t* dimensions;
uint64_t instance_ids_count;
const rocprofiler_counter_instance_id_t* instance_ids;
/// @var dimensions_count
/// @brief Number of dimensions for the counter
///
/// @var dimensions
/// @brief Dimension information of the counter
///
/// @var instance_ids_count
/// @brief Number of instance ids for the counter
///
/// @var instance_ids
/// @brief Instance ids that can be generated by the counter
} rocprofiler_counter_info_v1_t;
/**
* @brief (experimental) Query counter id information from record_id.
*
* @param [in] id record id from rocprofiler_record_counter_t
* @param [out] counter_id counter id associated with the record
* @return ::rocprofiler_status_t
* @retval ROCPROFILER_STATUS_SUCCESS if id decoded
*/
ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_status_t
rocprofiler_query_record_counter_id(rocprofiler_counter_instance_id_t id,
rocprofiler_counter_id_t* counter_id) ROCPROFILER_API
ROCPROFILER_NONNULL(2);
/**
* @brief (experimental) Query dimension position from record_id. If the dimension does not exist
* in the counter, the return will be 0.
*
* @param [in] id record id from @ref rocprofiler_record_counter_t
* @param [in] dim dimension for which positional info is requested (currently only
* 0 is allowed, i.e. flat array without dimension).
* @param [out] pos value of the dimension in id
* @return ::rocprofiler_status_t
* @retval ROCPROFILER_STATUS_SUCCESS if dimension decoded
*/
ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_status_t
rocprofiler_query_record_dimension_position(rocprofiler_counter_instance_id_t id,
rocprofiler_counter_dimension_id_t dim,
size_t* pos) ROCPROFILER_API ROCPROFILER_NONNULL(3);
/**
* @brief (experimental) Query Counter info such as name or description.
*
* @param [in] counter_id counter to get info for
* @param [in] version Version of struct in info, see @ref rocprofiler_counter_info_version_id_t for
* available types
* @param [out] info rocprofiler_counter_info_{version}_t struct to write info to.
* @return ::rocprofiler_status_t
* @retval ROCPROFILER_STATUS_SUCCESS if counter found
* @retval ROCPROFILER_STATUS_ERROR_COUNTER_NOT_FOUND if counter not found
* @retval ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_ABI Version is not supported
*/
ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_status_t
rocprofiler_query_counter_info(rocprofiler_counter_id_t counter_id,
rocprofiler_counter_info_version_id_t version,
void* info) ROCPROFILER_API ROCPROFILER_NONNULL(3);
/**
* @brief (experimental) Callback that gives a list of counters available on an agent. The
* counters variable is owned by rocprofiler and should not be free'd.
*
* @param [in] agent_id Agent ID of the current callback
* @param [in] counters An array of counters that are avialable on the agent
* @ref rocprofiler_iterate_agent_supported_counters was called on.
* @param [in] num_counters Number of counters contained in counters
* @param [in] user_data User data supplied by
* @ref rocprofiler_iterate_agent_supported_counters
*/
ROCPROFILER_SDK_EXPERIMENTAL typedef rocprofiler_status_t (*rocprofiler_available_counters_cb_t)(
rocprofiler_agent_id_t agent_id,
rocprofiler_counter_id_t* counters,
size_t num_counters,
void* user_data);
/**
* @brief (experimental) Query Agent Counters Availability.
*
* @param [in] agent_id GPU agent identifier
* @param [in] cb callback to caller to get counters
* @param [in] user_data data to pass into the callback
* @return ::rocprofiler_status_t
* @retval ROCPROFILER_STATUS_SUCCESS if counters found for agent
* @retval ROCPROFILER_STATUS_ERROR if no counters found for agent
*/
ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_status_t
rocprofiler_iterate_agent_supported_counters(rocprofiler_agent_id_t agent_id,
rocprofiler_available_counters_cb_t cb,
void* user_data) ROCPROFILER_API
ROCPROFILER_NONNULL(2);
/**
* @brief (experimental) Creates a new counter based on a derived metric provided. The counter will
* only be available for counter collection profiles created after the addition of this counter. Due
* to the regeneration of internal ASTs and dimension cache, this call may be slow and should
* generally be avoided in performance sensitive code blocks (i.e. dispatch callbacks).
*
* @param [in] name The name of the new counter.
* @param [in] name_len The length of the counter name.
* @param [in] expr The counter expression, formatted identically to YAML counter definitions.
* @param [in] expr_len The length of the expression.
* @param [in] agent The rocprofiler_agent_id_t specifying the agent for which to create the
* counter.
* @param [in] description The description of the new counter (optional).
* @param [in] description_len The length of the description.
* @param [out] counter_id The rocprofiler_counter_id_t of the created counter.
* @return ::rocprofiler_status_t
* @retval ROCPROFILER_STATUS_SUCCESS if the counter was successfully created.
* @retval ROCPROFILER_STATUS_ERROR_AST_GENERATION_FAILED if the counter could not be created.
* @retval ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT if a counter argument is incorrect
* @retval ROCPROFILER_STATUS_ERROR_AGENT_NOT_FOUND if the agent is not found
*/
ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_status_t
rocprofiler_create_counter(const char* name,
size_t name_len,
const char* expr,
size_t expr_len,
const char* description,
size_t description_len,
rocprofiler_agent_id_t agent,
rocprofiler_counter_id_t* counter_id) ROCPROFILER_NONNULL(1, 3, 8);
/** @} */
ROCPROFILER_EXTERN_C_FINI