SWDEV-465215 - hipFuncSetAttribute hipFuncGetAttributes fixes

Change-Id: I2151e4470d63918ff6b809a8fdeaae5bea5cc899


[ROCm/clr commit: c9955a1cea]
Этот коммит содержится в:
Ajay
2024-06-04 12:53:52 -07:00
коммит произвёл Ajay GunaShekar
родитель 343bdf3187
Коммит d7f4f778b3
6 изменённых файлов: 54 добавлений и 14 удалений
+9 -9
Просмотреть файл
@@ -183,21 +183,21 @@ hipError_t Function::getStatFuncAttr(hipFuncAttributes* func_attr, int deviceId)
const std::vector<amd::Device*>& devices = amd::Device::getDevices(CL_DEVICE_TYPE_GPU, false);
amd::Kernel* kernel = dFunc_[deviceId]->kernel();
const device::Kernel::WorkGroupInfo* wginfo = kernel->getDeviceKernel(*devices[deviceId])->workGroupInfo();
auto* device_handle = devices[deviceId];
const device::Kernel::WorkGroupInfo* wginfo =
kernel->getDeviceKernel(*device_handle)->workGroupInfo();
int binaryVersion = device_handle->isa().versionMajor() * 10 +
device_handle->isa().versionMinor();
func_attr->sharedSizeBytes = static_cast<int>(wginfo->localMemSize_);
func_attr->binaryVersion = static_cast<int>(kernel->signature().version());
func_attr->binaryVersion = binaryVersion;
func_attr->cacheModeCA = 0;
func_attr->constSizeBytes = 0;
func_attr->constSizeBytes = wginfo->constMemSize_ - 1;
func_attr->localSizeBytes = wginfo->privateMemSize_;
func_attr->maxDynamicSharedSizeBytes = static_cast<int>(wginfo->availableLDSSize_
- wginfo->localMemSize_);
func_attr->maxDynamicSharedSizeBytes = wginfo->maxDynamicSharedSizeBytes_;
func_attr->maxThreadsPerBlock = static_cast<int>(wginfo->size_);
func_attr->numRegs = static_cast<int>(wginfo->usedVGPRs_);
func_attr->preferredShmemCarveout = 0;
func_attr->ptxVersion = 30;
func_attr->ptxVersion = binaryVersion;
return hipSuccess;
}
+39 -5
Просмотреть файл
@@ -139,7 +139,7 @@ hipError_t hipFuncGetAttribute(int* value, hipFunction_attribute attrib, hipFunc
*value = static_cast<int>(wrkGrpInfo->size_);
break;
case HIP_FUNC_ATTRIBUTE_CONST_SIZE_BYTES:
*value = 0;
*value = static_cast<int>(wrkGrpInfo->constMemSize_ - 1);
break;
case HIP_FUNC_ATTRIBUTE_LOCAL_SIZE_BYTES:
*value = static_cast<int>(wrkGrpInfo->privateMemSize_);
@@ -148,10 +148,9 @@ hipError_t hipFuncGetAttribute(int* value, hipFunction_attribute attrib, hipFunc
*value = static_cast<int>(wrkGrpInfo->usedVGPRs_);
break;
case HIP_FUNC_ATTRIBUTE_PTX_VERSION:
*value = 30; // Defaults to 3.0 as HCC
break;
case HIP_FUNC_ATTRIBUTE_BINARY_VERSION:
*value = static_cast<int>(kernel->signature().version());
*value = hip::getCurrentDevice()->devices()[0]->isa().versionMajor() * 10 +
hip::getCurrentDevice()->devices()[0]->isa().versionMinor();
break;
case HIP_FUNC_ATTRIBUTE_CACHE_MODE_CA:
*value = 0;
@@ -180,7 +179,42 @@ hipError_t hipFuncGetAttributes(hipFuncAttributes* attr, const void* func) {
hipError_t hipFuncSetAttribute(const void* func, hipFuncAttribute attr, int value) {
HIP_INIT_API(hipFuncSetAttribute, func, attr, value);
// No way to set function attribute yet.
if (func == nullptr) {
HIP_RETURN(hipErrorInvalidDeviceFunction);
}
if (attr < 0 || attr > hipFuncAttributeMax) {
HIP_RETURN(hipErrorInvalidValue);
}
hipFunction_t h_func;
HIP_RETURN_ONFAIL(PlatformState::instance().getStatFunc(&h_func, func, ihipGetDevice()));
hip::DeviceFunc* function = hip::DeviceFunc::asFunction(h_func);
if (function == nullptr) {
HIP_RETURN(hipErrorInvalidHandle);
}
amd::Kernel* kernel = reinterpret_cast<hip::DeviceFunc*>(function)->kernel();
if (kernel == nullptr) {
HIP_RETURN(hipErrorInvalidDeviceFunction);
}
device::Kernel* d_kernel =
(device::Kernel*)(kernel->getDeviceKernel(
*(hip::getCurrentDevice()->devices()[0])));
if (attr == hipFuncAttributeMaxDynamicSharedMemorySize) {
if ((value < 0) || (value > (d_kernel->workGroupInfo()->availableLDSSize_ -
d_kernel->workGroupInfo()->localMemSize_))) {
HIP_RETURN(hipErrorInvalidValue);
}
d_kernel->workGroupInfo()->maxDynamicSharedSizeBytes_ = value;
}
if (attr == hipFuncAttributePreferredSharedMemoryCarveout) {
if (value < -1 || value > 100) {
HIP_RETURN(hipErrorInvalidValue);
}
}
HIP_RETURN(hipSuccess);
}
+1
Просмотреть файл
@@ -624,6 +624,7 @@ Kernel::Kernel(const amd::Device& dev, const std::string& name, const Program& p
workGroupInfo_.uniformWorkGroupSize_ = false;
workGroupInfo_.wavesPerSimdHint_ = 0;
workGroupInfo_.constMemSize_ = 0;
workGroupInfo_.maxDynamicSharedSizeBytes_ = 0;
}
// ================================================================================================
+1
Просмотреть файл
@@ -387,6 +387,7 @@ class Kernel : public amd::HeapObject {
size_t compileSizeHint_[3]; //!< kernel compiled workgroup size hint
size_t wavesPerSimdHint_; //!< waves per simd hit
size_t constMemSize_; //!< size of user-allocated constant memory
size_t maxDynamicSharedSizeBytes_;
std::string compileVecTypeHint_; //!< kernel compiled vector type hint
int maxOccupancyPerCu_; //!< Max occupancy per compute unit in threads
+2
Просмотреть файл
@@ -65,6 +65,8 @@ void HSAILKernel::setWorkGroupInfo(const uint32_t privateSegmentSize,
workGroupInfo_.availableVGPRs_ = 256;
workGroupInfo_.preferredSizeMultiple_ = workGroupInfo_.wavefrontPerSIMD_ = 64;
}
workGroupInfo_.maxDynamicSharedSizeBytes_ = static_cast<int>(workGroupInfo_.availableLDSSize_ -
workGroupInfo_.localMemSize_);
}
bool HSAILKernel::setKernelCode(amd::hsa::loader::Symbol* sym, amd_kernel_code_t* akc) {
+2
Просмотреть файл
@@ -188,6 +188,8 @@ bool LightningKernel::postLoad() {
workGroupInfo_.wavefrontPerSIMD_ = program()->rocDevice().info().maxWorkItemSizes_[0] / wavefront_size;
workGroupInfo_.wavefrontSize_ = wavefront_size;
workGroupInfo_.constMemSize_ = const_size_bytes;
workGroupInfo_.maxDynamicSharedSizeBytes_ = static_cast<int>(workGroupInfo_.availableLDSSize_ -
workGroupInfo_.localMemSize_);
if (workGroupInfo_.size_ == 0) {
return false;
}