From 86520ebd83841797dbd01ef84492d644bb79ce7e Mon Sep 17 00:00:00 2001 From: haoyuan2 Date: Fri, 10 Dec 2021 11:48:00 -0800 Subject: [PATCH] SWDEV-311585 - workaround dynamic loading functional issue in Blender Change-Id: I815724c0bdcb712e40ec1ed11b9632fab7243f69 [ROCm/clr commit: d1a491b30b49674e2d5417a448d0ffbd175849bf] --- projects/clr/hipamd/src/hip_device.cpp | 78 ++++++++++--------- .../clr/hipamd/src/hip_device_runtime.cpp | 12 +-- projects/clr/hipamd/src/hip_internal.hpp | 4 + 3 files changed, 52 insertions(+), 42 deletions(-) diff --git a/projects/clr/hipamd/src/hip_device.cpp b/projects/clr/hipamd/src/hip_device.cpp index ca08225eb5..4e30807aaf 100644 --- a/projects/clr/hipamd/src/hip_device.cpp +++ b/projects/clr/hipamd/src/hip_device.cpp @@ -37,17 +37,19 @@ amd::HostQueue* Device::NullStream(bool skip_alloc) { } -hipError_t hipDeviceGet(hipDevice_t *device, int deviceId) { - HIP_INIT_API(hipDeviceGet, device, deviceId); - - if (deviceId < 0 || - static_cast(deviceId) >= g_devices.size() || - device == nullptr) { - HIP_RETURN(hipErrorInvalidDevice); +hipError_t ihipDeviceGet(hipDevice_t* device, int deviceId) { + if (deviceId < 0 || static_cast(deviceId) >= g_devices.size() || device == nullptr) { + return hipErrorInvalidDevice; } *device = deviceId; - HIP_RETURN(hipSuccess); -}; + return hipSuccess; +} + +hipError_t hipDeviceGet(hipDevice_t* device, int deviceId) { + HIP_INIT_API(hipDeviceGet, device, deviceId); + + HIP_RETURN(ihipDeviceGet(device, deviceId)); +} hipError_t hipDeviceTotalMem (size_t *bytes, hipDevice_t device) { @@ -137,15 +139,13 @@ hipError_t hipDeviceGetName(char *name, int len, hipDevice_t device) { HIP_RETURN(hipSuccess); } -hipError_t hipGetDeviceProperties ( hipDeviceProp_t* props, hipDevice_t device ) { - HIP_INIT_API(hipGetDeviceProperties, props, device); - +hipError_t ihipGetDeviceProperties(hipDeviceProp_t* props, hipDevice_t device) { if (props == nullptr) { - HIP_RETURN(hipErrorInvalidValue); + return hipErrorInvalidValue; } if (unsigned(device) >= g_devices.size()) { - HIP_RETURN(hipErrorInvalidDevice); + return hipErrorInvalidDevice; } auto* deviceHandle = g_devices[device]->devices()[0]; @@ -176,30 +176,30 @@ hipError_t hipGetDeviceProperties ( hipDeviceProp_t* props, hipDevice_t device ) deviceProps.maxThreadsPerMultiProcessor = info.maxThreadsPerCU_; deviceProps.computeMode = 0; deviceProps.clockInstructionRate = info.timeStampFrequency_; - deviceProps.arch.hasGlobalInt32Atomics = 1; - deviceProps.arch.hasGlobalFloatAtomicExch = 1; - deviceProps.arch.hasSharedInt32Atomics = 1; - deviceProps.arch.hasSharedFloatAtomicExch = 1; - deviceProps.arch.hasFloatAtomicAdd = 1; - deviceProps.arch.hasGlobalInt64Atomics = 1; - deviceProps.arch.hasSharedInt64Atomics = 1; - deviceProps.arch.hasDoubles = 1; - deviceProps.arch.hasWarpVote = 1; - deviceProps.arch.hasWarpBallot = 1; - deviceProps.arch.hasWarpShuffle = 1; - deviceProps.arch.hasFunnelShift = 0; - deviceProps.arch.hasThreadFenceSystem = 1; - deviceProps.arch.hasSyncThreadsExt = 0; - deviceProps.arch.hasSurfaceFuncs = 0; - deviceProps.arch.has3dGrid = 1; - deviceProps.arch.hasDynamicParallelism = 0; + deviceProps.arch.hasGlobalInt32Atomics = 1; + deviceProps.arch.hasGlobalFloatAtomicExch = 1; + deviceProps.arch.hasSharedInt32Atomics = 1; + deviceProps.arch.hasSharedFloatAtomicExch = 1; + deviceProps.arch.hasFloatAtomicAdd = 1; + deviceProps.arch.hasGlobalInt64Atomics = 1; + deviceProps.arch.hasSharedInt64Atomics = 1; + deviceProps.arch.hasDoubles = 1; + deviceProps.arch.hasWarpVote = 1; + deviceProps.arch.hasWarpBallot = 1; + deviceProps.arch.hasWarpShuffle = 1; + deviceProps.arch.hasFunnelShift = 0; + deviceProps.arch.hasThreadFenceSystem = 1; + deviceProps.arch.hasSyncThreadsExt = 0; + deviceProps.arch.hasSurfaceFuncs = 0; + deviceProps.arch.has3dGrid = 1; + deviceProps.arch.hasDynamicParallelism = 0; deviceProps.concurrentKernels = 1; deviceProps.pciDomainID = info.pciDomainID; deviceProps.pciBusID = info.deviceTopology_.pcie.bus; deviceProps.pciDeviceID = info.deviceTopology_.pcie.device; deviceProps.maxSharedMemoryPerMultiProcessor = info.localMemSizePerCU_; deviceProps.canMapHostMemory = 1; - //FIXME: This should be removed, targets can have character names as well. + // FIXME: This should be removed, targets can have character names as well. deviceProps.gcnArch = isa.versionMajor() * 100 + isa.versionMinor() * 10 + isa.versionStepping(); sprintf(deviceProps.gcnArchName, "%s", isa.targetId()); deviceProps.cooperativeLaunch = info.cooperativeGroups_; @@ -210,7 +210,7 @@ hipError_t hipGetDeviceProperties ( hipDeviceProp_t* props, hipDevice_t device ) deviceProps.cooperativeMultiDeviceUnmatchedBlockDim = info.cooperativeMultiDeviceGroups_; deviceProps.cooperativeMultiDeviceUnmatchedSharedMem = info.cooperativeMultiDeviceGroups_; - deviceProps.maxTexture1DLinear = 16 * info.imageMaxBufferSize_; // Max pixel size is 16 bytes + deviceProps.maxTexture1DLinear = 16 * info.imageMaxBufferSize_; // Max pixel size is 16 bytes deviceProps.maxTexture1D = info.image1DMaxWidth_; deviceProps.maxTexture2D[0] = info.image2DMaxWidth_; deviceProps.maxTexture2D[1] = info.image2DMaxHeight_; @@ -224,17 +224,23 @@ hipError_t hipGetDeviceProperties ( hipDeviceProp_t* props, hipDevice_t device ) deviceProps.textureAlignment = info.imageBaseAddressAlignment_; deviceProps.texturePitchAlignment = info.imagePitchAlignment_; deviceProps.kernelExecTimeoutEnabled = 0; - deviceProps.ECCEnabled = info.errorCorrectionSupport_? 1:0; + deviceProps.ECCEnabled = info.errorCorrectionSupport_ ? 1 : 0; deviceProps.isLargeBar = info.largeBar_ ? 1 : 0; deviceProps.asicRevision = info.asicRevision_; // HMM capabilities deviceProps.managedMemory = info.hmmSupported_; - deviceProps.concurrentManagedAccess = info.hmmSupported_; + deviceProps.concurrentManagedAccess = info.hmmSupported_; deviceProps.directManagedMemAccessFromHost = info.hmmDirectHostAccess_; deviceProps.pageableMemoryAccess = info.hmmCpuMemoryAccessible_; deviceProps.pageableMemoryAccessUsesHostPageTables = info.hostUnifiedMemory_; *props = deviceProps; - HIP_RETURN(hipSuccess); + return hipSuccess; +} + +hipError_t hipGetDeviceProperties(hipDeviceProp_t* props, hipDevice_t device) { + HIP_INIT_API(hipGetDeviceProperties, props, device); + + HIP_RETURN(ihipGetDeviceProperties(props, device)); } diff --git a/projects/clr/hipamd/src/hip_device_runtime.cpp b/projects/clr/hipamd/src/hip_device_runtime.cpp index 384de70948..e6898fd183 100644 --- a/projects/clr/hipamd/src/hip_device_runtime.cpp +++ b/projects/clr/hipamd/src/hip_device_runtime.cpp @@ -39,7 +39,7 @@ hipError_t hipChooseDevice(int* device, const hipDeviceProp_t* properties) { hipDeviceProp_t currentProp = {0}; cl_uint validPropCount = 0; cl_uint matchedCount = 0; - hipError_t err = hipGetDeviceProperties(¤tProp, i); + hipError_t err = ihipGetDeviceProperties(¤tProp, i); if (properties->major != 0) { validPropCount++; if(currentProp.major >= properties->major) { @@ -152,7 +152,7 @@ hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device) //FIXME: should we cache the props, or just select from deviceHandle->info_? hipDeviceProp_t prop = {0}; - hipError_t err = hipGetDeviceProperties(&prop, device); + hipError_t err = ihipGetDeviceProperties(&prop, device); if (err != hipSuccess) { HIP_RETURN(err); } @@ -345,9 +345,9 @@ hipError_t hipDeviceGetByPCIBusId(int* device, const char*pciBusIdstr) { ihipDeviceGetCount(&count); for (cl_int i = 0; i < count; i++) { hipDevice_t dev; - hipDeviceGet(&dev, i); + ihipDeviceGet(&dev, i); hipDeviceProp_t prop; - hipGetDeviceProperties(&prop, dev); + ihipGetDeviceProperties(&prop, dev); if ((pciBusID == prop.pciBusID) && (pciDomainID == prop.pciDomainID) && (pciDeviceID == prop.pciDeviceID)) { @@ -385,7 +385,7 @@ hipError_t hipDeviceGetLimit ( size_t* pValue, hipLimit_t limit ) { } if(limit == hipLimitMallocHeapSize) { hipDeviceProp_t prop; - hipGetDeviceProperties(&prop, ihipGetDevice()); + ihipGetDeviceProperties(&prop, ihipGetDevice()); *pValue = prop.totalGlobalMem; HIP_RETURN(hipSuccess); @@ -409,7 +409,7 @@ hipError_t hipDeviceGetPCIBusId ( char* pciBusId, int len, int device ) { } hipDeviceProp_t prop; - hipGetDeviceProperties(&prop, device); + ihipGetDeviceProperties(&prop, device); snprintf (pciBusId, len, "%04x:%02x:%02x.0", prop.pciDomainID, diff --git a/projects/clr/hipamd/src/hip_internal.hpp b/projects/clr/hipamd/src/hip_internal.hpp index a711052e81..f6df46a462 100644 --- a/projects/clr/hipamd/src/hip_internal.hpp +++ b/projects/clr/hipamd/src/hip_internal.hpp @@ -434,6 +434,10 @@ extern amd::Memory* getMemoryObjectWithOffset(const void* ptr, const size_t size extern void getStreamPerThread(hipStream_t& stream); extern hipError_t ihipUnbindTexture(textureReference* texRef); +extern hipError_t ihipGetDeviceProperties(hipDeviceProp_t* props, hipDevice_t device); + +extern hipError_t ihipDeviceGet(hipDevice_t* device, int deviceId); + constexpr bool kOptionChangeable = true; constexpr bool kNewDevProg = false;