Skip to content

Commit 1113eff

Browse files
authored
SWDEV-493275 - Support scratch limit (#20)
Support programmatic query and change of scratch limit on AMD devices. Change-Id: Id5da355a77366f97868e462847f3916e87fd2af6
1 parent 4f2a4b1 commit 1113eff

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

hipamd/src/hip_device_runtime.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,15 @@ hipError_t hipDeviceGetLimit(size_t* pValue, hipLimit_t limit) {
519519
case hipLimitStackSize:
520520
*pValue = hip::getCurrentDevice()->devices()[0]->StackSize();
521521
break;
522+
case hipExtLimitScratchMin:
523+
*pValue = hip::getCurrentDevice()->devices()[0]->info().scratchLimitMin;
524+
break;
525+
case hipExtLimitScratchMax:
526+
*pValue = hip::getCurrentDevice()->devices()[0]->info().scratchLimitMax;;
527+
break;
528+
case hipExtLimitScratchCurrent:
529+
*pValue = hip::getCurrentDevice()->devices()[0]->ScratchLimitCurrent();
530+
break;
522531
default:
523532
LogPrintfError("UnsupportedLimit = %d is passed", limit);
524533
HIP_RETURN(hipErrorUnsupportedLimit);
@@ -601,6 +610,11 @@ hipError_t hipDeviceSetLimit(hipLimit_t limit, size_t value) {
601610
HIP_RETURN(hipErrorInvalidValue);
602611
}
603612
break;
613+
case hipExtLimitScratchCurrent:
614+
if (!hip::getCurrentDevice()->devices()[0]->UpdateScratchLimitCurrent(value)) {
615+
HIP_RETURN(hipErrorInvalidValue);
616+
}
617+
break;
604618
default:
605619
LogPrintfError("UnsupportedLimit = %d is passed", limit);
606620
HIP_RETURN(hipErrorUnsupportedLimit);

rocclr/device/device.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,9 @@ struct Info : public amd::EmbeddedObject {
658658
uint32_t luidLowPart_; //!< Luid low 4 bytes, available in Windows only
659659
uint32_t luidHighPart_; //!< Luid high 4 bytes, available in Windows only
660660
uint32_t luidDeviceNodeMask_; //!< Luid node mask
661+
662+
size_t scratchLimitMin; //! Minimum size of scratch limit of this device memory in bytes.
663+
size_t scratchLimitMax; //! Maximum size of scratch limit of this device memory in bytes.
661664
};
662665

663666
//! Device settings
@@ -1976,6 +1979,12 @@ class Device : public RuntimeObject {
19761979
return false;
19771980
}
19781981

1982+
//! Returns current scratch limit of the device. Valid only on rocm device.
1983+
virtual size_t ScratchLimitCurrent() const { return 0; }
1984+
1985+
//! Sets the current scratch limit of the device. Valid only on rocm device.
1986+
virtual bool UpdateScratchLimitCurrent(size_t limit) const { return true; }
1987+
19791988
//! Validate kernel
19801989
virtual bool validateKernel(const amd::Kernel& kernel,
19811990
const device::VirtualDevice* vdev,

rocclr/device/rocm/rocdevice.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,16 @@ bool Device::populateOCLDeviceConstants() {
11561156
return false;
11571157
}
11581158

1159+
uint64_t scratchLimitMax = 0;
1160+
if (HSA_STATUS_SUCCESS !=
1161+
hsa_agent_get_info(bkendDevice_, (hsa_agent_info_t)HSA_AMD_AGENT_INFO_SCRATCH_LIMIT_MAX ,
1162+
&scratchLimitMax)) {
1163+
LogWarning("HSA_AMD_AGENT_INFO_SCRATCH_LIMIT_MAX cannot be queried!");
1164+
return false;
1165+
}
1166+
info_.scratchLimitMin = 0;
1167+
info_.scratchLimitMax = scratchLimitMax;
1168+
11591169
checkAtomicSupport();
11601170

11611171
assert(system_segment_.handle != 0);
@@ -2749,6 +2759,28 @@ bool Device::GetSvmAttributes(void** data, size_t* data_sizes, int* attributes,
27492759
return true;
27502760
}
27512761

2762+
size_t Device::ScratchLimitCurrent() const {
2763+
uint64_t scratchLimitCurrent = 0;
2764+
hsa_status_t ret = hsa_agent_get_info(bkendDevice_,
2765+
(hsa_agent_info_t)HSA_AMD_AGENT_INFO_SCRATCH_LIMIT_CURRENT, &scratchLimitCurrent);
2766+
if (HSA_STATUS_SUCCESS != ret) {
2767+
LogPrintfError("HSA_AMD_AGENT_INFO_SCRATCH_LIMIT_CURRENT cannot be queried! Err: 0x%xh",
2768+
ret);
2769+
return 0;
2770+
}
2771+
return static_cast<size_t>(scratchLimitCurrent);
2772+
};
2773+
2774+
bool Device::UpdateScratchLimitCurrent(size_t limit) const {
2775+
hsa_status_t ret = hsa_amd_agent_set_async_scratch_limit(bkendDevice_, limit);
2776+
if (HSA_STATUS_SUCCESS != ret) {
2777+
LogPrintfError("hsa_amd_agent_set_async_scratch_limit(%zu) failed with err 0x%xh",
2778+
limit, ret);
2779+
return false;
2780+
}
2781+
return true;
2782+
};
2783+
27522784
// ================================================================================================
27532785
bool Device::SvmAllocInit(void* memory, size_t size) const {
27542786
amd::MemoryAdvice advice = amd::MemoryAdvice::SetAccessedBy;

rocclr/device/rocm/rocdevice.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ class Device : public NullDevice {
431431
amd::MemoryAdvice advice, bool use_cpu = false) const;
432432
virtual bool GetSvmAttributes(void** data, size_t* data_sizes, int* attributes,
433433
size_t num_attributes, const void* dev_ptr, size_t count) const;
434-
434+
virtual size_t ScratchLimitCurrent() const final;
435+
virtual bool UpdateScratchLimitCurrent(size_t limit) const final;
435436
virtual void* virtualAlloc(void* req_addr, size_t size, size_t alignment);
436437
virtual bool virtualFree(void* addr);
437438

0 commit comments

Comments
 (0)