Fix for error while reading gpu_metrics sysfs file
Signed-off-by: Divya Shikre <DivyaUday.Shikre@amd.com>
Change-Id: If69b7eeb3573ebece9ed0cb539f5ddffbe3c2f09
[ROCm/amdsmi commit: efd234c9e3]
This commit is contained in:
zatwierdzone przez
Divya Uday Shikre
rodzic
348ab2cf8e
commit
22516a3b63
@@ -178,7 +178,8 @@ class Device {
|
||||
int readDevInfoLine(DevInfoTypes type, std::string *line);
|
||||
int readDevInfo(DevInfoTypes type, std::string *val);
|
||||
int readDevInfo(DevInfoTypes type, std::vector<std::string> *retVec);
|
||||
int readDevInfo(DevInfoTypes type, std::vector<unsigned char> *retVec);
|
||||
int readDevInfo(DevInfoTypes type, std::size_t b_size,
|
||||
void *p_binary_data);
|
||||
int writeDevInfo(DevInfoTypes type, uint64_t val);
|
||||
int writeDevInfo(DevInfoTypes type, std::string val);
|
||||
|
||||
@@ -220,8 +221,8 @@ class Device {
|
||||
int readDevInfoStr(DevInfoTypes type, std::string *retStr);
|
||||
int readDevInfoMultiLineStr(DevInfoTypes type,
|
||||
std::vector<std::string> *retVec);
|
||||
int readDevInfoBinary(DevInfoTypes type,
|
||||
std::vector<unsigned char> *retVec);
|
||||
int readDevInfoBinary(DevInfoTypes type, std::size_t b_size,
|
||||
void *p_binary_data);
|
||||
int writeDevInfoStr(DevInfoTypes type, std::string valStr);
|
||||
uint64_t bdfid_;
|
||||
uint64_t kfd_gpu_id_;
|
||||
|
||||
@@ -81,8 +81,8 @@ rsmi_status_t
|
||||
GetDevValueVec(amd::smi::DevInfoTypes type,
|
||||
uint32_t dv_ind, std::vector<std::string> *val_vec);
|
||||
rsmi_status_t
|
||||
GetDevBinaryVec(amd::smi::DevInfoTypes type,
|
||||
uint32_t dv_ind, std::vector<unsigned char> *val_vec);
|
||||
GetDevBinaryBlob(amd::smi::DevInfoTypes type,
|
||||
uint32_t dv_ind, std::size_t b_size, void* p_binary_data);
|
||||
rsmi_status_t ErrnoToRsmiStatus(int err);
|
||||
|
||||
struct pthread_wrap {
|
||||
|
||||
@@ -2224,19 +2224,18 @@ rsmi_dev_gpu_metrics_info_get(uint32_t dv_ind, rsmi_gpu_metrics_t *smu) {
|
||||
DEVICE_MUTEX
|
||||
CHK_SUPPORT_NAME_ONLY(smu)
|
||||
|
||||
std::vector<unsigned char> val_vec;
|
||||
rsmi_status_t ret = GetDevBinaryVec(amd::smi::kDevGpuMetrics, dv_ind,
|
||||
&val_vec);
|
||||
rsmi_status_t ret = GetDevBinaryBlob(amd::smi::kDevGpuMetrics, dv_ind,
|
||||
sizeof(rsmi_gpu_metrics_t), smu);
|
||||
|
||||
// only supports gpu_metrics_v1_0 version
|
||||
if (smu->common_header.format_revision != 1) {
|
||||
return RSMI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
if (ret != RSMI_STATUS_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (val_vec.size() == 0) {
|
||||
return RSMI_STATUS_NOT_YET_IMPLEMENTED;
|
||||
}
|
||||
|
||||
smu = reinterpret_cast<rsmi_gpu_metrics_t *>(val_vec.data());
|
||||
|
||||
return ret;
|
||||
CATCH
|
||||
}
|
||||
|
||||
@@ -638,21 +638,23 @@ int Device::readDevInfoLine(DevInfoTypes type, std::string *line) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Device::readDevInfoBinary(DevInfoTypes type,
|
||||
std::vector<unsigned char> *retVec) {
|
||||
int Device::readDevInfoBinary(DevInfoTypes type, std::size_t b_size,
|
||||
void *p_binary_data) {
|
||||
auto sysfs_path = path_;
|
||||
|
||||
FILE *ptr;
|
||||
sysfs_path += "/device/";
|
||||
sysfs_path += kDevAttribNameMap.at(type);
|
||||
|
||||
std::ifstream fs(sysfs_path, std::ios::binary);
|
||||
if (!fs.is_open()) {
|
||||
ptr = fopen(sysfs_path.c_str(), "rb");
|
||||
if (!ptr) {
|
||||
return errno;
|
||||
}
|
||||
// copies all data into buffer
|
||||
retVec->insert(retVec->begin(),
|
||||
std::istreambuf_iterator<char>(fs), {});
|
||||
|
||||
size_t num = fread(p_binary_data, b_size, 1, ptr);
|
||||
fclose(ptr);
|
||||
if((num*b_size) != b_size){
|
||||
return ENOENT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -792,12 +794,13 @@ int Device::readDevInfo(DevInfoTypes type, std::vector<std::string> *val) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Device::readDevInfo(DevInfoTypes type, std::vector<unsigned char> *val) {
|
||||
assert(val != nullptr);
|
||||
int Device::readDevInfo(DevInfoTypes type, std::size_t b_size,
|
||||
void *p_binary_data) {
|
||||
assert(p_binary_data != nullptr);
|
||||
|
||||
switch (type) {
|
||||
case kDevGpuMetrics:
|
||||
return readDevInfoBinary(type, val);
|
||||
return readDevInfoBinary(type, b_size, p_binary_data);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -204,15 +204,16 @@ rsmi_status_t GetDevValueVec(amd::smi::DevInfoTypes type,
|
||||
return ErrnoToRsmiStatus(ret);
|
||||
}
|
||||
|
||||
rsmi_status_t GetDevBinaryVec(amd::smi::DevInfoTypes type,
|
||||
uint32_t dv_ind, std::vector<unsigned char> *val_vec) {
|
||||
assert(val_vec != nullptr);
|
||||
if (val_vec == nullptr) {
|
||||
rsmi_status_t
|
||||
GetDevBinaryBlob(amd::smi::DevInfoTypes type,
|
||||
uint32_t dv_ind, std::size_t b_size, void* p_binary_data) {
|
||||
assert(p_binary_data != nullptr);
|
||||
if (p_binary_data == nullptr) {
|
||||
return RSMI_STATUS_INVALID_ARGS;
|
||||
}
|
||||
GET_DEV_FROM_INDX
|
||||
|
||||
int ret = dev->readDevInfo(type, val_vec);
|
||||
int ret = dev->readDevInfo(type, b_size, p_binary_data);
|
||||
return ErrnoToRsmiStatus(ret);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user