From 1d0572dd0fab5fd11a017e84172ff3dd9cbd2144 Mon Sep 17 00:00:00 2001 From: foreman Date: Tue, 26 Feb 2019 11:47:55 -0500 Subject: [PATCH] P4 to Git Change 1748674 by cpaquot@cpaquot-ocl-lc-lnx on 2019/02/26 11:31:59 SWDEV-145570 - [HIP] Implemented texture object for ROCm backend Needed to implement sampler object and return the getHsaImageObject for roc::Image::cpuSrd. Affected files ... ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.cpp#118 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.hpp#34 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocmemory.hpp#15 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocvirtual.cpp#73 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocvirtual.hpp#22 edit [ROCm/clr commit: 2732ad0300be0a1a2345af955b82fb7e24dc4db9] --- .../rocclr/runtime/device/rocm/rocdevice.cpp | 61 ++++++++++++++++ .../rocclr/runtime/device/rocm/rocdevice.hpp | 36 +++++++--- .../rocclr/runtime/device/rocm/rocmemory.hpp | 6 +- .../rocclr/runtime/device/rocm/rocvirtual.cpp | 70 +------------------ .../rocclr/runtime/device/rocm/rocvirtual.hpp | 6 -- 5 files changed, 92 insertions(+), 87 deletions(-) diff --git a/projects/clr/rocclr/runtime/device/rocm/rocdevice.cpp b/projects/clr/rocclr/runtime/device/rocm/rocdevice.cpp index 16ca308911..48a5aad2e1 100644 --- a/projects/clr/rocclr/runtime/device/rocm/rocdevice.cpp +++ b/projects/clr/rocclr/runtime/device/rocm/rocdevice.cpp @@ -27,6 +27,7 @@ #ifdef WITH_AMDGPU_PRO #include "pro/prodriver.hpp" #endif +#include "platform/sampler.hpp" #include #include #include @@ -841,6 +842,66 @@ hsa_status_t Device::iterateCpuMemoryPoolCallback(hsa_amd_memory_pool_t pool, vo return HSA_STATUS_SUCCESS; } +bool Device::createSampler(const amd::Sampler& owner, device::Sampler** sampler) const { + *sampler = nullptr; + Sampler* gpuSampler = new Sampler(*this); + if ((nullptr == gpuSampler) || !gpuSampler->create(owner)) { + delete gpuSampler; + return false; + } + *sampler = gpuSampler; + return true; +} + +void Sampler::fillSampleDescriptor(hsa_ext_sampler_descriptor_t& samplerDescriptor, + const amd::Sampler& sampler) const { + samplerDescriptor.filter_mode = sampler.filterMode() == CL_FILTER_NEAREST + ? HSA_EXT_SAMPLER_FILTER_MODE_NEAREST + : HSA_EXT_SAMPLER_FILTER_MODE_LINEAR; + samplerDescriptor.coordinate_mode = sampler.normalizedCoords() + ? HSA_EXT_SAMPLER_COORDINATE_MODE_NORMALIZED + : HSA_EXT_SAMPLER_COORDINATE_MODE_UNNORMALIZED; + switch (sampler.addressingMode()) { + case CL_ADDRESS_CLAMP_TO_EDGE: + samplerDescriptor.address_mode = HSA_EXT_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE; + break; + case CL_ADDRESS_REPEAT: + samplerDescriptor.address_mode = HSA_EXT_SAMPLER_ADDRESSING_MODE_REPEAT; + break; + case CL_ADDRESS_CLAMP: + samplerDescriptor.address_mode = HSA_EXT_SAMPLER_ADDRESSING_MODE_CLAMP_TO_BORDER; + break; + case CL_ADDRESS_MIRRORED_REPEAT: + samplerDescriptor.address_mode = HSA_EXT_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT; + break; + case CL_ADDRESS_NONE: + samplerDescriptor.address_mode = HSA_EXT_SAMPLER_ADDRESSING_MODE_UNDEFINED; + break; + default: + return; + } +} + +bool Sampler::create(const amd::Sampler& owner) { + hsa_ext_sampler_descriptor_t samplerDescriptor; + fillSampleDescriptor(samplerDescriptor, owner); + + hsa_status_t status = hsa_ext_sampler_create(dev_.getBackendDevice(), &samplerDescriptor, &hsa_sampler); + + if (HSA_STATUS_SUCCESS != status) { + return false; + } + + hwSrd_ = reinterpret_cast(hsa_sampler.handle); + hwState_ = reinterpret_cast
(hsa_sampler.handle); + + return true; +} + +Sampler::~Sampler() { + hsa_ext_sampler_destroy(dev_.getBackendDevice(), hsa_sampler); +} + bool Device::populateOCLDeviceConstants() { info_.available_ = true; diff --git a/projects/clr/rocclr/runtime/device/rocm/rocdevice.hpp b/projects/clr/rocclr/runtime/device/rocm/rocdevice.hpp index c0783184f5..9e23dd0862 100644 --- a/projects/clr/rocclr/runtime/device/rocm/rocdevice.hpp +++ b/projects/clr/rocclr/runtime/device/rocm/rocdevice.hpp @@ -59,6 +59,31 @@ class VirtualDevice; class PrintfDbg; class IProDevice; +class Sampler : public device::Sampler { + public: + //! Constructor + Sampler(const Device& dev) : dev_(dev) {} + + //! Default destructor for the device memory object + virtual ~Sampler(); + + //! Creates a device sampler from the OCL sampler state + bool create(const amd::Sampler& owner //!< AMD sampler object + ); + + private: + void fillSampleDescriptor(hsa_ext_sampler_descriptor_t& samplerDescriptor, + const amd::Sampler& sampler) const; + Sampler& operator=(const Sampler&); + + //! Disable operator= + Sampler(const Sampler&); + + const Device& dev_; //!< Device object associated with the sampler + + hsa_ext_sampler_t hsa_sampler; +}; + // A NULL Device type used only for offline compilation // Only functions that are used for compilation will be in this device class NullDevice : public amd::Device { @@ -283,16 +308,7 @@ class Device : public NullDevice { //! Sampler object allocation virtual bool createSampler(const amd::Sampler& owner, //!< abstraction layer sampler object device::Sampler** sampler //!< device sampler object - ) const { - //! \todo HSA team has to implement sampler allocation. - //! Currently allocate the base device class - *sampler = new device::Sampler(); - if (*sampler == nullptr) { - return false; - } - return true; - } - + ) const; //! Just returns nullptr for the dummy device virtual device::Memory* createView( diff --git a/projects/clr/rocclr/runtime/device/rocm/rocmemory.hpp b/projects/clr/rocclr/runtime/device/rocm/rocmemory.hpp index 3788f5a237..5e742cd9d0 100644 --- a/projects/clr/rocclr/runtime/device/rocm/rocmemory.hpp +++ b/projects/clr/rocclr/runtime/device/rocm/rocmemory.hpp @@ -78,8 +78,6 @@ class Memory : public device::Memory { virtual uint64_t virtualAddress() const override { return reinterpret_cast(getDeviceMemory()); } - virtual const address cpuSrd() const override { return reinterpret_cast(getDeviceMemory()); } - // Accessors for indirect map memory object amd::Memory* mapMemory() const { return mapMemory_; } @@ -176,9 +174,11 @@ class Image : public roc::Memory { size_t getDeviceDataSize() { return deviceImageInfo_.size; } size_t getDeviceDataAlignment() { return deviceImageInfo_.alignment; } - hsa_ext_image_t getHsaImageObject() { return hsaImageObject_; } + hsa_ext_image_t getHsaImageObject() const { return hsaImageObject_; } const hsa_ext_image_descriptor_t& getHsaImageDescriptor() const { return imageDescriptor_; } + virtual const address cpuSrd() const { return reinterpret_cast(getHsaImageObject().handle); } + private: //! Disable copy constructor Image(const Buffer&); diff --git a/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp b/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp index 1c6567adfa..221e6407f7 100644 --- a/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp +++ b/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp @@ -186,35 +186,6 @@ void VirtualGPU::MemoryDependency::clear(bool all) { } } -static void fillSampleDescriptor(hsa_ext_sampler_descriptor_t& samplerDescriptor, - const amd::Sampler& sampler) { - samplerDescriptor.filter_mode = sampler.filterMode() == CL_FILTER_NEAREST - ? HSA_EXT_SAMPLER_FILTER_MODE_NEAREST - : HSA_EXT_SAMPLER_FILTER_MODE_LINEAR; - samplerDescriptor.coordinate_mode = sampler.normalizedCoords() - ? HSA_EXT_SAMPLER_COORDINATE_MODE_NORMALIZED - : HSA_EXT_SAMPLER_COORDINATE_MODE_UNNORMALIZED; - switch (sampler.addressingMode()) { - case CL_ADDRESS_CLAMP_TO_EDGE: - samplerDescriptor.address_mode = HSA_EXT_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE; - break; - case CL_ADDRESS_REPEAT: - samplerDescriptor.address_mode = HSA_EXT_SAMPLER_ADDRESSING_MODE_REPEAT; - break; - case CL_ADDRESS_CLAMP: - samplerDescriptor.address_mode = HSA_EXT_SAMPLER_ADDRESSING_MODE_CLAMP_TO_BORDER; - break; - case CL_ADDRESS_MIRRORED_REPEAT: - samplerDescriptor.address_mode = HSA_EXT_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT; - break; - case CL_ADDRESS_NONE: - samplerDescriptor.address_mode = HSA_EXT_SAMPLER_ADDRESSING_MODE_UNDEFINED; - break; - default: - return; - } -} - bool VirtualGPU::processMemObjects(const amd::Kernel& kernel, const_address params, size_t& ldsAddress) { Kernel& hsaKernel = const_cast(static_cast(*(kernel.getDeviceKernel(dev())))); const amd::KernelSignature& signature = kernel.signature(); @@ -395,36 +366,10 @@ bool VirtualGPU::processMemObjects(const amd::Kernel& kernel, const_address para const amd::Sampler* sampler = reinterpret_cast(params + kernelParams.samplerObjOffset())[index]; - hsa_ext_sampler_descriptor_t samplerDescriptor; - fillSampleDescriptor(samplerDescriptor, *sampler); + device::Sampler* devSampler = sampler->getDeviceSampler(dev()); - hsa_ext_sampler_t hsa_sampler; - hsa_status_t status = - hsa_ext_sampler_create(dev().getBackendDevice(), &samplerDescriptor, &hsa_sampler); - - if (status != HSA_STATUS_SUCCESS) { - // Wait on a kernel if one is outstanding - releaseGpuMemoryFence(); - // Release the sampler handles allocated for the various - // on one or more kernel submissions - for (const auto& it: samplerList_) { - if (hsa_ext_sampler_destroy(gpu_device_, it) != HSA_STATUS_SUCCESS) { - LogWarning("Error destroying device sampler object!"); - } - } - - samplerList_.clear(); - status = hsa_ext_sampler_create(dev().getBackendDevice(), &samplerDescriptor, &hsa_sampler); - if (status != HSA_STATUS_SUCCESS) { - LogError("Error creating device sampler object!"); - return false; - } - } - - uint64_t sampler_srd = hsa_sampler.handle; + uint64_t sampler_srd = devSampler->hwSrd(); WriteAqlArgAt(const_cast
(params), &sampler_srd, sizeof(sampler_srd), desc.offset_); - samplerList_.push_back(hsa_sampler); - // TODO: destroy sampler. } } @@ -896,17 +841,6 @@ void VirtualGPU::updateCommandsState(amd::Command* list) { current->release(); current = next; } - - // Release the sampler handles allocated for the various - // on one or more kernel submissions - for (const auto& it: samplerList_) { - if (hsa_ext_sampler_destroy(gpu_device_, it) != HSA_STATUS_SUCCESS) { - LogWarning("Error destroying device sampler object!"); - } - } - samplerList_.clear(); - - return; } void VirtualGPU::submitReadMemory(amd::ReadMemoryCommand& cmd) { diff --git a/projects/clr/rocclr/runtime/device/rocm/rocvirtual.hpp b/projects/clr/rocclr/runtime/device/rocm/rocvirtual.hpp index 7b7d9290b2..cf33fe3b55 100644 --- a/projects/clr/rocclr/runtime/device/rocm/rocvirtual.hpp +++ b/projects/clr/rocclr/runtime/device/rocm/rocvirtual.hpp @@ -291,12 +291,6 @@ class VirtualGPU : public device::VirtualDevice { std::vector xferWriteBuffers_; //!< Stage write buffers std::vector pinnedMems_; //!< Pinned memory list - /** - * @brief Maintains the list of sampler allocated for one or more kernel - * submissions. - */ - std::vector samplerList_; - /** * @brief Indicates if a kernel dispatch is outstanding. This flag is * used to synchronized on kernel outputs.