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

git-subtree-dir: projects/rdc
git-subtree-mainline: a68afa42a1
git-subtree-split: 5ae7eeb355
Esse commit está contido em:
systems-assistant[bot]
2025-07-22 22:52:37 +00:00
393 arquivos alterados com 49849 adições e 0 exclusões
@@ -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_
+50
Ver Arquivo
@@ -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_