2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2022-02-07 22:27:53 +08:00
|
|
|
* Copyright (C) 2018-2022 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-20 11:54:29 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
|
|
|
#include "shared/source/device/device.h"
|
|
|
|
#include "shared/source/gmm_helper/gmm.h"
|
|
|
|
#include "shared/source/memory_manager/allocations_list.h"
|
|
|
|
#include "shared/source/os_interface/os_context.h"
|
2021-10-15 00:53:11 +08:00
|
|
|
#include "shared/test/common/mocks/mock_allocation_properties.h"
|
2021-05-13 21:27:50 +08:00
|
|
|
#include "shared/test/common/mocks/mock_deferred_deleter.h"
|
2021-01-21 20:10:13 +08:00
|
|
|
#include "shared/test/common/mocks/mock_device.h"
|
|
|
|
#include "shared/test/common/mocks/mock_graphics_allocation.h"
|
2021-10-05 20:54:33 +08:00
|
|
|
#include "shared/test/common/mocks/mock_memory_manager.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2021-10-07 01:00:24 +08:00
|
|
|
#include "opencl/source/helpers/cl_memory_properties_helpers.h"
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/helpers/properties_helper.h"
|
|
|
|
#include "opencl/source/mem_obj/mem_obj.h"
|
|
|
|
#include "opencl/source/platform/platform.h"
|
2020-12-28 19:10:10 +08:00
|
|
|
#include "opencl/test/unit_test/command_queue/command_queue_fixture.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h"
|
2020-12-28 19:10:10 +08:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_buffer.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_context.h"
|
2020-03-17 21:25:44 +08:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_platform.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-07-04 16:41:58 +08:00
|
|
|
struct MySharingHandler : public SharingHandler {
|
|
|
|
MySharingHandler(MemObj *memObj) : memObj(memObj) {
|
|
|
|
auto alloc = getAllocation();
|
|
|
|
if (alloc) {
|
|
|
|
alloc->incReuseCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MySharingHandler(GraphicsAllocation *allocation) : allocation(allocation) {
|
|
|
|
auto alloc = getAllocation();
|
|
|
|
if (alloc) {
|
|
|
|
alloc->incReuseCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void releaseReusedGraphicsAllocation() override {
|
|
|
|
auto alloc = getAllocation();
|
|
|
|
if (alloc) {
|
|
|
|
alloc->decReuseCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsAllocation *getAllocation() {
|
|
|
|
if (memObj) {
|
2020-06-02 19:38:13 +08:00
|
|
|
return memObj->getMultiGraphicsAllocation().getDefaultGraphicsAllocation();
|
2018-07-04 16:41:58 +08:00
|
|
|
}
|
|
|
|
return allocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
MemObj *memObj = nullptr;
|
|
|
|
GraphicsAllocation *allocation = nullptr;
|
|
|
|
};
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
TEST(MemObj, GivenMemObjWhenInititalizedFromHostPtrThenInitializeFields) {
|
|
|
|
const size_t size = 64;
|
|
|
|
char buffer[size];
|
|
|
|
MockContext context;
|
|
|
|
MockGraphicsAllocation *mockAllocation = new MockGraphicsAllocation(buffer, sizeof(buffer));
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_USE_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
sizeof(buffer), buffer, buffer, GraphicsAllocationHelper::toMultiGraphicsAllocation(mockAllocation), true, false, false);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
EXPECT_EQ(&buffer, memObj.getCpuAddress());
|
|
|
|
EXPECT_EQ(&buffer, memObj.getHostPtr());
|
|
|
|
EXPECT_EQ(size, memObj.getSize());
|
2020-04-22 20:37:30 +08:00
|
|
|
EXPECT_EQ(static_cast<cl_mem_flags>(CL_MEM_USE_HOST_PTR), memObj.getFlags());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-02-09 03:55:31 +08:00
|
|
|
TEST(MemObj, givenMemObjectWhenAskedForTransferToHostPtrThenDoNothing) {
|
|
|
|
const size_t size = 64;
|
|
|
|
uint8_t hostPtr[size] = {};
|
|
|
|
uint8_t expectedHostPtr[size] = {};
|
2017-12-21 07:45:38 +08:00
|
|
|
MockContext context;
|
2018-02-09 03:55:31 +08:00
|
|
|
MockGraphicsAllocation *mockAllocation = new MockGraphicsAllocation(hostPtr, sizeof(hostPtr));
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_USE_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
size, hostPtr, hostPtr, GraphicsAllocationHelper::toMultiGraphicsAllocation(mockAllocation), true, false, false);
|
2018-02-09 03:55:31 +08:00
|
|
|
|
|
|
|
memset(memObj.getCpuAddress(), 123, size);
|
|
|
|
memset(hostPtr, 0, size);
|
|
|
|
|
2018-02-18 05:26:28 +08:00
|
|
|
MemObjOffsetArray copyOffset = {{0, 0, 0}};
|
|
|
|
MemObjSizeArray copySize = {{size, 0, 0}};
|
|
|
|
EXPECT_THROW(memObj.transferDataToHostPtr(copySize, copyOffset), std::exception);
|
2018-02-09 03:55:31 +08:00
|
|
|
|
|
|
|
EXPECT_TRUE(memcmp(hostPtr, expectedHostPtr, size) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MemObj, givenMemObjectWhenAskedForTransferFromHostPtrThenDoNothing) {
|
|
|
|
const size_t size = 64;
|
|
|
|
uint8_t hostPtr[size] = {};
|
|
|
|
uint8_t expectedBufferPtr[size] = {};
|
|
|
|
MockContext context;
|
|
|
|
MockGraphicsAllocation *mockAllocation = new MockGraphicsAllocation(hostPtr, sizeof(hostPtr));
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_PIPE, memoryProperties, CL_MEM_USE_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
size, hostPtr, hostPtr, GraphicsAllocationHelper::toMultiGraphicsAllocation(mockAllocation), true, false, false);
|
2018-02-09 03:55:31 +08:00
|
|
|
|
|
|
|
memset(memObj.getCpuAddress(), 123, size);
|
|
|
|
memset(expectedBufferPtr, 123, size);
|
|
|
|
|
2018-02-18 05:26:28 +08:00
|
|
|
MemObjOffsetArray copyOffset = {{0, 0, 0}};
|
|
|
|
MemObjSizeArray copySize = {{size, 0, 0}};
|
|
|
|
EXPECT_THROW(memObj.transferDataFromHostPtr(copySize, copyOffset), std::exception);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-02-09 03:55:31 +08:00
|
|
|
EXPECT_TRUE(memcmp(memObj.getCpuAddress(), expectedBufferPtr, size) == 0);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-02-13 20:20:34 +08:00
|
|
|
TEST(MemObj, givenHostPtrAndUseHostPtrFlagWhenAskingForBaseMapPtrThenReturnHostPtr) {
|
|
|
|
uint8_t hostPtr = 0;
|
|
|
|
MockContext context;
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_USE_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
1, nullptr, &hostPtr, 0, true, false, false);
|
2018-02-13 20:20:34 +08:00
|
|
|
|
2019-11-07 21:15:04 +08:00
|
|
|
EXPECT_EQ(&hostPtr, memObj.getBasePtrForMap(context.getDevice(0)->getRootDeviceIndex()));
|
2018-02-13 20:20:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MemObj, givenHostPtrWithoutUseHostPtrFlagWhenAskingForBaseMapPtrThenReturnAllocatedPtr) {
|
|
|
|
uint8_t hostPtr = 0;
|
|
|
|
MockContext context;
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_COPY_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_COPY_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
1, nullptr, &hostPtr, 0, true, false, false);
|
2018-02-13 20:20:34 +08:00
|
|
|
|
2019-11-07 21:15:04 +08:00
|
|
|
EXPECT_NE(&hostPtr, memObj.getBasePtrForMap(context.getDevice(0)->getRootDeviceIndex()));
|
|
|
|
EXPECT_EQ(memObj.getAllocatedMapPtr(), memObj.getBasePtrForMap(context.getDevice(0)->getRootDeviceIndex()));
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MemObj, givenMemObjWhenReleaseAllocatedPtrIsCalledTwiceThenItDoesntCrash) {
|
|
|
|
void *allocatedPtr = alignedMalloc(MemoryConstants::cacheLineSize, MemoryConstants::cacheLineSize);
|
|
|
|
|
|
|
|
MockContext context;
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_USE_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
1, nullptr, nullptr, 0, true, false, false);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-02-13 20:20:34 +08:00
|
|
|
memObj.setAllocatedMapPtr(allocatedPtr);
|
|
|
|
memObj.releaseAllocatedMapPtr();
|
|
|
|
EXPECT_EQ(nullptr, memObj.getAllocatedMapPtr());
|
|
|
|
memObj.releaseAllocatedMapPtr();
|
|
|
|
EXPECT_EQ(nullptr, memObj.getAllocatedMapPtr());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MemObj, givenNotReadyGraphicsAllocationWhenMemObjDestroysAllocationAsyncThenAllocationIsAddedToMemoryManagerAllocationList) {
|
|
|
|
MockContext context;
|
|
|
|
|
2019-02-18 20:59:16 +08:00
|
|
|
auto memoryManager = context.getDevice(0)->getExecutionEnvironment()->memoryManager.get();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-03-25 22:15:03 +08:00
|
|
|
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{context.getDevice(0)->getRootDeviceIndex(), MemoryConstants::pageSize});
|
2019-10-22 19:29:39 +08:00
|
|
|
auto defaultEngine = context.getDevice(0)->getDefaultEngine();
|
|
|
|
allocation->updateTaskCount(2, defaultEngine.osContext->getContextId());
|
|
|
|
*(defaultEngine.commandStreamReceiver->getTagAddress()) = 1;
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_COPY_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_COPY_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
MemoryConstants::pageSize, nullptr, nullptr, 0, true, false, false);
|
2019-10-22 19:29:39 +08:00
|
|
|
auto &allocationList = defaultEngine.commandStreamReceiver->getTemporaryAllocations();
|
2018-10-29 20:26:58 +08:00
|
|
|
EXPECT_TRUE(allocationList.peekIsEmpty());
|
2017-12-21 07:45:38 +08:00
|
|
|
memObj.destroyGraphicsAllocation(allocation, true);
|
|
|
|
|
2018-10-29 20:26:58 +08:00
|
|
|
EXPECT_FALSE(allocationList.peekIsEmpty());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MemObj, givenReadyGraphicsAllocationWhenMemObjDestroysAllocationAsyncThenAllocationIsNotAddedToMemoryManagerAllocationList) {
|
2020-02-03 23:18:21 +08:00
|
|
|
ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment();
|
2020-01-14 21:32:11 +08:00
|
|
|
auto device = std::make_unique<MockClDevice>(MockDevice::create<MockDevice>(executionEnvironment, 0));
|
2018-12-03 17:05:36 +08:00
|
|
|
MockContext context(device.get());
|
2019-01-23 18:59:54 +08:00
|
|
|
auto memoryManager = executionEnvironment->memoryManager.get();
|
2018-12-03 17:05:36 +08:00
|
|
|
|
2020-03-25 22:15:03 +08:00
|
|
|
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), MemoryConstants::pageSize});
|
2018-12-03 17:05:36 +08:00
|
|
|
allocation->updateTaskCount(1, device->getDefaultEngine().osContext->getContextId());
|
|
|
|
*device->getDefaultEngine().commandStreamReceiver->getTagAddress() = 1;
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_COPY_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
MemoryConstants::pageSize, nullptr, nullptr, 0, true, false, false);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-12-03 17:05:36 +08:00
|
|
|
auto &allocationList = device->getDefaultEngine().commandStreamReceiver->getTemporaryAllocations();
|
2018-10-29 20:26:58 +08:00
|
|
|
EXPECT_TRUE(allocationList.peekIsEmpty());
|
2017-12-21 07:45:38 +08:00
|
|
|
memObj.destroyGraphicsAllocation(allocation, true);
|
|
|
|
|
2018-10-29 20:26:58 +08:00
|
|
|
EXPECT_TRUE(allocationList.peekIsEmpty());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MemObj, givenNotUsedGraphicsAllocationWhenMemObjDestroysAllocationAsyncThenAllocationIsNotAddedToMemoryManagerAllocationList) {
|
|
|
|
MockContext context;
|
2018-10-01 22:10:54 +08:00
|
|
|
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-10-16 16:59:10 +08:00
|
|
|
context.memoryManager = &memoryManager;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-03-25 22:15:03 +08:00
|
|
|
auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{context.getDevice(0)->getRootDeviceIndex(), MemoryConstants::pageSize});
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_COPY_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_COPY_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
MemoryConstants::pageSize, nullptr, nullptr, 0, true, false, false);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-10-22 19:29:39 +08:00
|
|
|
auto &allocationList = context.getDevice(0)->getDefaultEngine().commandStreamReceiver->getTemporaryAllocations();
|
2018-10-29 20:26:58 +08:00
|
|
|
EXPECT_TRUE(allocationList.peekIsEmpty());
|
2017-12-21 07:45:38 +08:00
|
|
|
memObj.destroyGraphicsAllocation(allocation, true);
|
|
|
|
|
2018-10-29 20:26:58 +08:00
|
|
|
EXPECT_TRUE(allocationList.peekIsEmpty());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MemObj, givenMemoryManagerWithoutDeviceWhenMemObjDestroysAllocationAsyncThenAllocationIsNotAddedToMemoryManagerAllocationList) {
|
|
|
|
MockContext context;
|
2018-10-01 22:10:54 +08:00
|
|
|
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-10-16 16:59:10 +08:00
|
|
|
context.memoryManager = &memoryManager;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-03-25 22:15:03 +08:00
|
|
|
auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{context.getDevice(0)->getRootDeviceIndex(), MemoryConstants::pageSize});
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_COPY_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_COPY_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
MemoryConstants::pageSize, nullptr, nullptr, 0, true, false, false);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-10-22 19:29:39 +08:00
|
|
|
auto &allocationList = context.getDevice(0)->getDefaultEngine().commandStreamReceiver->getTemporaryAllocations();
|
2018-10-29 20:26:58 +08:00
|
|
|
EXPECT_TRUE(allocationList.peekIsEmpty());
|
2017-12-21 07:45:38 +08:00
|
|
|
memObj.destroyGraphicsAllocation(allocation, true);
|
|
|
|
|
2018-10-29 20:26:58 +08:00
|
|
|
EXPECT_TRUE(allocationList.peekIsEmpty());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-01-24 16:57:20 +08:00
|
|
|
TEST(MemObj, givenMemObjAndPointerToObjStorageWithProperCommandWhenCheckIfMemTransferRequiredThenReturnFalse) {
|
|
|
|
MockContext context;
|
2019-03-28 22:42:23 +08:00
|
|
|
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
|
2018-01-24 16:57:20 +08:00
|
|
|
|
2019-10-16 16:59:10 +08:00
|
|
|
context.memoryManager = &memoryManager;
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_COPY_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_COPY_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
MemoryConstants::pageSize, nullptr, nullptr, 0, true, false, false);
|
2018-01-24 16:57:20 +08:00
|
|
|
void *ptr = memObj.getCpuAddressForMemoryTransfer();
|
|
|
|
bool isMemTransferNeeded = memObj.checkIfMemoryTransferIsRequired(0, 0, ptr, CL_COMMAND_WRITE_BUFFER);
|
|
|
|
EXPECT_FALSE(isMemTransferNeeded);
|
|
|
|
|
|
|
|
isMemTransferNeeded = memObj.checkIfMemoryTransferIsRequired(0, 0, ptr, CL_COMMAND_READ_BUFFER);
|
|
|
|
EXPECT_FALSE(isMemTransferNeeded);
|
|
|
|
|
|
|
|
isMemTransferNeeded = memObj.checkIfMemoryTransferIsRequired(0, 0, ptr, CL_COMMAND_WRITE_BUFFER_RECT);
|
|
|
|
EXPECT_FALSE(isMemTransferNeeded);
|
|
|
|
|
|
|
|
isMemTransferNeeded = memObj.checkIfMemoryTransferIsRequired(0, 0, ptr, CL_COMMAND_READ_BUFFER_RECT);
|
|
|
|
EXPECT_FALSE(isMemTransferNeeded);
|
|
|
|
|
|
|
|
isMemTransferNeeded = memObj.checkIfMemoryTransferIsRequired(0, 0, ptr, CL_COMMAND_WRITE_IMAGE);
|
|
|
|
EXPECT_FALSE(isMemTransferNeeded);
|
|
|
|
|
|
|
|
isMemTransferNeeded = memObj.checkIfMemoryTransferIsRequired(0, 0, ptr, CL_COMMAND_READ_IMAGE);
|
|
|
|
EXPECT_FALSE(isMemTransferNeeded);
|
|
|
|
}
|
2020-05-25 23:14:10 +08:00
|
|
|
|
2018-01-24 16:57:20 +08:00
|
|
|
TEST(MemObj, givenMemObjAndPointerToObjStorageBadCommandWhenCheckIfMemTransferRequiredThenReturnTrue) {
|
|
|
|
MockContext context;
|
2019-03-28 22:42:23 +08:00
|
|
|
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
|
2018-01-24 16:57:20 +08:00
|
|
|
|
2019-10-16 16:59:10 +08:00
|
|
|
context.memoryManager = &memoryManager;
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_COPY_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_COPY_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
MemoryConstants::pageSize, nullptr, nullptr, 0, true, false, false);
|
2018-01-24 16:57:20 +08:00
|
|
|
void *ptr = memObj.getCpuAddressForMemoryTransfer();
|
|
|
|
bool isMemTransferNeeded = memObj.checkIfMemoryTransferIsRequired(0, 0, ptr, CL_COMMAND_FILL_BUFFER);
|
|
|
|
EXPECT_TRUE(isMemTransferNeeded);
|
|
|
|
}
|
2020-05-25 23:14:10 +08:00
|
|
|
|
2018-01-24 16:57:20 +08:00
|
|
|
TEST(MemObj, givenMemObjAndPointerToDiffrentStorageAndProperCommandWhenCheckIfMemTransferRequiredThenReturnTrue) {
|
|
|
|
MockContext context;
|
2019-03-28 22:42:23 +08:00
|
|
|
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
|
2018-01-24 16:57:20 +08:00
|
|
|
|
2019-10-16 16:59:10 +08:00
|
|
|
context.memoryManager = &memoryManager;
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_COPY_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_COPY_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
MemoryConstants::pageSize, nullptr, nullptr, 0, true, false, false);
|
2018-01-24 16:57:20 +08:00
|
|
|
void *ptr = (void *)0x1234;
|
|
|
|
bool isMemTransferNeeded = memObj.checkIfMemoryTransferIsRequired(0, 0, ptr, CL_COMMAND_WRITE_BUFFER);
|
|
|
|
EXPECT_TRUE(isMemTransferNeeded);
|
2018-02-09 05:59:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MemObj, givenSharingHandlerWhenAskedForCpuMappingThenReturnFalse) {
|
2019-08-26 15:27:30 +08:00
|
|
|
MockContext context;
|
|
|
|
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
|
2020-03-25 22:15:03 +08:00
|
|
|
auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{context.getDevice(0)->getRootDeviceIndex(), MemoryConstants::pageSize});
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_COPY_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_COPY_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
MemoryConstants::pageSize, nullptr, nullptr, GraphicsAllocationHelper::toMultiGraphicsAllocation(allocation), true, false, false);
|
2018-02-09 05:59:03 +08:00
|
|
|
memObj.setSharingHandler(new SharingHandler());
|
|
|
|
EXPECT_FALSE(memObj.mappingOnCpuAllowed());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MemObj, givenTiledObjectWhenAskedForCpuMappingThenReturnFalse) {
|
|
|
|
struct MyMemObj : public MemObj {
|
|
|
|
using MemObj::MemObj;
|
2019-08-26 15:27:30 +08:00
|
|
|
bool isTiledAllocation() const override { return true; }
|
2018-02-09 05:59:03 +08:00
|
|
|
};
|
2020-06-05 06:16:55 +08:00
|
|
|
MockContext context;
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_COPY_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MyMemObj memObj(nullptr, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_COPY_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
MemoryConstants::pageSize, nullptr, nullptr, 0, true, false, false);
|
2018-02-09 05:59:03 +08:00
|
|
|
|
|
|
|
EXPECT_FALSE(memObj.mappingOnCpuAllowed());
|
|
|
|
}
|
|
|
|
|
2021-12-03 21:52:16 +08:00
|
|
|
TEST(MemObj, givenCompressedGmmWhenAskingForMappingOnCpuThenDisallow) {
|
2018-07-09 21:03:42 +08:00
|
|
|
MockContext context;
|
2019-03-28 22:42:23 +08:00
|
|
|
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
|
2018-07-09 21:03:42 +08:00
|
|
|
|
2019-10-16 16:59:10 +08:00
|
|
|
context.memoryManager = &memoryManager;
|
2018-07-09 21:03:42 +08:00
|
|
|
|
2020-03-25 22:15:03 +08:00
|
|
|
auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{context.getDevice(0)->getRootDeviceIndex(), MemoryConstants::pageSize});
|
2022-02-04 21:50:19 +08:00
|
|
|
allocation->setDefaultGmm(new Gmm(context.getDevice(0)->getGmmClientContext(), nullptr, 1, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, false, {}, true));
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_READ_WRITE, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
1, allocation->getUnderlyingBuffer(), nullptr, GraphicsAllocationHelper::toMultiGraphicsAllocation(allocation), false, false, false);
|
2018-07-09 21:03:42 +08:00
|
|
|
|
2021-06-09 00:37:54 +08:00
|
|
|
allocation->getDefaultGmm()->isCompressionEnabled = false;
|
2018-07-09 21:03:42 +08:00
|
|
|
EXPECT_TRUE(memObj.mappingOnCpuAllowed());
|
2021-06-09 00:37:54 +08:00
|
|
|
allocation->getDefaultGmm()->isCompressionEnabled = true;
|
2018-07-09 21:03:42 +08:00
|
|
|
EXPECT_FALSE(memObj.mappingOnCpuAllowed());
|
|
|
|
}
|
|
|
|
|
2018-02-09 05:59:03 +08:00
|
|
|
TEST(MemObj, givenDefaultWhenAskedForCpuMappingThenReturnTrue) {
|
2018-07-09 21:03:42 +08:00
|
|
|
MockContext context;
|
2019-03-28 22:42:23 +08:00
|
|
|
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
|
2018-07-09 21:03:42 +08:00
|
|
|
|
2019-10-16 16:59:10 +08:00
|
|
|
context.memoryManager = &memoryManager;
|
2018-07-09 21:03:42 +08:00
|
|
|
|
2020-03-25 22:15:03 +08:00
|
|
|
auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{context.getDevice(0)->getRootDeviceIndex(), MemoryConstants::pageSize});
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_COPY_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_COPY_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
64, allocation->getUnderlyingBuffer(), nullptr, GraphicsAllocationHelper::toMultiGraphicsAllocation(allocation), true, false, false);
|
2018-02-09 05:59:03 +08:00
|
|
|
|
2019-08-26 15:27:30 +08:00
|
|
|
EXPECT_FALSE(memObj.isTiledAllocation());
|
2018-02-09 05:59:03 +08:00
|
|
|
EXPECT_FALSE(memObj.peekSharingHandler());
|
|
|
|
EXPECT_TRUE(memObj.mappingOnCpuAllowed());
|
|
|
|
}
|
2018-03-01 21:58:15 +08:00
|
|
|
|
2018-09-28 13:19:14 +08:00
|
|
|
TEST(MemObj, givenNonCpuAccessibleMemoryWhenAskingForMappingOnCpuThenDisallow) {
|
|
|
|
MockContext context;
|
2019-03-28 22:42:23 +08:00
|
|
|
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
|
2018-09-28 13:19:14 +08:00
|
|
|
|
2019-10-16 16:59:10 +08:00
|
|
|
context.memoryManager = &memoryManager;
|
2018-09-28 13:19:14 +08:00
|
|
|
|
2020-03-25 22:15:03 +08:00
|
|
|
auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{context.getDevice(0)->getRootDeviceIndex(), MemoryConstants::pageSize});
|
2022-02-04 21:50:19 +08:00
|
|
|
allocation->setDefaultGmm(new Gmm(context.getDevice(0)->getGmmClientContext(), nullptr, 1, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, false, {}, true));
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_READ_WRITE, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
1, allocation->getUnderlyingBuffer(), nullptr, GraphicsAllocationHelper::toMultiGraphicsAllocation(allocation), false, false, false);
|
2018-09-28 13:19:14 +08:00
|
|
|
|
|
|
|
EXPECT_TRUE(memObj.mappingOnCpuAllowed());
|
|
|
|
reinterpret_cast<MemoryAllocation *>(allocation)->overrideMemoryPool(MemoryPool::SystemCpuInaccessible);
|
|
|
|
EXPECT_FALSE(memObj.mappingOnCpuAllowed());
|
|
|
|
}
|
|
|
|
|
2018-03-01 21:58:15 +08:00
|
|
|
TEST(MemObj, givenMultipleMemObjectsWithReusedGraphicsAllocationWhenDestroyedThenFreeAllocationOnce) {
|
|
|
|
MockContext context;
|
2019-03-28 22:42:23 +08:00
|
|
|
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
|
2019-10-16 16:59:10 +08:00
|
|
|
context.memoryManager = &memoryManager;
|
2018-03-01 21:58:15 +08:00
|
|
|
|
2020-03-25 22:15:03 +08:00
|
|
|
auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{context.getDevice(0)->getRootDeviceIndex(), MemoryConstants::pageSize});
|
2018-03-01 21:58:15 +08:00
|
|
|
|
2020-07-21 16:21:15 +08:00
|
|
|
std::unique_ptr<MemObj> memObj1(new MemObj(&context, CL_MEM_OBJECT_BUFFER, {}, 0, 0, 1, nullptr, nullptr, GraphicsAllocationHelper::toMultiGraphicsAllocation(allocation), true, false, false));
|
2018-03-01 21:58:15 +08:00
|
|
|
memObj1->setSharingHandler(new MySharingHandler(allocation));
|
|
|
|
|
2020-07-21 16:21:15 +08:00
|
|
|
std::unique_ptr<MemObj> memObj2(new MemObj(&context, CL_MEM_OBJECT_BUFFER, {}, 0, 0, 1, nullptr, nullptr, GraphicsAllocationHelper::toMultiGraphicsAllocation(allocation), true, false, false));
|
2018-03-01 21:58:15 +08:00
|
|
|
memObj2->setSharingHandler(new MySharingHandler(allocation));
|
|
|
|
|
2020-07-21 16:21:15 +08:00
|
|
|
std::unique_ptr<MemObj> memObj3(new MemObj(&context, CL_MEM_OBJECT_BUFFER, {}, 0, 0, 1, nullptr, nullptr, GraphicsAllocationHelper::toMultiGraphicsAllocation(allocation), true, false, false));
|
2018-03-01 21:58:15 +08:00
|
|
|
memObj3->setSharingHandler(new MySharingHandler(allocation));
|
|
|
|
|
2018-03-05 17:56:34 +08:00
|
|
|
EXPECT_EQ(3u, allocation->peekReuseCount());
|
2018-03-01 21:58:15 +08:00
|
|
|
|
2018-03-05 17:56:34 +08:00
|
|
|
memObj3.reset(nullptr);
|
|
|
|
EXPECT_EQ(2u, allocation->peekReuseCount());
|
|
|
|
memObj1.reset(nullptr);
|
|
|
|
EXPECT_EQ(1u, allocation->peekReuseCount());
|
2018-03-01 21:58:15 +08:00
|
|
|
|
2018-03-05 17:56:34 +08:00
|
|
|
memObj2.reset(nullptr);
|
2018-03-01 21:58:15 +08:00
|
|
|
}
|
2018-04-07 19:11:23 +08:00
|
|
|
|
|
|
|
TEST(MemObj, givenMemObjectWhenContextIsNotNullThenContextOutlivesMemobjects) {
|
|
|
|
MockContext context;
|
|
|
|
EXPECT_EQ(1, context.getRefInternalCount());
|
|
|
|
{
|
2020-07-21 16:21:15 +08:00
|
|
|
MemObj memObj(&context, 0, {}, 0, 0, 0, nullptr, nullptr, 0, false, false, false);
|
2018-04-07 19:11:23 +08:00
|
|
|
EXPECT_EQ(2, context.getRefInternalCount());
|
|
|
|
}
|
|
|
|
EXPECT_EQ(1, context.getRefInternalCount());
|
|
|
|
}
|
2018-07-04 16:41:58 +08:00
|
|
|
|
|
|
|
TEST(MemObj, givenSharedMemObjectWithNullGfxAllocationWhenSettingGfxAllocationThenSucceed) {
|
|
|
|
MockContext context;
|
2019-03-28 22:42:23 +08:00
|
|
|
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
|
2019-10-16 16:59:10 +08:00
|
|
|
context.memoryManager = &memoryManager;
|
2018-07-04 16:41:58 +08:00
|
|
|
MockGraphicsAllocation *gfxAllocation = new MockGraphicsAllocation(nullptr, 0);
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_USE_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
1, nullptr, nullptr, 0, true, false, false);
|
2018-07-04 16:41:58 +08:00
|
|
|
memObj.setSharingHandler(new MySharingHandler(&memObj));
|
|
|
|
|
|
|
|
memObj.resetGraphicsAllocation(gfxAllocation);
|
|
|
|
gfxAllocation->incReuseCount();
|
|
|
|
|
|
|
|
ASSERT_EQ(1u, gfxAllocation->peekReuseCount());
|
2020-06-02 19:38:13 +08:00
|
|
|
EXPECT_EQ(gfxAllocation, memObj.getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex()));
|
2018-07-04 16:41:58 +08:00
|
|
|
}
|
|
|
|
|
2020-06-02 19:38:13 +08:00
|
|
|
TEST(MemObj, givenSharedMemObjectAndGfxAllocationWhenGraphicsAllocationIsRemovedThenTheAllocationIsNotAvailable) {
|
2018-07-04 16:41:58 +08:00
|
|
|
MockContext context;
|
2019-03-28 22:42:23 +08:00
|
|
|
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
|
2019-10-16 16:59:10 +08:00
|
|
|
context.memoryManager = &memoryManager;
|
2018-07-04 16:41:58 +08:00
|
|
|
MockGraphicsAllocation *graphicsAllocation = new MockGraphicsAllocation(nullptr, 0);
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_USE_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
1, nullptr, nullptr, GraphicsAllocationHelper::toMultiGraphicsAllocation(graphicsAllocation), true, false, false);
|
2018-07-04 16:41:58 +08:00
|
|
|
memObj.setSharingHandler(new MySharingHandler(&memObj));
|
|
|
|
|
|
|
|
graphicsAllocation->decReuseCount();
|
2020-06-02 19:38:13 +08:00
|
|
|
memObj.removeGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex());
|
2018-07-04 16:41:58 +08:00
|
|
|
|
2020-06-02 19:38:13 +08:00
|
|
|
EXPECT_EQ(nullptr, memObj.getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex()));
|
2018-07-04 16:41:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MemObj, givenSharedMemObjectAndZeroReuseCountWhenChangingGfxAllocationThenOldAllocationIsDestroyed) {
|
|
|
|
MockContext context;
|
2019-03-28 22:42:23 +08:00
|
|
|
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
|
2019-10-16 16:59:10 +08:00
|
|
|
context.memoryManager = &memoryManager;
|
2018-07-04 16:41:58 +08:00
|
|
|
MockGraphicsAllocation *oldGfxAllocation = new MockGraphicsAllocation(nullptr, 0);
|
|
|
|
MockGraphicsAllocation *newGfxAllocation = new MockGraphicsAllocation(nullptr, 0);
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_USE_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
1, nullptr, nullptr, GraphicsAllocationHelper::toMultiGraphicsAllocation(oldGfxAllocation), true, false, false);
|
2018-07-04 16:41:58 +08:00
|
|
|
memObj.setSharingHandler(new MySharingHandler(&memObj));
|
|
|
|
|
|
|
|
oldGfxAllocation->decReuseCount();
|
|
|
|
memObj.resetGraphicsAllocation(newGfxAllocation);
|
|
|
|
newGfxAllocation->incReuseCount();
|
|
|
|
|
|
|
|
ASSERT_EQ(1u, newGfxAllocation->peekReuseCount());
|
2020-06-02 19:38:13 +08:00
|
|
|
EXPECT_EQ(newGfxAllocation, memObj.getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex()));
|
2018-07-04 16:41:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MemObj, givenSharedMemObjectAndNonZeroReuseCountWhenChangingGfxAllocationThenOldAllocationIsNotDestroyed) {
|
|
|
|
MockContext context;
|
2019-03-28 22:42:23 +08:00
|
|
|
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
|
2019-10-16 16:59:10 +08:00
|
|
|
context.memoryManager = &memoryManager;
|
2018-07-04 16:41:58 +08:00
|
|
|
MockGraphicsAllocation *oldGfxAllocation = new MockGraphicsAllocation(nullptr, 0);
|
|
|
|
MockGraphicsAllocation *newGfxAllocation = new MockGraphicsAllocation(nullptr, 0);
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_USE_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
1, nullptr, nullptr, GraphicsAllocationHelper::toMultiGraphicsAllocation(oldGfxAllocation), true, false, false);
|
2018-07-04 16:41:58 +08:00
|
|
|
memObj.setSharingHandler(new MySharingHandler(&memObj));
|
|
|
|
|
|
|
|
memObj.resetGraphicsAllocation(newGfxAllocation);
|
|
|
|
newGfxAllocation->incReuseCount();
|
|
|
|
|
|
|
|
ASSERT_EQ(1u, newGfxAllocation->peekReuseCount());
|
2020-06-02 19:38:13 +08:00
|
|
|
EXPECT_EQ(newGfxAllocation, memObj.getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex()));
|
2018-07-04 16:41:58 +08:00
|
|
|
memoryManager.checkGpuUsageAndDestroyGraphicsAllocations(oldGfxAllocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MemObj, givenNotSharedMemObjectWhenChangingGfxAllocationThenOldAllocationIsDestroyed) {
|
|
|
|
MockContext context;
|
2019-03-28 22:42:23 +08:00
|
|
|
MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment());
|
2019-10-16 16:59:10 +08:00
|
|
|
context.memoryManager = &memoryManager;
|
2018-07-04 16:41:58 +08:00
|
|
|
MockGraphicsAllocation *oldGfxAllocation = new MockGraphicsAllocation(nullptr, 0);
|
|
|
|
MockGraphicsAllocation *newGfxAllocation = new MockGraphicsAllocation(nullptr, 0);
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_USE_HOST_PTR, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
1, nullptr, nullptr, GraphicsAllocationHelper::toMultiGraphicsAllocation(oldGfxAllocation), true, false, false);
|
2018-07-04 16:41:58 +08:00
|
|
|
|
|
|
|
memObj.resetGraphicsAllocation(newGfxAllocation);
|
|
|
|
|
2020-06-02 19:38:13 +08:00
|
|
|
EXPECT_EQ(newGfxAllocation, memObj.getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex()));
|
2018-07-04 16:41:58 +08:00
|
|
|
}
|
2018-08-23 00:41:52 +08:00
|
|
|
|
|
|
|
TEST(MemObj, givenGraphicsAllocationWhenCallingIsAllocDumpableThenItReturnsTheCorrectValue) {
|
2018-10-30 22:24:15 +08:00
|
|
|
MockGraphicsAllocation gfxAllocation(nullptr, 0);
|
2018-08-23 00:41:52 +08:00
|
|
|
EXPECT_FALSE(gfxAllocation.isAllocDumpable());
|
2020-07-10 22:04:01 +08:00
|
|
|
gfxAllocation.setAllocDumpable(true, false);
|
2018-08-23 00:41:52 +08:00
|
|
|
EXPECT_TRUE(gfxAllocation.isAllocDumpable());
|
|
|
|
}
|
2019-04-08 20:49:35 +08:00
|
|
|
|
2020-12-09 01:43:41 +08:00
|
|
|
TEST(MemObj, givenMemObjNotUsingHostPtrWhenGettingBasePtrTwiceThenReturnSameMapPtr) {
|
2019-04-08 20:49:35 +08:00
|
|
|
MockContext context;
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context.getDevice(0)->getDevice());
|
2019-10-09 23:29:00 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_READ_WRITE, 0,
|
2020-07-21 16:21:15 +08:00
|
|
|
1, nullptr, nullptr, 0, true, false, false);
|
2019-04-08 20:49:35 +08:00
|
|
|
|
2019-11-07 21:15:04 +08:00
|
|
|
void *mapPtr = memObj.getBasePtrForMap(context.getDevice(0)->getRootDeviceIndex());
|
2019-04-08 20:49:35 +08:00
|
|
|
EXPECT_NE(nullptr, mapPtr);
|
2020-07-23 20:52:32 +08:00
|
|
|
auto mapAllocation = memObj.getMapAllocation(context.getDevice(0)->getRootDeviceIndex());
|
2019-04-08 20:49:35 +08:00
|
|
|
ASSERT_NE(nullptr, mapAllocation);
|
|
|
|
EXPECT_EQ(mapPtr, mapAllocation->getUnderlyingBuffer());
|
|
|
|
EXPECT_EQ(mapPtr, memObj.getAllocatedMapPtr());
|
|
|
|
}
|
2019-12-04 20:45:32 +08:00
|
|
|
|
|
|
|
using MemObjMultiRootDeviceTests = MultiRootDeviceFixture;
|
|
|
|
|
2020-05-25 23:14:10 +08:00
|
|
|
TEST_F(MemObjMultiRootDeviceTests, WhenMemObjMapIsCreatedThenAllocationHasCorrectRootDeviceIndex) {
|
2020-11-20 19:04:46 +08:00
|
|
|
auto allocation = mockMemoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device1->getRootDeviceIndex(), MemoryConstants::pageSize});
|
2020-07-23 20:52:32 +08:00
|
|
|
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context->getDevice(0)->getDevice());
|
2020-08-13 19:42:31 +08:00
|
|
|
std::unique_ptr<MemObj> memObj(
|
|
|
|
new MemObj(context.get(), CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_READ_WRITE, 0,
|
|
|
|
1, nullptr, nullptr, GraphicsAllocationHelper::toMultiGraphicsAllocation(allocation), true, false, false));
|
2019-12-04 20:45:32 +08:00
|
|
|
|
2020-11-20 19:04:46 +08:00
|
|
|
void *mapPtr = memObj->getBasePtrForMap(device1->getRootDeviceIndex());
|
2019-12-04 20:45:32 +08:00
|
|
|
EXPECT_NE(nullptr, mapPtr);
|
|
|
|
|
2020-11-20 19:04:46 +08:00
|
|
|
auto mapAllocation = memObj->getMapAllocation(device1->getRootDeviceIndex());
|
2019-12-04 20:45:32 +08:00
|
|
|
ASSERT_NE(nullptr, mapAllocation);
|
|
|
|
EXPECT_EQ(expectedRootDeviceIndex, mapAllocation->getRootDeviceIndex());
|
2020-08-13 19:42:31 +08:00
|
|
|
|
|
|
|
memObj.reset(nullptr);
|
2020-01-14 21:32:11 +08:00
|
|
|
}
|
2020-07-23 20:52:32 +08:00
|
|
|
|
|
|
|
TEST_F(MemObjMultiRootDeviceTests, WhenMemObjIsCreatedWithMultiGraphicsAllocationThenAllAllocationAreDestroyedProperly) {
|
|
|
|
auto allocation0 = mockMemoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{0, MemoryConstants::pageSize});
|
|
|
|
auto allocation1 = mockMemoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{1, MemoryConstants::pageSize});
|
|
|
|
|
|
|
|
auto multiGraphicsAllocation = MultiGraphicsAllocation(1);
|
|
|
|
multiGraphicsAllocation.addAllocation(allocation0);
|
|
|
|
multiGraphicsAllocation.addAllocation(allocation1);
|
|
|
|
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context->getDevice(0)->getDevice());
|
2020-08-13 19:42:31 +08:00
|
|
|
std::unique_ptr<MemObj> memObj(
|
|
|
|
new MemObj(context.get(), CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_READ_WRITE, 0,
|
|
|
|
1, nullptr, nullptr, multiGraphicsAllocation, true, false, false));
|
2020-07-23 20:52:32 +08:00
|
|
|
|
|
|
|
EXPECT_NE(nullptr, memObj->getMultiGraphicsAllocation().getGraphicsAllocation(0));
|
|
|
|
EXPECT_NE(nullptr, memObj->getMultiGraphicsAllocation().getGraphicsAllocation(1));
|
|
|
|
|
|
|
|
EXPECT_NE(memObj->getMultiGraphicsAllocation().getGraphicsAllocation(0), memObj->getMultiGraphicsAllocation().getGraphicsAllocation(1));
|
|
|
|
|
2020-08-13 19:42:31 +08:00
|
|
|
memObj.reset(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(MemObjMultiRootDeviceTests, WhenMemObjMapAreCreatedThenAllAllocationAreDestroyedProperly) {
|
2020-09-28 19:11:58 +08:00
|
|
|
auto allocation0 = mockMemoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{2, MemoryConstants::pageSize});
|
2020-08-13 19:42:31 +08:00
|
|
|
auto allocation1 = mockMemoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{1, MemoryConstants::pageSize});
|
|
|
|
|
2020-09-28 19:11:58 +08:00
|
|
|
auto multiGraphicsAllocation = MultiGraphicsAllocation(2);
|
2020-08-13 19:42:31 +08:00
|
|
|
multiGraphicsAllocation.addAllocation(allocation0);
|
|
|
|
multiGraphicsAllocation.addAllocation(allocation1);
|
|
|
|
|
2021-10-07 01:00:24 +08:00
|
|
|
auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context->getDevice(1)->getDevice());
|
2020-08-13 19:42:31 +08:00
|
|
|
std::unique_ptr<MemObj> memObj(
|
|
|
|
new MemObj(context.get(), CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_READ_WRITE, 0,
|
|
|
|
1, nullptr, nullptr, multiGraphicsAllocation, true, false, false));
|
|
|
|
|
2020-09-28 19:11:58 +08:00
|
|
|
auto mapAllocation0 = memObj->getMapAllocation(2);
|
2020-08-13 19:42:31 +08:00
|
|
|
auto mapAllocation1 = memObj->getMapAllocation(1);
|
|
|
|
|
|
|
|
EXPECT_EQ(nullptr, mapAllocation0);
|
|
|
|
EXPECT_EQ(nullptr, mapAllocation1);
|
|
|
|
|
2020-09-28 19:11:58 +08:00
|
|
|
EXPECT_NE(nullptr, memObj->getBasePtrForMap(2));
|
|
|
|
EXPECT_EQ(memObj->getBasePtrForMap(2), memObj->getBasePtrForMap(1));
|
2020-08-13 19:42:31 +08:00
|
|
|
|
2020-09-28 19:11:58 +08:00
|
|
|
mapAllocation0 = memObj->getMapAllocation(2);
|
2020-08-13 19:42:31 +08:00
|
|
|
mapAllocation1 = memObj->getMapAllocation(1);
|
|
|
|
|
|
|
|
ASSERT_NE(nullptr, mapAllocation0);
|
|
|
|
ASSERT_NE(nullptr, mapAllocation1);
|
|
|
|
ASSERT_NE(mapAllocation0, mapAllocation1);
|
|
|
|
|
|
|
|
memObj.reset(nullptr);
|
2020-07-23 20:52:32 +08:00
|
|
|
}
|