From 4bfc88db5ff85eb34e78f258680fb88d379b0179 Mon Sep 17 00:00:00 2001 From: Tony Tye Date: Sun, 10 Jan 2021 03:22:41 +0000 Subject: [PATCH] Simplify handling of Settings roc:Settings and pal::Settings are derivations. Allocate them as their derived class then assign that to the base class member to avoid the need for a static_cast. Use device::settings to access the Settings consistently. Change-Id: I0f85157962fbf6fed176da0caf83b723bcbe1452 [ROCm/clr commit: 583dddf6b61d337ef148d173f8544b4dd9126349] --- projects/clr/rocclr/device/pal/paldevice.cpp | 4 +-- projects/clr/rocclr/device/rocm/rocdevice.cpp | 25 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/projects/clr/rocclr/device/pal/paldevice.cpp b/projects/clr/rocclr/device/pal/paldevice.cpp index db6eaf8cdc..3758e080b9 100644 --- a/projects/clr/rocclr/device/pal/paldevice.cpp +++ b/projects/clr/rocclr/device/pal/paldevice.cpp @@ -264,8 +264,8 @@ bool NullDevice::create(uint id, Pal::GfxIpLevel ipLevel) { properties.gfxLevel = ipLevel; uint subtarget = 0; - settings_ = new pal::Settings(); - pal::Settings* palSettings = reinterpret_cast(settings_); + pal::Settings* palSettings = new pal::Settings(); + settings_ = palSettings; // Report 512MB for all offline devices Pal::GpuMemoryHeapProperties heaps[Pal::GpuHeapCount]; diff --git a/projects/clr/rocclr/device/rocm/rocdevice.cpp b/projects/clr/rocclr/device/rocm/rocdevice.cpp index d6e9f101bc..ebf99a8c8a 100644 --- a/projects/clr/rocclr/device/rocm/rocdevice.cpp +++ b/projects/clr/rocclr/device/rocm/rocdevice.cpp @@ -131,9 +131,10 @@ bool NullDevice::create(const AMDDeviceInfo& deviceInfo) { info_.type_ = CL_DEVICE_TYPE_GPU; info_.vendorId_ = 0x1002; - settings_ = new Settings(); - roc::Settings* hsaSettings = static_cast(settings_); - if ((hsaSettings == nullptr) || !hsaSettings->create(false, deviceInfo_.gfxipMajor_, deviceInfo_.gfxipMinor_)) { + roc::Settings* hsaSettings = new roc::Settings(); + settings_ = hsaSettings; + if (!hsaSettings || + !hsaSettings->create(false, deviceInfo_.gfxipMajor_, deviceInfo_.gfxipMinor_)) { LogError("Error creating settings for nullptr HSA device"); return false; } @@ -599,11 +600,11 @@ bool Device::create() { // Create HSA settings assert(!settings_); - settings_ = new Settings(); - roc::Settings* hsaSettings = static_cast(settings_); - if ((hsaSettings == nullptr) || - !hsaSettings->create((agent_profile_ == HSA_PROFILE_FULL), - deviceInfo_.gfxipMajor_, deviceInfo_.gfxipMinor_, coop_groups)) { + roc::Settings* hsaSettings = new roc::Settings(); + settings_ = hsaSettings; + if (!hsaSettings || + !hsaSettings->create((agent_profile_ == HSA_PROFILE_FULL), deviceInfo_.gfxipMajor_, + deviceInfo_.gfxipMinor_, coop_groups)) { return false; } @@ -994,8 +995,6 @@ Memory* Device::getGpuMemory(amd::Memory* mem) const { bool Device::populateOCLDeviceConstants() { info_.available_ = true; - roc::Settings* hsa_settings = static_cast(settings_); - hsa_isa_t isa = {0}; if (hsa_agent_get_info(_bkendDevice, HSA_AGENT_INFO_ISA, &isa) != HSA_STATUS_SUCCESS) { return false; @@ -1278,12 +1277,12 @@ bool Device::populateOCLDeviceConstants() { info_.singleFPConfig_ = CL_FP_ROUND_TO_NEAREST | CL_FP_ROUND_TO_ZERO | CL_FP_ROUND_TO_INF | CL_FP_INF_NAN | CL_FP_FMA; - if (hsa_settings->doublePrecision_) { + if (settings().doublePrecision_) { info_.doubleFPConfig_ = info_.singleFPConfig_ | CL_FP_DENORM; info_.singleFPConfig_ |= CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT; } - if (hsa_settings->singleFpDenorm_) { + if (settings().singleFpDenorm_) { info_.singleFPConfig_ |= CL_FP_DENORM; } @@ -1386,7 +1385,7 @@ bool Device::populateOCLDeviceConstants() { // Enable SVM Capabilities of Hsa device. Ensure // user has not setup memory to be non-coherent info_.svmCapabilities_ = 0; - if (hsa_settings->enableNCMode_ == false) { + if (!settings().enableNCMode_) { info_.svmCapabilities_ = CL_DEVICE_SVM_COARSE_GRAIN_BUFFER; info_.svmCapabilities_ |= CL_DEVICE_SVM_FINE_GRAIN_BUFFER; // Report fine-grain system only on full profile