Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 7 additions & 4 deletions projects/clr/hipamd/src/hip_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,15 @@ hipError_t ihipMalloc(void** ptr, size_t sizeBytes, unsigned int flags) {
return hipErrorOutOfMemory;
}

const auto& dev_info = amdContext->devices()[0]->info();
const amd::Device& device = *amdContext->devices()[0];
const auto& dev_info = device.info();
hip::getCurrentDevice()->SetActiveStatus();

size_t max_device_size = IS_LINUX
? dev_info.maxMemAllocSize_
: (dev_info.maxMemAllocSize_ + dev_info.maxPhysicalMemAllocSize_);
// maxMemAllocSize_ already covers the aperture, adding host memory double-counts it.
size_t max_device_size =
(IS_LINUX || device.settings().umaLargeMemory_)
Comment thread
jaydeeppatel1111 marked this conversation as resolved.
Resolved
? dev_info.maxMemAllocSize_
: (dev_info.maxMemAllocSize_ + dev_info.maxPhysicalMemAllocSize_);
Comment thread
jaydeeppatel1111 marked this conversation as resolved.
Resolved

if ((useHostDevice && dev_info.maxPhysicalMemAllocSize_ < sizeBytes) ||
(!useHostDevice && max_device_size < sizeBytes)) {
Expand Down
4 changes: 3 additions & 1 deletion projects/clr/rocclr/device/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,9 @@ class Settings {
uint groupMemCarveout_ : 1; //!< Group memory carveout functionality
uint sdma_indirect_supported_ : 1; //!< SDMA linear indirect copy (gfx1250+)
uint aql_device_ring_buf_ : 1; //!< Place the AQL queue ring buffer in device memory
uint reserved_ : 8;
uint umaLargeMemory_ : 1; //!< Unified memory device: report the whole DRAM
// pool rather than a heuristic estimate
uint reserved_ : 7;
};
uint value_;
};
Expand Down
59 changes: 51 additions & 8 deletions projects/clr/rocclr/device/pal/paldevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,24 +342,46 @@ void NullDevice::fillDeviceInfo(const Pal::DeviceProperties& palProp,
info_.globalMemCacheType_ = CL_NONE;
}

uint64_t localRAM;
uint64_t visibleFB, invisibleFB;
if (GPU_ADD_HBCC_SIZE) {
localRAM = heaps[Pal::GpuHeapLocal].logicalSize + heaps[Pal::GpuHeapInvisible].logicalSize;
visibleFB = heaps[Pal::GpuHeapLocal].logicalSize;
invisibleFB = heaps[Pal::GpuHeapInvisible].logicalSize;
} else {
Comment thread
jaydeeppatel1111 marked this conversation as resolved.
Resolved
localRAM = heaps[Pal::GpuHeapLocal].physicalSize + heaps[Pal::GpuHeapInvisible].physicalSize;
visibleFB = heaps[Pal::GpuHeapLocal].physicalSize;
invisibleFB = heaps[Pal::GpuHeapInvisible].physicalSize;
}
const uint64_t localRAM = visibleFB + invisibleFB;

info_.globalMemSize_ = (static_cast<uint64_t>(std::min(GPU_MAX_HEAP_SIZE, 100u)) *
static_cast<uint64_t>(localRAM) / 100u);

const uint64_t gartSize = static_cast<uint64_t>(heaps[Pal::GpuHeapGartUswc].logicalSize);
const uint64_t hostRAM = amd::Os::getPhysicalMemSize();

const bool umaLargeMemory = settings().umaLargeMemory_;

uint uswcPercentAvailable =
((static_cast<uint64_t>(heaps[Pal::GpuHeapGartUswc].logicalSize) / Mi) > 1536 && IS_WINDOWS)
? 75
: 50;

// The aperture is host DRAM the GPU addresses directly, so discounting it only
// makes the runtime under-report.
if (umaLargeMemory) {
uswcPercentAvailable = 100;
}

uint64_t gartCredit = (gartSize * uswcPercentAvailable) / 100;

if (umaLargeMemory) {
// Crediting the whole aperture can leave the OS nothing, so hold back a floor of
// host memory. Binds only where the BIOS reserves too little on its own.
const uint64_t osFloor = std::min<uint64_t>(16 * Gi, hostRAM / 4);
gartCredit = std::min(gartCredit, (hostRAM > osFloor) ? (hostRAM - osFloor) : 0);
}

if (settings().apuSystem_) {
info_.globalMemSize_ +=
(static_cast<uint64_t>(heaps[Pal::GpuHeapGartUswc].logicalSize) * uswcPercentAvailable) /
100;
info_.globalMemSize_ += gartCredit;
}

// Find the largest heap form FB memory
Expand All @@ -379,13 +401,23 @@ void NullDevice::fillDeviceInfo(const Pal::DeviceProperties& palProp,
info_.maxMemAllocSize_);
}
#endif

if (umaLargeMemory) {
// One allocation is not confined to a single heap. Measured on gfx1151: 100 GiB
// verified across a carve-out split 64 GiB visible plus 32 GiB invisible.
info_.maxMemAllocSize_ = std::max(info_.globalMemSize_, info_.maxMemAllocSize_);
}

info_.maxMemAllocSize_ =
uint64_t(info_.maxMemAllocSize_ * std::min(GPU_SINGLE_ALLOC_PERCENT, 100u) / 100u);

//! \note Force max single allocation size.
//! 4GB limit for the blit kernels and 64 bit optimizations.
info_.maxMemAllocSize_ =
std::min(info_.maxMemAllocSize_, static_cast<uint64_t>(settings().maxAllocSize_));
//! Skipped on large unified memory parts: the cap reports far below what they deliver.
if (!umaLargeMemory) {
info_.maxMemAllocSize_ =
std::min(info_.maxMemAllocSize_, static_cast<uint64_t>(settings().maxAllocSize_));
}

if (info_.maxMemAllocSize_ < uint64_t(128 * Mi)) {
LogError(
Expand All @@ -406,6 +438,17 @@ void NullDevice::fillDeviceInfo(const Pal::DeviceProperties& palProp,
// that 4x single alloc
info_.globalMemSize_ = std::min(4 * info_.maxMemAllocSize_, info_.globalMemSize_);

// Offline devices populate only the Local heap, so the rest of heaps[] is stale here.
if (isOnline()) {
ClPrint(amd::LOG_INFO, amd::LOG_INIT,
"PAL memory: visible FB %llu MiB, invisible FB %llu MiB, aperture %llu MiB "
"(credited %llu MiB at %u%%), host %llu MiB, apu %u, umaLargeMemory %u, "
"globalMemSize %llu MiB, maxMemAllocSize %llu MiB",
visibleFB / Mi, invisibleFB / Mi, gartSize / Mi, gartCredit / Mi, uswcPercentAvailable,
hostRAM / Mi, settings().apuSystem_ ? 1u : 0u, umaLargeMemory ? 1u : 0u,
info_.globalMemSize_ / Mi, info_.maxMemAllocSize_ / Mi);
}

// Use 64 bit pointers
info_.addressBits_ = 64;
if (!settings().use64BitPtr_) {
Expand Down
7 changes: 7 additions & 0 deletions projects/clr/rocclr/device/pal/palsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Settings::Settings() {

// GPU device by default
apuSystem_ = false;
umaLargeMemory_ = false;

// Disable 64 bit pointers support by default
use64BitPtr_ = false;
Expand Down Expand Up @@ -133,6 +134,12 @@ bool Settings::create(const Pal::DeviceProperties& palProp,
apuSystem_ = true;
}

// Scoped to the parts where large unified memory has been validated. Others keep the
// existing memory reporting until measured.
if (palProp.revision == Pal::AsicRevision::StrixHalo) {
umaLargeMemory_ = true;
}

enableXNACK_ = (isa.xnack() == amd::Isa::Feature::Enabled);
bool useWavefront64 = false;

Expand Down
Loading