2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2021-05-17 02:51:16 +08:00
|
|
|
* Copyright (C) 2018-2021 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-11-02 22:54:01 +08:00
|
|
|
#include "shared/source/memory_manager/os_agnostic_memory_manager.h"
|
2021-10-21 22:50:10 +08:00
|
|
|
#include "shared/test/common/fixtures/memory_management_fixture.h"
|
2021-07-06 21:44:16 +08:00
|
|
|
#include "shared/test/common/mocks/mock_execution_environment.h"
|
2021-10-05 20:54:33 +08:00
|
|
|
#include "shared/test/common/mocks/mock_memory_manager.h"
|
2021-12-15 01:40:08 +08:00
|
|
|
#include "shared/test/common/test_macros/test.h"
|
2020-11-02 22:54:01 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/mem_obj/buffer.h"
|
2020-05-28 20:05:12 +08:00
|
|
|
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/fixtures/platform_fixture.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_context.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
|
|
|
|
|
|
|
class TestedMemoryManager : public OsAgnosticMemoryManager {
|
|
|
|
public:
|
2018-10-01 22:10:54 +08:00
|
|
|
using OsAgnosticMemoryManager::OsAgnosticMemoryManager;
|
2018-11-30 18:01:33 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override {
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_NE(0u, expectedSize);
|
2018-11-30 18:01:33 +08:00
|
|
|
if (expectedSize == allocationData.size) {
|
|
|
|
EXPECT_TRUE(allocationData.flags.forcePin);
|
2017-12-21 07:45:38 +08:00
|
|
|
allocCount++;
|
|
|
|
}
|
2018-11-30 18:01:33 +08:00
|
|
|
return OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment(allocationData);
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2019-02-28 21:12:13 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemory64kb(const AllocationData &allocationData) override {
|
2017-12-21 07:45:38 +08:00
|
|
|
return nullptr;
|
|
|
|
};
|
2018-11-30 18:01:33 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryWithHostPtr(const AllocationData &properties) override {
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_NE(0u, HPExpectedSize);
|
2018-11-30 18:01:33 +08:00
|
|
|
if (HPExpectedSize == properties.size) {
|
|
|
|
EXPECT_TRUE(properties.flags.forcePin);
|
2017-12-21 07:45:38 +08:00
|
|
|
HPAllocCount++;
|
|
|
|
}
|
2018-11-30 18:01:33 +08:00
|
|
|
return OsAgnosticMemoryManager::allocateGraphicsMemoryWithHostPtr(properties);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2021-06-02 21:57:28 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &properties) override {
|
|
|
|
EXPECT_NE(0u, HPExpectedSize);
|
|
|
|
if (HPExpectedSize == properties.size) {
|
|
|
|
EXPECT_TRUE(properties.flags.forcePin);
|
|
|
|
HPAllocCount++;
|
|
|
|
}
|
|
|
|
return OsAgnosticMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(properties);
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
size_t expectedSize = 0;
|
|
|
|
uint32_t allocCount = 0;
|
|
|
|
size_t HPExpectedSize = 0;
|
|
|
|
uint32_t HPAllocCount = 0;
|
|
|
|
};
|
|
|
|
|
2020-05-09 01:50:20 +08:00
|
|
|
TEST(BufferTests, WhenBufferIsCreatedThenPinIsSet) {
|
2020-03-25 01:19:49 +08:00
|
|
|
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
|
2019-03-28 22:42:23 +08:00
|
|
|
std::unique_ptr<TestedMemoryManager> mm(new MemoryManagerCreate<TestedMemoryManager>(false, false, executionEnvironment));
|
2021-05-06 22:15:19 +08:00
|
|
|
if (mm->isLimitedGPU(0)) {
|
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
{
|
|
|
|
MockContext context;
|
|
|
|
auto size = MemoryConstants::pageSize * 32;
|
|
|
|
auto retVal = CL_INVALID_OPERATION;
|
|
|
|
mm->expectedSize = size;
|
|
|
|
mm->HPExpectedSize = 0u;
|
2019-10-16 16:59:10 +08:00
|
|
|
context.memoryManager = mm.get();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
auto buffer = Buffer::create(
|
|
|
|
&context,
|
|
|
|
0,
|
|
|
|
size,
|
|
|
|
nullptr,
|
|
|
|
retVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(1u, mm->allocCount);
|
|
|
|
|
|
|
|
delete buffer;
|
|
|
|
}
|
|
|
|
}
|
2020-05-09 01:50:20 +08:00
|
|
|
TEST(BufferTests, GivenHostPtrWhenBufferIsCreatedThenPinIsSet) {
|
2020-03-25 01:19:49 +08:00
|
|
|
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
|
2019-03-15 17:22:35 +08:00
|
|
|
std::unique_ptr<TestedMemoryManager> mm(new TestedMemoryManager(executionEnvironment));
|
2021-05-06 22:15:19 +08:00
|
|
|
if (mm->isLimitedGPU(0)) {
|
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
{
|
|
|
|
MockContext context;
|
|
|
|
auto retVal = CL_INVALID_OPERATION;
|
|
|
|
auto size = MemoryConstants::pageSize * 32;
|
|
|
|
mm->expectedSize = 0u;
|
|
|
|
mm->HPExpectedSize = size;
|
2019-10-16 16:59:10 +08:00
|
|
|
context.memoryManager = mm.get();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// memory must be aligned to use zero-copy
|
|
|
|
void *bff = alignedMalloc(size, MemoryConstants::pageSize);
|
|
|
|
|
|
|
|
auto buffer = Buffer::create(
|
|
|
|
&context,
|
2020-10-05 22:17:51 +08:00
|
|
|
CL_MEM_USE_HOST_PTR | CL_MEM_FORCE_HOST_MEMORY_INTEL,
|
2017-12-21 07:45:38 +08:00
|
|
|
size,
|
|
|
|
bff,
|
|
|
|
retVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(1u, mm->HPAllocCount);
|
|
|
|
|
|
|
|
delete buffer;
|
|
|
|
alignedFree(bff);
|
|
|
|
}
|
|
|
|
}
|