Add 'projects/rdc/' from commit '5ae7eeb3550d4cb14cbc31d3022e545b054f1ad1'

git-subtree-dir: projects/rdc
git-subtree-mainline: a68afa42a1
git-subtree-split: 5ae7eeb355
This commit is contained in:
systems-assistant[bot]
2025-07-22 22:52:37 +00:00
393 changed files with 49849 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+66
View File
@@ -0,0 +1,66 @@
#ifndef INCLUDE_RDC_RDC_PRIVATE_H_
#define INCLUDE_RDC_RDC_PRIVATE_H_
#include "rdc/rdc.h"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
#ifdef __cplusplus
// cstddef include causes issues on older GCC
// use stddef.h instead
#if __GNUC__ < 9
#include <stddef.h>
#else
#include <cstddef>
#endif // __GNUC__
#include <cstdint>
#else
#include <stddef.h>
#include <stdint.h>
#endif // __cplusplus
/**
* @brief The maximum string length occupied by version information.
*/
#define USR_MAX_VERSION_STR_LENGTH 60
/**
* @brief Version information of mixed components
*/
typedef struct {
char version[USR_MAX_VERSION_STR_LENGTH];
} mixed_component_version_t;
/**
* @brief Type of Components
*/
typedef enum {
RDCD_COMPONENT
//If needed later, add them one by one
} mixed_component_t;
/**
* @brief Get ersion information of mixed components.
*
* @details Given a component type, return its version information.
*
* @param[in] p_rdc_handle The RDC handler.
*
* @param[in] component Component type.
*
* @param[out] p_mixed_compv Version information of the corresponding component.
*
* @retval ::RDC_ST_OK is returned upon successful call.
*/
rdc_status_t get_mixed_component_version(rdc_handle_t p_rdc_handle, mixed_component_t component, mixed_component_version_t* p_mixed_compv);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // INCLUDE_RDC_RDC_PRIVATE_H_
@@ -0,0 +1,85 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_RDCCACHEMANAGER_H_
#define INCLUDE_RDC_LIB_RDCCACHEMANAGER_H_
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "rdc/rdc.h"
#include "rdc_lib/rdc_common.h"
namespace amd {
namespace rdc {
class RdcCacheManager {
public:
virtual rdc_status_t rdc_field_get_latest_value(uint32_t gpu_index, rdc_field_t field,
rdc_field_value* value) = 0;
virtual rdc_status_t rdc_field_get_value_since(uint32_t gpu_index, rdc_field_t field,
uint64_t since_time_stamp,
uint64_t* next_since_time_stamp,
rdc_field_value* value) = 0;
virtual rdc_status_t rdc_update_cache(uint32_t gpu_index, const rdc_field_value& value) = 0;
virtual rdc_status_t evict_cache(uint32_t gpu_index, rdc_field_t field_id,
uint64_t max_keep_samples, double max_keep_age) = 0;
virtual std::string get_cache_stats() = 0;
virtual rdc_status_t rdc_job_get_stats(const char job_id[64], const rdc_gpu_gauges_t& gpu_gauges,
rdc_job_info_t* p_job_info) = 0;
virtual rdc_status_t rdc_job_start_stats(const char job_id[64], const rdc_group_info_t& group,
const rdc_field_group_info_t& finfo,
const rdc_gpu_gauges_t& gpu_gauges) = 0;
virtual rdc_status_t rdc_job_stop_stats(const char job_id[64],
const rdc_gpu_gauges_t& gpu_gauge) = 0;
virtual rdc_status_t rdc_update_job_stats(uint32_t gpu_index, const std::string& job_id,
const rdc_field_value& value) = 0;
virtual rdc_status_t rdc_job_remove(const char job_id[64]) = 0;
virtual rdc_status_t rdc_job_remove_all() = 0;
virtual rdc_status_t rdc_health_set(rdc_gpu_group_t group_id,
uint32_t gpu_index,
const rdc_field_value& value) = 0;
virtual rdc_status_t rdc_health_get_values(rdc_gpu_group_t group_id,
uint32_t gpu_index,
rdc_field_t field_id,
uint64_t start_timestamp,
uint64_t end_timestamp,
rdc_field_value* start_value,
rdc_field_value* end_value) = 0;
virtual rdc_status_t rdc_health_clear(rdc_gpu_group_t group_id) = 0;
virtual rdc_status_t rdc_update_health_stats(rdc_gpu_group_t group_id,
uint32_t gpu_index,
const rdc_field_value& value) = 0;
virtual ~RdcCacheManager() {}
};
typedef std::shared_ptr<RdcCacheManager> RdcCacheManagerPtr;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_RDCCACHEMANAGER_H_
@@ -0,0 +1,50 @@
/*
Copyright (c) 2024 - 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 INCLUDE_RDC_LIB_RDCCONFIGSETTINGS_H_
#define INCLUDE_RDC_LIB_RDCCONFIGSETTINGS_H_
#include <memory.h>
#include "rdc/rdc.h"
namespace amd {
namespace rdc {
class RdcConfigSettings {
public:
// Set one configure
virtual rdc_status_t rdc_config_set(rdc_gpu_group_t group_id, rdc_config_setting_t setting) = 0;
// Get the setting
virtual rdc_status_t rdc_config_get(rdc_gpu_group_t group_id,
rdc_config_setting_list_t* settings) = 0;
// Clear the setting
virtual rdc_status_t rdc_config_clear(rdc_gpu_group_t group_id) = 0;
virtual ~RdcConfigSettings() {}
};
typedef std::shared_ptr<RdcConfigSettings> RdcConfigSettingsPtr;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_RDCCONFIGSETTINGS_H_
@@ -0,0 +1,59 @@
/*
Copyright (c) 2021 - 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 INCLUDE_RDC_LIB_RDCDIAGNOSTIC_H_
#define INCLUDE_RDC_LIB_RDCDIAGNOSTIC_H_
#include <memory>
#include "rdc/rdc.h"
namespace amd {
namespace rdc {
class RdcDiagnostic {
public:
// get support test cases
virtual rdc_status_t rdc_diag_test_cases_query(rdc_diag_test_cases_t test_cases[MAX_TEST_CASES],
uint32_t* test_case_count) = 0;
// Run a specific test case
virtual rdc_status_t rdc_test_case_run(rdc_diag_test_cases_t test_case,
uint32_t gpu_index[RDC_MAX_NUM_DEVICES],
uint32_t gpu_count, const char* config, size_t config_size,
rdc_diag_test_result_t* result, rdc_diag_callback_t* callback) = 0;
// Run multiple test cases
virtual rdc_status_t rdc_diagnostic_run(const rdc_group_info_t& gpus, rdc_diag_level_t level,
const char* config, size_t config_size,
rdc_diag_response_t* response, rdc_diag_callback_t* callback) = 0;
virtual rdc_status_t rdc_diag_init(uint64_t flags) = 0;
virtual rdc_status_t rdc_diag_destroy() = 0;
virtual ~RdcDiagnostic() {}
};
typedef std::shared_ptr<RdcDiagnostic> RdcDiagnosticPtr;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_RDCDIAGNOSTIC_H_
@@ -0,0 +1,48 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_RDCDIAGNOSTICLIBINTERFACE_H_
#define INCLUDE_RDC_LIB_RDCDIAGNOSTICLIBINTERFACE_H_
// The telemetry interface for libraries, for example, AMD-SMI.
#include <rdc/rdc.h>
extern "C" {
// The library will implement below function
// Which test cases are supported in the library
rdc_status_t rdc_diag_test_cases_query(rdc_diag_test_cases_t test_cases[MAX_TEST_CASES],
uint32_t* test_case_count);
// Run a specific test case
rdc_status_t rdc_diag_test_case_run(rdc_diag_test_cases_t test_case,
uint32_t gpu_index[RDC_MAX_NUM_DEVICES], uint32_t gpu_count,
const char* config, size_t config_size,
rdc_diag_test_result_t* result, rdc_diag_callback_t* callback);
rdc_status_t rdc_diag_init(uint64_t flags);
rdc_status_t rdc_diag_destroy();
}
#endif // INCLUDE_RDC_LIB_RDCDIAGNOSTICLIBINTERFACE_H_
@@ -0,0 +1,54 @@
/*
Copyright (c) 2025 - 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 INCLUDE_RDC_LIB_RDCENTITYCODEC_H_
#define INCLUDE_RDC_LIB_RDCENTITYCODEC_H_
#include "rdc/rdc.h"
/*
*
* See rdc.h for description of entity_index
* Shifts and masks help get only the bits in question to decode/encode
*
* Ex, RDC_ENTITY_TYPE_SHIFT = 29 helps shift the 29 irrelevant bits, so we're
* only left with the top 3 type bits.
* Then, the corresponding 3 type bits are anded with the RDC_ENTITY_TYPE_MASK = 0x7
* which = 111 in binary, "copying" the type bits.
*
*
*/
static constexpr uint32_t RDC_ENTITY_TYPE_SHIFT = 29;
static constexpr uint32_t RDC_ENTITY_ROLE_SHIFT = 27;
static constexpr uint32_t RDC_ENTITY_INSTANCE_SHIFT = 11;
static constexpr uint32_t RDC_ENTITY_DEVICE_SHIFT = 0;
static constexpr uint32_t RDC_ENTITY_TYPE_MASK = 0x7; // 3 bits for type.
static constexpr uint32_t RDC_ENTITY_ROLE_MASK = 0x3; // 2 bits for role.
static constexpr uint32_t RDC_ENTITY_INSTANCE_MASK = 0x3FF; // 10 bits for instance.
static constexpr uint32_t RDC_ENTITY_DEVICE_MASK = 0x3FF; // 10 bits for device.
rdc_entity_info_t rdc_get_info_from_entity_index(uint32_t entity_index);
uint32_t rdc_get_entity_index_from_info(rdc_entity_info_t info);
bool rdc_is_partition_string(const char* s);
bool rdc_parse_partition_string(const char* s, uint32_t* physicalGpu, uint32_t* partition);
#endif // INCLUDE_RDC_LIB_RDCENTITYCODEC_H_
@@ -0,0 +1,49 @@
/*
Copyright (c) 2019 - 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 INCLUDE_RDC_LIB_RDCEXCEPTION_H_
#define INCLUDE_RDC_LIB_RDCEXCEPTION_H_
#include <exception>
#include <string>
#include "rdc/rdc.h"
namespace amd {
namespace rdc {
class RdcException : public std::exception {
public:
RdcException(rdc_status_t error, const std::string description)
: err_(error), desc_(description) {}
rdc_status_t error_code() const noexcept { return err_; }
const char* what() const noexcept override { return desc_.c_str(); }
private:
rdc_status_t err_;
std::string desc_;
};
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_RDCEXCEPTION_H_
@@ -0,0 +1,61 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_RDCGROUPSETTINGS_H_
#define INCLUDE_RDC_LIB_RDCGROUPSETTINGS_H_
#include <memory>
#include "rdc/rdc.h"
#include "rdc_lib/rdc_common.h"
namespace amd {
namespace rdc {
class RdcGroupSettings {
public:
virtual rdc_status_t rdc_group_gpu_create(const char* group_name,
rdc_gpu_group_t* p_rdc_group_id) = 0;
virtual rdc_status_t rdc_group_gpu_destroy(rdc_gpu_group_t p_rdc_group_id) = 0;
virtual rdc_status_t rdc_group_gpu_add(rdc_gpu_group_t groupId, uint32_t gpu_index) = 0;
virtual rdc_status_t rdc_group_gpu_get_info(rdc_gpu_group_t p_rdc_group_id,
rdc_group_info_t* p_rdc_group_info) = 0;
virtual rdc_status_t rdc_group_get_all_ids(rdc_gpu_group_t group_id_list[], uint32_t* count) = 0;
virtual rdc_status_t rdc_group_field_create(uint32_t num_field_ids, rdc_field_t* field_ids,
const char* field_group_name,
rdc_field_grp_t* rdc_field_group_id) = 0;
virtual rdc_status_t rdc_group_field_destroy(rdc_field_grp_t rdc_field_group_id) = 0;
virtual rdc_status_t rdc_group_field_get_info(rdc_field_grp_t rdc_field_group_id,
rdc_field_group_info_t* field_group_info) = 0;
virtual rdc_status_t rdc_group_field_get_all_ids(rdc_field_grp_t field_group_id_list[],
uint32_t* count) = 0;
virtual ~RdcGroupSettings() {}
};
typedef std::shared_ptr<RdcGroupSettings> RdcGroupSettingsPtr;
const uint32_t JOB_FIELD_ID = 0;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_RDCGROUPSETTINGS_H_
+146
View File
@@ -0,0 +1,146 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_RDCHANDLER_H_
#define INCLUDE_RDC_LIB_RDCHANDLER_H_
#include "rdc/rdc.h"
#include "rdc/rdc_private.h"
#include "rdc_lib/rdc_common.h"
namespace amd {
namespace rdc {
// Interface class
class RdcHandler {
public:
// Job API
virtual rdc_status_t rdc_job_start_stats(rdc_gpu_group_t groupId, const char job_id[64],
uint64_t update_freq) = 0;
virtual rdc_status_t rdc_job_get_stats(const char jobId[64], rdc_job_info_t* p_job_info) = 0;
virtual rdc_status_t rdc_job_stop_stats(const char job_id[64]) = 0;
virtual rdc_status_t rdc_job_remove(const char job_id[64]) = 0;
virtual rdc_status_t rdc_job_remove_all() = 0;
// Discovery API
virtual rdc_status_t rdc_device_get_all(uint32_t gpu_index_list[RDC_MAX_NUM_DEVICES],
uint32_t* count) = 0;
virtual rdc_status_t rdc_device_get_attributes(uint32_t gpu_index,
rdc_device_attributes_t* p_rdc_attr) = 0;
virtual rdc_status_t rdc_device_get_component_version(rdc_component_t component,
rdc_component_version_t* p_rdc_compv) = 0;
// Group API
virtual rdc_status_t rdc_group_gpu_create(rdc_group_type_t type, const char* group_name,
rdc_gpu_group_t* p_rdc_group_id) = 0;
virtual rdc_status_t rdc_group_gpu_add(rdc_gpu_group_t groupId, uint32_t gpu_index) = 0;
virtual rdc_status_t rdc_group_field_create(uint32_t num_field_ids, rdc_field_t* field_ids,
const char* field_group_name,
rdc_field_grp_t* rdc_field_group_id) = 0;
virtual rdc_status_t rdc_group_field_get_info(rdc_field_grp_t rdc_field_group_id,
rdc_field_group_info_t* field_group_info) = 0;
virtual rdc_status_t rdc_group_gpu_get_info(rdc_gpu_group_t p_rdc_group_id,
rdc_group_info_t* p_rdc_group_info) = 0;
virtual rdc_status_t rdc_group_get_all_ids(rdc_gpu_group_t group_id_list[], uint32_t* count) = 0;
virtual rdc_status_t rdc_group_field_get_all_ids(rdc_field_grp_t field_group_id_list[],
uint32_t* count) = 0;
virtual rdc_status_t rdc_group_gpu_destroy(rdc_gpu_group_t p_rdc_group_id) = 0;
virtual rdc_status_t rdc_group_field_destroy(rdc_field_grp_t rdc_field_group_id) = 0;
// Field API
virtual rdc_status_t rdc_field_watch(rdc_gpu_group_t group_id, rdc_field_grp_t field_group_id,
uint64_t update_freq, double max_keep_age,
uint32_t max_keep_samples) = 0;
virtual rdc_status_t rdc_field_get_latest_value(uint32_t gpu_index, rdc_field_t field,
rdc_field_value* value) = 0;
virtual rdc_status_t rdc_field_get_value_since(uint32_t gpu_index, rdc_field_t field,
uint64_t since_time_stamp,
uint64_t* next_since_time_stamp,
rdc_field_value* value) = 0;
virtual rdc_status_t rdc_field_unwatch(rdc_gpu_group_t group_id,
rdc_field_grp_t field_group_id) = 0;
// Diagnostic API
virtual rdc_status_t rdc_diagnostic_run(rdc_gpu_group_t group_id, rdc_diag_level_t level,
const char* config, size_t config_size,
rdc_diag_response_t* response,
rdc_diag_callback_t* callback) = 0;
virtual rdc_status_t rdc_test_case_run(rdc_gpu_group_t group_id, rdc_diag_test_cases_t test_case,
const char* config, size_t config_size,
rdc_diag_test_result_t* result,
rdc_diag_callback_t* callback) = 0;
// Control API
virtual rdc_status_t rdc_field_update_all(uint32_t wait_for_update) = 0;
// It is just a client interface under the GRPC framework and is not used as an RDC API.
// The reason is that RdcEmbeddedHandler::get_mixed_component_version does not need to be called.
virtual rdc_status_t get_mixed_component_version(mixed_component_t component,
mixed_component_version_t* p_mixed_compv) = 0;
// Policy API
virtual rdc_status_t rdc_policy_set(rdc_gpu_group_t group_id, rdc_policy_t policy) = 0;
virtual rdc_status_t rdc_policy_get(rdc_gpu_group_t group_id, uint32_t* count,
rdc_policy_t policies[RDC_MAX_POLICY_SETTINGS]) = 0;
virtual rdc_status_t rdc_policy_delete(rdc_gpu_group_t group_id,
rdc_policy_condition_type_t condition_type) = 0;
virtual rdc_status_t rdc_policy_register(rdc_gpu_group_t group_id,
rdc_policy_register_callback callback) = 0;
virtual rdc_status_t rdc_policy_unregister(rdc_gpu_group_t group_id) = 0;
// Health API
virtual rdc_status_t rdc_health_set(rdc_gpu_group_t group_id, unsigned int components) = 0;
virtual rdc_status_t rdc_health_get(rdc_gpu_group_t group_id, unsigned int* components) = 0;
virtual rdc_status_t rdc_health_check(rdc_gpu_group_t group_id,
rdc_health_response_t* response) = 0;
virtual rdc_status_t rdc_health_clear(rdc_gpu_group_t group_id) = 0;
// topology API
virtual rdc_status_t rdc_device_topology_get(uint32_t gpu_index,
rdc_device_topology_t* results) = 0;
virtual rdc_status_t rdc_link_status_get(rdc_link_status_t* results) = 0;
// Set one configure
virtual rdc_status_t rdc_config_set(rdc_gpu_group_t group_id, rdc_config_setting_t setting) = 0;
// Get the setting
virtual rdc_status_t rdc_config_get(rdc_gpu_group_t group_id,
rdc_config_setting_list_t* settings) = 0;
// Clear the setting
virtual rdc_status_t rdc_config_clear(rdc_gpu_group_t group_id) = 0;
virtual rdc_status_t rdc_get_num_partition(uint32_t index, uint16_t* num_partition) = 0;
virtual rdc_status_t rdc_instance_profile_get(uint32_t entity_index,
rdc_instance_resource_type_t resource_type,
rdc_resource_profile_t* profile) = 0;
virtual ~RdcHandler() {}
};
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_RDCHANDLER_H_
@@ -0,0 +1,101 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_RDCLIBRARYLOADER_H_
#define INCLUDE_RDC_LIB_RDCLIBRARYLOADER_H_
#include <dlfcn.h>
#include <mutex> // NOLINT(build/c++11)
#include "rdc/rdc.h"
#include "rdc_lib/RdcException.h"
#include "rdc_lib/RdcLogger.h"
namespace amd {
namespace rdc {
class RdcLibraryLoader {
public:
RdcLibraryLoader();
// throws RdcException if lib not found
rdc_status_t load(const char* filename);
template <typename T>
rdc_status_t load_symbol(T* func_handler, const char* func_name);
template <typename T>
rdc_status_t load(const char* filename, T* func_make_handler);
rdc_status_t unload();
~RdcLibraryLoader();
private:
void* libHandler_;
std::mutex library_mutex_;
};
template <typename T>
rdc_status_t RdcLibraryLoader::load_symbol(T* func_handler, const char* func_name) {
if (!libHandler_) {
RDC_LOG(RDC_ERROR, "Must load the library before loading the symbol");
return RDC_ST_FAIL_LOAD_MODULE;
}
if (!func_handler || !func_name) {
return RDC_ST_FAIL_LOAD_MODULE;
}
std::lock_guard<std::mutex> guard(library_mutex_);
*reinterpret_cast<void**>(func_handler) = dlsym(libHandler_, func_name);
if (*func_handler == nullptr) {
char* error = dlerror();
RDC_LOG(RDC_ERROR, "RdcLibraryLoader: Fail to load the symbol " << func_name << ": " << error);
return RDC_ST_FAIL_LOAD_MODULE;
}
return RDC_ST_OK;
}
template <typename T>
rdc_status_t RdcLibraryLoader::load(const char* filename, T* func_make_handler) {
if (filename == nullptr || func_make_handler == nullptr) {
return RDC_ST_FAIL_LOAD_MODULE;
}
try {
rdc_status_t status = load(filename);
if (status != RDC_ST_OK) {
return status;
}
} catch (RdcException& e) {
RDC_LOG(RDC_ERROR, e.what());
return e.error_code();
}
return load_symbol(func_make_handler, "make_handler");
}
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_RDCLIBRARYLOADER_H_
+66
View File
@@ -0,0 +1,66 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_RDCLOGGER_H_
#define INCLUDE_RDC_LIB_RDCLOGGER_H_
#include <chrono> // NOLINT
#include <iostream>
#include <string>
#define RDC_ERROR 0
#define RDC_INFO 1
#define RDC_DEBUG 2
#define RDC_LOG(debug_level, msg) \
do { \
auto& logger = amd::rdc::RdcLogger::getLogger(); \
if (logger.should_log((debug_level))) { \
logger.get_ostream() << logger.get_log_header((debug_level), __FILE__, __LINE__) << msg \
<< std::endl; \
} \
} while (0)
namespace amd {
namespace rdc {
class RdcLogger {
public:
explicit RdcLogger(std::ostream& os);
static RdcLogger& getLogger() {
static RdcLogger logger(std::cout);
return logger;
}
bool should_log(uint32_t severity) { return log_level_ >= severity; }
std::ostream& get_ostream() { return os_; }
std::string get_log_header(uint32_t severity, const char* file, int line);
private:
std::ostream& os_;
uint32_t log_level_;
};
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_RDCLOGGER_H_
@@ -0,0 +1,54 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_RDCMETRICFETCHER_H_
#define INCLUDE_RDC_LIB_RDCMETRICFETCHER_H_
#include <memory>
#include <vector>
#include "rdc/rdc.h"
#include "rdc_lib/RdcTelemetryLibInterface.h"
#include "rdc_lib/rdc_common.h"
namespace amd {
namespace rdc {
class RdcMetricFetcher {
public:
virtual rdc_status_t acquire_smi_handle(RdcFieldKey fk) = 0;
virtual rdc_status_t delete_smi_handle(RdcFieldKey fk) = 0;
virtual rdc_status_t fetch_smi_field(uint32_t gpu_index, rdc_field_t field_id,
rdc_field_value* value) = 0;
virtual rdc_status_t bulk_fetch_smi_fields(
rdc_gpu_field_t* fields, uint32_t fields_count,
std::vector<rdc_gpu_field_value_t>& results) = 0; // NOLINT
virtual ~RdcMetricFetcher() {}
};
typedef std::shared_ptr<RdcMetricFetcher> RdcMetricFetcherPtr;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_RDCMETRICFETCHER_H_
@@ -0,0 +1,41 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_RDCMETRICSUPDATER_H_
#define INCLUDE_RDC_LIB_RDCMETRICSUPDATER_H_
#include <memory>
namespace amd {
namespace rdc {
class RdcMetricsUpdater {
public:
virtual void start() = 0;
virtual void stop() = 0;
};
typedef std::shared_ptr<RdcMetricsUpdater> RdcMetricsUpdaterPtr;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_RDCMETRICSUPDATER_H_
@@ -0,0 +1,45 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_RDCMODULEMGR_H_
#define INCLUDE_RDC_LIB_RDCMODULEMGR_H_
#include <memory>
#include "rdc_lib/RdcDiagnostic.h"
#include "rdc_lib/RdcTelemetry.h"
namespace amd {
namespace rdc {
class RdcModuleMgr {
public:
virtual ~RdcModuleMgr() = default;
virtual RdcTelemetryPtr get_telemetry_module() = 0;
virtual RdcDiagnosticPtr get_diagnostic_module() = 0;
};
typedef std::shared_ptr<RdcModuleMgr> RdcModuleMgrPtr;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_RDCMODULEMGR_H_
@@ -0,0 +1,60 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_RDCNOTIFICATION_H_
#define INCLUDE_RDC_LIB_RDCNOTIFICATION_H_
#include <memory>
#include <vector>
#include "rdc/rdc.h"
#include "rdc_lib/rdc_common.h"
namespace amd {
namespace rdc {
extern const uint32_t kMaxRSMIEvents;
typedef struct {
uint32_t gpu_id;
rdc_field_value field;
} rdc_evnt_notification_t;
class RdcNotification {
public:
virtual bool is_notification_event(rdc_field_t field) const = 0;
virtual rdc_status_t set_listen_events(const std::vector<RdcFieldKey> fk_arr) = 0;
// Blocking
virtual rdc_status_t listen(rdc_evnt_notification_t* events, uint32_t* num_events,
uint32_t timeout_ms) = 0;
virtual rdc_status_t stop_listening(uint32_t gpu_id) = 0;
virtual ~RdcNotification() {}
};
typedef std::shared_ptr<RdcNotification> RdcNotificationPtr;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_RDCNOTIFICATION_H_
@@ -0,0 +1,47 @@
/*
Copyright (c) 2025 - 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 INCLUDE_RDC_LIB_RDCPARTITION_H_
#define INCLUDE_RDC_LIB_RDCPARTITION_H_
#include <memory>
#include "rdc/rdc.h"
namespace amd {
namespace rdc {
class RdcPartition {
public:
virtual rdc_status_t rdc_instance_profile_get_impl(uint32_t entity_index,
rdc_instance_resource_type_t resource_type,
rdc_resource_profile_t* profile) = 0;
virtual rdc_status_t rdc_get_num_partition_impl(uint32_t index, uint16_t* num_partition) = 0;
virtual ~RdcPartition() {}
};
typedef std::shared_ptr<RdcPartition> RdcPartitionPtr;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_RDCPARTITION_H_
@@ -0,0 +1,87 @@
/*
Copyright (c) 2021 - 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 INCLUDE_RDC_LIB_RDCRdcPerfTimer_H_
#define INCLUDE_RDC_LIB_RDCRdcPerfTimer_H_
#include <stdint.h>
#include <iostream>
#include <string>
#include <vector>
/// \file
/// Timer related class.
namespace amd {
namespace rdc {
class RdcPerfTimer {
private:
struct Timer {
std::string name; /* < name name of time object*/
uint64_t _freq; /* < _freq frequency*/
uint64_t _clocks; /* < _clocks number of ticks at end*/
uint64_t _start; /* < _start start point ticks*/
};
std::vector<Timer*> _timers; /*< _timers vector to Timer objects */
double freq_in_100mhz;
public:
RdcPerfTimer(void);
~RdcPerfTimer(void);
/// Create a new timer.
/// \returns A new timer instance index
int CreateTimer(void);
/// Start the timer associated with the given index
/// \param[in] index Index of the timer to start
/// \returns int 0 for success, non-zero otherwise
int StartTimer(int index);
/// Stop the timer associated with the given index
/// \param[in] Index Index of the timer to stop
/// \returns int 0 for success, non-zero otherwise
int StopTimer(int index);
/// Reset the timer to 0
/// param[in] Index of the timer to reset
/// \returns void
void ResetTimer(int index);
/// Read the time value of the timer associated with the provided index.
/// Units are seconds
/// \param[in] index Index of the timer to read
/// \returns double Value of the timer
double ReadTimer(int index);
private:
void Error(std::string str);
uint64_t CoarseTimestampUs();
uint64_t MeasureTSCFreqHz();
};
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_RDCRdcPerfTimer_H_
+57
View File
@@ -0,0 +1,57 @@
/*
Copyright (c) 2024 - 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 INCLUDE_RDC_LIB_RDCPOLICY_H_
#define INCLUDE_RDC_LIB_RDCPOLICY_H_
#include <memory>
#include <vector>
#include "rdc/rdc.h"
#include "rdc_lib/rdc_common.h"
namespace amd {
namespace rdc {
class RdcPolicy {
public:
virtual rdc_status_t rdc_policy_set(rdc_gpu_group_t group_id, rdc_policy_t policy) = 0;
virtual rdc_status_t rdc_policy_get(rdc_gpu_group_t group_id, uint32_t* count,
rdc_policy_t policies[RDC_MAX_POLICY_SETTINGS]) = 0;
virtual rdc_status_t rdc_policy_delete(rdc_gpu_group_t group_id,
rdc_policy_condition_type_t condition_type) = 0;
virtual rdc_status_t rdc_policy_register(rdc_gpu_group_t group_id,
rdc_policy_register_callback callback) = 0;
virtual rdc_status_t rdc_policy_unregister(rdc_gpu_group_t group_id) = 0;
virtual ~RdcPolicy() {}
};
typedef std::shared_ptr<RdcPolicy> RdcPolicyPtr;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_RDCPOLICY_H_
@@ -0,0 +1,57 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_RDCTELEMETRY_H_
#define INCLUDE_RDC_LIB_RDCTELEMETRY_H_
#include <memory>
#include "rdc/rdc.h"
#include "rdc_lib/RdcTelemetryLibInterface.h"
namespace amd {
namespace rdc {
class RdcTelemetry {
public:
// get support field ids
virtual rdc_status_t rdc_telemetry_fields_query(uint32_t field_ids[MAX_NUM_FIELDS],
uint32_t* field_count) = 0;
// Fetch
virtual rdc_status_t rdc_telemetry_fields_value_get(rdc_gpu_field_t* fields,
uint32_t fields_count,
rdc_field_value_f callback,
void* user_data) = 0;
virtual rdc_status_t rdc_telemetry_fields_watch(rdc_gpu_field_t* fields,
uint32_t fields_count) = 0;
virtual rdc_status_t rdc_telemetry_fields_unwatch(rdc_gpu_field_t* fields,
uint32_t fields_count) = 0;
virtual ~RdcTelemetry() {}
};
typedef std::shared_ptr<RdcTelemetry> RdcTelemetryPtr;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_RDCTELEMETRY_H_
@@ -0,0 +1,63 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_RDCTELEMETRYLIBINTERFACE_H_
#define INCLUDE_RDC_LIB_RDCTELEMETRYLIBINTERFACE_H_
// The telemetry interface for libraries, for example, AMD-SMI.
#include <rdc/rdc.h>
#include <cstdint>
extern "C" {
// Structure to keep both gup index and field value
typedef struct {
uint32_t gpu_index;
rdc_field_value field_value;
} rdc_gpu_field_value_t;
typedef struct {
uint32_t gpu_index;
rdc_field_t field_id;
} rdc_gpu_field_t;
#define MAX_NUM_FIELDS 8192
typedef rdc_status_t (*rdc_field_value_f)(rdc_gpu_field_value_t* values, uint32_t num_values,
void* user_data);
// The library will implement below function
rdc_status_t rdc_telemetry_fields_query(uint32_t field_ids[MAX_NUM_FIELDS], uint32_t* field_count);
rdc_status_t rdc_telemetry_fields_value_get(rdc_gpu_field_t* fields, uint32_t fields_count,
rdc_field_value_f callback, void* user_data);
rdc_status_t rdc_telemetry_fields_watch(rdc_gpu_field_t* fields, uint32_t fields_count);
rdc_status_t rdc_telemetry_fields_unwatch(rdc_gpu_field_t* fields, uint32_t fields_count);
rdc_status_t rdc_module_init(uint64_t flags);
rdc_status_t rdc_module_destroy();
}
#endif // INCLUDE_RDC_LIB_RDCTELEMETRYLIBINTERFACE_H_
@@ -0,0 +1,48 @@
/*
Copyright (c) 2024 - 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 INCLUDE_RDC_LIB_RDCTOPOLOGYLINK_H_
#define INCLUDE_RDC_LIB_RDCTOPOLOGYLINK_H_
#include <memory>
#include <vector>
#include "rdc/rdc.h"
#include "rdc_lib/rdc_common.h"
namespace amd {
namespace rdc {
class RdcTopologyLink {
public:
virtual rdc_status_t rdc_device_topology_get(uint32_t gpu_index,
rdc_device_topology_t* results) = 0;
virtual rdc_status_t rdc_link_status_get(rdc_link_status_t* results) = 0;
virtual ~RdcTopologyLink() {}
};
typedef std::shared_ptr<RdcTopologyLink> RdcTopologyLinkPtr;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_RDCTOPOLOGYLINK_H_
@@ -0,0 +1,69 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_RDCWATCHTABLE_H_
#define INCLUDE_RDC_LIB_RDCWATCHTABLE_H_
#include <memory>
#include <vector>
#include "rdc/rdc.h"
#include "rdc_lib/rdc_common.h"
namespace amd {
namespace rdc {
class RdcWatchTable {
public:
virtual rdc_status_t rdc_field_update_all() = 0;
virtual rdc_status_t rdc_field_listen_notif(uint32_t timeout_ms) = 0;
virtual rdc_status_t rdc_job_start_stats(rdc_gpu_group_t group_id, const char job_id[64],
uint64_t update_freq,
const rdc_gpu_gauges_t& gpu_gauge) = 0;
virtual rdc_status_t rdc_job_stop_stats(const char job_id[64],
const rdc_gpu_gauges_t& gpu_gauge) = 0;
virtual rdc_status_t rdc_job_remove(const char job_id[64]) = 0;
virtual rdc_status_t rdc_job_remove_all() = 0;
virtual rdc_status_t rdc_field_watch(rdc_gpu_group_t group_id, rdc_field_grp_t field_group_id,
uint64_t update_freq, double max_keep_age,
uint32_t max_keep_samples) = 0;
virtual rdc_status_t rdc_field_unwatch(rdc_gpu_group_t group_id,
rdc_field_grp_t field_group_id) = 0;
virtual rdc_status_t rdc_health_set(rdc_gpu_group_t group_id,
unsigned int components) = 0;
virtual rdc_status_t rdc_health_get(rdc_gpu_group_t group_id,
unsigned int* components) = 0;
virtual rdc_status_t rdc_health_check(rdc_gpu_group_t group_id,
rdc_health_response_t *response) = 0;
virtual rdc_status_t rdc_health_clear(rdc_gpu_group_t group_id) = 0;
virtual ~RdcWatchTable() {}
};
typedef std::shared_ptr<RdcWatchTable> RdcWatchTablePtr;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_RDCWATCHTABLE_H_
@@ -0,0 +1,143 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_IMPL_RDCCACHEMANAGERIMPL_H_
#define INCLUDE_RDC_LIB_IMPL_RDCCACHEMANAGERIMPL_H_
#include <array>
#include <map>
#include <memory>
#include <mutex> // NOLINT(build/c++11)
#include <string>
#include <vector>
#include "rdc/rdc.h"
#include "rdc_lib/RdcCacheManager.h"
#include "rdc_lib/rdc_common.h"
#define HEALTH_MAX_KEEP_SAMPLES 300
namespace amd {
namespace rdc {
// Note, the .cc code relies on RdcCacheEntry only having plain-old-data
// types and arrays (no pointers). If a pointer is added, make sure to update
// any code that copies this structure.
struct RdcCacheEntry {
uint64_t last_time;
rdc_field_type_t type;
rdc_field_value_data value;
};
typedef std::map<RdcFieldKey, std::vector<RdcCacheEntry>> RdcCacheSamples;
struct FieldSummaryStats {
int64_t max_value;
int64_t min_value;
int64_t total_value;
// Use Welford algorithm to calculate the standard deviations.
// https://en.wikipedia.org/wiki/Standard_deviation#Rapid_calculation_methods
// https://www.johndcook.com/blog/standard_deviation/
double old_m;
double old_s;
double new_m;
double new_s;
uint64_t last_time;
uint64_t count;
};
struct GpuSummaryStats {
uint64_t energy_consumed;
uint64_t energy_last_time;
uint64_t ecc_correct_init; // Init counter when job starts
uint64_t ecc_uncorrect_init; // Init counter when job starts
std::map<uint32_t, FieldSummaryStats> field_summaries;
};
// Per job entry
struct RdcJobStatsCacheEntry {
uint64_t start_time;
uint64_t end_time;
std::map<uint32_t, GpuSummaryStats> gpu_stats;
uint32_t num_processes = 0;
std::array<rdc_process_status_info_t, RDC_MAX_NUM_PROCESSES_STATUS> processes{};
std::map<uint32_t, uint32_t> pid_to_index;
};
// <job_id, job_stats>
typedef std::map<std::string, RdcJobStatsCacheEntry> RdcJobStatsCache;
// <group_id, health_samples>
typedef std::map<rdc_gpu_group_t, RdcCacheSamples> RdcHealthStatsCache;
class RdcCacheManagerImpl : public RdcCacheManager {
public:
rdc_status_t rdc_field_get_latest_value(uint32_t gpu_index, rdc_field_t field,
rdc_field_value* value) override;
rdc_status_t rdc_field_get_value_since(uint32_t gpu_index, rdc_field_t field,
uint64_t since_time_stamp, uint64_t* next_since_time_stamp,
rdc_field_value* value) override;
rdc_status_t rdc_update_cache(uint32_t gpu_index, const rdc_field_value& value) override;
rdc_status_t evict_cache(uint32_t gpu_index, rdc_field_t field_id, uint64_t max_keep_samples,
double max_keep_age) override;
std::string get_cache_stats() override;
rdc_status_t rdc_job_get_stats(const char job_id[64], const rdc_gpu_gauges_t& gpu_gauges,
rdc_job_info_t* p_job_info) override;
rdc_status_t rdc_job_start_stats(const char job_id[64], const rdc_group_info_t& group,
const rdc_field_group_info_t& finfo,
const rdc_gpu_gauges_t& gpu_gauges) override;
rdc_status_t rdc_job_stop_stats(const char job_id[64],
const rdc_gpu_gauges_t& gpu_gauge) override;
rdc_status_t rdc_update_job_stats(uint32_t gpu_index, const std::string& job_id,
const rdc_field_value& value) override;
rdc_status_t rdc_job_remove(const char job_id[64]) override;
rdc_status_t rdc_job_remove_all() override;
rdc_status_t rdc_health_set(rdc_gpu_group_t group_id, uint32_t gpu_index,
const rdc_field_value& value) override;
rdc_status_t rdc_health_get_values(rdc_gpu_group_t group_id, uint32_t gpu_index,
rdc_field_t field_id, uint64_t start_timestamp,
uint64_t end_timestamp, rdc_field_value* start_value,
rdc_field_value* end_value) override;
rdc_status_t rdc_health_clear(rdc_gpu_group_t group_id) override;
rdc_status_t rdc_update_health_stats(rdc_gpu_group_t group_id, uint32_t gpu_index,
const rdc_field_value& value) override;
private:
void set_summary(const FieldSummaryStats& stats, rdc_stats_summary_t& gpu,
rdc_stats_summary_t& summary, // NOLINT
unsigned int adjuster);
void set_average_summary(rdc_stats_summary_t& summary,
uint32_t num_gpus); // NOLINT
RdcCacheSamples cache_samples_;
RdcJobStatsCache cache_jobs_;
RdcHealthStatsCache cache_health_;
std::mutex cache_mutex_;
};
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_RDCCACHEMANAGERIMPL_H_
@@ -0,0 +1,73 @@
/*
Copyright (c) 2024 - 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 INCLUDE_RDC_LIB_IMPL_RDCCONFIGSETTINGSIMPL_H_
#define INCLUDE_RDC_LIB_IMPL_RDCCONFIGSETTINGSIMPL_H_
#include <atomic>
#include <condition_variable>
#include <mutex> // NOLINT
#include <thread>
#include <unordered_map>
#include "rdc_lib/RdcConfigSettings.h"
#include "rdc_lib/RdcGroupSettings.h"
namespace amd {
namespace rdc {
class RdcConfigSettingsImpl : public RdcConfigSettings {
public:
// Set one configure
rdc_status_t rdc_config_set(rdc_gpu_group_t group_id, rdc_config_setting_t setting) override;
// Get the setting
rdc_status_t rdc_config_get(rdc_gpu_group_t group_id,
rdc_config_setting_list_t* settings) override;
// clear the setting
rdc_status_t rdc_config_clear(rdc_gpu_group_t group_id) override;
explicit RdcConfigSettingsImpl(const RdcGroupSettingsPtr& group_settings);
private:
RdcGroupSettingsPtr group_settings_;
std::unordered_map<rdc_gpu_group_t, std::unordered_map<rdc_config_type_t, rdc_config_setting_t>>
cached_group_settings_;
std::thread monitor_thread_;
std::mutex mutex_; // Mutex for cached_group_settings_
std::atomic<bool> is_running_; // Bool for if the thread should keep running
std::condition_variable cv_;
// monitorSettings() is kicked off from the RdcConfigSettingsImpl constructor as it's own thread
// Every minute, it will check if gpu settings from amdsmi are the same as inside
// cached_group_settings_ If not, it sets the mismatched values to the value in
// cached_group_settings_
void monitorSettings();
uint64_t wattsToMicrowatts(uint64_t watts) const;
uint64_t microwattsToWatts(int microwatts) const;
rdc_status_t get_group_info(rdc_gpu_group_t group_id, rdc_group_info_t* rdc_group_info);
};
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_RDCCONFIGSETTINGSIMPL_H_
@@ -0,0 +1,72 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_IMPL_DIAGNOSTICMODULE_H_
#define INCLUDE_RDC_LIB_IMPL_DIAGNOSTICMODULE_H_
#include <list>
#include <map>
#include <memory>
#include <vector>
#include "rdc/rdc.h"
#include "rdc_lib/RdcDiagnostic.h"
#include "rdc_lib/RdcTelemetryLibInterface.h"
namespace amd {
namespace rdc {
class RdcDiagnosticModule : public RdcDiagnostic {
public:
rdc_status_t rdc_diag_test_cases_query(rdc_diag_test_cases_t test_cases[MAX_TEST_CASES],
uint32_t* test_case_count) override;
// Run a specific test case
rdc_status_t rdc_test_case_run(rdc_diag_test_cases_t test_case,
uint32_t gpu_index[RDC_MAX_NUM_DEVICES], uint32_t gpu_count,
const char* config, size_t config_size,
rdc_diag_test_result_t* result, rdc_diag_callback_t* callback) override;
rdc_status_t rdc_diagnostic_run(const rdc_group_info_t& gpus, rdc_diag_level_t level,
const char* config, size_t config_size,
rdc_diag_response_t* response, rdc_diag_callback_t* callback) override;
rdc_status_t rdc_diag_init(uint64_t flags) override;
rdc_status_t rdc_diag_destroy() override;
explicit RdcDiagnosticModule(std::list<RdcDiagnosticPtr> diagnostic_modules);
private:
//< Helper function to dispatch fields to module
void get_fields_for_module(
rdc_gpu_field_t* fields, uint32_t fields_count,
std::map<RdcDiagnosticPtr, std::vector<rdc_gpu_field_t>>& fields_in_module,
std::vector<rdc_gpu_field_value_t>& unsupport_fields); // NOLINT
std::list<RdcDiagnosticPtr> diagnostic_modules_;
std::map<rdc_diag_test_cases_t, RdcDiagnosticPtr> testcases_to_module_;
};
typedef std::shared_ptr<RdcDiagnosticModule> RdcDiagnosticModulePtr;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_DIAGNOSTICMODULE_H_
@@ -0,0 +1,170 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_IMPL_RDCEMBEDDEDHANDLER_H_
#define INCLUDE_RDC_LIB_IMPL_RDCEMBEDDEDHANDLER_H_
#include <future> // NOLINT(build/c++11)
#include "rdc_lib/RdcCacheManager.h"
#include "rdc_lib/RdcConfigSettings.h"
#include "rdc_lib/RdcGroupSettings.h"
#include "rdc_lib/RdcHandler.h"
#include "rdc_lib/RdcMetricFetcher.h"
#include "rdc_lib/RdcMetricsUpdater.h"
#include "rdc_lib/RdcModuleMgr.h"
#include "rdc_lib/RdcNotification.h"
#include "rdc_lib/RdcPartition.h"
#include "rdc_lib/RdcPolicy.h"
#include "rdc_lib/RdcTopologyLink.h"
#include "rdc_lib/RdcWatchTable.h"
namespace amd {
namespace rdc {
class RdcEmbeddedHandler final : public RdcHandler {
public:
// Job API
rdc_status_t rdc_job_start_stats(rdc_gpu_group_t groupId, const char job_id[64],
uint64_t update_freq) override;
rdc_status_t rdc_job_get_stats(const char jobId[64], rdc_job_info_t* p_job_info) override;
rdc_status_t rdc_job_stop_stats(const char job_id[64]) override;
rdc_status_t rdc_job_remove(const char job_id[64]) override;
rdc_status_t rdc_job_remove_all() override;
// Discovery API
rdc_status_t rdc_device_get_all(uint32_t gpu_index_list[RDC_MAX_NUM_DEVICES],
uint32_t* count) override;
rdc_status_t rdc_device_get_attributes(uint32_t gpu_index,
rdc_device_attributes_t* p_rdc_attr) override;
rdc_status_t rdc_device_get_component_version(rdc_component_t component,
rdc_component_version_t* p_rdc_compv) override;
// Group API
rdc_status_t rdc_group_gpu_create(rdc_group_type_t type, const char* group_name,
rdc_gpu_group_t* p_rdc_group_id) override;
rdc_status_t rdc_group_gpu_add(rdc_gpu_group_t groupId, uint32_t gpu_index) override;
rdc_status_t rdc_group_field_create(uint32_t num_field_ids, rdc_field_t* field_ids,
const char* field_group_name,
rdc_field_grp_t* rdc_field_group_id) override;
rdc_status_t rdc_group_field_get_info(rdc_field_grp_t rdc_field_group_id,
rdc_field_group_info_t* field_group_info) override;
rdc_status_t rdc_group_gpu_get_info(rdc_gpu_group_t p_rdc_group_id,
rdc_group_info_t* p_rdc_group_info) override;
rdc_status_t rdc_group_get_all_ids(rdc_gpu_group_t group_id_list[], uint32_t* count) override;
rdc_status_t rdc_group_field_get_all_ids(rdc_field_grp_t field_group_id_list[],
uint32_t* count) override;
rdc_status_t rdc_group_gpu_destroy(rdc_gpu_group_t p_rdc_group_id) override;
rdc_status_t rdc_group_field_destroy(rdc_field_grp_t rdc_field_group_id) override;
// Field API
rdc_status_t rdc_field_watch(rdc_gpu_group_t group_id, rdc_field_grp_t field_group_id,
uint64_t update_freq, double max_keep_age,
uint32_t max_keep_samples) override;
rdc_status_t rdc_field_get_latest_value(uint32_t gpu_index, rdc_field_t field,
rdc_field_value* value) override;
rdc_status_t rdc_field_get_value_since(uint32_t gpu_index, rdc_field_t field,
uint64_t since_time_stamp, uint64_t* next_since_time_stamp,
rdc_field_value* value) override;
rdc_status_t rdc_field_unwatch(rdc_gpu_group_t group_id, rdc_field_grp_t field_group_id) override;
// Diagnostic API
rdc_status_t rdc_diagnostic_run(rdc_gpu_group_t group_id, rdc_diag_level_t level,
const char* config, size_t config_size,
rdc_diag_response_t* response,
rdc_diag_callback_t* callback) override;
rdc_status_t rdc_test_case_run(rdc_gpu_group_t group_id, rdc_diag_test_cases_t test_case,
const char* config, size_t config_size,
rdc_diag_test_result_t* result,
rdc_diag_callback_t* callback) override;
// Control API
rdc_status_t rdc_field_update_all(uint32_t wait_for_update) override;
// It is just a client interface under the GRPC framework and is not used as an RDC API.
// Pure virtual functions need to be overridden.
rdc_status_t get_mixed_component_version(mixed_component_t component,
mixed_component_version_t* p_mixed_compv) override;
// Policy API
rdc_status_t rdc_policy_set(rdc_gpu_group_t group_id, rdc_policy_t policy) override;
rdc_status_t rdc_policy_get(rdc_gpu_group_t group_id, uint32_t* count,
rdc_policy_t policies[RDC_MAX_POLICY_SETTINGS]) override;
rdc_status_t rdc_policy_delete(rdc_gpu_group_t group_id,
rdc_policy_condition_type_t condition_type) override;
rdc_status_t rdc_policy_register(rdc_gpu_group_t group_id,
rdc_policy_register_callback callback) override;
rdc_status_t rdc_policy_unregister(rdc_gpu_group_t group_id) override;
// Health API
rdc_status_t rdc_health_set(rdc_gpu_group_t group_id, unsigned int components) override;
rdc_status_t rdc_health_get(rdc_gpu_group_t group_id, unsigned int* components) override;
rdc_status_t rdc_health_check(rdc_gpu_group_t group_id, rdc_health_response_t* response) override;
rdc_status_t rdc_health_clear(rdc_gpu_group_t group_id) override;
rdc_status_t rdc_device_topology_get(uint32_t gpu_index, rdc_device_topology_t* results) override;
rdc_status_t rdc_link_status_get(rdc_link_status_t* results) override;
// Set one configure
rdc_status_t rdc_config_set(rdc_gpu_group_t group_id, rdc_config_setting_t setting) override;
// Get the setting
rdc_status_t rdc_config_get(rdc_gpu_group_t group_id,
rdc_config_setting_list_t* settings) override;
// Clear the setting
rdc_status_t rdc_config_clear(rdc_gpu_group_t group_id) override;
rdc_status_t rdc_get_num_partition(uint32_t index, uint16_t* num_partition) override;
rdc_status_t rdc_instance_profile_get(uint32_t entity_index,
rdc_instance_resource_type_t resource_type,
rdc_resource_profile_t* profile) override;
explicit RdcEmbeddedHandler(rdc_operation_mode_t op_mode);
~RdcEmbeddedHandler() final;
private:
rdc_status_t get_gpu_gauges(rdc_gpu_gauges_t* gpu_gauges);
RdcPartitionPtr partition_;
RdcGroupSettingsPtr group_settings_;
RdcCacheManagerPtr cache_mgr_;
RdcMetricFetcherPtr metric_fetcher_;
RdcModuleMgrPtr rdc_module_mgr_;
RdcNotificationPtr rdc_notif_;
RdcWatchTablePtr watch_table_;
RdcMetricsUpdaterPtr metrics_updater_;
RdcPolicyPtr policy_;
RdcTopologyLinkPtr topologylink_;
RdcConfigSettingsPtr config_handler_;
std::future<void> updater_;
};
} // namespace rdc
} // namespace amd
extern "C" {
amd::rdc::RdcHandler* make_handler(rdc_operation_mode_t op_mode);
}
#endif // INCLUDE_RDC_LIB_IMPL_RDCEMBEDDEDHANDLER_H_
@@ -0,0 +1,70 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_IMPL_RDCGROUPSETTINGSIMPL_H_
#define INCLUDE_RDC_LIB_IMPL_RDCGROUPSETTINGSIMPL_H_
#include <map>
#include <memory>
#include <mutex> // NOLINT
#include <string>
#include "rdc_lib/RdcGroupSettings.h"
#include "rdc_lib/impl/RdcPartitionImpl.h"
namespace amd {
namespace rdc {
class RdcGroupSettingsImpl : public RdcGroupSettings {
public:
rdc_status_t rdc_group_gpu_create(const char* group_name,
rdc_gpu_group_t* p_rdc_group_id) override;
rdc_status_t rdc_group_gpu_destroy(rdc_gpu_group_t p_rdc_group_id) override;
rdc_status_t rdc_group_gpu_add(rdc_gpu_group_t groupId, uint32_t gpu_index) override;
rdc_status_t rdc_group_gpu_get_info(rdc_gpu_group_t p_rdc_group_id,
rdc_group_info_t* p_rdc_group_info) override;
rdc_status_t rdc_group_get_all_ids(rdc_gpu_group_t group_id_list[], uint32_t* count) override;
rdc_status_t rdc_group_field_create(uint32_t num_field_ids, rdc_field_t* field_ids,
const char* field_group_name,
rdc_field_grp_t* rdc_field_group_id) override;
rdc_status_t rdc_group_field_destroy(rdc_field_grp_t rdc_field_group_id) override;
rdc_status_t rdc_group_field_get_info(rdc_field_grp_t rdc_field_group_id,
rdc_field_group_info_t* field_group_info) override;
rdc_status_t rdc_group_field_get_all_ids(rdc_field_grp_t field_group_id_list[],
uint32_t* count) override;
explicit RdcGroupSettingsImpl(const RdcPartitionPtr& partition);
private:
std::map<rdc_gpu_group_t, rdc_group_info_t> gpu_group_;
std::map<rdc_field_grp_t, rdc_field_group_info_t> field_group_;
uint32_t cur_group_id_ = 1;
uint32_t cur_field_group_id_ = 0;
std::mutex group_mutex_;
std::mutex field_group_mutex_;
RdcPartitionPtr partition_;
};
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_RDCGROUPSETTINGSIMPL_H_
@@ -0,0 +1,107 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_IMPL_RDCMETRICFETCHERIMPL_H_
#define INCLUDE_RDC_LIB_IMPL_RDCMETRICFETCHERIMPL_H_
#include <condition_variable> // NOLINT(build/c++11)
#include <future> // NOLINT(build/c++11)
#include <map>
#include <memory>
#include <mutex> // NOLINT(build/c++11)
#include <queue>
#include "amd_smi/amdsmi.h"
#include "rdc_lib/RdcMetricFetcher.h"
#include "rdc_lib/rdc_common.h"
namespace amd {
namespace rdc {
//!< Some metrics, like PCIe throughput may take a second to retreive. The
//!< MetricValue will cache those metrics for async retreive.
struct MetricValue {
uint64_t cache_ttl;
uint64_t last_time;
rdc_field_value value;
};
// This union represents any SMI handles require initialization and/or
// shut down. There should only be one instance of this for each raw event
// used. For example, if a field group includes a pseudo-event and the
// underlying raw event, then only one FieldSMIData should be created,
// and it should be used by both events.
struct FieldSMIData {
union {
amdsmi_event_handle_t evt_handle;
};
union {
amdsmi_counter_value_t counter_val;
};
~FieldSMIData() {}
FieldSMIData() : evt_handle(0), counter_val{0, 0, 0} {}
};
//!< The data structure to store the async fetch task
class RdcMetricFetcherImpl;
struct MetricTask {
RdcFieldKey field;
std::function<void(RdcMetricFetcherImpl&, RdcFieldKey)> task;
};
class RdcMetricFetcherImpl final : public RdcMetricFetcher {
public:
rdc_status_t fetch_smi_field(uint32_t gpu_index, rdc_field_t field_id,
rdc_field_value* value) override;
rdc_status_t bulk_fetch_smi_fields(
rdc_gpu_field_t* fields, uint32_t fields_count,
std::vector<rdc_gpu_field_value_t>& results) override; // NOLINT
RdcMetricFetcherImpl();
~RdcMetricFetcherImpl() final;
rdc_status_t acquire_smi_handle(RdcFieldKey fk) override;
rdc_status_t delete_smi_handle(RdcFieldKey fk) override;
private:
std::shared_ptr<FieldSMIData> get_smi_data(RdcFieldKey key);
uint64_t now();
void get_ecc(uint32_t gpu_index, rdc_field_t field_id, rdc_field_value* value);
void get_ecc_total(uint32_t gpu_index, rdc_field_t field_id, rdc_field_value* value);
//!< return true if starting async_get
bool async_get_pcie_throughput(uint32_t gpu_index, rdc_field_t field_id, rdc_field_value* value);
void get_pcie_throughput(const RdcFieldKey& key);
//!< Async metric retreive
std::map<RdcFieldKey, MetricValue> async_metrics_;
std::map<RdcFieldKey, std::shared_ptr<FieldSMIData>> smi_data_;
std::queue<MetricTask> updated_tasks_;
std::mutex task_mutex_;
std::future<void> updater_; // keep the future of updater
std::condition_variable cv_;
std::atomic<bool> task_started_;
};
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_RDCMETRICFETCHERIMPL_H_
@@ -0,0 +1,53 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_IMPL_RDCMETRICSUPDATERIMPL_H_
#define INCLUDE_RDC_LIB_IMPL_RDCMETRICSUPDATERIMPL_H_
#include <future> // NOLINT(build/c++11)
#include <memory>
#include "rdc_lib/RdcMetricsUpdater.h"
#include "rdc_lib/RdcWatchTable.h"
namespace amd {
namespace rdc {
class RdcMetricsUpdaterImpl final : public RdcMetricsUpdater {
public:
void start() override;
void stop() override;
explicit RdcMetricsUpdaterImpl(const RdcWatchTablePtr& watch_table,
const uint32_t check_frequency);
~RdcMetricsUpdaterImpl() = default;
private:
RdcWatchTablePtr watch_table_;
std::atomic<bool> started_;
std::future<void> updater_; // keep the future of updater
std::future<void> notif_updater_; // keep the future of notif updater
const uint32_t _check_frequency; // Check frequency in milliseconds
};
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_RDCMETRICSUPDATERIMPL_H_
@@ -0,0 +1,68 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_IMPL_RDCMODULEMGRIMPL_H_
#define INCLUDE_RDC_LIB_IMPL_RDCMODULEMGRIMPL_H_
#include <list>
#include "rdc_lib/RdcMetricFetcher.h"
#include "rdc_lib/RdcModuleMgr.h"
#include "rdc_lib/RdcTelemetry.h"
namespace amd {
namespace rdc {
class RdcModuleMgrImpl : public RdcModuleMgr {
public:
RdcTelemetryPtr get_telemetry_module() override;
RdcDiagnosticPtr get_diagnostic_module() override;
explicit RdcModuleMgrImpl(const RdcMetricFetcherPtr& fetcher);
private:
// Modules
std::list<RdcDiagnosticPtr> diagnostic_modules_;
std::list<RdcTelemetryPtr> telemetry_modules_;
// base case
template <typename T>
rdc_status_t insert_modules();
// recursive case
template <typename T, typename R, typename... TArgs>
rdc_status_t insert_modules();
// pass shared_ptr instead of creating it
template <typename T>
rdc_status_t insert_modules(std::shared_ptr<T> ptr);
// Function module
RdcTelemetryPtr rdc_telemetry_module_;
RdcDiagnosticPtr rdc_diagnostic_module_;
// Domain module
RdcMetricFetcherPtr fetcher_;
};
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_RDCMODULEMGRIMPL_H_
@@ -0,0 +1,57 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_IMPL_RDCNOTIFICATIONIMPL_H_
#define INCLUDE_RDC_LIB_IMPL_RDCNOTIFICATIONIMPL_H_
#include <map>
#include <memory>
#include <mutex>
#include <vector>
#include "rdc/rdc.h"
#include "rdc_lib/RdcNotification.h"
#include "rdc_lib/rdc_common.h"
namespace amd {
namespace rdc {
class RdcNotificationImpl : public RdcNotification {
public:
RdcNotificationImpl();
~RdcNotificationImpl();
bool is_notification_event(rdc_field_t field) const override;
rdc_status_t set_listen_events(const std::vector<RdcFieldKey> fk_arr) override;
// Blocking
rdc_status_t listen(rdc_evnt_notification_t* events, uint32_t* num_events,
uint32_t timeout_ms) override;
rdc_status_t stop_listening(uint32_t gpu_id) override;
private:
std::map<uint32_t, uint64_t> gpu_evnt_notif_masks_;
std::mutex notif_mutex_;
};
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_RDCNOTIFICATIONIMPL_H_
@@ -0,0 +1,44 @@
/*
Copyright (c) 2025 - 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 INCLUDE_RDC_LIB_IMPL_RDCPARTITIONIMPL_H_
#define INCLUDE_RDC_LIB_IMPL_RDCPARTITIONIMPL_H_
#include <memory>
#include "rdc/rdc.h"
#include "rdc_lib/RdcPartition.h"
namespace amd {
namespace rdc {
class RdcPartitionImpl : public RdcPartition {
public:
rdc_status_t rdc_instance_profile_get_impl(uint32_t entity_index,
rdc_instance_resource_type_t resource_type,
rdc_resource_profile_t* profile);
rdc_status_t rdc_get_num_partition_impl(uint32_t index, uint16_t* num_partition);
};
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_RDCPARTITIONIMPL_H_
@@ -0,0 +1,77 @@
/*
Copyright (c) 2024 - 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 INCLUDE_RDC_LIB_IMPL_RDCPOLICYIMPL_H_
#define INCLUDE_RDC_LIB_IMPL_RDCPOLICYIMPL_H_
#include <atomic>
#include <map>
#include <memory>
#include <mutex> // NOLINT
#include <string>
#include <utility>
#include <vector>
#include <future>
#include "amd_smi/amdsmi.h"
#include "rdc_lib/RdcPolicy.h"
#include "rdc_lib/RdcMetricFetcher.h"
#include "rdc_lib/RdcGroupSettings.h"
namespace amd {
namespace rdc {
class RdcPolicyImpl : public RdcPolicy {
public:
RdcPolicyImpl(const RdcGroupSettingsPtr& group_settings, const RdcMetricFetcherPtr& metric_fetcher);
~RdcPolicyImpl();
rdc_status_t rdc_policy_set(rdc_gpu_group_t group_id, rdc_policy_t policy) override;
rdc_status_t rdc_policy_get(rdc_gpu_group_t group_id, uint32_t* count,
rdc_policy_t policies[RDC_MAX_POLICY_SETTINGS]) override;
rdc_status_t rdc_policy_delete(rdc_gpu_group_t group_id,
rdc_policy_condition_type_t condition_type) override;
rdc_status_t rdc_policy_register(rdc_gpu_group_t group_id,rdc_policy_register_callback callback) override;
rdc_status_t rdc_policy_unregister(rdc_gpu_group_t group_id) override;
private:
RdcGroupSettingsPtr group_settings_;
RdcMetricFetcherPtr metric_fetcher_;
std::mutex policy_mutex_;
std::thread thread_;
bool start_;
std::map<rdc_gpu_group_t, std::vector<rdc_policy_t> > settings_;
std::map<rdc_gpu_group_t, rdc_policy_register_callback> callbacks_;
void rdc_policy_check_condition();
void rdc_policy_gpu_reset(uint32_t gpu_index);
rdc_policy_register_callback rdc_policy_get_callback(rdc_gpu_group_t group_id);
};
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_RDCPOLICYIMPL_H_
@@ -0,0 +1,70 @@
/*
Copyright (c) 2023 - 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 INCLUDE_RDC_LIB_IMPL_RDCRVSLIB_H_
#define INCLUDE_RDC_LIB_IMPL_RDCRVSLIB_H_
#include <memory>
#include "rdc/rdc.h"
#include "rdc_lib/RdcDiagnostic.h"
#include "rdc_lib/RdcLibraryLoader.h"
namespace amd {
namespace rdc {
class RdcRVSLib : public RdcDiagnostic {
public:
rdc_status_t rdc_diag_test_cases_query(rdc_diag_test_cases_t test_cases[MAX_TEST_CASES],
uint32_t* test_case_count) override;
// Run a specific test case
rdc_status_t rdc_test_case_run(rdc_diag_test_cases_t test_case,
uint32_t gpu_index[RDC_MAX_NUM_DEVICES], uint32_t gpu_count,
const char* config, size_t config_size,
rdc_diag_test_result_t* result, rdc_diag_callback_t* callback) override;
rdc_status_t rdc_diagnostic_run(const rdc_group_info_t& gpus, rdc_diag_level_t level,
const char* config, size_t config_size,
rdc_diag_response_t* response, rdc_diag_callback_t* callback) override;
rdc_status_t rdc_diag_init(uint64_t flags) override;
rdc_status_t rdc_diag_destroy() override;
RdcRVSLib();
~RdcRVSLib() override;
private:
RdcLibraryLoader lib_loader_;
rdc_status_t (*test_case_run_)(rdc_diag_test_cases_t, uint32_t[RDC_MAX_NUM_DEVICES], uint32_t,
const char* config, size_t config_size, rdc_diag_test_result_t*,
rdc_diag_callback_t*);
rdc_status_t (*diag_test_cases_query_)(rdc_diag_test_cases_t[MAX_TEST_CASES], uint32_t*);
rdc_status_t (*diag_init_)(uint64_t);
rdc_status_t (*diag_destroy_)();
};
typedef std::shared_ptr<RdcRVSLib> RdcRVSLibPtr;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_RDCRVSLIB_H_
@@ -0,0 +1,76 @@
/*
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 INCLUDE_RDC_LIB_IMPL_RDCROCPLIB_H_
#define INCLUDE_RDC_LIB_IMPL_RDCROCPLIB_H_
#include <cstdint>
#include <memory>
#include <vector>
#include "rdc_lib/RdcLibraryLoader.h"
#include "rdc_lib/RdcTelemetry.h"
namespace amd {
namespace rdc {
class RdcRocpLib : public RdcTelemetry {
public:
/* Telemetry */
// get support field ids
rdc_status_t rdc_telemetry_fields_query(uint32_t field_ids[MAX_NUM_FIELDS],
uint32_t* field_count) override;
// Fetch
rdc_status_t rdc_telemetry_fields_value_get(rdc_gpu_field_t* fields, uint32_t fields_count,
rdc_field_value_f callback, void* user_data) override;
rdc_status_t rdc_telemetry_fields_watch(rdc_gpu_field_t* fields, uint32_t fields_count) override;
rdc_status_t rdc_telemetry_fields_unwatch(rdc_gpu_field_t* fields,
uint32_t fields_count) override;
RdcRocpLib();
~RdcRocpLib();
private:
RdcLibraryLoader lib_loader_;
rdc_status_t (*telemetry_fields_query_)(uint32_t field_ids[MAX_NUM_FIELDS],
uint32_t* field_count);
rdc_status_t (*telemetry_fields_value_get_)(rdc_gpu_field_t* fields, uint32_t fields_count,
rdc_field_value_f callback, void* user_data);
rdc_status_t (*telemetry_fields_watch_)(rdc_gpu_field_t* fields, uint32_t fields_count);
rdc_status_t (*telemetry_fields_unwatch_)(rdc_gpu_field_t* fields, uint32_t fields_count);
rdc_status_t (*rdc_module_init_)(uint64_t);
rdc_status_t (*rdc_module_destroy_)();
/**
* @brief Make sure HSA_TOOLS_LIB is not set as it breaks rocprofiler-sdk
* @details
* Rocprofilerv1 needed HSA_TOOLS_LIB set to librocprofiler64.so.1.
* That breaks rocprofiler-sdk because it tries to load both v1 and sdk libraries.
*/
void rdc_unset_hsa_tools_lib();
};
using RdcRocpLibPtr = std::shared_ptr<RdcRocpLib>;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_RDCROCPLIB_H_
@@ -0,0 +1,70 @@
/*
Copyright (c) 2021 - 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 INCLUDE_RDC_LIB_IMPL_RDCROCRLIB_H_
#define INCLUDE_RDC_LIB_IMPL_RDCROCRLIB_H_
#include <memory>
#include <vector>
#include "rdc_lib/RdcDiagnostic.h"
#include "rdc_lib/RdcLibraryLoader.h"
namespace amd {
namespace rdc {
class RdcRocrLib : public RdcDiagnostic {
public:
rdc_status_t rdc_diag_test_cases_query(rdc_diag_test_cases_t test_cases[MAX_TEST_CASES],
uint32_t* test_case_count) override;
// Run a specific test case
rdc_status_t rdc_test_case_run(rdc_diag_test_cases_t test_case,
uint32_t gpu_index[RDC_MAX_NUM_DEVICES], uint32_t gpu_count,
const char* config, size_t config_size,
rdc_diag_test_result_t* result, rdc_diag_callback_t* callback) override;
rdc_status_t rdc_diagnostic_run(const rdc_group_info_t& gpus, rdc_diag_level_t level,
const char* config, size_t config_size,
rdc_diag_response_t* response, rdc_diag_callback_t* callback) override;
rdc_status_t rdc_diag_init(uint64_t flags) override;
rdc_status_t rdc_diag_destroy() override;
RdcRocrLib();
~RdcRocrLib();
private:
RdcLibraryLoader lib_loader_;
rdc_status_t (*test_case_run_)(rdc_diag_test_cases_t, uint32_t[RDC_MAX_NUM_DEVICES], uint32_t,
const char*, size_t, rdc_diag_test_result_t*, rdc_diag_callback_t*);
rdc_status_t (*diag_test_cases_query_)(rdc_diag_test_cases_t[MAX_TEST_CASES], uint32_t*);
rdc_status_t (*diag_init_)(uint64_t);
rdc_status_t (*diag_destroy_)();
};
typedef std::shared_ptr<RdcRocrLib> RdcRocrLibPtr;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_RDCROCRLIB_H_
@@ -0,0 +1,60 @@
/*
Copyright (c) 2021 - 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 INCLUDE_RDC_LIB_IMPL_RDCSMIDIAGNOSTICIMPL_H_
#define INCLUDE_RDC_LIB_IMPL_RDCSMIDIAGNOSTICIMPL_H_
#include <memory>
#include <string>
#include "amd_smi/amdsmi.h"
#include "rdc/rdc.h"
namespace amd {
namespace rdc {
class RdcSmiDiagnosticImpl {
public:
RdcSmiDiagnosticImpl();
rdc_status_t check_smi_process_info(uint32_t gpu_index[RDC_MAX_NUM_DEVICES], uint32_t gpu_count,
rdc_diag_test_result_t* result);
rdc_status_t check_smi_topo_info(uint32_t gpu_index[RDC_MAX_NUM_DEVICES], uint32_t gpu_count,
rdc_diag_test_result_t* result);
rdc_status_t check_smi_param_info(uint32_t gpu_index[RDC_MAX_NUM_DEVICES], uint32_t gpu_count,
rdc_diag_test_result_t* result);
private:
rdc_diag_result_t check_temperature_level(uint32_t gpu_index, amdsmi_temperature_type_t type,
char msg[MAX_DIAG_MSG_LENGTH],
char per_gpu_msg[MAX_DIAG_MSG_LENGTH]);
std::string get_temperature_string(amdsmi_temperature_type_t type) const;
rdc_diag_result_t check_voltage_level(uint32_t gpu_index, amdsmi_voltage_type_t type,
char msg[MAX_DIAG_MSG_LENGTH],
char per_gpu_msg[MAX_DIAG_MSG_LENGTH]);
std::string get_voltage_string(amdsmi_voltage_type_t type) const;
};
typedef std::shared_ptr<RdcSmiDiagnosticImpl> RdcSmiDiagnosticPtr;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_RDCSMIDIAGNOSTICIMPL_H_
@@ -0,0 +1,78 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_IMPL_RDCSMILIB_H_
#define INCLUDE_RDC_LIB_IMPL_RDCSMILIB_H_
#include <memory>
#include "rdc_lib/RdcDiagnostic.h"
#include "rdc_lib/RdcMetricFetcher.h"
#include "rdc_lib/RdcTelemetry.h"
#include "rdc_lib/impl/RdcSmiDiagnosticImpl.h"
namespace amd {
namespace rdc {
class RdcSmiLib : public RdcTelemetry, public RdcDiagnostic {
public:
// get support field ids
rdc_status_t rdc_telemetry_fields_query(uint32_t field_ids[MAX_NUM_FIELDS],
uint32_t* field_count) override;
// Fetch
rdc_status_t rdc_telemetry_fields_value_get(rdc_gpu_field_t* fields, uint32_t fields_count,
rdc_field_value_f callback, void* user_data) override;
rdc_status_t rdc_telemetry_fields_watch(rdc_gpu_field_t* fields, uint32_t fields_count) override;
rdc_status_t rdc_telemetry_fields_unwatch(rdc_gpu_field_t* fields,
uint32_t fields_count) override;
rdc_status_t rdc_diag_test_cases_query(rdc_diag_test_cases_t test_cases[MAX_TEST_CASES],
uint32_t* test_case_count) override;
// Run a specific test case
rdc_status_t rdc_test_case_run(rdc_diag_test_cases_t test_case,
uint32_t gpu_index[RDC_MAX_NUM_DEVICES], uint32_t gpu_count,
const char* config, size_t config_size,
rdc_diag_test_result_t* result, rdc_diag_callback_t* callback) override;
rdc_status_t rdc_diagnostic_run(const rdc_group_info_t& gpus, rdc_diag_level_t level,
const char* config, size_t config_size,
rdc_diag_response_t* response, rdc_diag_callback_t* callback) override;
rdc_status_t rdc_diag_init(uint64_t flags) override;
rdc_status_t rdc_diag_destroy() override;
explicit RdcSmiLib(const RdcMetricFetcherPtr& mf);
private:
RdcMetricFetcherPtr metric_fetcher_;
bool bulk_fetch_enabled_;
RdcSmiDiagnosticPtr smi_diag_;
};
typedef std::shared_ptr<RdcSmiLib> RdcSmiLibPtr;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_RDCSMILIB_H_
@@ -0,0 +1,166 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_IMPL_RDCSTANDALONEHANDLER_H_
#define INCLUDE_RDC_LIB_IMPL_RDCSTANDALONEHANDLER_H_
#include <grpcpp/grpcpp.h>
#include <future>
#include <memory>
#include <thread>
#include "rdc.grpc.pb.h" // NOLINT
#include "rdc/rdc.h"
#include "rdc_lib/RdcHandler.h"
namespace amd {
namespace rdc {
class RdcStandaloneHandler : public RdcHandler {
public:
// Job RdcAPI
rdc_status_t rdc_job_start_stats(rdc_gpu_group_t groupId, const char job_id[64],
uint64_t update_freq) override;
rdc_status_t rdc_job_get_stats(const char jobId[64], rdc_job_info_t* p_job_info) override;
rdc_status_t rdc_job_stop_stats(const char job_id[64]) override;
rdc_status_t rdc_job_remove(const char job_id[64]) override;
rdc_status_t rdc_job_remove_all() override;
// Discovery RdcAPI
rdc_status_t rdc_device_get_all(uint32_t gpu_index_list[RDC_MAX_NUM_DEVICES],
uint32_t* count) override;
rdc_status_t rdc_device_get_attributes(uint32_t gpu_index,
rdc_device_attributes_t* p_rdc_attr) override;
rdc_status_t rdc_device_get_component_version(rdc_component_t component,
rdc_component_version_t* p_rdc_compv) override;
// Group RdcAPI
rdc_status_t rdc_group_gpu_create(rdc_group_type_t type, const char* group_name,
rdc_gpu_group_t* p_rdc_group_id) override;
rdc_status_t rdc_group_gpu_add(rdc_gpu_group_t groupId, uint32_t gpu_index) override;
rdc_status_t rdc_group_field_create(uint32_t num_field_ids, rdc_field_t* field_ids,
const char* field_group_name,
rdc_field_grp_t* rdc_field_group_id) override;
rdc_status_t rdc_group_field_get_info(rdc_field_grp_t rdc_field_group_id,
rdc_field_group_info_t* field_group_info) override;
rdc_status_t rdc_group_gpu_get_info(rdc_gpu_group_t p_rdc_group_id,
rdc_group_info_t* p_rdc_group_info) override;
rdc_status_t rdc_group_get_all_ids(rdc_gpu_group_t group_id_list[], uint32_t* count) override;
rdc_status_t rdc_group_field_get_all_ids(rdc_field_grp_t field_group_id_list[],
uint32_t* count) override;
rdc_status_t rdc_group_gpu_destroy(rdc_gpu_group_t p_rdc_group_id) override;
rdc_status_t rdc_group_field_destroy(rdc_field_grp_t rdc_field_group_id) override;
// Field RdcAPI
rdc_status_t rdc_field_watch(rdc_gpu_group_t group_id, rdc_field_grp_t field_group_id,
uint64_t update_freq, double max_keep_age,
uint32_t max_keep_samples) override;
rdc_status_t rdc_field_get_latest_value(uint32_t gpu_index, rdc_field_t field,
rdc_field_value* value) override;
rdc_status_t rdc_field_get_value_since(uint32_t gpu_index, rdc_field_t field,
uint64_t since_time_stamp, uint64_t* next_since_time_stamp,
rdc_field_value* value) override;
rdc_status_t rdc_field_unwatch(rdc_gpu_group_t group_id, rdc_field_grp_t field_group_id) override;
// Diagnostic API
rdc_status_t rdc_diagnostic_run(rdc_gpu_group_t group_id, rdc_diag_level_t level,
const char* config, size_t config_size,
rdc_diag_response_t* response,
rdc_diag_callback_t* callback) override;
rdc_status_t rdc_test_case_run(rdc_gpu_group_t group_id, rdc_diag_test_cases_t test_case,
const char* config, size_t config_size,
rdc_diag_test_result_t* result,
rdc_diag_callback_t* callback) override;
// Control RdcAPI
rdc_status_t rdc_field_update_all(uint32_t wait_for_update) override;
// Set one configure
rdc_status_t rdc_config_set(rdc_gpu_group_t group_id, rdc_config_setting_t setting) override;
// Get the setting
rdc_status_t rdc_config_get(rdc_gpu_group_t group_id,
rdc_config_setting_list_t* settings) override;
// Clear the setting
rdc_status_t rdc_config_clear(rdc_gpu_group_t group_id) override;
// It is just a client interface under the GRPC framework and is not used as an RDC API.
// Pure virtual functions need to be overridden
rdc_status_t get_mixed_component_version(mixed_component_t component,
mixed_component_version_t* p_mixed_compv) override;
// Policy API
rdc_status_t rdc_policy_set(rdc_gpu_group_t group_id, rdc_policy_t policy) override;
rdc_status_t rdc_policy_get(rdc_gpu_group_t group_id, uint32_t* count,
rdc_policy_t policies[RDC_MAX_POLICY_SETTINGS]) override;
rdc_status_t rdc_policy_delete(rdc_gpu_group_t group_id,
rdc_policy_condition_type_t condition_type) override;
rdc_status_t rdc_policy_register(rdc_gpu_group_t group_id,
rdc_policy_register_callback callback) override;
rdc_status_t rdc_policy_unregister(rdc_gpu_group_t group_id) override;
// Health API
rdc_status_t rdc_health_set(rdc_gpu_group_t group_id, unsigned int components) override;
rdc_status_t rdc_health_get(rdc_gpu_group_t group_id, unsigned int* components) override;
rdc_status_t rdc_health_check(rdc_gpu_group_t group_id, rdc_health_response_t* response) override;
rdc_status_t rdc_health_clear(rdc_gpu_group_t group_id) override;
rdc_status_t rdc_device_topology_get(uint32_t gpu_index, rdc_device_topology_t* results) override;
rdc_status_t rdc_link_status_get(rdc_link_status_t* results) override;
rdc_status_t rdc_get_num_partition(uint32_t index, uint16_t* num_partition) override;
rdc_status_t rdc_instance_profile_get(uint32_t entity_index,
rdc_instance_resource_type_t resource_type,
rdc_resource_profile_t* profile) override;
explicit RdcStandaloneHandler(const char* ip_and_port, const char* root_ca,
const char* client_cert, const char* client_key);
private:
// Helper function to handle the error
rdc_status_t error_handle(::grpc::Status status, uint32_t rdc_status);
bool copy_gpu_usage_info(const ::rdc::GpuUsageInfo& src, rdc_gpu_usage_info_t* target);
std::unique_ptr<::rdc::RdcAPI::Stub> stub_;
// thread for policy callback
struct policy_thread_context {
bool start;
std::thread* t;
};
std::map<uint32_t, struct policy_thread_context> policy_threads_;
};
} // namespace rdc
} // namespace amd
extern "C" {
amd::rdc::RdcHandler* make_handler(const char* ip_port, const char* root_ca,
const char* client_cert, const char* client_key);
}
#endif // INCLUDE_RDC_LIB_IMPL_RDCSTANDALONEHANDLER_H_
@@ -0,0 +1,66 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_IMPL_RDCTELEMETRYMODULE_H_
#define INCLUDE_RDC_LIB_IMPL_RDCTELEMETRYMODULE_H_
#include <list>
#include <map>
#include <memory>
#include <vector>
#include "rdc_lib/RdcMetricFetcher.h"
#include "rdc_lib/RdcTelemetry.h"
#include "rdc_lib/impl/RdcSmiLib.h"
namespace amd {
namespace rdc {
class RdcTelemetryModule : public RdcTelemetry {
public:
rdc_status_t rdc_telemetry_fields_value_get(rdc_gpu_field_t* fields, uint32_t fields_count,
rdc_field_value_f callback, void* user_data);
rdc_status_t rdc_telemetry_fields_query(uint32_t field_ids[MAX_NUM_FIELDS],
uint32_t* field_count);
rdc_status_t rdc_telemetry_fields_watch(rdc_gpu_field_t* fields, uint32_t fields_count);
rdc_status_t rdc_telemetry_fields_unwatch(rdc_gpu_field_t* fields, uint32_t fields_count);
explicit RdcTelemetryModule(std::list<RdcTelemetryPtr> telemetry_modules);
private:
//< Helper function to dispatch fields to module
void get_fields_for_module(
rdc_gpu_field_t* fields, uint32_t fields_count,
std::map<RdcTelemetryPtr, std::vector<rdc_gpu_field_t>>& fields_in_module,
std::vector<rdc_gpu_field_value_t>& unsupport_fields); // NOLINT
std::list<RdcTelemetryPtr> telemetry_modules_;
std::map<uint32_t, RdcTelemetryPtr> fields_id_module_;
};
typedef std::shared_ptr<RdcTelemetryModule> RdcTelemetryModulePtr;
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_RDCTELEMETRYMODULE_H_
@@ -0,0 +1,60 @@
/*
Copyright (c) 2024 - 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 INCLUDE_RDC_LIB_IMPL_RDCTOPOLINKYIMPL_H_
#define INCLUDE_RDC_LIB_IMPL_RDCTOPOLINKYIMPL_H_
#include <atomic>
#include <future>
#include <map>
#include <memory>
#include <mutex> // NOLINT
#include <string>
#include <utility>
#include <vector>
#include "amd_smi/amdsmi.h"
#include "rdc_lib/RdcGroupSettings.h"
#include "rdc_lib/RdcMetricFetcher.h"
#include "rdc_lib/RdcTopologyLink.h"
namespace amd {
namespace rdc {
class RdcTopologyLinkImpl : public RdcTopologyLink {
public:
RdcTopologyLinkImpl(const RdcGroupSettingsPtr& group_settings,
RdcMetricFetcherPtr metric_fetcher);
~RdcTopologyLinkImpl();
rdc_status_t rdc_device_topology_get(uint32_t gpu_index, rdc_device_topology_t* results) override;
rdc_status_t rdc_link_status_get(rdc_link_status_t* results) override;
private:
RdcGroupSettingsPtr group_settings_;
RdcMetricFetcherPtr metric_fetcher_;
};
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_RDCTOPOLINKYIMPL_H_
@@ -0,0 +1,185 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_IMPL_RDCWATCHTABLEIMPL_H_
#define INCLUDE_RDC_LIB_IMPL_RDCWATCHTABLEIMPL_H_
#include <atomic>
#include <map>
#include <memory>
#include <mutex> // NOLINT
#include <string>
#include <utility>
#include <vector>
#include "amd_smi/amdsmi.h"
#include "rdc_lib/RdcCacheManager.h"
#include "rdc_lib/RdcGroupSettings.h"
#include "rdc_lib/RdcMetricFetcher.h"
#include "rdc_lib/RdcModuleMgr.h"
#include "rdc_lib/RdcNotification.h"
#include "rdc_lib/RdcWatchTable.h"
namespace amd {
namespace rdc {
//!< The settings for a field or a group of field in the watch table.
struct FieldSettings {
uint64_t update_freq;
uint32_t max_keep_samples;
double max_keep_age;
bool is_watching;
uint64_t last_update_time;
};
struct JobWatchTableEntry {
uint32_t group_id;
std::vector<RdcFieldKey> fields; //< store fields for faster query
};
struct HealthWatchTableEntry {
unsigned int components;
rdc_field_grp_t field_group_id;
std::vector<RdcFieldKey> fields; //< store fields for faster query
};
class RdcWatchTableImpl : public RdcWatchTable {
public:
rdc_status_t rdc_job_start_stats(rdc_gpu_group_t group_id, const char job_id[64],
uint64_t update_freq,
const rdc_gpu_gauges_t& gpu_gauge) override;
rdc_status_t rdc_job_stop_stats(const char job_id[64],
const rdc_gpu_gauges_t& gpu_gauge) override;
rdc_status_t rdc_job_remove(const char job_id[64]) override;
rdc_status_t rdc_job_remove_all() override;
rdc_status_t rdc_field_watch(rdc_gpu_group_t group_id, rdc_field_grp_t field_group_id,
uint64_t update_freq, double max_keep_age,
uint32_t max_keep_samples) override;
//!< rdc_field_unwatch() will not remove the entry from watch_table.
//!< The unwatched entry is still kept until the max_keep_age of the entry
//!< is reached, which will be handled in the clean_up() function.
rdc_status_t rdc_field_unwatch(rdc_gpu_group_t group_id, rdc_field_grp_t field_group_id) override;
rdc_status_t rdc_health_set(rdc_gpu_group_t group_id, unsigned int components) override;
rdc_status_t rdc_health_get(rdc_gpu_group_t group_id, unsigned int* components) override;
rdc_status_t rdc_health_check(rdc_gpu_group_t group_id, rdc_health_response_t *response) override;
rdc_status_t rdc_health_clear(rdc_gpu_group_t group_id) override;
//!< When the RDC is running as RDC_OPERATION_MODE_MANUAL, the user will
//!< call this function periodically. Instead of providing other APIs to
//!< cleanup the cache, this function will update and cleanup the cache.
//!<
//!< This function may be called very frequently, and the cache cleanup
//!< is expensive. Internally, this function will throttle the cleanup to
//!< once per second.
rdc_status_t rdc_field_update_all() override;
rdc_status_t rdc_field_listen_notif(uint32_t timeout_ms) override;
RdcWatchTableImpl(const RdcGroupSettingsPtr& group_settings, const RdcCacheManagerPtr& cache_mgr,
const RdcMetricFetcherPtr& metric_fetcher, const RdcModuleMgrPtr& module_mgr,
const RdcNotificationPtr& notif);
private:
//!< Helper function to Update the fields_in_table when unwatch tables
rdc_status_t update_field_in_table_when_unwatch(const RdcFieldGroupKey& entry);
//!< Helper function to clean up the watch table and cache
void clean_up();
//!< Helper function for debug information in watch table and cache
void debug_status();
//!< Helper function to get the fields using the group and the field group.
rdc_status_t get_fields_from_group(rdc_gpu_group_t group_id, rdc_field_grp_t field_group_id,
std::vector<RdcFieldKey>& fields); // NOLINT
bool is_job_watch_field(uint32_t gpu_index, rdc_field_t field_id,
std::string& job_id) const; // NOLINT
bool is_health_watch_field(uint32_t gpu_index, rdc_field_t field_id,
rdc_gpu_group_t& group_id) const;
rdc_status_t rdc_notif_update_cache(rdc_evnt_notification_t* events, uint32_t num_events);
//!< The function will be pass as the callback for bulk fetch
static rdc_status_t handle_fields(rdc_gpu_field_value_t* values, uint32_t num_values,
void* user_data);
rdc_status_t create_health_field_group(unsigned int components,
rdc_field_grp_t* field_group_id);
//!< output: Whether health incidents are full
bool add_health_incident(uint32_t gpu_index,
rdc_health_system_t component,
rdc_health_result_t health,
uint32_t err_code,
std::string err_msg,
rdc_health_incidents_t* incident,
rdc_health_response_t* response);
rdc_status_t get_start_end_values(rdc_gpu_group_t group_id,
uint32_t gpu_index,
rdc_field_t field,
uint64_t start_timestamp,
rdc_field_value *start_value,
rdc_field_value *end_value);
rdc_status_t pcie_check(rdc_gpu_group_t group_id,
uint32_t gpu_index, rdc_health_response_t* response);
rdc_status_t xgmi_check(rdc_gpu_group_t group_id,
uint32_t gpu_index, rdc_health_response_t* response);
rdc_status_t memory_check(rdc_gpu_group_t group_id,
uint32_t gpu_index, rdc_health_response_t* response);
rdc_status_t eeprom_check(rdc_gpu_group_t group_id,
uint32_t gpu_index, rdc_health_response_t* response);
rdc_status_t thermal_check(rdc_gpu_group_t group_id,
uint32_t gpu_index, rdc_health_response_t* response);
rdc_status_t power_check(rdc_gpu_group_t group_id,
uint32_t gpu_index, rdc_health_response_t* response);
RdcGroupSettingsPtr group_settings_;
RdcCacheManagerPtr cache_mgr_;
RdcMetricFetcherPtr metric_fetcher_;
RdcModuleMgrPtr rdc_module_mgr_;
RdcNotificationPtr notifications_;
//!< The watch table to store the watch settings.
std::map<RdcFieldGroupKey, FieldSettings> watch_table_;
//!< <job_id, gpu_group_id> pairs
std::map<std::string, JobWatchTableEntry> job_watch_table_;
//!< The settings for each field can be deduced from watch_table. But every
//!< rdc_field_update_all() call needs to deduce them. To improve the
//!< performance, the fields_to_watch_ is used to track the field settings.
//!< Those settings will only be updated when watching or unwatching.
std::map<RdcFieldKey, FieldSettings> fields_to_watch_;
//!< The health watch table to store the health settings.
std::map<uint32_t, HealthWatchTableEntry> health_watch_table_;
//!< The last clean up time
std::atomic<uint64_t> last_cleanup_time_;
std::mutex watch_mutex_;
};
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_RDCWATCHTABLEIMPL_H_
@@ -0,0 +1,50 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_IMPL_RSMIUTILS_H_
#define INCLUDE_RDC_LIB_IMPL_RSMIUTILS_H_
#include <vector>
#include "amd_smi/amdsmi.h"
#include "rdc/rdc.h"
namespace amd {
namespace rdc {
rdc_status_t Smi2RdcError(amdsmi_status_t rsmi);
amdsmi_status_t get_processor_handle_from_id(uint32_t gpu_id,
amdsmi_processor_handle* processor_handle);
amdsmi_status_t get_gpu_id_from_processor_handle(amdsmi_processor_handle processor_handle,
uint32_t* gpu_index);
amdsmi_status_t get_processor_count(uint32_t& all_processor_count);
amdsmi_status_t get_socket_handles(std::vector<amdsmi_socket_handle>& sockets);
amdsmi_status_t get_processor_handles(amdsmi_socket_handle socket,
std::vector<amdsmi_processor_handle>& processors);
amdsmi_status_t get_kfd_partition_id(amdsmi_processor_handle proc, uint32_t* partition_id);
amdsmi_status_t get_metrics_info(amdsmi_processor_handle proc, amdsmi_gpu_metrics_t* metrics);
amdsmi_status_t get_num_partition(uint32_t index, uint16_t* num_partition);
} // namespace rdc
} // namespace amd
#endif // INCLUDE_RDC_LIB_IMPL_RSMIUTILS_H_
+56
View File
@@ -0,0 +1,56 @@
/*
Copyright (c) 2020 - 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 INCLUDE_RDC_LIB_RDC_COMMON_H_
#define INCLUDE_RDC_LIB_RDC_COMMON_H_
#include <iostream>
#include <map>
#include <utility>
#include "rdc/rdc.h"
//<! The key to identify the field with <gpu_id, field_id>
typedef std::pair<uint32_t, rdc_field_t> RdcFieldKey;
//<! The key to identify the field with <gpu_id, field_group_id>
typedef std::pair<uint32_t, uint32_t> RdcFieldGroupKey;
//!< The gauge metrics do not require aggregations
typedef std::map<RdcFieldKey, uint64_t> rdc_gpu_gauges_t;
/**
* @brief The strncpy but with null terminated
*
* @details It will copy at most n-1 bytes from src to dst, and
* always adds a null terminator following the bytes copied to dst.
*
* @param[out] dest The destination string to copy
*
* @param[in] src The source string to be copied
*
* @param[in] n At most n-1 bytes will be copied
*
* @retval Return a pointer to the destination string.
*/
char* strncpy_with_null(char* dest, const char* src, size_t n);
#endif // INCLUDE_RDC_LIB_RDC_COMMON_H_
@@ -0,0 +1,127 @@
/*
* =============================================================================
* ROC Runtime Conformance Release License
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2017, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
*
* AMD Research and AMD ROC Software Development
*
* Advanced Micro Devices, Inc.
*
* www.amd.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal with 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:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimers in
* the documentation and/or other materials provided with the distribution.
* - Neither the names of <Name of Development Group, Name of Institution>,
* nor the names of its contributors may be used to endorse or promote
* products derived from this Software without specific prior written
* permission.
*
* 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 CONTRIBUTORS 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 WITH THE SOFTWARE.
*
*/
/**
* One instance of this kernel call is a thread.
* Each thread finds out the segment in which it should look for the element.
* After that, it checks if the element is between the lower bound and upper
* bound of its segment. If yes, then this segment becomes the total
* searchspace for the next pass.
*
* To achieve this, it writes the lower bound and upper bound to the output
* array. In case the element at the left end (lower bound) matches the element
* we are looking for, that is marked in the output and we no longer need to
* look any further.
*/
__kernel void
binarySearch(__global uint4 * outputArray,
__const __global uint2 * sortedArray,
const unsigned int findMe) {
unsigned int tid = get_global_id(0);
// Then we find the elements for this thread
uint2 element = sortedArray[tid];
// If the element to be found does not lie between
// them, then nothing left to do in this thread
if((element.x > findMe) || (element.y < findMe)) {
return;
} else {
// However, if the element does lie between the lower
// and upper bounds of this thread's searchspace
// we need to narrow down the search further in this
// search space
// The search space for this thread is marked in the
// output as being the total search space for the next pass
outputArray[0].x = tid;
outputArray[0].w = 1;
}
}
__kernel void
binarySearch_mulkeys(__global int *keys,
__global uint *input,
const unsigned int numKeys,
__global int *output) {
int gid = get_global_id(0);
int lBound = gid * 256;
int uBound = lBound + 255;
for(int i = 0; i < numKeys; i++) {
if(keys[i] >= input[lBound] && keys[i] <= input[uBound])
output[i]=lBound;
}
}
__kernel void
binarySearch_mulkeysConcurrent(__global uint *keys,
__global uint *input,
const unsigned int inputSize, // num. of inputs
const unsigned int numSubdivisions,
__global int *output) {
int lBound = (get_global_id(0) % numSubdivisions) * (inputSize / numSubdivisions);
int uBound = lBound + inputSize / numSubdivisions;
int myKey = keys[get_global_id(0) / numSubdivisions];
int mid;
while(uBound >= lBound) {
mid = (lBound + uBound) / 2;
if(input[mid] == myKey) {
output[get_global_id(0) / numSubdivisions] = mid;
return;
} else if(input[mid] > myKey) {
uBound = mid - 1;
} else {
lBound = mid + 1;
}
}
}
@@ -0,0 +1,110 @@
/*
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_
#include <rocprofiler-sdk/agent.h>
#include <cstdint>
#include <map>
#include <unordered_set>
#include <utility>
#include <vector>
#include "rdc/rdc.h"
#include "rdc_lib/RdcTelemetryLibInterface.h"
#include "rdc_modules/rdc_rocp/RdcRocpCounterSampler.h"
namespace amd {
namespace rdc {
/// Common interface for RocP tests and samples
class RdcRocpBase {
public:
RdcRocpBase();
RdcRocpBase(const RdcRocpBase&) = default;
RdcRocpBase(RdcRocpBase&&) = delete;
RdcRocpBase& operator=(const RdcRocpBase&) = delete;
RdcRocpBase& operator=(RdcRocpBase&&) = delete;
~RdcRocpBase();
/**
* @brief Lookup ROCProfiler counter
*
* @param[in] gpu_field GPU_ID and FIELD_ID of requested metric
* @param[out] value A pointer that will be populated with returned value
*
* @retval ::ROCMTOOLS_STATUS_SUCCESS The function has been executed
* successfully.
*/
rdc_status_t rocp_lookup(rdc_gpu_field_t gpu_field, rdc_field_value_data* value,
rdc_field_type_t* type);
const char* get_field_id_from_name(rdc_field_t);
const std::vector<rdc_field_t> get_field_ids();
protected:
private:
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;
/**
* @brief By default all profiler values are read as doubles
*/
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();
void init_rocp_if_not();
std::vector<rocprofiler_agent_v0_t> agents = {};
std::vector<std::shared_ptr<CounterSampler>> samplers = {};
std::map<rdc_field_t, const char*> field_to_metric = {};
std::map<uint32_t, uint32_t> entity_to_prof_map = {};
bool m_is_initialized = false;
// these fields must be divided by time passed
std::unordered_set<rdc_field_t> eval_fields = {
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,
};
/**
* @brief Convert from profiler status into RDC status
*/
rdc_status_t Rocp2RdcError(rocprofiler_status_t status);
};
} // namespace rdc
} // namespace amd
#endif // RDC_MODULES_RDC_ROCP_RDCROCPBASE_H_
@@ -0,0 +1,91 @@
// MIT License
//
// Copyright (c) 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.
#ifndef RDC_MODULES_RDC_ROCP_RDCROCPCOUNTERSAMPLER_H_
#define RDC_MODULES_RDC_ROCP_RDCROCPCOUNTERSAMPLER_H_
#include <rocprofiler-sdk/fwd.h>
#include <rocprofiler-sdk/registration.h>
#include <rocprofiler-sdk/rocprofiler.h>
#include <map>
#include <memory>
#include <unordered_map>
#include <vector>
namespace amd {
namespace rdc {
class CounterSampler {
public:
// Setup system profiling for an agent
explicit CounterSampler(rocprofiler_agent_id_t agent);
~CounterSampler();
// Decode the counter name of a record
const std::string& decode_record_name(const rocprofiler_record_counter_t& rec) const;
// Get the dimensions of a record (what CU/SE/etc the counter is for). High cost operation
// should be cached if possible.
std::unordered_map<std::string, size_t> get_record_dimensions(
const rocprofiler_record_counter_t& rec);
// Sample the counter values for a set of counters, returns the records in the out parameter.
void sample_counter_values(const std::vector<std::string>& counters,
std::vector<rocprofiler_record_counter_t>& out, uint64_t duration);
rocprofiler_agent_id_t get_agent() const { return agent_; }
// Get the supported counters for an agent
static std::unordered_map<std::string, rocprofiler_counter_id_t> get_supported_counters(
rocprofiler_agent_id_t agent);
// Get the available agents on the system
static std::vector<rocprofiler_agent_v0_t> get_available_agents();
static std::vector<std::shared_ptr<CounterSampler>>& get_samplers();
private:
rocprofiler_agent_id_t agent_ = {};
rocprofiler_context_id_t ctx_ = {};
rocprofiler_counter_config_id_t counter_ = {.handle = 0};
std::map<std::vector<std::string>, rocprofiler_counter_config_id_t> cached_counter_;
std::map<uint64_t, uint64_t> counter_sizes_;
// Internal function used to set the profile for the agent when start_context is called
void set_profile(rocprofiler_context_id_t ctx, rocprofiler_device_counting_agent_cb_t cb) const;
// Get the size of a counter in number of records
size_t get_counter_size(rocprofiler_counter_id_t counter);
// Get the dimensions of a counter
std::vector<rocprofiler_record_dimension_info_t> get_counter_dimensions(
rocprofiler_counter_id_t counter);
static std::vector<std::shared_ptr<CounterSampler>> samplers_;
};
} // namespace rdc
} // namespace amd
#endif // RDC_MODULES_RDC_ROCP_RDCROCPCOUNTERSAMPLER_H_
@@ -0,0 +1,114 @@
/*
Copyright (c) 2021 - 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_ROCR_COMPUTEQUEUETEST_H_
#define RDC_MODULES_RDC_ROCR_COMPUTEQUEUETEST_H_
#include "hsa/hsa.h"
#include "rdc_modules/rdc_rocr/TestBase.h"
namespace amd {
namespace rdc {
// Hold all the info specific to binary search
typedef struct BinarySearch {
// Binary Search parameters
uint32_t length;
uint32_t work_group_size;
uint32_t work_grid_size;
uint32_t num_sub_divisions;
uint32_t find_me;
// Buffers needed for this application
uint32_t* input;
uint32_t* input_arr;
uint32_t* input_arr_local;
uint32_t* output;
// Keneral argument buffers and addresses
void* kern_arg_buffer; // Begin of allocated memory
// this pointer to be deallocated
void* kern_arg_address; // Properly aligned address to be used in aql
// packet (don't use for deallocation)
// Kernel code
std::string kernel_file_name;
std::string kernel_name;
uint32_t kernarg_size;
uint32_t kernarg_align;
// HSA/RocR objects needed for this application
hsa_agent_t gpu_dev;
hsa_agent_t cpu_dev;
hsa_signal_t signal;
hsa_queue_t* queue;
hsa_amd_memory_pool_t cpu_pool;
hsa_amd_memory_pool_t gpu_pool;
hsa_amd_memory_pool_t kern_arg_pool;
// Other items we need to populate AQL packet
uint64_t kernel_object;
uint32_t group_segment_size; ///< Kernel group seg size
uint32_t private_segment_size; ///< Kernel private seg size
} BinarySearch;
class ComputeQueueTest : public TestBase {
public:
explicit ComputeQueueTest(uint32_t gpu_index);
// @Brief: Destructor for test case of ComputeQueueTest
virtual ~ComputeQueueTest();
// @Brief: Setup the environment for measurement
virtual hsa_status_t SetUp();
// @Brief: Core measurement execution
virtual void Run();
// @Brief: Clean up and retrive the resource
virtual void Close();
// @Brief: Display results
virtual void DisplayResults() const;
// @Brief: Display information about what this test does
virtual void DisplayTestInfo(void);
hsa_status_t RunBinarySearchTest(void);
private:
void InitializeBinarySearch(BinarySearch* bs);
hsa_status_t FindPools(BinarySearch* bs);
hsa_status_t AllocateAndInitBuffers(BinarySearch* bs);
hsa_status_t LoadKernelFromObjFile(BinarySearch* bs);
hsa_status_t Run(BinarySearch* bs);
hsa_status_t CleanUp(BinarySearch* bs);
void PopulateAQLPacket(BinarySearch const* bs, hsa_kernel_dispatch_packet_t* aql);
hsa_status_t AgentMemcpy(void* dst, const void* src, size_t size, hsa_agent_t dst_ag,
hsa_agent_t src_ag);
hsa_status_t AllocAndSetKernArgs(BinarySearch* bs, void* args, size_t arg_size,
void** aql_buf_ptr);
void WriteAQLToQueue(hsa_kernel_dispatch_packet_t const* in_aql, hsa_queue_t* q);
};
} // namespace rdc
} // namespace amd
#endif // RDC_MODULES_RDC_ROCR_COMPUTEQUEUETEST_H_
@@ -0,0 +1,68 @@
/*
Copyright (c) 2021 - 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_ROCR_MEMORYACCESS_H_
#define RDC_MODULES_RDC_ROCR_MEMORYACCESS_H_
#include "hsa/hsa.h"
#include "rdc_modules/rdc_rocr/TestBase.h"
namespace amd {
namespace rdc {
class MemoryAccessTest : public TestBase {
public:
explicit MemoryAccessTest(uint32_t gpu_index);
// @Brief: Destructor for test case of MemoryTest
virtual ~MemoryAccessTest();
// @Brief: Setup the environment for measurement
virtual hsa_status_t SetUp();
// @Brief: Core measurement execution
virtual void Run();
// @Brief: Clean up and retrive the resource
virtual void Close();
// @Brief: Display results
virtual void DisplayResults() const;
// @Brief: Display information about what this test does
virtual void DisplayTestInfo(void);
// @Brief: This test verify that CPU is able to Read & write GPU memory
void CPUAccessToGPUMemoryTest(void);
// @Brief: This test verify that GPU is able to Read & write CPU memory
void GPUAccessToCPUMemoryTest(void);
private:
void CPUAccessToGPUMemoryTest(hsa_agent_t cpuAgent, hsa_agent_t gpuAgent,
hsa_amd_memory_pool_t pool);
void GPUAccessToCPUMemoryTest(hsa_agent_t cpuAgent, hsa_agent_t gpuAgent);
};
} // namespace rdc
} // namespace amd
#endif // RDC_MODULES_RDC_ROCR_MEMORYACCESS_H_
@@ -0,0 +1,63 @@
/*
Copyright (c) 2021 - 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_ROCR_MEMORYTEST_H_
#define RDC_MODULES_RDC_ROCR_MEMORYTEST_H_
#include "hsa/hsa.h"
#include "rdc_modules/rdc_rocr/TestBase.h"
namespace amd {
namespace rdc {
class MemoryTest : public TestBase {
public:
explicit MemoryTest(uint32_t gpu_index);
// @Brief: Destructor for test case of MemoryTest
virtual ~MemoryTest();
// @Brief: Setup the environment for measurement
virtual hsa_status_t SetUp();
// @Brief: Core measurement execution
virtual void Run();
// @Brief: Clean up and retrive the resource
virtual void Close();
// @Brief: Display results
virtual void DisplayResults() const;
// @Brief: Display information about what this test does
virtual void DisplayTestInfo(void);
hsa_status_t MaxSingleAllocationTest(void);
hsa_status_t TestAllocate(hsa_amd_memory_pool_t pool, size_t sz);
private:
hsa_status_t MaxSingleAllocationTest(hsa_agent_t ag, hsa_amd_memory_pool_t pool);
};
} // namespace rdc
} // namespace amd
#endif // RDC_MODULES_RDC_ROCR_MEMORYTEST_H_
@@ -0,0 +1,179 @@
/*
Copyright (c) 2021 - 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_ROCR_RDCROCRBASE_H_
#define RDC_MODULES_RDC_ROCR_RDCROCRBASE_H_
#include <stdint.h>
#include <stdio.h>
#include <string>
#include "hsa/hsa.h"
#include "hsa/hsa_ext_amd.h"
#include "rdc_lib/RdcPerfTimer.h"
namespace amd {
namespace rdc {
/// Common interface for RocR tests and samples
class RdcRocrBase {
public:
RdcRocrBase(void);
virtual ~RdcRocrBase(void);
///< Setters and Getters
void set_gpu_device1(hsa_agent_t in_dev) { gpu_device1_.handle = in_dev.handle; }
hsa_agent_t* gpu_device1(void) { return &gpu_device1_; }
void set_cpu_device(hsa_agent_t in_dev) { cpu_device_.handle = in_dev.handle; }
hsa_agent_t* cpu_device(void) { return &cpu_device_; }
void set_kernel_file_name(const char* in_file_name) { kernel_file_name_ = in_file_name; }
std::string const kernel_file_name(void) const { return kernel_file_name_; }
void set_kernel_name(std::string in_kernel_name) { kernel_name_ = in_kernel_name; }
std::string const kernel_name(void) const { return kernel_name_; }
void set_agent_name(std::string in_agent_name) { agent_name_ = in_agent_name; }
std::string const get_agent_name(void) const { return agent_name_; }
void set_kernel_object(uint64_t in_kernel_object) { kernel_object_ = in_kernel_object; }
uint64_t kernel_object(void) const { return kernel_object_; }
void set_profile(hsa_profile_t in_prof) { profile_ = in_prof; }
hsa_profile_t profile(void) const { return profile_; }
uint32_t private_segment_size(void) const { return private_segment_size_; }
void set_private_segment_size(uint32_t sz) { private_segment_size_ = sz; }
void set_group_segment_size(uint32_t sz) { group_segment_size_ = sz; }
uint32_t group_segment_size(void) const { return group_segment_size_; }
void set_group_size(uint32_t sz) { group_size_ = sz; }
uint32_t group_size(void) const { return group_size_; }
void set_main_queue(hsa_queue_t* q) { main_queue_ = q; }
hsa_queue_t* main_queue(void) const { return main_queue_; }
hsa_kernel_dispatch_packet_t& aql(void) { return aql_; }
void set_num_iteration(int num) { num_iteration_ = num; }
uint32_t num_iteration(void) const { return num_iteration_; }
hsa_amd_memory_pool_t& device_pool(void) { return device_pool_; }
hsa_amd_memory_pool_t& cpu_pool(void) { return cpu_pool_; }
hsa_amd_memory_pool_t& kern_arg_pool(void) { return kern_arg_pool_; }
void set_kernarg_size(uint32_t sz) { kernarg_size_ = sz; }
uint32_t kernarg_size(void) const { return kernarg_size_; }
void set_kernarg_align(uint32_t align) { kernarg_align_ = align; }
uint32_t kernarg_align(void) const { return kernarg_align_; }
void* kernarg_buffer(void) const { return kernarg_buffer_; }
void set_kernarg_buffer(void* buffer) { kernarg_buffer_ = buffer; }
int32_t requires_profile(void) const { return requires_profile_; }
char* orig_hsa_enable_interrupt() const { return orig_hsa_enable_interrupt_; }
bool enable_interrupt() const { return enable_interrupt_; }
void set_title(std::string name) { title_ = name; }
std::string title(void) const { return title_; }
RdcPerfTimer* hsa_timer(void) { return &hsa_timer_; }
void set_verbosity(uint32_t v) { verbosity_ = v; }
uint32_t verbosity(void) const { return verbosity_; }
void set_monitor_verbosity(uint32_t m) { monitor_verbosity_ = m; }
uint32_t monitor_verbosity(void) const { return monitor_verbosity_; }
protected:
void set_requires_profile(int32_t reqd_prof) { requires_profile_ = reqd_prof; }
void set_enable_interrupt(bool doEnable) { enable_interrupt_ = doEnable; }
private:
uint64_t num_iteration_; ///< Number of times to execute test
hsa_queue_t* main_queue_; ///< AQL queue used for packets
hsa_agent_t gpu_device1_; ///< Handle to first GPU found
hsa_agent_t cpu_device_; ///< Handle to CPU
hsa_amd_memory_pool_t device_pool_; ///< Memory pool on gpu pool list
hsa_amd_memory_pool_t cpu_pool_; ///< Memory pool on cpu pool list
hsa_amd_memory_pool_t kern_arg_pool_; ///< Memory pool suitable for args
uint64_t kernel_object_; ///< Handle to kernel code
std::string kernel_file_name_; ///< Code object file name
std::string kernel_name_; ///< Kernel name
std::string agent_name_; ///< Agent name
hsa_kernel_dispatch_packet_t aql_; ///< Kernel dispatch packet
uint32_t group_segment_size_; ///< Kernel group seg size
uint32_t kernarg_size_; ///< Kernarg memory size
uint32_t kernarg_align_; ///< Alignment for kern argument memory
void* kernarg_buffer_; ///< Unaligned allocated kernel arg. buffer
hsa_profile_t profile_; ///< Device profile.
uint32_t group_size_; ///< Number of work items in one group
uint32_t private_segment_size_; ///< Kernel private seg size
int32_t requires_profile_; ///< Profile required by test (-1 if no req.)
char* orig_hsa_enable_interrupt_; ///< Orig. value of HSA_ENABLE_INTERRUPT
bool enable_interrupt_; ///< Whether to enable/disable interrupts for test
std::string title_; ///< Displayed title of test
uint32_t verbosity_; ///< How much additional output to produce
uint32_t monitor_verbosity_; ///< verbose or not
RdcPerfTimer hsa_timer_; ///< Timer to be used for timing parts of test
};
} // namespace rdc
} // namespace amd
#endif // RDC_MODULES_RDC_ROCR_RDCROCRBASE_H_
@@ -0,0 +1,81 @@
/*
Copyright (c) 2021 - 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_ROCR_TESTBASE_H_
#define RDC_MODULES_RDC_ROCR_TESTBASE_H_
#include <memory>
#include <string>
#include <vector>
#include "rdc_modules/rdc_rocr/RdcRocrBase.h"
namespace amd {
namespace rdc {
class TestBase : public RdcRocrBase {
public:
explicit TestBase(uint32_t gpu_index);
virtual ~TestBase(void);
enum VerboseLevel { VERBOSE_MIN = 0, VERBOSE_STANDARD, VERBOSE_PROGRESS };
// @Brief: Before run the core measure codes, do something to set up
// i.e. init runtime, prepare packet...
virtual hsa_status_t SetUp(void);
// @Brief: Core measurement codes executing here
virtual void Run(void);
// @Brief: Do something clean up
virtual void Close(void);
// @Brief: Display the results
virtual void DisplayResults(void) const;
// @Brief: Display information about the test
virtual void DisplayTestInfo(void);
const std::string& description(void) const { return description_; }
void set_description(std::string d);
const std::string& get_gpu_info() const { return gpu_info_; }
const std::string& get_per_gpu_info() const { return per_gpu_info_; }
hsa_status_t FindGPUIndex(hsa_agent_t agent, void* data);
// Return the agent by GPU index in amd_smi
hsa_status_t get_agent_by_gpu_index(uint32_t gpu_index, hsa_agent_t* agent);
protected:
uint32_t gpu_index_;
std::string gpu_info_;
std::string per_gpu_info_;
private:
std::string description_;
};
} // namespace rdc
} // namespace amd
#endif // RDC_MODULES_RDC_ROCR_TESTBASE_H_
@@ -0,0 +1,168 @@
/*
Copyright (c) 2021 - 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_ROCR_BASE_ROCR_UTILS_H_
#define RDC_MODULES_RDC_ROCR_BASE_ROCR_UTILS_H_
/// \file
/// Prototypes of utility functions that act on RdcRocrBase objects.
#include <string>
#include "hsa/hsa.h"
#include "rdc_modules/rdc_rocr/RdcRocrBase.h"
#include "rdc_modules/rdc_rocr/common.h"
namespace amd {
namespace rdc {
/// Open binary kernel object file and set all member data related to the
/// kernel. Assumes that input test already has the kernel file name,
/// agent name and kernel function specifed
/// \param[in] test Test for which the kernel will be loaded.
/// \param[in] agent for which the kernel will be loaded .
/// \returns HSA_STATUS_SUCCESS if no errors
hsa_status_t LoadKernelFromObjFile(RdcRocrBase* test, hsa_agent_t* agent);
/// Do initialization tasks for HSA test program.
/// \param[in] test Test to initialize
/// \returns HSA_STATUS_SUCCESS if no errors
hsa_status_t InitAndSetupHSA(RdcRocrBase* test);
/// Find and set the cpu and gpu agent member variables. Also checks that
/// gpu agent meets test requirements (e.g., FULL profile vs. BASE profile).
hsa_status_t SetDefaultAgents(RdcRocrBase* test);
/// For the provided device agent, create an AQL queue
/// \param[in] device Device for which a queue is to be created
/// \param[out] queue Address to which created queue pointer will be written
/// \param[in] num_pkts Size of the queue to create
/// \param[in] do_profile [Optional] Specificy whether profiled queue should
/// be created
/// \returns HSA_STATUS_SUCCESS if no errors encountered
hsa_status_t CreateQueue(hsa_agent_t device, hsa_queue_t** queue, uint32_t num_pkts = 0);
/// This function sets some reasonable default values for an AQL packet.
/// Override any field as necessary after calling this function.
/// \param[in] test Test from which information to populate aql packet can
/// be drawn.
/// \param[inout] aql Caller provided pointer to aql packet that will be
/// populated
/// \returns Appropriate hsa_status_t
hsa_status_t InitializeAQLPacket(const RdcRocrBase* test, hsa_kernel_dispatch_packet_t* aql);
/// This function writes all of the aql packet fields to the queue besides
/// "setup" and "header". This assumes all the aql fields have be set
/// appropriately.
/// \param[in] test Test containing the queue and aql packet to be written.
/// \returns Pointer to dispatch packet in queue that was written to
hsa_kernel_dispatch_packet_t* WriteAQLToQueue(RdcRocrBase* test, uint64_t* ind);
void WriteAQLToQueueLoc(hsa_queue_t* queue, uint64_t indx, hsa_kernel_dispatch_packet_t* aql_pkt);
/// This function writes the first 32 bits of an aql packet to the provided
/// aql packet. This function is meant to be called immediately before
/// ringing door_bell signal.
/// \param[in] header Value to be written to header field
/// \param[in] setup Value to be written to setup field
/// \param[in] queue_packet Start address of in queue memory of aql packet to
/// be written
/// \returns void
inline void AtomicSetPacketHeader(uint16_t header, uint16_t setup,
hsa_kernel_dispatch_packet_t* queue_packet) {
__atomic_store_n(reinterpret_cast<uint32_t*>(queue_packet), header | (setup << 16),
__ATOMIC_RELEASE);
}
/// Perform common operations to clean up after executing a test. Specifically,
/// hsa_shut_down() is called and environment variables that were changed are
/// reset to their original values.
/// \param[in] test Test for which clean up with be performed
/// \returns HSA_STATUS_SUCCESS if everything cleaned up ok, or appropriate HSA
/// error code otherwise.
hsa_status_t CommonCleanUp(RdcRocrBase* test);
/// Check to see if target machine has the necessary profile to run the
/// provided test.
/// \param[1] test The test that specifies the required profile.
bool CheckProfile(RdcRocrBase const* test);
/// Allocate memory from the kernel args pool and write the provided argument
/// data to the kernel arg memory. Assumes kern_arg memory pool has been
/// assigned. The amount of memory allocated will actually be \p arg_size
/// plus the alignment required by the kernel arguments. The argument will
/// be written with the proper alignment within the allocated buffer.
/// \p test kernarg_buffer() will point to the allocated buffer, and it should
/// be freed when the kernel is no longer being used.
/// \param test Test from which to find kern_arg pool to write arguments
/// \param args pointer to block of data containing kernel arguments to be
/// written. Arguments are assumed to be of the correct placement, length,
/// and with any padding that is expected by the OpenCL kernel
/// \param arg_size Size of the kernel arg data (including padding) to be
/// written
/// \returns HSA_STATUS_SUCCESS if no errors
hsa_status_t AllocAndSetKernArgs(RdcRocrBase* test, void* args, size_t arg_size);
/// Verify that the machine running the test has the required profile.
/// This function will verify that the execution machine meets any specific
/// test requirement for a profile (HSA_PROFILE_BASE or HSA_PROFILE_FULL).
/// \param[in] test Test that provides profile requirements.
/// \returns bool
/// - true Machine meets test requirements
/// - false Machine does not meet test requirements
bool CheckProfileAndInform(RdcRocrBase* test);
/// This function will set the cpu and gpu memory pools to the type used in
/// many applications.
/// \param[in] test Test that provides profile requirements.
/// \returns HSA_STATUS_SUCCESS if everything cleaned up ok, or appropriate HSA
/// error code otherwise.
hsa_status_t SetPoolsTypical(RdcRocrBase* test);
/// Work-around for hsa_amd_memory_fill, which is currently broken.
/// \param[in] ptr Pointer to start of memory location to be filled
/// \param[in] value Value to write to each byte of input buffer
/// \param[in] count Size of buffer to fill
/// \param[in] dst_ag Agent owning the buffer to be filled
/// \param[in] src_ag Agent wanting to do the fill
/// \param[in] test Test that has handles to cpu and gpu agents that can own
/// either source or destination of fill
/// \returns HSA_STATUS_OK if not errors
hsa_status_t hsa_memory_fill_workaround_gen(void* ptr, uint32_t value, size_t count,
hsa_agent_t dst_ag, hsa_agent_t src_ag,
RdcRocrBase* test);
/// Get the library directory which is loaded by current process.
/// It will search /proc/self/maps for it.
/// return empty string if fail.
std::string get_lib_dir(const char* lib_name);
/// Get the app dir by looking at link of /proc/self/exe
std::string get_app_dir();
// Search multiple folder for the hsaco file
// Return empty if cannot find it.
std::string search_hsaco_full_path(const char* hsaco_file_name, const char* agent_name);
} // namespace rdc
} // namespace amd
#endif // RDC_MODULES_RDC_ROCR_BASE_ROCR_UTILS_H_
@@ -0,0 +1,226 @@
/*
Copyright (c) 2021 - 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.
*/
/// \file
/// RocR related helper functions for sequeneces that come up frequently
#ifndef RDC_MODULES_RDC_ROCR_COMMON_H_
#define RDC_MODULES_RDC_ROCR_COMMON_H_
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include "hsa/hsa.h"
#include "hsa/hsa_ext_amd.h"
namespace amd {
namespace rdc {
#if defined(_MSC_VER)
#define ALIGNED_(x) __declspec(align(x))
#else
#if defined(__GNUC__)
#define ALIGNED_(x) __attribute__((aligned(x)))
#endif // __GNUC__
#endif // _MSC_VER
#define MULTILINE(...) #__VA_ARGS__
#define ASSERT_EQ(a, b) (a == b)
void SetEnv(const char* env_var_name, const char* env_var_value);
intptr_t AlignDown(intptr_t value, size_t alignment);
void* AlignDown(void* value, size_t alignment);
void* AlignUp(void* value, size_t alignment);
// define below should be deleted. Leaving in commented out until code that
// refers to it has been corrected
// #define HSA_ARGUMENT_ALIGN_BYTES 16
// This structure holds memory pool information acquired through hsa info
// related calls, and is later used for reference when displaying the
// information.
typedef struct pool_info_t_ {
uint32_t segment;
size_t size;
bool alloc_allowed;
size_t alloc_granule;
size_t alloc_alignment;
bool accessible_by_all;
uint32_t global_flag;
uint64_t aggregate_alloc_max;
inline bool operator==(const pool_info_t_& a) {
if (a.segment == segment && a.size == size && a.alloc_allowed == alloc_allowed &&
a.alloc_granule == alloc_granule && a.alloc_alignment == alloc_alignment &&
a.accessible_by_all == accessible_by_all && a.aggregate_alloc_max == aggregate_alloc_max &&
a.global_flag == global_flag)
return true;
else
return false;
}
} pool_info_t;
struct agent_pools_t {
hsa_agent_t agent;
std::vector<hsa_amd_memory_pool_t> pools;
};
/// Fill in the pool_info_t structure for the provided pool.
/// \param[in] pool Pool for which information will be retrieved
/// \param[out] pool_i Pointer to structure where pool info will be stored
/// \returns HSA_STATUS_SUCCESS if no errors are encountered.
hsa_status_t AcquirePoolInfo(hsa_amd_memory_pool_t pool, pool_info_t* pool_i);
/// If the provided agent is associated with a GPU, return that agent through
/// output parameter. This function is meant to be the call-back function used
/// with hsa_iterate_agents to find GPU agents.
/// \param[in] agent Agent to evaluate if GPU
/// \param[out] data If agent is associated with a GPU, this pointer will point
/// to the agent upon return
/// \returns HSA_STATUS_SUCCESS if no errors are encountered.
hsa_status_t FindGPUDevice(hsa_agent_t agent, void* data);
/// If the provided agent is associated with a CPU, return that agent through
/// output parameter. This function is meant to be the call-back function used
/// with hsa_iterate_agents to find CPU agents.
/// \param[in] agent Agent to evaluate if CPU
/// \param[out] data If agent is associated with a CPU, this pointer will point
/// to the agent upon return
/// \returns HSA_STATUS_SUCCESS if no errors are encountered.
hsa_status_t FindCPUDevice(hsa_agent_t agent, void* data);
// TODO(cfreehil): get rid of FindGlobalPool and replace with FindStandardPool
hsa_status_t FindGlobalPool(hsa_amd_memory_pool_t pool, void* data);
/// If the provided agent is associated with a CPU, return that agent through
/// output parameter. This function is meant to be the call-back function used
/// with hsa_iterate_agents to find all the CPU agents.
/// \param[in] agent Agent to evaluate if CPU
/// \param[out] data If agent is associated with a CPU, this pointer will point
/// to the agent upon return
/// \returns HSA_STATUS_SUCCESS if no errors are encountered.
hsa_status_t IterateCPUAgents(hsa_agent_t agent, void* data);
/// If the provided agent is associated with a GPU, return that agent through
/// output parameter. This function is meant to be the call-back function used
/// with hsa_iterate_agents to find all the GPU agents.
/// \param[in] agent Agent to evaluate if GPU
/// \param[out] data If agent is associated with a GPU, this pointer will point
/// to the agent upon return
/// \returns HSA_STATUS_SUCCESS if no errors are encountered.
hsa_status_t IterateGPUAgents(hsa_agent_t agent, void* data);
/// Find a GLOBAL memory pool. By this, we mean not a kernel args pool.
/// This function is meant to be the call-back function used
/// with hsa_amd_agent_iterate_memory_pools.
/// \param[in] pool Pool to evaluate for required properties
/// \param[in] data If pool meets criteria, this pointer will point
/// to the pool upon return
/// \returns hsa_status_t
/// -HSA_STATUS_INFO_BREAK - we found a pool that meets criteria
/// -HSA_STATUS_SUCCESS - we did not find a pool that meets the criteria
/// -else return an appropriate error code for any error encountered
hsa_status_t GetGlobalMemoryPool(hsa_amd_memory_pool_t pool, void* data);
/// Find a "kernel arg" pool.
/// This function is meant to be the call-back function used
/// with hsa_amd_agent_iterate_memory_pools.
/// \param[in] pool Pool to evaluate for required properties
/// \param[in] data If pool meets criteria, this pointer will point
/// to the pool upon return
/// \returns hsa_status_t
/// -HSA_STATUS_INFO_BREAK - we found a pool that meets criteria
/// -HSA_STATUS_SUCCESS - we did not find a pool that meets the criteria
/// -else return an appropriate error code for any error encountered
hsa_status_t GetKernArgMemoryPool(hsa_amd_memory_pool_t pool, void* data);
/// Find a "standard" pool. By this, we mean not a kernel args pool.
/// The pool found will have the following properties:
/// HSA_AMD_MEMORY_POOL_INFO_ACCESSIBLE_BY_ALL: Don't care
/// HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_KERNARG_INIT: Off
/// HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_FINE_GRAINED: Don't care
/// This function is meant to be the call-back function used
/// with hsa_amd_agent_iterate_memory_pools.
/// \param[in] pool Pool to evaluate for required properties
/// \param[in] data If pool meets criteria, this pointer will point
/// to the pool upon return
/// \returns hsa_status_t
/// -HSA_STATUS_INFO_BREAK - we found a pool that meets criteria
/// -HSA_STATUS_SUCCESS - we did not find a pool that meets the criteria
/// -else return an appropriate error code for any error encountered
hsa_status_t FindStandardPool(hsa_amd_memory_pool_t pool, void* data);
hsa_status_t FindAPUStandardPool(hsa_amd_memory_pool_t pool, void* data);
/// Find a "kernel arg" pool.
/// The pool found will have the following properties:
/// HSA_AMD_MEMORY_POOL_INFO_ACCESSIBLE_BY_ALL: Don't care
/// HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_KERNARG_INIT: On
/// HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_FINE_GRAINED: Don't care
/// This function is meant to be the call-back function used
/// with hsa_amd_agent_iterate_memory_pools.
/// \param[in] pool Pool to evaluate for required properties
/// \param[in] data If pool meets criteria, this pointer will point
/// to the pool upon return
/// \returns hsa_status_t
/// -HSA_STATUS_INFO_BREAK - we found a pool that meets criteria
/// -HSA_STATUS_SUCCESS - we did not find a pool that meets the criteria
/// -else return an appropriate error code for any error encountered
hsa_status_t FindKernArgPool(hsa_amd_memory_pool_t pool, void* data);
/// Dump information about provided memory pool to STDOUT
/// \param[in] pool Pool to gather and dump information for
/// \param[in] indent Number of spaces to indent output.
/// \returns hsa_status_t HSA_STATUS_SUCCESS if no errors
hsa_status_t DumpMemoryPoolInfo(const pool_info_t* pool_i, uint32_t indent = 0);
/// Dump information about a provided pointer to STDOUT.
/// \param[in] ptr Pointer about which information is dumped.
/// \returns HSA_STATUS_SUCCESS if there are no errors
hsa_status_t DumpPointerInfo(void* ptr);
hsa_status_t GetAgentPools(std::vector<std::shared_ptr<agent_pools_t>>* agent_pools);
void throw_if_error(hsa_status_t err, const std::string& msg = "");
void throw_if_skip(const std::string& msg);
// The customize exception when the test has to be skipped
class SkipException : public std::exception {
public:
explicit SkipException(const char* msg) : _msg(msg) {}
virtual const char* what() const noexcept { return _msg.c_str(); }
private:
std::string _msg;
};
} // namespace rdc
} // namespace amd
#endif // RDC_MODULES_RDC_ROCR_COMMON_H_
@@ -0,0 +1,164 @@
/*
Copyright (c) 2023 - 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_RVS_RVSBASE_H_
#define RDC_MODULES_RDC_RVS_RVSBASE_H_
#include <amd_smi/amdsmi.h>
#include <cstddef>
#include <cstdio>
#include <map>
#include <string>
#include <vector>
#include "rdc/rdc.h"
#include "rdc_lib/RdcLogger.h"
#include "rvs/rvs.h"
static constexpr size_t MAX_CONFIG_LENGTH = 1024;
// this map only makes sense in context of test config locations as originally
// designed in RVS
static const std::map<uint64_t, std::string> gfx_to_rvs_conf = {
{0x90a, "MI210"}, // ?
{0x940, "MI300A"}, // ?
{0x941, "MI300A"}, // ?
{0x942, "MI300X"}, // ?
{0x94a, "MI308X"}, // ?
{0x1030, "nv21"}, //
{0x1031, "nv21"}, // ?
{0x1032, "nv21"}, // ?
{0x1033, "nv21"}, // ?
{0x1034, "nv21"}, // ?
{0x1035, "nv21"}, // ?
{0x1100, "nv31"}, // ?
{0x1101, "nv31"}, // ?
{0x1102, "nv31"}, // ?
{0x1103, "nv31"}, // ?
};
static const std::map<rdc_diag_test_cases_t, std::string> test_to_name = {
{RDC_DIAG_RVS_GST_TEST, "gst_single.conf"},
{RDC_DIAG_RVS_MEMBW_TEST, "babel.conf"},
{RDC_DIAG_RVS_H2DD2H_TEST, "pebb_single.conf"},
{RDC_DIAG_RVS_IET_TEST, "iet_stress.conf"},
{RDC_DIAG_RVS_GST_LONG_TEST, "gst_single_long.conf"},
{RDC_DIAG_RVS_MEMBW_LONG_TEST, "babel_long.conf"},
{RDC_DIAG_RVS_H2DD2H_LONG_TEST, "pebb_single_long.conf"},
{RDC_DIAG_RVS_IET_LONG_TEST, "iet_stress_long.conf"},
{RDC_DIAG_RVS_CUSTOM, "CUSTOM_CONFIG"},
};
namespace amd {
namespace rdc {
inline amdsmi_status_t get_processor_handle_from_id(uint32_t gpu_id,
amdsmi_processor_handle* processor_handle) {
uint32_t socket_count;
uint32_t processor_count;
auto ret = amdsmi_get_socket_handles(&socket_count, nullptr);
if (ret != AMDSMI_STATUS_SUCCESS) {
return ret;
}
std::vector<amdsmi_socket_handle> sockets(socket_count);
std::vector<amdsmi_processor_handle> all_processors{};
ret = amdsmi_get_socket_handles(&socket_count, sockets.data());
for (auto& socket : sockets) {
ret = amdsmi_get_processor_handles(socket, &processor_count, nullptr);
if (ret != AMDSMI_STATUS_SUCCESS) {
return ret;
}
std::vector<amdsmi_processor_handle> processors(processor_count);
ret = amdsmi_get_processor_handles(socket, &processor_count, processors.data());
if (ret != AMDSMI_STATUS_SUCCESS) {
return ret;
}
for (auto& processor : processors) {
processor_type_t processor_type = {};
ret = amdsmi_get_processor_type(processor, &processor_type);
if (processor_type != AMDSMI_PROCESSOR_TYPE_AMD_GPU) {
RDC_LOG(RDC_ERROR, "Expect AMD_GPU device type!");
return AMDSMI_STATUS_NOT_SUPPORTED;
}
all_processors.push_back(processor);
}
}
if (gpu_id >= all_processors.size()) {
return AMDSMI_STATUS_INPUT_OUT_OF_BOUNDS;
}
// Get processor handle from GPU id
*processor_handle = all_processors[gpu_id];
return AMDSMI_STATUS_SUCCESS;
}
class RdcRVSBase {
public:
RdcRVSBase();
~RdcRVSBase();
// only one instance allowed
RdcRVSBase(const RdcRVSBase&) = delete;
RdcRVSBase& operator=(const RdcRVSBase&) = delete;
// no moving allowed
RdcRVSBase(RdcRVSBase&&) = delete;
RdcRVSBase& operator=(RdcRVSBase&&) = delete;
rvs_status_t run_rvs_app(const char* config, size_t config_size, rdc_diag_callback_t* callback);
std::vector<std::string> get_rvs_configs();
std::map<rdc_diag_test_cases_t, std::string> get_test_to_conf();
private:
static RdcRVSBase* s_instance;
volatile rvs_session_state_t _state = RVS_SESSION_STATE_IDLE;
rdc_diag_callback_t* _callback = nullptr;
rvs_session_callback _rvs_callback = nullptr;
std::vector<std::string> _rvs_config_list = {};
std::map<rdc_diag_test_cases_t, std::string> _test_to_conf = {};
// Static callback function that the C API will call
static void static_callback(rvs_session_id_t session_id, const rvs_results_t* results) {
// Forward the call to the current instance if it exists
if (s_instance) {
s_instance->session_callback(session_id, results);
}
}
void session_callback(rvs_session_id_t /*session_id*/, const rvs_results_t* results) {
_state = results->state;
// std::string output = "\n";
// output += "session id -> " + std::to_string(session_id) + "\n";
// output += " state -> " + std::to_string(results->state) + "\n";
// output += " status -> " + std::to_string(results->status) + "\n";
// output += " output -> " + std::string(results->output_log);
std::string output = std::string(results->output_log);
if (_callback != nullptr && _callback->callback != nullptr && _callback->cookie != nullptr) {
_callback->callback(_callback->cookie, output.data());
}
}
};
} // namespace rdc
} // namespace amd
#endif // RDC_MODULES_RDC_RVS_RVSBASE_H_