From f3db4e12e622f3ec9265a595bdc4998c785424b2 Mon Sep 17 00:00:00 2001 From: German Andryeyev Date: Thu, 7 Mar 2024 14:12:29 -0500 Subject: [PATCH] SWDEV-311271 - Correct the error codes in mempool Change-Id: Iacf8ad2cc454dfe53ccdb47c08d871b24ecf4107 [ROCm/clr commit: 1d8562eb7d92a10d467a7f137d6900488d73d0ec] --- projects/clr/hipamd/src/hip_mempool.cpp | 18 +++++++++++++++--- projects/clr/hipamd/src/hip_mempool_impl.hpp | 19 ++++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/projects/clr/hipamd/src/hip_mempool.cpp b/projects/clr/hipamd/src/hip_mempool.cpp index 1740dacaaa..18e3532d58 100644 --- a/projects/clr/hipamd/src/hip_mempool.cpp +++ b/projects/clr/hipamd/src/hip_mempool.cpp @@ -303,8 +303,13 @@ hipError_t hipMemPoolCreate(hipMemPool_t* mem_pool, const hipMemPoolProps* pool_ (pool_props->location.id >= g_devices.size())) { HIP_RETURN(hipErrorInvalidValue); } + + if (IS_WINDOWS && pool_props->handleTypes == hipMemHandleTypePosixFileDescriptor) { + HIP_RETURN(hipErrorInvalidValue); + } + auto device = g_devices[pool_props->location.id]; - auto pool = new hip::MemoryPool(device, pool_props->handleTypes != hipMemHandleTypeNone); + auto pool = new hip::MemoryPool(device, pool_props); if (pool == nullptr) { HIP_RETURN(hipErrorInvalidValue); } @@ -376,11 +381,14 @@ hipError_t hipMemPoolExportToShareableHandle( hipMemAllocationHandleType handle_type, unsigned int flags) { HIP_INIT_API(hipMemPoolExportToShareableHandle, shared_handle, mem_pool, handle_type, flags); - if (mem_pool == nullptr || shared_handle == nullptr || flags == -1) { + if (mem_pool == nullptr || shared_handle == nullptr || flags != 0) { HIP_RETURN(hipErrorInvalidValue); } auto mpool = reinterpret_cast(mem_pool); + if ((handle_type != mpool->Properties().handleTypes) || (handle_type == hipMemHandleTypeNone)) { + HIP_RETURN(hipErrorInvalidValue); + } auto handle = mpool->Export(); if (!handle) { HIP_RETURN(hipErrorInvalidValue); @@ -397,7 +405,11 @@ hipError_t hipMemPoolImportFromShareableHandle( hipMemAllocationHandleType handle_type, unsigned int flags) { HIP_INIT_API(hipMemPoolImportFromShareableHandle, mem_pool, shared_handle, handle_type, flags); - if (mem_pool == nullptr || shared_handle == nullptr || flags == -1) { + if (mem_pool == nullptr || shared_handle == nullptr || flags != 0) { + HIP_RETURN(hipErrorInvalidValue); + } + + if (handle_type == hipMemHandleTypeNone) { HIP_RETURN(hipErrorInvalidValue); } diff --git a/projects/clr/hipamd/src/hip_mempool_impl.hpp b/projects/clr/hipamd/src/hip_mempool_impl.hpp index c4dd51f8ca..e7469ff05d 100644 --- a/projects/clr/hipamd/src/hip_mempool_impl.hpp +++ b/projects/clr/hipamd/src/hip_mempool_impl.hpp @@ -196,7 +196,7 @@ class MemoryPool : public amd::ReferenceCountedObject { SharedAccess access_[kMaxMgpuAccess]; //!< The list of devices for access }; - MemoryPool(hip::Device* device, bool interprocess = false) + MemoryPool(hip::Device* device, const hipMemPoolProps* props = nullptr) : busy_heap_(device), free_heap_(device), lock_pool_ops_("Pool operations", true), @@ -208,7 +208,16 @@ class MemoryPool : public amd::ReferenceCountedObject { state_.event_dependencies_ = 1; state_.opportunistic_ = 1; state_.internal_dependencies_ = 1; - state_.interprocess_ = interprocess; + if (props != nullptr) { + properties_ = *props; + } else { + properties_ = {.allocType = hipMemAllocationTypePinned, + .handleTypes = hipMemHandleTypeNone, + .location = {.type = hipMemLocationTypeDevice, .id = device_->deviceId()}, + .win32SecurityAttributes = nullptr, + .reserved = {}}; + } + state_.interprocess_ = properties_.handleTypes != hipMemHandleTypeNone; } virtual ~MemoryPool() { @@ -282,6 +291,9 @@ class MemoryPool : public amd::ReferenceCountedObject { /// Imports memory pool from an OS specific handle bool Import(amd::Os::FileDesc handle); + /// Returns properties of this memory pool + const hipMemPoolProps& Properties() const { return properties_; } + /// Accessors for the pool state bool EventDependencies() const { return (state_.event_dependencies_) ? true : false; } bool Opportunistic() const { return (state_.opportunistic_) ? true : false; } @@ -308,7 +320,8 @@ class MemoryPool : public amd::ReferenceCountedObject { uint32_t value_; } state_; - amd::Monitor lock_pool_ops_; //!< Access to the pool must be lock protected + hipMemPoolProps properties_; //!< Properties of the memory pool + amd::Monitor lock_pool_ops_; //!< Access to the pool must be lock protected std::map access_map_; //!< Map of access to the pool from devices hip::Device* device_; //!< Hip device the heap will reside SharedMemPool* shared_; //!< Pointer to shared memory for IPC