Merge pull request #25 from cfreehill/master

Add rsmi_dev_memory_total_get()and rsmi_dev_memory_usage_get()

[ROCm/rocm_smi_lib commit: a8e7d0cdee]
Αυτή η υποβολή περιλαμβάνεται σε:
Chris Freehill
2019-03-04 18:30:52 -06:00
υποβλήθηκε από GitHub
γονέας 0e342efad1 5d91dac776
υποβολή ff30ecd3c4
13 αρχεία άλλαξαν με 896 προσθήκες και 442 διαγραφές
Το δυαδικό αρχείο δεν εμφανίζεται.
Το diff αρχείου καταστέλλεται επειδή είναι πολύ μεγάλο Φόρτωση Διαφορών
@@ -1,6 +1,4 @@
/*
* =============================================================================
* ROC Runtime Conformance Release License
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
@@ -73,8 +71,12 @@ enum DevInfoTypes {
kDevErrCntSDMA,
kDevErrCntUMC,
kDevErrCntGFX,
// Reserve spots for future ErrCnt blocks.
// Next, non-ErrCnt device enum should start at 100
kDevMemTotGTT,
kDevMemTotVisVRAM,
kDevMemTotVRAM,
kDevMemUsedGTT,
kDevMemUsedVisVRAM,
kDevMemUsedVRAM,
};
class Device {
@@ -88,9 +90,7 @@ class Device {
const std::shared_ptr<PowerMon>& power_monitor() {return power_monitor_;}
void set_power_monitor(std::shared_ptr<PowerMon> pm) {power_monitor_ = pm;}
#if 0 // This is not being used right now.
int readDevInfo(DevInfoTypes type, uint32_t *val);
#endif
int readDevInfo(DevInfoTypes type, uint64_t *val);
int readDevInfoLine(DevInfoTypes type, std::string *line);
int readDevInfo(DevInfoTypes type, std::string *val);
int readDevInfo(DevInfoTypes type, std::vector<std::string> *retVec);
@@ -287,6 +287,13 @@ static rsmi_status_t get_dev_value_str(amd::smi::DevInfoTypes type,
return errno_to_rsmi_status(ret);
}
static rsmi_status_t get_dev_value_int(amd::smi::DevInfoTypes type,
uint32_t dv_ind, uint64_t *val_int) {
GET_DEV_FROM_INDX
int ret = dev->readDevInfo(type, val_int);
return errno_to_rsmi_status(ret);
}
static rsmi_status_t get_dev_value_line(amd::smi::DevInfoTypes type,
uint32_t dv_ind, std::string *val_str) {
@@ -1374,6 +1381,73 @@ rsmi_dev_power_profile_set(uint32_t dv_ind, uint32_t sensor_ind,
CATCH
}
rsmi_status_t
rsmi_dev_memory_total_get(uint32_t dv_ind, rsmi_memory_type_t mem_type,
uint64_t *total) {
TRY
rsmi_status_t ret;
amd::smi::DevInfoTypes mem_type_file;
if (total == nullptr) {
return RSMI_STATUS_INVALID_ARGS;
}
switch (mem_type) {
case RSMI_MEM_TYPE_GTT:
mem_type_file = amd::smi::kDevMemTotGTT;
break;
case RSMI_MEM_TYPE_VIS_VRAM:
mem_type_file = amd::smi::kDevMemTotVisVRAM;
break;
case RSMI_MEM_TYPE_VRAM:
mem_type_file = amd::smi::kDevMemTotVRAM;
break;
default:
assert(!"Unexpected memory type");
return RSMI_STATUS_INVALID_ARGS;
}
ret = get_dev_value_int(mem_type_file, dv_ind, total);
return ret;
CATCH
}
rsmi_status_t
rsmi_dev_memory_usage_get(uint32_t dv_ind, rsmi_memory_type_t mem_type,
uint64_t *used) {
TRY
rsmi_status_t ret;
amd::smi::DevInfoTypes mem_type_file;
if (used == nullptr) {
return RSMI_STATUS_INVALID_ARGS;
}
switch (mem_type) {
case RSMI_MEM_TYPE_GTT:
mem_type_file = amd::smi::kDevMemUsedGTT;
break;
case RSMI_MEM_TYPE_VIS_VRAM:
mem_type_file = amd::smi::kDevMemUsedVisVRAM;
break;
case RSMI_MEM_TYPE_VRAM:
mem_type_file = amd::smi::kDevMemUsedVRAM;
break;
default:
assert(!"Unexpected memory type");
return RSMI_STATUS_INVALID_ARGS;
}
ret = get_dev_value_int(mem_type_file, dv_ind, used);
return ret;
CATCH
}
rsmi_status_t
rsmi_status_string(rsmi_status_t status, const char **status_string) {
TRY
@@ -1,4 +1,4 @@
/* ROC Runtime Conformance Release License
/*
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
@@ -74,6 +74,12 @@ static const char *kDevPCIEThruPutFName = "pcie_bw";
static const char *kDevErrCntSDMAFName = "ras/sdma_err_count";
static const char *kDevErrCntUMCFName = "ras/umc_err_count";
static const char *kDevErrCntGFXFName = "ras/gfx_err_count";
static const char *kDevMemTotGTTFName = "mem_info_gtt_total";
static const char *kDevMemTotVisVRAMFName = "mem_info_vis_vram_total";
static const char *kDevMemTotVRAMFName = "mem_info_vram_total";
static const char *kDevMemUsedGTTFName = "mem_info_gtt_used";
static const char *kDevMemUsedVisVRAMFName = "mem_info_vis_vram_used";
static const char *kDevMemUsedVRAMFName = "mem_info_vram_used";
// Strings that are found within sysfs files
static const char *kDevPerfLevelAutoStr = "auto";
@@ -101,6 +107,12 @@ static const std::map<DevInfoTypes, const char *> kDevAttribNameMap = {
{kDevErrCntSDMA, kDevErrCntSDMAFName},
{kDevErrCntUMC, kDevErrCntUMCFName},
{kDevErrCntGFX, kDevErrCntGFXFName},
{kDevMemTotGTT, kDevMemTotGTTFName},
{kDevMemTotVisVRAM, kDevMemTotVisVRAMFName},
{kDevMemTotVRAM, kDevMemTotVRAMFName},
{kDevMemUsedGTT, kDevMemUsedGTTFName},
{kDevMemUsedVisVRAM, kDevMemUsedVisVRAMFName},
{kDevMemUsedVRAM, kDevMemUsedVRAMFName},
};
static const std::map<rsmi_dev_perf_level, const char *> kDevPerfLvlMap = {
@@ -296,8 +308,7 @@ int Device::readDevInfoMultiLineStr(DevInfoTypes type,
return 0;
}
#if 0
int Device::readDevInfo(DevInfoTypes type, uint32_t *val) {
int Device::readDevInfo(DevInfoTypes type, uint64_t *val) {
assert(val != nullptr);
std::string tempStr;
@@ -311,9 +322,15 @@ int Device::readDevInfo(DevInfoTypes type, uint32_t *val) {
case kDevUsage:
case kDevOverDriveLevel:
case kDevMemTotGTT:
case kDevMemTotVisVRAM:
case kDevMemTotVRAM:
case kDevMemUsedGTT:
case kDevMemUsedVisVRAM:
case kDevMemUsedVRAM:
ret = readDevInfoStr(type, &tempStr);
RET_IF_NONZERO(ret);
*val = std::stoi(tempStr, 0);
*val = std::stoul(tempStr, 0);
break;
default:
@@ -321,7 +338,7 @@ int Device::readDevInfo(DevInfoTypes type, uint32_t *val) {
}
return 0;
}
#endif
int Device::readDevInfo(DevInfoTypes type, std::vector<std::string> *val) {
assert(val != nullptr);
@@ -1,6 +1,4 @@
/*
* =============================================================================
* ROC Runtime Conformance Release License
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
@@ -1,6 +1,4 @@
/*
* =============================================================================
* ROC Runtime Conformance Release License
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
@@ -1,6 +1,4 @@
/*
* =============================================================================
* ROC Runtime Conformance Release License
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
@@ -85,16 +85,15 @@ void TestErrCntRead::Close() {
void TestErrCntRead::Run(void) {
rsmi_status_t err;
rsmi_error_count_t ec;
TestBase::Run();
TestBase::Run();
for (uint32_t i = 0; i < num_monitor_devs(); ++i) {
PrintDeviceHeader(i);
for (uint32_t b = RSMI_GPU_BLOCK_FIRST; b <= RSMI_GPU_BLOCK_LAST; ++b) {
err = rsmi_dev_error_count_get(i, static_cast<rsmi_gpu_block_t>(b), &ec);
if (err == RSMI_STATUS_NOT_SUPPORTED) {
std::cout << "\t**Error Count for " <<
GetBlockNameStr(static_cast<rsmi_gpu_block_t>(b)) <<
+140
Προβολή Αρχείου
@@ -0,0 +1,140 @@
/*
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2019, 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.
*
*/
#include <stdint.h>
#include <stddef.h>
#include <iostream>
#include <string>
#include <map>
#include "gtest/gtest.h"
#include "rocm_smi/rocm_smi.h"
#include "rocm_smi_test/functional/mem_util_read.h"
#include "rocm_smi_test/test_common.h"
TestMemUtilRead::TestMemUtilRead() : TestBase() {
set_title("Memory Utilization Read Test");
set_description("The Memory Utilization Read tests verifies that "
"memory utilization can be read properly.");
}
TestMemUtilRead::~TestMemUtilRead(void) {
}
void TestMemUtilRead::SetUp(void) {
TestBase::SetUp();
return;
}
void TestMemUtilRead::DisplayTestInfo(void) {
TestBase::DisplayTestInfo();
}
void TestMemUtilRead::DisplayResults(void) const {
TestBase::DisplayResults();
return;
}
void TestMemUtilRead::Close() {
// This will close handles opened within rsmitst utility calls and call
// rsmi_shut_down(), so it should be done after other hsa cleanup
TestBase::Close();
}
static const std::map<rsmi_memory_type_t, const char *>
kDevMemoryTypeNameMap = {
{RSMI_MEM_TYPE_VRAM, "VRAM memory"},
{RSMI_MEM_TYPE_VIS_VRAM, "Visible VRAM memory"},
{RSMI_MEM_TYPE_GTT, "GTT memory"},
};
void TestMemUtilRead::Run(void) {
rsmi_status_t err;
uint64_t total;
uint64_t usage;
TestBase::Run();
auto err_chk = [&](const char *str) {
if (err != RSMI_STATUS_SUCCESS) {
if (err == RSMI_STATUS_FILE_ERROR) {
IF_VERB(STANDARD) {
std::cout << "\t** " << str << ": Not supported on this machine"
<< std::endl;
}
} else {
CHK_ERR_ASRT(err)
}
}
};
for (uint32_t i = 0; i < num_monitor_devs(); ++i) {
PrintDeviceHeader(i);
for (uint32_t mem_type = RSMI_MEM_TYPE_FIRST;
mem_type <= RSMI_MEM_TYPE_LAST; ++mem_type) {
err = rsmi_dev_memory_total_get(i,
static_cast<rsmi_memory_type_t>(mem_type), &total);
err_chk("rsmi_dev_memory_total_get()");
if (err != RSMI_STATUS_SUCCESS) {
return;
}
err = rsmi_dev_memory_usage_get(i,
static_cast<rsmi_memory_type_t>(mem_type), &usage);
err_chk("rsmi_dev_memory_usage_get()");
if (err != RSMI_STATUS_SUCCESS) {
return;
}
IF_VERB(STANDARD) {
std::cout << "\t**" <<
kDevMemoryTypeNameMap.at(static_cast<rsmi_memory_type_t>(mem_type)) <<
" Utilization: " << (static_cast<float>(usage)*100)/total << "% ("<<
usage << "/" << total << ")" << std::endl;
}
}
}
}
+71
Προβολή Αρχείου
@@ -0,0 +1,71 @@
/*
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2019, 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.
*
*/
#ifndef TESTS_ROCM_SMI_TEST_FUNCTIONAL_MEM_UTIL_READ_H_
#define TESTS_ROCM_SMI_TEST_FUNCTIONAL_MEM_UTIL_READ_H_
#include "rocm_smi_test/test_base.h"
class TestMemUtilRead : public TestBase {
public:
TestMemUtilRead();
// @Brief: Destructor for test case of TestMemUtilRead
virtual ~TestMemUtilRead();
// @Brief: Setup the environment for measurement
virtual void 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);
};
#endif // TESTS_ROCM_SMI_TEST_FUNCTIONAL_MEM_UTIL_READ_H_
@@ -54,7 +54,8 @@
#include "rocm_smi_test/functional/perf_level_read_write.h"
#include "rocm_smi_test/test_common.h"
static const std::map<rsmi_dev_perf_level_t, const char *> kDevPerfLvlNameMap = {
static const std::map<rsmi_dev_perf_level_t, const char *>
kDevPerfLvlNameMap = {
{RSMI_DEV_PERF_LEVEL_AUTO, "RSMI_DEV_PERF_LEVEL_AUTO"},
{RSMI_DEV_PERF_LEVEL_LOW, "RSMI_DEV_PERF_LEVEL_LOW"},
{RSMI_DEV_PERF_LEVEL_HIGH, "RSMI_DEV_PERF_LEVEL_HIGH"},
@@ -129,7 +130,7 @@ void TestPerfLevelReadWrite::Run(void) {
" ..." << std::endl;
}
ret = rsmi_dev_perf_level_set(dv_ind,
static_cast<rsmi_dev_perf_level_t>(pfl_i));
static_cast<rsmi_dev_perf_level_t>(pfl_i));
CHK_ERR_ASRT(ret)
ret = rsmi_dev_perf_level_get(dv_ind, &pfl);
CHK_ERR_ASRT(ret)
@@ -69,6 +69,7 @@
#include "functional/power_cap_read_write.h"
#include "functional/version_read.h"
#include "functional/err_cnt_read.h"
#include "functional/mem_util_read.h"
static RSMITstGlobals *sRSMIGlvalues = nullptr;
@@ -186,6 +187,10 @@ TEST(rsmitstReadOnly, TestErrCntRead) {
TestErrCntRead tst;
RunGenericTest(&tst);
}
TEST(rsmitstReadOnly, TestMemUtilRead) {
TestMemUtilRead tst;
RunGenericTest(&tst);
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);