mirror of
https://github.com/intel/compute-runtime.git
synced 2025-11-10 05:49:51 +08:00
Move close shared handle to the upper layer on Linux
Related-To: NEO-5274 Signed-off-by: Slawomir Milczarek <slawomir.milczarek@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
fc9be73491
commit
b4444c7660
@@ -113,6 +113,8 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh
|
||||
|
||||
auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false);
|
||||
|
||||
memoryManager->closeSharedHandle(sharedHandle);
|
||||
|
||||
imgDesc.image_row_pitch = imgInfo.rowPitch;
|
||||
imgDesc.image_slice_pitch = 0u;
|
||||
imgInfo.slicePitch = 0u;
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "opencl/source/mem_obj/buffer.h"
|
||||
#include "opencl/source/mem_obj/image.h"
|
||||
#include "opencl/source/os_interface/linux/drm_command_stream.h"
|
||||
#include "opencl/source/sharings/va/va_surface.h"
|
||||
#include "opencl/test/unit_test/helpers/unit_test_helper.h"
|
||||
#include "opencl/test/unit_test/mocks/linux/mock_drm_allocation.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_allocation_properties.h"
|
||||
@@ -40,6 +41,7 @@
|
||||
#include "opencl/test/unit_test/mocks/mock_gmm.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_platform.h"
|
||||
#include "opencl/test/unit_test/os_interface/linux/drm_mock.h"
|
||||
#include "opencl/test/unit_test/sharings/va/mock_va_sharing.h"
|
||||
#include "test.h"
|
||||
|
||||
#include "drm/i915_drm.h"
|
||||
@@ -2201,8 +2203,6 @@ TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleAndBi
|
||||
auto drmAllocation = static_cast<DrmAllocation *>(graphicsAllocation);
|
||||
EXPECT_TRUE(graphicsAllocation->is32BitAllocation());
|
||||
EXPECT_EQ(1, lseekCalledCount);
|
||||
EXPECT_EQ(1, closeCalledCount);
|
||||
EXPECT_EQ(this->mock->inputFd, closeInputFd);
|
||||
EXPECT_EQ(GmmHelper::canonize(memoryManager->getExternalHeapBaseAddress(graphicsAllocation->getRootDeviceIndex(), drmAllocation->isAllocatedInLocalMemoryPool())), drmAllocation->getGpuBaseAddress());
|
||||
memoryManager->freeGraphicsMemory(graphicsAllocation);
|
||||
}
|
||||
@@ -2221,8 +2221,6 @@ TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleIsCre
|
||||
|
||||
EXPECT_FALSE(graphicsAllocation->is32BitAllocation());
|
||||
EXPECT_EQ(1, lseekCalledCount);
|
||||
EXPECT_EQ(1, closeCalledCount);
|
||||
EXPECT_EQ(this->mock->inputFd, closeInputFd);
|
||||
|
||||
EXPECT_EQ(0llu, drmAllocation->getGpuBaseAddress());
|
||||
|
||||
@@ -2244,8 +2242,6 @@ TEST_F(DrmMemoryManagerTest, givenLimitedRangeAllocatorWhenBufferFromSharedHandl
|
||||
|
||||
EXPECT_EQ(0llu, drmAllocation->getGpuBaseAddress());
|
||||
EXPECT_EQ(1, lseekCalledCount);
|
||||
EXPECT_EQ(1, closeCalledCount);
|
||||
EXPECT_EQ(this->mock->inputFd, closeInputFd);
|
||||
memoryManager->freeGraphicsMemory(graphicsAllocation);
|
||||
}
|
||||
|
||||
@@ -2262,8 +2258,6 @@ TEST_F(DrmMemoryManagerTest, givenNon32BitAddressingWhenBufferFromSharedHandleIs
|
||||
auto drmAllocation = static_cast<DrmAllocation *>(graphicsAllocation);
|
||||
EXPECT_FALSE(graphicsAllocation->is32BitAllocation());
|
||||
EXPECT_EQ(1, lseekCalledCount);
|
||||
EXPECT_EQ(1, closeCalledCount);
|
||||
EXPECT_EQ(this->mock->inputFd, closeInputFd);
|
||||
EXPECT_EQ(0llu, drmAllocation->getGpuBaseAddress());
|
||||
memoryManager->freeGraphicsMemory(graphicsAllocation);
|
||||
}
|
||||
@@ -2607,8 +2601,6 @@ TEST_F(DrmMemoryManagerTest, givenSharedAllocationWithSmallerThenRealSizeWhenCre
|
||||
EXPECT_EQ(1u, bo->getRefCount());
|
||||
EXPECT_EQ(realSize, bo->peekSize());
|
||||
EXPECT_EQ(1, lseekCalledCount);
|
||||
EXPECT_EQ(1, closeCalledCount);
|
||||
EXPECT_EQ(this->mock->inputFd, closeInputFd);
|
||||
memoryManager->freeGraphicsMemory(graphicsAllocation);
|
||||
}
|
||||
|
||||
@@ -4155,4 +4147,24 @@ TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenIsaIsRegisteredThenC
|
||||
allocation.freeRegisteredBOBindExtHandles(&drm);
|
||||
EXPECT_EQ(2u, drm.unregisterCalledCount);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedVaSurfaceIsImportedWithDrmPrimeFdToHandleThenDrmPrimeFdCanBeClosed) {
|
||||
mock->ioctl_expected.total = -1;
|
||||
|
||||
MockContext context(device);
|
||||
MockVaSharing vaSharing;
|
||||
VASurfaceID vaSurfaceId = 0u;
|
||||
|
||||
vaSharing.updateAcquiredHandle(1);
|
||||
std::unique_ptr<Image> sharedImage1(VASurface::createSharedVaSurface(&context, &vaSharing.sharingFunctions,
|
||||
CL_MEM_READ_WRITE, 0, &vaSurfaceId, 0, nullptr));
|
||||
EXPECT_EQ(1, closeCalledCount);
|
||||
EXPECT_EQ(1, closeInputFd);
|
||||
|
||||
vaSharing.updateAcquiredHandle(2);
|
||||
std::unique_ptr<Image> sharedImage2(VASurface::createSharedVaSurface(&context, &vaSharing.sharingFunctions,
|
||||
CL_MEM_READ_WRITE, 0, &vaSurfaceId, 0, nullptr));
|
||||
EXPECT_EQ(2, closeCalledCount);
|
||||
EXPECT_EQ(2, closeInputFd);
|
||||
}
|
||||
} // namespace NEO
|
||||
|
||||
@@ -87,7 +87,7 @@ class MemoryManager {
|
||||
|
||||
virtual bool verifyHandle(osHandle handle, uint32_t rootDeviceIndex, bool) { return true; }
|
||||
virtual GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) = 0;
|
||||
|
||||
virtual void closeSharedHandle(osHandle handle){};
|
||||
virtual GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex) = 0;
|
||||
|
||||
virtual bool mapAuxGpuVA(GraphicsAllocation *graphicsAllocation);
|
||||
|
||||
@@ -586,8 +586,6 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o
|
||||
pushSharedBufferObject(bo);
|
||||
}
|
||||
|
||||
closeFunction(handle);
|
||||
|
||||
lock.unlock();
|
||||
|
||||
auto drmAllocation = new DrmAllocation(properties.rootDeviceIndex, properties.allocationType, bo, reinterpret_cast<void *>(bo->gpuAddress), bo->size,
|
||||
@@ -615,6 +613,10 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o
|
||||
return drmAllocation;
|
||||
}
|
||||
|
||||
void DrmMemoryManager::closeSharedHandle(osHandle handle) {
|
||||
closeFunction(handle);
|
||||
}
|
||||
|
||||
GraphicsAllocation *DrmMemoryManager::createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) {
|
||||
uint64_t gpuRange = 0llu;
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ class DrmMemoryManager : public MemoryManager {
|
||||
void handleFenceCompletion(GraphicsAllocation *allocation) override;
|
||||
GraphicsAllocation *createGraphicsAllocationFromExistingStorage(AllocationProperties &properties, void *ptr, MultiGraphicsAllocation &multiGraphicsAllocation) override;
|
||||
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override;
|
||||
void closeSharedHandle(osHandle handle) override;
|
||||
GraphicsAllocation *createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) override;
|
||||
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex) override { return nullptr; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user