diff --git a/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp b/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp index edee88b73..997fabf00 100644 --- a/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp +++ b/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp @@ -44,6 +44,7 @@ #include #include +#include #include #include @@ -64,7 +65,7 @@ XdnaDriver::~XdnaDriver() { FreeDeviceHeap(); } hsa_status_t XdnaDriver::DiscoverDriver() { const int max_minor_num(64); - const std::string devnode_prefix("/dev/accel/accel"); + static const std::string devnode_prefix("/dev/accel/accel"); for (int i = 0; i < max_minor_num; ++i) { std::unique_ptr xdna_drv( @@ -84,6 +85,12 @@ hsa_status_t XdnaDriver::DiscoverDriver() { return HSA_STATUS_ERROR; } +uint64_t XdnaDriver::GetSystemMemoryByteSize() { + const long pagesize = sysconf(_SC_PAGESIZE); + const long page_count = sysconf(_SC_PHYS_PAGES); + return pagesize * page_count; +} + uint64_t XdnaDriver::GetDevHeapByteSize() { return dev_heap_size; } diff --git a/runtime/hsa-runtime/core/inc/amd_xdna_driver.h b/runtime/hsa-runtime/core/inc/amd_xdna_driver.h index 4c0cad47f..156a9b0b4 100644 --- a/runtime/hsa-runtime/core/inc/amd_xdna_driver.h +++ b/runtime/hsa-runtime/core/inc/amd_xdna_driver.h @@ -133,6 +133,9 @@ class XdnaDriver final : public core::Driver { static hsa_status_t DiscoverDriver(); + /// @brief Returns the size of the system memory heap in bytes. + static uint64_t GetSystemMemoryByteSize(); + /// @brief Returns the size of the dev heap in bytes. static uint64_t GetDevHeapByteSize(); diff --git a/runtime/hsa-runtime/core/runtime/amd_aie_agent.cpp b/runtime/hsa-runtime/core/runtime/amd_aie_agent.cpp index 3c823b464..d655d0fa2 100644 --- a/runtime/hsa-runtime/core/runtime/amd_aie_agent.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_aie_agent.cpp @@ -282,25 +282,34 @@ void AieAgent::InitRegionList() { /// This should be easier once the ROCt source is incorporated into the /// ROCr source. Since the AIE itself currently has no memory regions of /// its own all memory is just the system DRAM. + const uint64_t total_system_memory = XdnaDriver::GetSystemMemoryByteSize(); /// For allocating kernel arguments or other objects that only need /// system memory. HsaMemoryProperties sys_mem_props = {}; sys_mem_props.HeapType = HSA_HEAPTYPE_SYSTEM; + sys_mem_props.SizeInBytes = total_system_memory; + + /// For any other allocation, e.g., buffers. + HsaMemoryProperties other_mem_props = {}; + other_mem_props.HeapType = HSA_HEAPTYPE_SYSTEM; + other_mem_props.SizeInBytes = total_system_memory; /// For allocating memory for programmable device image (PDI) files. These /// need to be mapped to the device so the hardware can access the PDIs. HsaMemoryProperties dev_mem_props = {}; - dev_mem_props.HeapType = HSA_HEAPTYPE_DEVICE_SVM, + dev_mem_props.HeapType = HSA_HEAPTYPE_DEVICE_SVM; dev_mem_props.SizeInBytes = XdnaDriver::GetDevHeapByteSize(); /// As of now the AIE devices support coarse-grain memory regions that require /// explicit sync operations. - regions_.reserve(2); + regions_.reserve(3); regions_.push_back( new MemoryRegion(false, true, false, false, true, this, sys_mem_props)); regions_.push_back( new MemoryRegion(false, false, false, false, true, this, dev_mem_props)); + regions_.push_back(new MemoryRegion(false, false, false, false, true, this, + other_mem_props)); } void AieAgent::GetAgentProperties() {