Implement the rdc_lib API to support the job stats

Add the function to start and stop the job recording.
Add the function to get the job stats for each GPU and summary of multiple GPUs
Add the function to remove the jobs.

Add a class RdcLogger which can control the log level using the environment variable RDC_LOG.
This is similar to GRPC_VERBOSITY gRPC. When the customer has the issues, he can enable the verbose
log to help us to troubleshoot the issues.

Add the -u support in the rdci group, fieldgroup and dmon for connecting to rdcd without authentication.

Change-Id: I22c591823c1ee6485db106b911bed8271d1b2769
Αυτή η υποβολή περιλαμβάνεται σε:
Bill(Shuzhou) Liu
2020-04-08 08:47:29 -04:00
υποβλήθηκε από Chris Freehill
γονέας 16bce67835
υποβολή a547dc7efd
26 αρχεία άλλαξαν με 805 προσθήκες και 102 διαγραφές
+31 -6
Προβολή Αρχείου
@@ -52,6 +52,7 @@ typedef enum {
RDC_ST_NOT_FOUND, //!< Cannot find the value
RDC_ST_CONFLICT, //!< Conflict with current state
RDC_ST_CLIENT_ERROR, //!< The RDC client error
RDC_ST_ALREADY_EXIST, //!< The item already exists
RDC_ST_MAX_LIMIT //!< Max limit recording for the object
} rdc_status_t;
@@ -371,15 +372,10 @@ rdc_status_t rdc_disconnect(rdc_handle_t p_rdc_handle);
*
* @param[in] update_freq How often to update this field in usec.
*
* @param[in] max_keep_age How long to keep data for this field in seconds.
*
* @param[in] max_keep_samples Maximum number of samples to keep. 0=no limit.
*
* @retval ::RDC_ST_OK is returned upon successful call.
*/
rdc_status_t rdc_job_start_stats(rdc_handle_t p_rdc_handle,
rdc_gpu_group_t group_id, char job_id[64], uint64_t update_freq,
double max_keep_age, uint32_t max_keep_samples);
rdc_gpu_group_t group_id, char job_id[64], uint64_t update_freq);
/**
* @brief Get the stats of the job using the job id.
@@ -415,6 +411,35 @@ rdc_status_t rdc_job_get_stats(rdc_handle_t p_rdc_handle, char job_id[64],
rdc_status_t rdc_job_stop_stats(rdc_handle_t p_rdc_handle,
char job_id[64]);
/**
* @brief Request RDC to stop tracking the job given by job_id
*
* @details After this call, you will no longer be able to call
* rdc_job_get_stats() on this job_id. But you will be able to reuse
* the job_id after this call.
*
* @param[in] p_rdc_handle The RDC handler.
*
* @param[in] job_id The name of the job.
*
* @retval ::RDC_ST_OK is returned upon successful call.
*/
rdc_status_t rdc_job_remove(rdc_handle_t p_rdc_handle,
char job_id[64]);
/**
* @brief Request RDC to stop tracking all the jobs
*
* @details After this call, you will no longer be able to call
* rdc_job_get_stats() on any job id. But you will be able to reuse
* the any previous used job id after this call.
*
* @param[in] p_rdc_handle The RDC handler.
*
* @retval ::RDC_ST_OK is returned upon successful call.
*/
rdc_status_t rdc_job_remove_all(rdc_handle_t p_rdc_handle);
/**
* @brief Request RDC to update all fields to be watched.
*
@@ -24,6 +24,7 @@ THE SOFTWARE.
#include <memory>
#include <utility>
#include <string>
#include <vector>
#include <map>
#include "rdc_lib/rdc_common.h"
@@ -31,6 +32,7 @@ THE SOFTWARE.
namespace amd {
namespace rdc {
typedef std::map<uint32_t, uint64_t> rdc_gpu_total_memory_t;
class RdcCacheManager {
public:
@@ -43,7 +45,19 @@ class RdcCacheManager {
const rdc_field_value& value) = 0;
virtual rdc_status_t evict_cache(uint32_t gpu_index, uint32_t field_id,
uint64_t max_keep_samples, double max_keep_age) = 0;
virtual uint32_t get_cache_size() = 0;
virtual std::string get_cache_stats() = 0;
virtual rdc_status_t rdc_job_get_stats(char jobId[64],
const rdc_gpu_total_memory_t& total_memory,
rdc_job_info_t* p_job_info) = 0;
virtual rdc_status_t rdc_job_start_stats(char jobId[64],
const rdc_group_info_t& group,
const rdc_field_group_info_t& finfo) = 0;
virtual rdc_status_t rdc_job_stop_stats(char job_id[64]) = 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(char job_id[64]) = 0;
virtual rdc_status_t rdc_job_remove_all() = 0;
virtual ~RdcCacheManager() {}
};
@@ -59,7 +59,7 @@ class RdcGroupSettings {
};
typedef std::shared_ptr<RdcGroupSettings> RdcGroupSettingsPtr;
const uint32_t JOB_FIELD_ID = 0;
} // namespace rdc
} // namespace amd
@@ -33,12 +33,12 @@ class RdcHandler {
public:
// Job API
virtual rdc_status_t rdc_job_start_stats(rdc_gpu_group_t groupId,
char job_id[64], uint64_t update_freq, double max_keep_age,
uint32_t max_keep_samples) = 0;
virtual rdc_status_t rdc_job_get_stats(char jobId[64],
char job_id[64], uint64_t update_freq) = 0;
virtual rdc_status_t rdc_job_get_stats(char jobId[64],
rdc_job_info_t* p_job_info)= 0;
virtual rdc_status_t rdc_job_stop_stats(char job_id[64]) = 0;
virtual rdc_status_t rdc_job_stop_stats(char job_id[64]) = 0;
virtual rdc_status_t rdc_job_remove(char job_id[64]) = 0;
virtual rdc_status_t rdc_job_remove_all() = 0;
// Discovery API
virtual rdc_status_t rdc_device_get_all(
@@ -0,0 +1,59 @@
/*
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 RDC_LIB_RDCLOGGER_H_
#define RDC_LIB_RDCLOGGER_H_
#include <iostream>
#include <string>
#include <chrono> // NOLINT
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 // RDC_LIB_RDCLOGGER_H_
@@ -36,10 +36,10 @@ class RdcWatchTable {
virtual rdc_status_t rdc_field_update_all() = 0;
virtual rdc_status_t rdc_job_start_stats(rdc_gpu_group_t group_id,
char job_id[64]) = 0;
virtual rdc_status_t rdc_watch_job_fields(rdc_gpu_group_t group_id,
uint64_t update_freq, double max_keep_age,
uint32_t max_keep_samples) = 0;
char job_id[64], uint64_t update_freq) = 0;
virtual rdc_status_t rdc_job_stop_stats(char job_id[64]) = 0;
virtual rdc_status_t rdc_job_remove(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,
@@ -23,7 +23,8 @@ THE SOFTWARE.
#define RDC_LIB_IMPL_RDCCACHEMANAGERIMPL_H_
#include <memory>
#include <mutex>
#include <mutex> // NOLINT(build/c++11)
#include <string>
#include <vector>
#include <map>
#include "rdc_lib/RdcCacheManager.h"
@@ -41,6 +42,29 @@ struct RdcCacheEntry {
typedef std::map<RdcFieldKey, std::vector<RdcCacheEntry>> RdcCacheSamples;
struct FieldSummaryStats {
int64_t max_value;
int64_t min_value;
int64_t total_value;
uint64_t last_time;
uint64_t count;
};
struct GpuSummaryStats {
uint64_t energy_consumed;
uint64_t energy_last_time;
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;
};
// <job_id, job_stats>
typedef std::map<std::string, RdcJobStatsCacheEntry> RdcJobStatsCache;
class RdcCacheManagerImpl: public RdcCacheManager {
public:
@@ -53,10 +77,27 @@ class RdcCacheManagerImpl: public RdcCacheManager {
const rdc_field_value& value) override;
rdc_status_t evict_cache(uint32_t gpu_index, uint32_t field_id,
uint64_t max_keep_samples, double max_keep_age) override;
uint32_t get_cache_size() override;
std::string get_cache_stats() override;
rdc_status_t rdc_job_get_stats(char job_id[64],
const rdc_gpu_total_memory_t& total_memory,
rdc_job_info_t* p_job_info) override;
rdc_status_t rdc_job_start_stats(char job_id[64],
const rdc_group_info_t& group,
const rdc_field_group_info_t& finfo) override;
rdc_status_t rdc_job_stop_stats(char job_id[64]) 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(char job_id[64]) override;
rdc_status_t rdc_job_remove_all() override;
private:
void set_summary(const FieldSummaryStats & stats,
rdc_stats_summary_t& gpu, rdc_stats_summary_t& summary, // NOLINT
unsigned int adjuster);
RdcCacheSamples cache_samples_;
RdcJobStatsCache cache_jobs_;
std::mutex cache_mutex_;
};
@@ -36,11 +36,12 @@ class RdcEmbeddedHandler: public RdcHandler {
public:
// Job API
rdc_status_t rdc_job_start_stats(rdc_gpu_group_t groupId,
char job_id[64], uint64_t update_freq, double max_keep_age,
uint32_t max_keep_samples) override;
rdc_status_t rdc_job_get_stats(char jobId[64],
char job_id[64], uint64_t update_freq) override;
rdc_status_t rdc_job_get_stats(char jobId[64],
rdc_job_info_t* p_job_info) override;
rdc_status_t rdc_job_stop_stats(char job_id[64]) override;
rdc_status_t rdc_job_stop_stats(char job_id[64]) override;
rdc_status_t rdc_job_remove(char job_id[64]) override;
rdc_status_t rdc_job_remove_all() override;
// Discovery API
rdc_status_t rdc_device_get_all(
@@ -61,8 +61,8 @@ class RdcGroupSettingsImpl: public RdcGroupSettings {
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_ = 0;
uint32_t cur_filed_group_id_ = 0;
uint32_t cur_group_id_ = 1;
uint32_t cur_field_group_id_ = 0;
std::mutex group_mutex_;
std::mutex field_group_mutex_;
};
@@ -33,11 +33,12 @@ class RdcStandaloneHandler: public RdcHandler {
public:
// Job RdcAPI
rdc_status_t rdc_job_start_stats(rdc_gpu_group_t groupId,
char job_id[64], uint64_t update_freq, double max_keep_age,
uint32_t max_keep_samples) override;
rdc_status_t rdc_job_get_stats(char jobId[64],
char job_id[64], uint64_t update_freq) override;
rdc_status_t rdc_job_get_stats(char jobId[64],
rdc_job_info_t* p_job_info) override;
rdc_status_t rdc_job_stop_stats(char job_id[64]) override;
rdc_status_t rdc_job_stop_stats(char job_id[64]) override;
rdc_status_t rdc_job_remove(char job_id[64]) override;
rdc_status_t rdc_job_remove_all() override;
// Discovery RdcAPI
rdc_status_t rdc_device_get_all(
@@ -22,11 +22,12 @@ THE SOFTWARE.
#ifndef RDC_LIB_IMPL_RDCWATCHTABLEIMPL_H_
#define RDC_LIB_IMPL_RDCWATCHTABLEIMPL_H_
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <memory>
#include <mutex>
#include <mutex> // NOLINT
#include <atomic>
#include "rdc_lib/RdcWatchTable.h"
#include "rdc_lib/RdcGroupSettings.h"
@@ -45,14 +46,18 @@ struct FieldSettings {
uint64_t last_update_time;
};
struct JobWatchTableEntry {
uint32_t 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,
char job_id[64]) override;
rdc_status_t rdc_watch_job_fields(rdc_gpu_group_t group_id,
uint64_t update_freq, double max_keep_age,
uint32_t max_keep_samples) override;
char job_id[64], uint64_t update_freq) override;
rdc_status_t rdc_job_stop_stats(char job_id[64]) override;
rdc_status_t rdc_job_remove(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,
@@ -84,10 +89,16 @@ class RdcWatchTableImpl : public RdcWatchTable {
//!< 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);
rdc_field_grp_t field_group_id,
std::vector<RdcFieldKey> & fields); // NOLINT
bool is_job_watch_field(uint32_t gpu_index, uint32_t field_id,
std::string& job_id) const; // NOLINT
RdcGroupSettingsPtr group_settings_;
RdcCacheManagerPtr cache_mgr_;
@@ -96,6 +107,10 @@ class RdcWatchTableImpl : public RdcWatchTable {
//!< The watch table to store the watch settings.
std::map<RdcFieldKey, 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.
@@ -24,12 +24,18 @@ THE SOFTWARE.
#define RDC_LIB_RDC_COMMON_H_
#include <iostream>
#define RDC_ERROR 0
#define RDC_INFO 1
#define RDC_DEBUG 2
#ifdef DEBUG
#define LOG_DEBUG(message) std::cout << message << std::endl
#else
#define LOG_DEBUG(message)
#endif
#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)
/**
* @brief The strncpy but with null terminated