Reimplement hipMemGetInfo (#1447)

Addresses SWDEV-136570. hipMemGetInfo changed to compute free memory based on information from kfd instead of relying on hc::am_tracker.


[ROCm/hip commit: 3d661e4706]
This commit is contained in:
satyanveshd
2019-10-01 12:40:36 +05:30
committed by Maneesh Gupta
parent 52f126b557
commit bfb64c43a4
3 changed files with 34 additions and 13 deletions
+9 -3
View File
@@ -505,13 +505,19 @@ ihipDevice_t::ihipDevice_t(unsigned deviceId, unsigned deviceCnt, hc::accelerato
: _deviceId(deviceId), _acc(acc), _state(0), _criticalData(this) { : _deviceId(deviceId), _acc(acc), _state(0), _criticalData(this) {
hsa_agent_t* agent = static_cast<hsa_agent_t*>(acc.get_hsa_agent()); hsa_agent_t* agent = static_cast<hsa_agent_t*>(acc.get_hsa_agent());
if (agent) { if (agent) {
int err = hsa_agent_get_info( int err;
err = hsa_agent_get_info(
*agent, (hsa_agent_info_t)HSA_AMD_AGENT_INFO_COMPUTE_UNIT_COUNT, &_computeUnits); *agent, (hsa_agent_info_t)HSA_AMD_AGENT_INFO_COMPUTE_UNIT_COUNT, &_computeUnits);
if (err != HSA_STATUS_SUCCESS) { if (err != HSA_STATUS_SUCCESS) {
_computeUnits = 1; _computeUnits = 1;
} }
err = hsa_agent_get_info(
_hsaAgent = *agent; *agent, (hsa_agent_info_t) HSA_AMD_AGENT_INFO_DRIVER_NODE_ID, &_driver_node_id);
if (err != HSA_STATUS_SUCCESS){
_driver_node_id = 0;
}
_hsaAgent = *agent;
} else { } else {
_hsaAgent.handle = static_cast<uint64_t>(-1); _hsaAgent.handle = static_cast<uint64_t>(-1);
} }
+3
View File
@@ -802,6 +802,9 @@ class ihipDevice_t {
// TODO - report this through device properties, base on HCC API call. // TODO - report this through device properties, base on HCC API call.
int _isLargeBar; int _isLargeBar;
// Node id reported by kfd for this device
uint32_t _driver_node_id;
ihipCtx_t* _primaryCtx; ihipCtx_t* _primaryCtx;
+22 -10
View File
@@ -19,7 +19,6 @@ 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 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
#include <hc_am.hpp> #include <hc_am.hpp>
#include "hsa/hsa.h" #include "hsa/hsa.h"
#include "hsa/hsa_ext_amd.h" #include "hsa/hsa_ext_amd.h"
@@ -28,6 +27,8 @@ THE SOFTWARE.
#include "hip_hcc_internal.h" #include "hip_hcc_internal.h"
#include "trace_helper.h" #include "trace_helper.h"
#include <fstream>
__device__ char __hip_device_heap[__HIP_SIZE_OF_HEAP]; __device__ char __hip_device_heap[__HIP_SIZE_OF_HEAP];
__device__ uint32_t __hip_device_page_flag[__HIP_NUM_PAGES]; __device__ uint32_t __hip_device_page_flag[__HIP_NUM_PAGES];
@@ -1967,16 +1968,27 @@ hipError_t hipMemGetInfo(size_t* free, size_t* total) {
} else { } else {
e = hipErrorInvalidValue; e = hipErrorInvalidValue;
} }
if (free) { if (free) {
// TODO - replace with kernel-level for reporting free memory: if (!device->_driver_node_id) return ihipLogStatus(hipErrorInvalidDevice);
size_t deviceMemSize, hostMemSize, userMemSize;
hc::am_memtracker_sizeinfo(device->_acc, &deviceMemSize, &hostMemSize, &userMemSize); std::string fileName = std::string("/sys/class/kfd/kfd/topology/nodes/") + std::to_string(device->_driver_node_id) + std::string("/mem_banks/0/used_memory");
std::ifstream file;
*free = device->_props.totalGlobalMem - deviceMemSize; file.open(fileName);
if (!file) return ihipLogStatus(hipErrorFileNotFound);
// Deduct the amount of memory from the free memory reported from the system
if (HIP_HIDDEN_FREE_MEM) *free -= (size_t)HIP_HIDDEN_FREE_MEM * 1024 * 1024; std::string deviceSize;
size_t deviceMemSize;
file >> deviceSize;
file.close();
if ((deviceMemSize=strtol(deviceSize.c_str(),NULL,10))){
*free = device->_props.totalGlobalMem - deviceMemSize;
// Deduct the amount of memory from the free memory reported from the system
if (HIP_HIDDEN_FREE_MEM) *free -= (size_t)HIP_HIDDEN_FREE_MEM * 1024 * 1024;
} else {
return ihipLogStatus(hipErrorInvalidValue);
}
} else { } else {
e = hipErrorInvalidValue; e = hipErrorInvalidValue;
} }