diff --git a/projects/clr/rocclr/runtime/device/pal/paldevice.cpp b/projects/clr/rocclr/runtime/device/pal/paldevice.cpp index 0dc6730f9b..c016d97833 100644 --- a/projects/clr/rocclr/runtime/device/pal/paldevice.cpp +++ b/projects/clr/rocclr/runtime/device/pal/paldevice.cpp @@ -1302,6 +1302,7 @@ Device::createBuffer( Resource::CreateParams params; params.owner_ = &owner; params.gpu_ = static_cast(owner.getVirtualDevice()); + params.svmBase_ = static_cast(owner.svmBase()); // Create memory object result = gpuMemory->create(type, ¶ms); diff --git a/projects/clr/rocclr/runtime/device/pal/palresource.cpp b/projects/clr/rocclr/runtime/device/pal/palresource.cpp index 8c87427e50..f72fc39d83 100644 --- a/projects/clr/rocclr/runtime/device/pal/palresource.cpp +++ b/projects/clr/rocclr/runtime/device/pal/palresource.cpp @@ -529,7 +529,7 @@ Resource::create(MemoryType memType, CreateParams* params) //! @todo PAL query for image/buffer object doesn't work properly! #if 0 bool isImage = false; - if (Pal::Result::Success != + if (Pal::Result::Success != dev().iDev()->DetermineExternalSharedResourceType(openInfo, &isImage)) { return false; } @@ -1028,7 +1028,6 @@ Resource::create(MemoryType memType, CreateParams* params) return true; } - if ((nullptr != params) && (nullptr != params->owner_) && (nullptr != params->owner_->getSvmPtr())) { @@ -1040,7 +1039,10 @@ Resource::create(MemoryType memType, CreateParams* params) Pal::SvmGpuMemoryCreateInfo createInfo = {}; createInfo.size = allocSize; createInfo.alignment = MaxGpuAlignment; - //createInfo.gpuVirtAddr = svmPtr; + if (svmPtr != 0) { + createInfo.flags.useReservedGpuVa = true; + createInfo.pReservedGpuVaOwner = params->svmBase_->iMem(); + } memRef_ = GpuMemoryReference::Create(dev(), createInfo); } else { @@ -1049,7 +1051,10 @@ Resource::create(MemoryType memType, CreateParams* params) createInfo.alignment = MaxGpuAlignment; createInfo.vaRange = Pal::VaRange::Svm; createInfo.priority = Pal::GpuMemPriority::Normal; - //createInfo.gpuVirtAddr = svmPtr; + if (svmPtr != 0) { + createInfo.flags.useReservedGpuVa = true; + createInfo.pReservedGpuVaOwner = params->svmBase_->iMem(); + } memTypeToHeap(&createInfo); memRef_ = GpuMemoryReference::Create(dev(), createInfo); } diff --git a/projects/clr/rocclr/runtime/device/pal/palresource.hpp b/projects/clr/rocclr/runtime/device/pal/palresource.hpp index a49d63cecf..5a090766ca 100644 --- a/projects/clr/rocclr/runtime/device/pal/palresource.hpp +++ b/projects/clr/rocclr/runtime/device/pal/palresource.hpp @@ -81,7 +81,8 @@ public: struct CreateParams : public amd::StackObject { amd::Memory* owner_; //!< Resource's owner VirtualGPU* gpu_; //!< Resource won't be shared between multiple queues - CreateParams(): owner_(NULL), gpu_(NULL) {} + const Resource* svmBase_; //!< SVM base for MGPU allocations + CreateParams(): owner_(nullptr), gpu_(nullptr), svmBase_(nullptr) {} }; struct PinnedParams : public CreateParams { diff --git a/projects/clr/rocclr/runtime/platform/memory.cpp b/projects/clr/rocclr/runtime/platform/memory.cpp index 7855c39a35..92e0750e18 100644 --- a/projects/clr/rocclr/runtime/platform/memory.cpp +++ b/projects/clr/rocclr/runtime/platform/memory.cpp @@ -330,6 +330,9 @@ Memory::addDeviceMemory(const Device* dev) // Mark the allocation with the complete flag deviceAlloced_[dev] = AllocComplete; + if (getSvmPtr() != nullptr) { + svmBase_ = dm; + } } else { // Mark the allocation as an empty @@ -629,7 +632,7 @@ Image::Image( initDimension(); } -bool +bool Image::validateDimensions( const std::vector& devices, cl_mem_object_type type, @@ -669,7 +672,7 @@ Image::validateDimensions( case CL_MEM_OBJECT_IMAGE2D: if ((width == 0) || (height == 0)) { return false; - } + } for (const auto dev : devices) { if ((dev->info().image2DMaxHeight_ >= height) && (dev->info().image2DMaxWidth_ >= width)) { @@ -1027,7 +1030,7 @@ Image::numSupportedFormats(const Context& context, cl_mem_object_type image_type bool supportRA = false; bool supportDepthsRGB = false; bool supportDepthStencil = false; - + // Add RA if RA is supported. for (uint i = 0; i < devices.size(); i++) { if (devices[i]->settings().supportRA_) { @@ -1076,7 +1079,7 @@ Image::numSupportedFormats(const Context& context, cl_mem_object_type image_type cl_uint Image::getSupportedFormats( - const Context& context, + const Context& context, cl_mem_object_type image_type, const cl_uint num_entries, cl_image_format *image_formats, @@ -1088,7 +1091,7 @@ Image::getSupportedFormats( bool supportRA = false; bool supportDepthsRGB = false; bool supportDepthStencil = false; - + // Add RA if RA is supported. for (uint i = 0; i < devices.size(); i++) { if (devices[i]->settings().supportRA_) { @@ -1255,7 +1258,7 @@ Image::copyToBackingStore(void* initFrom) size_t cpySize = getWidth() * getImageFormat().getElementSize(); for (uint z = 0; z < getDepth(); ++z) { - src = reinterpret_cast(initFrom) + z * getSlicePitch(); + src = reinterpret_cast(initFrom) + z * getSlicePitch(); for (uint y = 0; y < getHeight(); ++y) { memcpy(dst, src, cpySize); dst += cpySize; @@ -1290,7 +1293,7 @@ round_to_even(float v) v += magicVal; v -= magicVal; } - + return static_cast(v); } @@ -1300,7 +1303,7 @@ float2half_rtz(float f) union{ float f; cl_uint u; } u = {f}; cl_uint sign = (u.u >> 16) & 0x8000; float x = fabsf(f); - + //Nan if (x != x) { u.u >>= (24-11); @@ -1316,21 +1319,21 @@ float2half_rtz(float f) } return 0x7bff | sign; } - + // underflow if (x < *reinterpret_cast(&values[1])) { return sign; // The halfway case can return 0x0001 or 0. 0 is even. } - + // half denormal if (x < *reinterpret_cast(&values[2])) { x *= *reinterpret_cast(&values[3]); return static_cast((int) x | sign); } - + u.u &= 0xFFFFE000U; u.u -= 0x38000000U; - + return (u.u >> (24-11)) | sign; } diff --git a/projects/clr/rocclr/runtime/platform/memory.hpp b/projects/clr/rocclr/runtime/platform/memory.hpp index cc07cb7f15..a2d3b4dd5a 100644 --- a/projects/clr/rocclr/runtime/platform/memory.hpp +++ b/projects/clr/rocclr/runtime/platform/memory.hpp @@ -173,7 +173,8 @@ protected: std::atomic_uint mapCount_; //!< Keep track of number of mappings for a memory object void * svmHostAddress_; //!< svm host address; bool svmPtrCommited_; //!< svm host address committed flag; - bool canBeCached_; //!< flag to if the object can be cached; + bool canBeCached_; //!< flag to if the object can be cached; + private: //! Disable default assignment operator Memory& operator=(const Memory&); @@ -183,6 +184,8 @@ private: Monitor lockMemoryOps_; //!< Lock to serialize memory operations std::list subBuffers_; //!< List of all subbuffers for this memory object + device::Memory* svmBase_; //!< svmBase allocation for MGPU case + protected: //! The constructor creates a memory object but does not allocate either host memory //! or device memory. Default parameters are appropriate for Buffer creation. @@ -359,6 +362,7 @@ public: void commitSvmMemory(); //!< svm host address committed accessor; void setCacheStatus(bool canBeCached) { canBeCached_ = canBeCached; }//!< set the memobject cached status; bool canBeCached() const { return canBeCached_; } //!< get the memobject cached status; + device::Memory* svmBase() const { return svmBase_; } //!< Returns SVM base for MGPU case }; //! Buffers are a specialization of memory. Just a wrapper, really, @@ -418,7 +422,7 @@ protected: virtual void initDeviceMemory(); public: - Pipe(Context& context, Flags flags, size_t size, size_t pipe_packet_size, size_t pipe_max_packets) + Pipe(Context& context, Flags flags, size_t size, size_t pipe_packet_size, size_t pipe_max_packets) : Buffer(context, CL_MEM_OBJECT_PIPE, flags, size) , initialized_(false) {