diff --git a/projects/clr/hipamd/src/hip_device_runtime.cpp b/projects/clr/hipamd/src/hip_device_runtime.cpp index d878b2ba99..eb9e5dac43 100644 --- a/projects/clr/hipamd/src/hip_device_runtime.cpp +++ b/projects/clr/hipamd/src/hip_device_runtime.cpp @@ -448,6 +448,9 @@ hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device) case hipDeviceAttributeNumberOfXccs: *pi = static_cast(g_devices[device]->devices()[0]->info().numberOfXccs_); break; + case hipDeviceAttributeMaxAvailableVgprsPerThread: + *pi = static_cast(g_devices[device]->devices()[0]->info().availableVGPRs_); + break; default: HIP_RETURN(hipErrorInvalidValue); } diff --git a/projects/clr/hipamd/src/hip_platform.cpp b/projects/clr/hipamd/src/hip_platform.cpp index da290fd5ed..7d91f209cd 100644 --- a/projects/clr/hipamd/src/hip_platform.cpp +++ b/projects/clr/hipamd/src/hip_platform.cpp @@ -397,7 +397,7 @@ hipError_t ihipOccupancyMaxActiveBlocksPerMultiprocessor( } if (VgprWaves == 0) { - // This should not happen ideally, but in case the usedVGPRs_/availableVGPRs_ values are + // This should not happen ideally, but in case the value is // incorrect, it can lead to a crash. By returning error, API can exit gracefully. return hipErrorUnknown; } diff --git a/projects/clr/rocclr/device/device.hpp b/projects/clr/rocclr/device/device.hpp index afe33850e9..e3b3f736df 100644 --- a/projects/clr/rocclr/device/device.hpp +++ b/projects/clr/rocclr/device/device.hpp @@ -552,10 +552,12 @@ struct Info : public amd::EmbeddedObject { uint32_t wavefrontWidth_; //! Available number of SGPRs uint32_t availableSGPRs_; - //! Available number of VGPRs - uint32_t availableVGPRs_; - //! Available number of registers per CU - uint32_t availableRegistersPerCU_; + + uint32_t availableVGPRs_; //!< Number of addressable VGPRs per thread in DWORDs + uint32_t vgprsPerSimd_; //!< Number of VGPRs per SIMD in DWORDs + uint32_t vgprAllocGranularity_; //!< Number of VGPRs allocation granularity per thread in DWORDs + uint32_t availableRegistersPerCU_; //!< Number of VGPRs per CU in DWORDs + //! Number of global memory channels uint32_t globalMemChannels_; //! Number of banks in each global memory channel @@ -650,9 +652,7 @@ struct Info : public amd::EmbeddedObject { uint32_t driverNodeId_; //! Number of Physical SGPRs per SIMD uint32_t sgprsPerSimd_; - //! Number of VGPRs per SIMD - uint32_t vgprsPerSimd_; - uint32_t vgprAllocGranularity_; + uint32_t numSDMAengines_; //!< Number of available SDMA engines uint32_t luidLowPart_; //!< Luid low 4 bytes, available in Windows only diff --git a/projects/clr/rocclr/device/devkernel.cpp b/projects/clr/rocclr/device/devkernel.cpp index 1bb97cb390..3cb121a544 100644 --- a/projects/clr/rocclr/device/devkernel.cpp +++ b/projects/clr/rocclr/device/devkernel.cpp @@ -619,7 +619,7 @@ Kernel::Kernel(const amd::Device& dev, const std::string& name, const Program& p workGroupInfo_.usedGPRs_ = 0; workGroupInfo_.availableSGPRs_ = 0; workGroupInfo_.usedSGPRs_ = 0; - workGroupInfo_.availableVGPRs_ = 0; + workGroupInfo_.availableVGPRs_ = dev.info().availableVGPRs_; workGroupInfo_.usedVGPRs_ = 0; workGroupInfo_.availableLDSSize_ = 0; workGroupInfo_.usedLDSSize_ = 0; diff --git a/projects/clr/rocclr/device/devkernel.hpp b/projects/clr/rocclr/device/devkernel.hpp index fd5918642b..0a4fc1edd6 100644 --- a/projects/clr/rocclr/device/devkernel.hpp +++ b/projects/clr/rocclr/device/devkernel.hpp @@ -218,8 +218,8 @@ class Kernel : public amd::HeapObject { size_t usedGPRs_; //!< GPRs used by the program size_t availableSGPRs_; //!< SGPRs available to the program size_t usedSGPRs_; //!< SGPRs used by the program - size_t availableVGPRs_; //!< VGPRs available to the program - size_t usedVGPRs_; //!< VGPRs used by the program + size_t availableVGPRs_; //!< VGPRs addressable to the program per thread in DWORDs + size_t usedVGPRs_; //!< VGPRs used by the program per thread in DWORDs size_t availableLDSSize_; //!< available LDS size size_t usedLDSSize_; //!< used LDS size size_t availableStackSize_; //!< available stack size diff --git a/projects/clr/rocclr/device/pal/paldevice.cpp b/projects/clr/rocclr/device/pal/paldevice.cpp index 03a087b0f1..351eba93d7 100644 --- a/projects/clr/rocclr/device/pal/paldevice.cpp +++ b/projects/clr/rocclr/device/pal/paldevice.cpp @@ -678,8 +678,9 @@ void NullDevice::fillDeviceInfo(const Pal::DeviceProperties& palProp, static_cast(palProp.gpuMemoryProperties.virtualMemAllocGranularity); info_.vgprAllocGranularity_ = palProp.gfxipProperties.shaderCore.vgprAllocGranularity; info_.vgprsPerSimd_ = palProp.gfxipProperties.shaderCore.vgprsPerSimd; + info_.availableVGPRs_ = palProp.gfxipProperties.shaderCore.numAvailableVgprs; info_.sgprsPerSimd_ = palProp.gfxipProperties.shaderCore.sgprsPerSimd; - info_.availableRegistersPerCU_ = info_.vgprsPerSimd_ * info_.simdPerCU_ * 32; + info_.availableRegistersPerCU_ = info_.vgprsPerSimd_ * info_.simdPerCU_ * info_.wavefrontWidth_; #if IS_WINDOWS info_.luidLowPart_ = palProp.osProperties.luidLowPart; info_.luidHighPart_ = palProp.osProperties.luidHighPart; diff --git a/projects/clr/rocclr/device/rocm/rocdevice.cpp b/projects/clr/rocclr/device/rocm/rocdevice.cpp index a0a7e8987c..7ada04d7ea 100644 --- a/projects/clr/rocclr/device/rocm/rocdevice.cpp +++ b/projects/clr/rocclr/device/rocm/rocdevice.cpp @@ -1634,12 +1634,21 @@ bool Device::populateOCLDeviceConstants() { // Get Values from from Comgr amd_comgr_metadata_node_t isaMeta; if (getIsaMeta(std::move(isa().isaName()), isaMeta)) { - std::string vgprValue; - info_.availableVGPRs_ = (getValueFromIsaMeta(isaMeta, "AddressableNumVGPRs", vgprValue)) - ? (atoi(vgprValue.c_str()) * info_.simdPerCU_) - : 0; + std::string addressableNumVGPRs, totalNumVGPRs, vGPRAllocGranule; + info_.availableVGPRs_ = getValueFromIsaMeta(isaMeta, "AddressableNumVGPRs", + addressableNumVGPRs) ? atoi(addressableNumVGPRs.c_str()) : 0; + info_.vgprsPerSimd_ = getValueFromIsaMeta(isaMeta, "TotalNumVGPRs", + totalNumVGPRs) ? atoi(totalNumVGPRs.c_str()) : 0; + info_.vgprAllocGranularity_ = getValueFromIsaMeta(isaMeta, "VGPRAllocGranule", + vGPRAllocGranule) ? atoi(vGPRAllocGranule.c_str()) : 0; - info_.availableRegistersPerCU_ = info_.availableVGPRs_ * 64; // 64 registers per VGPR + info_.availableRegistersPerCU_ = info_.vgprsPerSimd_ * info_.simdPerCU_ * + info_.wavefrontWidth_; + ClPrint(amd::LOG_INFO, amd::LOG_INIT, + "addressableNumVGPRs=%u, totalNumVGPRs=%u, vGPRAllocGranule=%u," \ + " availableRegistersPerCU_=%u", + info_.availableVGPRs_, info_.vgprsPerSimd_, info_.vgprAllocGranularity_, + info_.availableRegistersPerCU_); std::string sgprValue; info_.availableSGPRs_ = (getValueFromIsaMeta(isaMeta, "AddressableNumSGPRs", sgprValue)) @@ -1648,6 +1657,8 @@ bool Device::populateOCLDeviceConstants() { if (!releaseIsaMeta(isaMeta)) { LogInfo("Can not release the isa meta node"); } + } else { + ClPrint(amd::LOG_ERROR, amd::LOG_INIT, "getIsaMeta(%s) failed!", isa().isaName().c_str()); } // Generic support for HMM interfaces @@ -1694,82 +1705,6 @@ bool Device::populateOCLDeviceConstants() { } HIP_MEM_POOL_USE_VM &= info_.virtualMemoryManagement_; - switch (isa().versionMajor()) { - case (12): - if (isa().versionMinor() == 0) { - switch (isa().versionStepping()) { - case (0): - case (1): - default: - info_.vgprAllocGranularity_ = 24; - info_.vgprsPerSimd_ = 1536; - break; - } - } - break; - case (11): - if (isa().versionMinor() == 0) { - switch (isa().versionStepping()) { - case (0): - case (1): - case (5): - info_.vgprAllocGranularity_ = 24; - info_.vgprsPerSimd_ = 1536; - break; - case (2): - case (3): - default: - info_.vgprAllocGranularity_ = 16; - info_.vgprsPerSimd_ = 1024; - break; - } - } else if (isa().versionMinor() == 5) { - switch (isa().versionStepping()) { - case (1): - info_.vgprAllocGranularity_ = 24; - info_.vgprsPerSimd_ = 1536; - break; - default: - info_.vgprAllocGranularity_ = 16; - info_.vgprsPerSimd_ = 1024; - break; - } - } else { - info_.vgprAllocGranularity_ = 16; - info_.vgprsPerSimd_ = 1024; - } - break; - case (10): - switch (isa().versionMinor()) { - case (0): - case (1): - info_.vgprAllocGranularity_ = 8; - info_.vgprsPerSimd_ = 1024; - break; - case (3): - default: - info_.vgprAllocGranularity_ = 16; - info_.vgprsPerSimd_ = 1024; - break; - } - break; - case (9): - if ((isa().versionMinor() == 0 && isa().versionStepping() == 10) || - isa().versionMinor() == 4 || isa().versionMinor() == 5) { - info_.vgprAllocGranularity_ = 8; - info_.vgprsPerSimd_ = 512; - } else { - info_.vgprAllocGranularity_ = 4; - info_.vgprsPerSimd_ = 256; - } - break; - default: - // For gfx<=8 - info_.vgprAllocGranularity_ = 4; - info_.vgprsPerSimd_ = 256; - break; - } - if (isa().versionMajor() < 8) { info_.sgprsPerSimd_ = 512; } else if (isa().versionMajor() < 10) {