2022-12-13 14:37:59 -06:00
|
|
|
/*
|
|
|
|
|
Copyright (c) 2022 - present 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef RDC_MODULES_RDC_ROCP_RDCROCPBASE_H_
|
|
|
|
|
#define RDC_MODULES_RDC_ROCP_RDCROCPBASE_H_
|
2024-12-13 16:50:32 -06:00
|
|
|
#include <rocprofiler-sdk/agent.h>
|
2023-12-04 15:24:34 -06:00
|
|
|
|
2022-12-13 14:37:59 -06:00
|
|
|
#include <cstdint>
|
|
|
|
|
#include <map>
|
2024-06-04 19:37:42 -05:00
|
|
|
#include <unordered_set>
|
2024-06-10 15:10:06 -05:00
|
|
|
#include <utility>
|
2024-02-22 02:40:58 -06:00
|
|
|
#include <vector>
|
2023-12-04 15:24:34 -06:00
|
|
|
|
2022-12-13 14:37:59 -06:00
|
|
|
#include "rdc/rdc.h"
|
2024-06-10 15:10:06 -05:00
|
|
|
#include "rdc_lib/RdcTelemetryLibInterface.h"
|
2024-12-13 16:50:32 -06:00
|
|
|
#include "rdc_modules/rdc_rocp/RdcRocpCounterSampler.h"
|
2022-12-13 14:37:59 -06:00
|
|
|
|
|
|
|
|
namespace amd {
|
|
|
|
|
namespace rdc {
|
|
|
|
|
|
|
|
|
|
/// Common interface for RocP tests and samples
|
|
|
|
|
class RdcRocpBase {
|
|
|
|
|
public:
|
2023-12-04 15:24:34 -06:00
|
|
|
RdcRocpBase();
|
|
|
|
|
RdcRocpBase(const RdcRocpBase&) = default;
|
|
|
|
|
RdcRocpBase(RdcRocpBase&&) = delete;
|
|
|
|
|
RdcRocpBase& operator=(const RdcRocpBase&) = delete;
|
|
|
|
|
RdcRocpBase& operator=(RdcRocpBase&&) = delete;
|
|
|
|
|
~RdcRocpBase();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Lookup ROCProfiler counter
|
|
|
|
|
*
|
2024-06-10 15:10:06 -05:00
|
|
|
* @param[in] gpu_field GPU_ID and FIELD_ID of requested metric
|
2023-12-04 15:24:34 -06:00
|
|
|
* @param[out] value A pointer that will be populated with returned value
|
|
|
|
|
*
|
|
|
|
|
* @retval ::ROCMTOOLS_STATUS_SUCCESS The function has been executed
|
|
|
|
|
* successfully.
|
|
|
|
|
*/
|
2025-04-16 21:00:19 +00:00
|
|
|
rdc_status_t rocp_lookup(rdc_gpu_field_t gpu_field, rdc_field_value_data* value,
|
|
|
|
|
rdc_field_type_t* type);
|
2025-12-17 05:56:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Bulk lookup of multiple ROCProfiler counters for a single GPU
|
|
|
|
|
*
|
|
|
|
|
* @param[in] fields Vector of fields to lookup (all for the same GPU)
|
|
|
|
|
* @param[out] values Vector to be populated with returned values
|
|
|
|
|
* @param[out] types Vector to be populated with returned types
|
|
|
|
|
* @param[out] statuses Vector to be populated with status for each field
|
|
|
|
|
*
|
|
|
|
|
* @retval ::RDC_ST_OK The function has been executed successfully.
|
|
|
|
|
*/
|
|
|
|
|
rdc_status_t rocp_lookup_bulk(const std::vector<rdc_gpu_field_t>& fields,
|
|
|
|
|
std::vector<rdc_field_value_data>& values,
|
|
|
|
|
std::vector<rdc_field_type_t>& types,
|
|
|
|
|
std::vector<rdc_status_t>& statuses);
|
|
|
|
|
|
2024-05-09 14:40:53 -05:00
|
|
|
const char* get_field_id_from_name(rdc_field_t);
|
|
|
|
|
const std::vector<rdc_field_t> get_field_ids();
|
2023-12-04 15:24:34 -06:00
|
|
|
|
2022-12-13 14:37:59 -06:00
|
|
|
protected:
|
|
|
|
|
private:
|
2024-06-10 15:10:06 -05:00
|
|
|
typedef std::pair<uint32_t, rdc_field_t> rdc_field_pair_t;
|
|
|
|
|
/**
|
|
|
|
|
* @brief Tweak this to change for how long each metric is collected
|
|
|
|
|
*/
|
|
|
|
|
static const uint32_t collection_duration_us_k = 10000;
|
|
|
|
|
|
2025-04-16 21:00:19 +00:00
|
|
|
/**
|
|
|
|
|
* @brief By default all profiler values are read as doubles
|
|
|
|
|
*/
|
2025-05-21 18:40:15 -05:00
|
|
|
double run_profiler(uint32_t agent_index, rdc_field_t field);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description Create a map from entity_id to profiler agent_index.
|
|
|
|
|
* This is required due to different structure and ordering.
|
|
|
|
|
* Populates entity_to_prof_map.
|
|
|
|
|
*/
|
|
|
|
|
rdc_status_t map_entity_to_profiler();
|
2024-06-10 15:10:06 -05:00
|
|
|
|
2025-07-07 15:41:22 -05:00
|
|
|
void init_rocp_if_not();
|
|
|
|
|
|
2024-12-13 16:50:32 -06:00
|
|
|
std::vector<rocprofiler_agent_v0_t> agents = {};
|
|
|
|
|
std::vector<std::shared_ptr<CounterSampler>> samplers = {};
|
2024-05-22 01:53:34 -05:00
|
|
|
std::map<rdc_field_t, const char*> field_to_metric = {};
|
2025-05-21 18:40:15 -05:00
|
|
|
std::map<uint32_t, uint32_t> entity_to_prof_map = {};
|
2024-06-10 15:10:06 -05:00
|
|
|
|
2025-07-07 15:41:22 -05:00
|
|
|
bool m_is_initialized = false;
|
|
|
|
|
|
2024-06-04 19:37:42 -05:00
|
|
|
// these fields must be divided by time passed
|
|
|
|
|
std::unordered_set<rdc_field_t> eval_fields = {
|
2025-04-09 05:08:36 +00:00
|
|
|
RDC_FI_PROF_EVAL_MEM_R_BW, RDC_FI_PROF_EVAL_MEM_W_BW,
|
|
|
|
|
RDC_FI_PROF_EVAL_FLOPS_16, RDC_FI_PROF_EVAL_FLOPS_32,
|
|
|
|
|
RDC_FI_PROF_EVAL_FLOPS_64, RDC_FI_PROF_EVAL_FLOPS_16_PERCENT,
|
|
|
|
|
RDC_FI_PROF_EVAL_FLOPS_32_PERCENT, RDC_FI_PROF_EVAL_FLOPS_64_PERCENT,
|
2024-06-04 19:37:42 -05:00
|
|
|
};
|
2022-12-13 14:37:59 -06:00
|
|
|
|
2025-12-17 05:56:33 -08:00
|
|
|
/**
|
|
|
|
|
* @brief Apply field-specific transformations to raw profiler values
|
|
|
|
|
*
|
|
|
|
|
* @param[in] field Field ID to transform
|
|
|
|
|
* @param[in] agent_index Index of the agent/GPU
|
|
|
|
|
* @param[in] raw_value Raw value from profiler
|
|
|
|
|
* @param[in] elapsed_time_ms Elapsed time in milliseconds (for eval fields)
|
|
|
|
|
* @param[in] sampled_values Map of all sampled values (for fields needing multiple metrics)
|
|
|
|
|
* @param[out] output Transformed output value
|
|
|
|
|
* @param[out] type Output type
|
|
|
|
|
*
|
|
|
|
|
* @retval ::RDC_ST_OK Transformation successful
|
|
|
|
|
*/
|
|
|
|
|
rdc_status_t apply_field_transformation(rdc_field_t field, uint32_t agent_index,
|
|
|
|
|
double raw_value, double elapsed_time_ms,
|
|
|
|
|
const std::map<std::string, double>& sampled_values,
|
|
|
|
|
rdc_field_value_data* output,
|
|
|
|
|
rdc_field_type_t* type);
|
|
|
|
|
|
2023-12-04 15:24:34 -06:00
|
|
|
/**
|
2024-12-13 16:50:32 -06:00
|
|
|
* @brief Convert from profiler status into RDC status
|
2023-12-04 15:24:34 -06:00
|
|
|
*/
|
2024-12-13 16:50:32 -06:00
|
|
|
rdc_status_t Rocp2RdcError(rocprofiler_status_t status);
|
2022-12-13 14:37:59 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace rdc
|
|
|
|
|
} // namespace amd
|
|
|
|
|
|
|
|
|
|
#endif // RDC_MODULES_RDC_ROCP_RDCROCPBASE_H_
|