Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rocr/aie: AIE agent memory pools correct size and user data pool #265

Open
wants to merge 4 commits into
base: amd-staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

#include <sys/ioctl.h>
#include <sys/mman.h>
#include <unistd.h>

#include <memory>
#include <string>
Expand All @@ -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<Driver> xdna_drv(
Expand All @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions runtime/hsa-runtime/core/inc/amd_xdna_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
13 changes: 11 additions & 2 deletions runtime/hsa-runtime/core/runtime/amd_aie_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down