From d810b669170106458389b22d2de96877d4477ab2 Mon Sep 17 00:00:00 2001 From: Felix Kuehling Date: Tue, 23 Apr 2019 20:38:27 -0400 Subject: [PATCH] Use non-paged memory for IPC signals Non-paged memory can be IPC-shared even when HSA_USERPTR_FOR_PAGED_MEM is enabled. Change-Id: I8b1fa6d7a4a9327c78a77b3679697fbf55397093 Signed-off-by: Felix Kuehling [ROCm/ROCR-Runtime commit: 0c6b9532d4b6f372a5cc54da1881e6f3f4e6c69c] --- .../rocr-runtime/runtime/hsa-runtime/core/common/shared.h | 8 ++++---- .../runtime/hsa-runtime/core/inc/memory_region.h | 1 + .../hsa-runtime/core/runtime/amd_memory_region.cpp | 2 ++ .../runtime/hsa-runtime/core/runtime/signal.cpp | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/common/shared.h b/projects/rocr-runtime/runtime/hsa-runtime/core/common/shared.h index 374d770d41..dc33ac7d45 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/common/shared.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/common/shared.h @@ -71,8 +71,8 @@ class BaseShared { /// @brief Default Allocator for Shared. Ensures allocations are whole pages. template class PageAllocator : private BaseShared { public: - __forceinline static T* alloc() { - T* ret = reinterpret_cast(allocate_(AlignUp(sizeof(T), 4096), 4096, 0)); + __forceinline static T* alloc(int flags = 0) { + T* ret = reinterpret_cast(allocate_(AlignUp(sizeof(T), 4096), 4096, flags)); if (ret == nullptr) throw std::bad_alloc(); MAKE_NAMED_SCOPE_GUARD(throwGuard, [&]() { free_(ret); }); @@ -96,14 +96,14 @@ template class PageAllocator : private BaseShared { template > class Shared final : private BaseShared { public: - explicit Shared(Allocator* pool = nullptr) : pool_(pool) { + explicit Shared(Allocator* pool = nullptr, int flags = 0) : pool_(pool) { assert(allocate_ != nullptr && free_ != nullptr && "Shared object allocator is not set"); if (pool_) shared_object_ = pool_->alloc(); else - shared_object_ = PageAllocator::alloc(); + shared_object_ = PageAllocator::alloc(flags); } ~Shared() { diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/memory_region.h b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/memory_region.h index af79bce97d..6281413d1b 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/memory_region.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/memory_region.h @@ -86,6 +86,7 @@ class MemoryRegion : public Checked<0x9C961F19EE175BB3> { AllocateExecutable = (1 << 1), // Set executable permission AllocateDoubleMap = (1 << 2), // Map twice VA allocation to backing store AllocateDirect = (1 << 3), // Bypass fragment cache. + AllocateIPC = (1 << 4), // System memory that can be IPC-shared }; typedef uint32_t AllocateFlags; diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp index e0bc2be05c..97daa85045 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp @@ -158,6 +158,8 @@ hsa_status_t MemoryRegion::Allocate(size_t& size, AllocateFlags alloc_flags, voi (alloc_flags & AllocateExecutable ? 1 : 0); kmt_alloc_flags.ui32.AQLQueueMemory = (alloc_flags & AllocateDoubleMap ? 1 : 0); + if (IsSystem() && (alloc_flags & AllocateIPC)) + kmt_alloc_flags.ui32.NonPaged = 1; // Only allow using the suballocator for ordinary VRAM. if (IsLocalMemory()) { diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/signal.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/signal.cpp index de943e2465..fa24c421d0 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/signal.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/signal.cpp @@ -121,7 +121,8 @@ void SharedSignalPool_t::free(SharedSignal* ptr) { LocalSignal::LocalSignal(hsa_signal_value_t initial_value, bool exportable) : local_signal_(exportable ? nullptr - : core::Runtime::runtime_singleton_->GetSharedSignalPool()) { + : core::Runtime::runtime_singleton_->GetSharedSignalPool(), + exportable ? core::MemoryRegion::AllocateIPC : 0) { local_signal_.shared_object()->amd_signal.value = initial_value; }