feature: support memory policy for GEM_CREATE

Modified ioctl_helper_prelim to support the extension of gem_create_ext,
i.e. prelim_drm_i915_gem_create_ext_mempolicy.

Added two debug variables to be used for the mempolicy extension.

Modified functions in memory_info and drm_memory_manager to support extension

Added numaif.h from https://github.com/numactl/numactl/tree/master,
v2.0.14

Related-To: NEO-8276
Signed-off-by: Young Jin Yoon <young.jin.yoon@intel.com>
This commit is contained in:
Young Jin Yoon
2023-12-06 19:30:05 +00:00
committed by Compute-Runtime-Automation
parent 80c2664b2a
commit 4ccae1dbb4
36 changed files with 1425 additions and 119 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Intel Corporation
* Copyright (C) 2022-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -164,21 +164,38 @@ int DrmMockPrelimContext::handlePrelimRequest(DrmIoctl request, void *arg) {
return EINVAL;
}
prelim_drm_i915_gem_create_ext_setparam *pairSetparamRegion = nullptr;
prelim_drm_i915_gem_create_ext_setparam *chunkingSetparamRegion = nullptr;
prelim_drm_i915_gem_create_ext_vm_private *vmPrivateExt = nullptr;
if (extension->base.next_extension != 0) {
prelim_drm_i915_gem_create_ext_setparam *pairSetparamRegion = nullptr;
pairSetparamRegion = reinterpret_cast<prelim_drm_i915_gem_create_ext_setparam *>(extension->base.next_extension);
if (pairSetparamRegion->base.name == PRELIM_I915_GEM_CREATE_EXT_SETPARAM) {
if ((pairSetparamRegion->base.name & PRELIM_I915_PARAM_SET_PAIR) == 0) {
return EINVAL;
}
} else {
vmPrivateExt = reinterpret_cast<prelim_drm_i915_gem_create_ext_vm_private *>(extension->base.next_extension);
if (vmPrivateExt->base.name != PRELIM_I915_GEM_CREATE_EXT_VM_PRIVATE) {
prelim_drm_i915_gem_create_ext_memory_policy *memPolicyExt = nullptr;
void *next_extension = reinterpret_cast<void *>(extension->base.next_extension);
while (next_extension != 0) {
auto *setparamCandidate = reinterpret_cast<prelim_drm_i915_gem_create_ext_setparam *>(next_extension);
if (setparamCandidate->base.name == PRELIM_I915_GEM_CREATE_EXT_SETPARAM) {
if ((setparamCandidate->param.param & PRELIM_I915_PARAM_SET_PAIR) != 0) {
pairSetparamRegion = setparamCandidate;
} else if ((setparamCandidate->param.param & PRELIM_I915_PARAM_SET_CHUNK_SIZE) != 0) {
chunkingSetparamRegion = setparamCandidate;
} else {
return EINVAL;
}
next_extension = reinterpret_cast<void *>(setparamCandidate->base.next_extension);
continue;
}
auto *vmPrivateCandidate = reinterpret_cast<prelim_drm_i915_gem_create_ext_vm_private *>(next_extension);
if (vmPrivateCandidate->base.name == PRELIM_I915_GEM_CREATE_EXT_VM_PRIVATE) {
vmPrivateExt = vmPrivateCandidate;
next_extension = reinterpret_cast<void *>(vmPrivateCandidate->base.next_extension);
continue;
}
auto *memPolicyCandidate = reinterpret_cast<prelim_drm_i915_gem_create_ext_memory_policy *>(next_extension);
if (memPolicyCandidate->base.name == PRELIM_I915_GEM_CREATE_EXT_MEMORY_POLICY) {
memPolicyExt = memPolicyCandidate;
next_extension = reinterpret_cast<void *>(memPolicyCandidate->base.next_extension);
continue;
}
// incorrect extension detected
return EINVAL;
}
auto data = reinterpret_cast<MemoryClassInstance *>(extension->param.data);
@@ -194,6 +211,20 @@ int DrmMockPrelimContext::handlePrelimRequest(DrmIoctl request, void *arg) {
receivedCreateGemExt->vmPrivateExt = CreateGemExt::VmPrivate{vmPrivateExt->vm_id};
}
if (memPolicyExt != nullptr) {
receivedCreateGemExt->memPolicyExt = CreateGemExt::MemPolicy{memPolicyExt->mode, std::vector<unsigned long>()};
auto *memPolicyPtr = reinterpret_cast<unsigned long *>(memPolicyExt->nodemask_ptr);
for (auto i = 0u; i < memPolicyExt->nodemask_max; i++) {
receivedCreateGemExt->memPolicyExt.nodeMask.value().push_back(memPolicyPtr[i]);
}
}
if (pairSetparamRegion != nullptr) {
receivedCreateGemExt->pairSetParamExt = CreateGemExt::SetParam{pairSetparamRegion->param.handle, pairSetparamRegion->param.size, pairSetparamRegion->param.param};
}
if (chunkingSetparamRegion != nullptr) {
receivedCreateGemExt->chunkingSetParamExt = CreateGemExt::SetParam{chunkingSetparamRegion->param.handle, chunkingSetparamRegion->param.size, chunkingSetparamRegion->param.param};
}
receivedCreateGemExt->memoryRegions.clear();
for (uint32_t i = 0; i < extension->param.size; i++) {
receivedCreateGemExt->memoryRegions.push_back({data[i].memoryClass, data[i].memoryInstance});

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Intel Corporation
* Copyright (C) 2022-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -37,6 +37,8 @@ struct CreateGemExt {
uint64_t param{0};
};
std::optional<SetParam> setParamExt{};
std::optional<SetParam> pairSetParamExt{};
std::optional<SetParam> chunkingSetParamExt{};
struct MemoryClassInstance {
uint16_t memoryClass{0};
@@ -48,6 +50,12 @@ struct CreateGemExt {
std::optional<uint32_t> vmId{};
};
VmPrivate vmPrivateExt{};
struct MemPolicy {
std::optional<uint32_t> mode{};
std::optional<std::vector<unsigned long>> nodeMask{};
};
MemPolicy memPolicyExt{};
};
struct GemContextParamAcc {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2023 Intel Corporation
* Copyright (C) 2021-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -9,6 +9,7 @@
#include "shared/source/os_interface/os_library.h"
#include <unordered_map>
class MockOsLibrary : public NEO::OsLibrary {
public:
MockOsLibrary(void *procAddress, bool isLoaded) : getProcAddressReturn{procAddress}, isLoadedReturn{isLoaded} {}
@@ -40,3 +41,16 @@ class MockOsLibrary : public NEO::OsLibrary {
return ptr;
}
};
class MockOsLibraryCustom : public MockOsLibrary {
public:
using MockOsLibrary::MockOsLibrary;
std::unordered_map<std::string, void *> procMap;
void *getProcAddress(const std::string &procName) override {
if (procMap.find(procName) != procMap.end()) {
return procMap[procName];
} else {
return getProcAddressReturn;
}
}
};

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2023 Intel Corporation
* Copyright (C) 2019-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -69,14 +69,14 @@ struct MockedMemoryInfo : public NEO::MemoryInfo {
size_t getMemoryRegionSize(uint32_t memoryBank) override {
return 1024u;
}
int createGemExt(const MemRegionsVec &memClassInstances, size_t allocSize, uint32_t &handle, uint64_t patIndex, std::optional<uint32_t> vmId, int32_t pairHandle, bool isChunked, uint32_t numOfChunks) override {
int createGemExt(const MemRegionsVec &memClassInstances, size_t allocSize, uint32_t &handle, uint64_t patIndex, std::optional<uint32_t> vmId, int32_t pairHandle, bool isChunked, uint32_t numOfChunks, bool isUSMHostAllocation, void *addr) override {
if (allocSize == 0) {
return EINVAL;
}
handle = 1u;
return 0;
}
int createGemExtWithSingleRegion(uint32_t memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, int32_t pairHandle) override {
int createGemExtWithSingleRegion(uint32_t memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, int32_t pairHandle, bool isUSMHostAllocation, void *addr) override {
if (allocSize == 0) {
return EINVAL;
}
@@ -84,7 +84,7 @@ struct MockedMemoryInfo : public NEO::MemoryInfo {
pairHandlePassed = pairHandle;
return 0;
}
int createGemExtWithMultipleRegions(uint32_t memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex) override {
int createGemExtWithMultipleRegions(uint32_t memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, bool isUSMHostAllocation, void *addr) override {
if (allocSize == 0) {
return EINVAL;
}
@@ -92,7 +92,7 @@ struct MockedMemoryInfo : public NEO::MemoryInfo {
banks = memoryBanks;
return 0;
}
int createGemExtWithMultipleRegions(uint32_t memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, int32_t pairHandle, bool isChunked, uint32_t numOfChunks) override {
int createGemExtWithMultipleRegions(uint32_t memoryBanks, size_t allocSize, uint32_t &handle, uint64_t patIndex, int32_t pairHandle, bool isChunked, uint32_t numOfChunks, bool isUSMHostAllocation, void *addr) override {
if (allocSize == 0) {
return EINVAL;
}

View File

@@ -575,4 +575,6 @@ InOrderDuplicatedCounterStorageEnabled = -1
OverrideCpuCaching = -1
EnableDeviceUsmAllocationPool = -1
EnableHostUsmAllocationPool = -1
EnableHostAllocationMemPolicy = 0
OverrideHostAllocationMemPolicyMode = -1
# Please don't edit below this line

View File

@@ -1,5 +1,5 @@
#
# Copyright (C) 2020-2023 Intel Corporation
# Copyright (C) 2020-2024 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
@@ -33,6 +33,7 @@ set(NEO_CORE_OS_INTERFACE_TESTS_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/drm_uuid_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_version_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/file_logger_linux_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/numa_library_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/product_helper_uuid_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/product_helper_linux_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/product_helper_linux_tests.h

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Intel Corporation
* Copyright (C) 2022-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -8,11 +8,13 @@
#include "shared/source/memory_manager/memory_banks.h"
#include "shared/source/os_interface/linux/i915.h"
#include "shared/source/os_interface/linux/memory_info.h"
#include "shared/source/os_interface/linux/numa_library.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/variable_backup.h"
#include "shared/test/common/libult/linux/drm_mock_helper.h"
#include "shared/test/common/libult/linux/drm_query_mock.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/mocks/mock_os_library.h"
#include "shared/test/common/test_macros/test.h"
#include "gtest/gtest.h"
@@ -373,7 +375,7 @@ TEST(MemoryInfo, givenMemoryInfoWithRegionsWhenCreatingGemWithExtensionsThenRetu
ASSERT_NE(nullptr, memoryInfo);
uint32_t numOfChunks = 0;
auto ret = memoryInfo->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks);
auto ret = memoryInfo->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks, false, nullptr);
EXPECT_EQ(1u, handle);
EXPECT_EQ(0, ret);
EXPECT_EQ(1u, drm->ioctlCallsCount);
@@ -397,7 +399,7 @@ TEST(MemoryInfo, givenMemoryInfoWithRegionsWhenCreatingGemExtWithSingleRegionThe
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo, *drm);
ASSERT_NE(nullptr, memoryInfo);
auto ret = memoryInfo->createGemExtWithSingleRegion(1, 1024, handle, 0, -1);
auto ret = memoryInfo->createGemExtWithSingleRegion(1, 1024, handle, 0, -1, false, nullptr);
EXPECT_EQ(1u, handle);
EXPECT_EQ(0, ret);
EXPECT_EQ(1u, drm->ioctlCallsCount);
@@ -428,16 +430,310 @@ TEST(MemoryInfo, givenMemoryInfoWithRegionsWhenCreatingGemExtWithPairHandleThenR
uint32_t pairHandle = 0;
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo, *drm);
ASSERT_NE(nullptr, memoryInfo);
auto ret = memoryInfo->createGemExtWithSingleRegion(1, 1024, pairHandle, 0, -1);
auto ret = memoryInfo->createGemExtWithSingleRegion(1, 1024, pairHandle, 0, -1, false, nullptr);
EXPECT_EQ(0, ret);
EXPECT_EQ(1u, drm->ioctlCallsCount);
uint32_t handle = 0;
ret = memoryInfo->createGemExtWithSingleRegion(1, 1024, handle, 0, pairHandle);
ret = memoryInfo->createGemExtWithSingleRegion(1, 1024, handle, 0, pairHandle, false, nullptr);
EXPECT_EQ(0, ret);
EXPECT_EQ(2u, drm->ioctlCallsCount);
}
struct WhiteBoxNumaLibrary : Linux::NumaLibrary {
using Linux::NumaLibrary::numaLibNameStr;
using Linux::NumaLibrary::procGetMemPolicyStr;
using Linux::NumaLibrary::procNumaAvailableStr;
using Linux::NumaLibrary::procNumaMaxNodeStr;
using OsLibraryLoadPtr = NumaLibrary::OsLibraryLoadPtr;
using GetMemPolicyPtr = NumaLibrary::GetMemPolicyPtr;
using NumaAvailablePtr = NumaLibrary::NumaAvailablePtr;
using NumaMaxNodePtr = NumaLibrary::NumaMaxNodePtr;
using Linux::NumaLibrary::getMemPolicyFunction;
using Linux::NumaLibrary::osLibrary;
using Linux::NumaLibrary::osLibraryLoadFunction;
};
TEST(MemoryInfo, givenMemoryInfoWithMemoryPolicyEnabledWhenCallingCreateGemExtWithNonHostAllocationThenIoctlIsReturnedWithoutMemPolicy) {
DebugManagerStateRestore restorer;
debugManager.flags.EnableHostAllocationMemPolicy.set(1);
debugManager.flags.OverrideHostAllocationMemPolicyMode.set(-1);
std::vector<MemoryRegion> regionInfo(3);
regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 0};
regionInfo[0].probedSize = 8 * MemoryConstants::gigaByte;
regionInfo[1].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0};
regionInfo[1].probedSize = 16 * MemoryConstants::gigaByte;
regionInfo[2].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 1};
regionInfo[2].probedSize = 32 * MemoryConstants::gigaByte;
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto drm = std::make_unique<DrmQueryMock>(*executionEnvironment->rootDeviceEnvironments[0]);
// setup numa library in MemoryInfo
WhiteBoxNumaLibrary::GetMemPolicyPtr memPolicyHandler =
[](int *, unsigned long[], unsigned long, void *, unsigned long) -> long { return 0; };
WhiteBoxNumaLibrary::NumaAvailablePtr numaAvailableHandler =
[](void) -> int { return 0; };
WhiteBoxNumaLibrary::NumaMaxNodePtr numaMaxNodeHandler =
[](void) -> int { return 4; };
MockOsLibrary::loadLibraryNewObject = new MockOsLibraryCustom(nullptr, true);
MockOsLibraryCustom *osLibrary = static_cast<MockOsLibraryCustom *>(MockOsLibrary::loadLibraryNewObject);
// register proc pointers
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procGetMemPolicyStr)] = reinterpret_cast<void *>(memPolicyHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaAvailableStr)] = reinterpret_cast<void *>(numaAvailableHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaMaxNodeStr)] = reinterpret_cast<void *>(numaMaxNodeHandler);
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibraryCustom::load;
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo, *drm);
ASSERT_NE(nullptr, memoryInfo);
ASSERT_TRUE(memoryInfo->isMemPolicySupported());
uint32_t handle = 0;
MemRegionsVec memClassInstance = {regionInfo[0].region, regionInfo[1].region};
uint32_t numOfChunks = 0;
auto ret = memoryInfo->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks, false, nullptr);
EXPECT_EQ(1u, handle);
EXPECT_EQ(0, ret);
ASSERT_TRUE(drm->context.receivedCreateGemExt);
EXPECT_EQ(1024u, drm->context.receivedCreateGemExt->size);
EXPECT_EQ(std::nullopt, drm->context.receivedCreateGemExt->memPolicyExt.mode);
EXPECT_EQ(std::nullopt, drm->context.receivedCreateGemExt->memPolicyExt.nodeMask);
MockOsLibrary::loadLibraryNewObject = nullptr;
WhiteBoxNumaLibrary::osLibrary.reset();
}
TEST(MemoryInfo, givenMemoryInfoWithMemoryPolicyEnabledWhenCallingCreateGemExtForHostAllocationThenIoctlIsCalledWithMemoryPolicy) {
DebugManagerStateRestore restorer;
debugManager.flags.EnableHostAllocationMemPolicy.set(1);
debugManager.flags.OverrideHostAllocationMemPolicyMode.set(-1);
std::vector<MemoryRegion> regionInfo(3);
regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 0};
regionInfo[0].probedSize = 8 * MemoryConstants::gigaByte;
regionInfo[1].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0};
regionInfo[1].probedSize = 16 * MemoryConstants::gigaByte;
regionInfo[2].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 1};
regionInfo[2].probedSize = 32 * MemoryConstants::gigaByte;
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto drm = std::make_unique<DrmQueryMock>(*executionEnvironment->rootDeviceEnvironments[0]);
constexpr int num_numa = 4;
// setup numa library in MemoryInfo
WhiteBoxNumaLibrary::GetMemPolicyPtr memPolicyHandler =
[](int *mode, unsigned long nodeMask[], unsigned long, void *, unsigned long) -> long {
if (mode) {
*mode = 0;
}
for (int i = 0; i < num_numa; i++) {
nodeMask[i] = i;
}
return 0;
};
WhiteBoxNumaLibrary::NumaAvailablePtr numaAvailableHandler =
[](void) -> int { return 0; };
WhiteBoxNumaLibrary::NumaMaxNodePtr numaMaxNodeHandler =
[](void) -> int { return num_numa - 1; };
MockOsLibrary::loadLibraryNewObject = new MockOsLibraryCustom(nullptr, true);
MockOsLibraryCustom *osLibrary = static_cast<MockOsLibraryCustom *>(MockOsLibrary::loadLibraryNewObject);
// register proc pointers
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procGetMemPolicyStr)] = reinterpret_cast<void *>(memPolicyHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaAvailableStr)] = reinterpret_cast<void *>(numaAvailableHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaMaxNodeStr)] = reinterpret_cast<void *>(numaMaxNodeHandler);
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibraryCustom::load;
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo, *drm);
ASSERT_NE(nullptr, memoryInfo);
ASSERT_TRUE(memoryInfo->isMemPolicySupported());
uint32_t handle = 0;
MemRegionsVec memClassInstance = {regionInfo[0].region, regionInfo[1].region};
uint32_t numOfChunks = 0;
auto ret = memoryInfo->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks, true, nullptr);
EXPECT_EQ(1u, handle);
EXPECT_EQ(0, ret);
ASSERT_TRUE(drm->context.receivedCreateGemExt);
EXPECT_EQ(1024u, drm->context.receivedCreateGemExt->size);
EXPECT_EQ(0u, drm->context.receivedCreateGemExt->memPolicyExt.mode);
EXPECT_EQ(4u, drm->context.receivedCreateGemExt->memPolicyExt.nodeMask.value().size());
for (auto i = 0u; i < drm->context.receivedCreateGemExt->memPolicyExt.nodeMask.value().size(); i++) {
EXPECT_EQ(i, drm->context.receivedCreateGemExt->memPolicyExt.nodeMask.value()[i]);
}
MockOsLibrary::loadLibraryNewObject = nullptr;
WhiteBoxNumaLibrary::osLibrary.reset();
}
TEST(MemoryInfo, givenMemoryInfoWithMemoryPolicyEnabledAndOverrideMemoryPolicyModeWhenCallingCreateGemExtForHostAllocationThenIoctlIsCalledWithMemoryPolicy) {
DebugManagerStateRestore restorer;
debugManager.flags.EnableHostAllocationMemPolicy.set(1);
debugManager.flags.OverrideHostAllocationMemPolicyMode.set(0);
std::vector<MemoryRegion> regionInfo(3);
regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 0};
regionInfo[0].probedSize = 8 * MemoryConstants::gigaByte;
regionInfo[1].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0};
regionInfo[1].probedSize = 16 * MemoryConstants::gigaByte;
regionInfo[2].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 1};
regionInfo[2].probedSize = 32 * MemoryConstants::gigaByte;
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto drm = std::make_unique<DrmQueryMock>(*executionEnvironment->rootDeviceEnvironments[0]);
constexpr int num_numa = 4;
// setup numa library in MemoryInfo
WhiteBoxNumaLibrary::GetMemPolicyPtr memPolicyHandler =
[](int *mode, unsigned long nodeMask[], unsigned long, void *, unsigned long) -> long {
if (mode) {
*mode = 3;
}
for (int i = 0; i < num_numa; i++) {
nodeMask[i] = i;
}
return 0;
};
WhiteBoxNumaLibrary::NumaAvailablePtr numaAvailableHandler =
[](void) -> int { return 0; };
WhiteBoxNumaLibrary::NumaMaxNodePtr numaMaxNodeHandler =
[](void) -> int { return num_numa - 1; };
MockOsLibrary::loadLibraryNewObject = new MockOsLibraryCustom(nullptr, true);
MockOsLibraryCustom *osLibrary = static_cast<MockOsLibraryCustom *>(MockOsLibrary::loadLibraryNewObject);
// register proc pointers
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procGetMemPolicyStr)] = reinterpret_cast<void *>(memPolicyHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaAvailableStr)] = reinterpret_cast<void *>(numaAvailableHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaMaxNodeStr)] = reinterpret_cast<void *>(numaMaxNodeHandler);
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibraryCustom::load;
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo, *drm);
ASSERT_NE(nullptr, memoryInfo);
ASSERT_TRUE(memoryInfo->isMemPolicySupported());
uint32_t handle = 0;
MemRegionsVec memClassInstance = {regionInfo[0].region, regionInfo[1].region};
uint32_t numOfChunks = 0;
auto ret = memoryInfo->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks, true, nullptr);
EXPECT_EQ(1u, handle);
EXPECT_EQ(0, ret);
ASSERT_TRUE(drm->context.receivedCreateGemExt);
EXPECT_EQ(1024u, drm->context.receivedCreateGemExt->size);
EXPECT_EQ(0u, drm->context.receivedCreateGemExt->memPolicyExt.mode);
EXPECT_EQ(4u, drm->context.receivedCreateGemExt->memPolicyExt.nodeMask.value().size());
for (auto i = 0u; i < drm->context.receivedCreateGemExt->memPolicyExt.nodeMask.value().size(); i++) {
EXPECT_EQ(i, drm->context.receivedCreateGemExt->memPolicyExt.nodeMask.value()[i]);
}
MockOsLibrary::loadLibraryNewObject = nullptr;
WhiteBoxNumaLibrary::osLibrary.reset();
}
TEST(MemoryInfo, givenMemoryInfoWithMemoryPolicyEnabledWhenCallingCreateGemExtWithIncorrectGetMemPolicyHandlerThenIoctlIsReturnedWithoutMemPolicy) {
DebugManagerStateRestore restorer;
debugManager.flags.EnableHostAllocationMemPolicy.set(1);
debugManager.flags.OverrideHostAllocationMemPolicyMode.set(-1);
std::vector<MemoryRegion> regionInfo(3);
regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 0};
regionInfo[0].probedSize = 8 * MemoryConstants::gigaByte;
regionInfo[1].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0};
regionInfo[1].probedSize = 16 * MemoryConstants::gigaByte;
regionInfo[2].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 1};
regionInfo[2].probedSize = 32 * MemoryConstants::gigaByte;
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto drm = std::make_unique<DrmQueryMock>(*executionEnvironment->rootDeviceEnvironments[0]);
// setup numa library in MemoryInfo
WhiteBoxNumaLibrary::GetMemPolicyPtr memPolicyHandler =
[](int *, unsigned long[], unsigned long, void *, unsigned long) -> long { return -1; };
WhiteBoxNumaLibrary::NumaAvailablePtr numaAvailableHandler =
[](void) -> int { return 0; };
WhiteBoxNumaLibrary::NumaMaxNodePtr numaMaxNodeHandler =
[](void) -> int { return 4; };
MockOsLibrary::loadLibraryNewObject = new MockOsLibraryCustom(nullptr, true);
MockOsLibraryCustom *osLibrary = static_cast<MockOsLibraryCustom *>(MockOsLibrary::loadLibraryNewObject);
// register proc pointers
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procGetMemPolicyStr)] = reinterpret_cast<void *>(memPolicyHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaAvailableStr)] = reinterpret_cast<void *>(numaAvailableHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaMaxNodeStr)] = reinterpret_cast<void *>(numaMaxNodeHandler);
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibraryCustom::load;
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo, *drm);
ASSERT_NE(nullptr, memoryInfo);
ASSERT_TRUE(memoryInfo->isMemPolicySupported());
uint32_t handle = 0;
MemRegionsVec memClassInstance = {regionInfo[0].region, regionInfo[1].region};
uint32_t numOfChunks = 0;
auto ret = memoryInfo->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks, true, nullptr);
EXPECT_EQ(1u, handle);
EXPECT_EQ(0, ret);
ASSERT_TRUE(drm->context.receivedCreateGemExt);
EXPECT_EQ(1024u, drm->context.receivedCreateGemExt->size);
EXPECT_EQ(std::nullopt, drm->context.receivedCreateGemExt->memPolicyExt.mode);
EXPECT_EQ(std::nullopt, drm->context.receivedCreateGemExt->memPolicyExt.nodeMask);
MockOsLibrary::loadLibraryNewObject = nullptr;
WhiteBoxNumaLibrary::osLibrary.reset();
}
TEST(MemoryInfo, givenMemoryInfoWithMemoryPolicyEnabledAndInvalidOsLibraryWhenCallingInitializingNumaLibraryThenMemPolicyIsNotSupported) {
DebugManagerStateRestore restorer;
debugManager.flags.EnableHostAllocationMemPolicy.set(1);
debugManager.flags.OverrideHostAllocationMemPolicyMode.set(-1);
std::vector<MemoryRegion> regionInfo(3);
regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 0};
regionInfo[0].probedSize = 8 * MemoryConstants::gigaByte;
regionInfo[1].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0};
regionInfo[1].probedSize = 16 * MemoryConstants::gigaByte;
regionInfo[2].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 1};
regionInfo[2].probedSize = 32 * MemoryConstants::gigaByte;
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto drm = std::make_unique<DrmQueryMock>(*executionEnvironment->rootDeviceEnvironments[0]);
MockOsLibrary::loadLibraryNewObject = nullptr;
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibraryCustom::load;
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo, *drm);
ASSERT_NE(nullptr, memoryInfo);
ASSERT_FALSE(memoryInfo->isMemPolicySupported());
MockOsLibrary::loadLibraryNewObject = nullptr;
WhiteBoxNumaLibrary::osLibrary.reset();
}
TEST(MemoryInfo, givenMemoryInfoWithMemoryPolicyDisabledAndValidOsLibraryWhenCallingInitializingNumaLibraryThenMemPolicyIsNotSupported) {
DebugManagerStateRestore restorer;
debugManager.flags.EnableHostAllocationMemPolicy.set(0);
debugManager.flags.OverrideHostAllocationMemPolicyMode.set(-1);
std::vector<MemoryRegion> regionInfo(3);
regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 0};
regionInfo[0].probedSize = 8 * MemoryConstants::gigaByte;
regionInfo[1].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0};
regionInfo[1].probedSize = 16 * MemoryConstants::gigaByte;
regionInfo[2].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 1};
regionInfo[2].probedSize = 32 * MemoryConstants::gigaByte;
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto drm = std::make_unique<DrmQueryMock>(*executionEnvironment->rootDeviceEnvironments[0]);
// setup numa library in MemoryInfo
WhiteBoxNumaLibrary::GetMemPolicyPtr memPolicyHandler =
[](int *, unsigned long[], unsigned long, void *, unsigned long) -> long { return -1; };
WhiteBoxNumaLibrary::NumaAvailablePtr numaAvailableHandler =
[](void) -> int { return 0; };
WhiteBoxNumaLibrary::NumaMaxNodePtr numaMaxNodeHandler =
[](void) -> int { return 4; };
MockOsLibrary::loadLibraryNewObject = new MockOsLibraryCustom(nullptr, true);
MockOsLibraryCustom *osLibrary = static_cast<MockOsLibraryCustom *>(MockOsLibrary::loadLibraryNewObject);
// register proc pointers
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procGetMemPolicyStr)] = reinterpret_cast<void *>(memPolicyHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaAvailableStr)] = reinterpret_cast<void *>(numaAvailableHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaMaxNodeStr)] = reinterpret_cast<void *>(numaMaxNodeHandler);
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibraryCustom::load;
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo, *drm);
ASSERT_NE(nullptr, memoryInfo);
ASSERT_FALSE(memoryInfo->isMemPolicySupported());
MockOsLibrary::loadLibraryNewObject = nullptr;
WhiteBoxNumaLibrary::osLibrary.reset();
}
TEST(MemoryInfo, givenMemoryInfoWithRegionsWhenCreatingGemExtWithChunkingButSizeLessThanAllowedThenExceptionIsThrown) {
DebugManagerStateRestore restorer;
debugManager.flags.EnableLocalMemory.set(1);
@@ -461,7 +757,7 @@ TEST(MemoryInfo, givenMemoryInfoWithRegionsWhenCreatingGemExtWithChunkingButSize
bool isChunked = true;
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo, *drm);
ASSERT_NE(nullptr, memoryInfo);
EXPECT_THROW(memoryInfo->createGemExtWithMultipleRegions(1, allocSize, handle, 0, pairHandle, isChunked, numOfChunks), std::runtime_error);
EXPECT_THROW(memoryInfo->createGemExtWithMultipleRegions(1, allocSize, handle, 0, pairHandle, isChunked, numOfChunks, false, nullptr), std::runtime_error);
}
TEST(MemoryInfo, givenMemoryInfoWithRegionsWhenCreatingGemExtWithChunkingWithSizeGreaterThanAllowedThenAllocationIsCreatedWithChunking) {
@@ -487,7 +783,7 @@ TEST(MemoryInfo, givenMemoryInfoWithRegionsWhenCreatingGemExtWithChunkingWithSiz
bool isChunked = true;
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo, *drm);
ASSERT_NE(nullptr, memoryInfo);
auto ret = memoryInfo->createGemExtWithMultipleRegions(1, allocSize, handle, 0, pairHandle, isChunked, numOfChunks);
auto ret = memoryInfo->createGemExtWithMultipleRegions(1, allocSize, handle, 0, pairHandle, isChunked, numOfChunks, false, nullptr);
EXPECT_EQ(0, ret);
EXPECT_EQ(1u, drm->ioctlCallsCount);
}
@@ -511,7 +807,7 @@ TEST(MemoryInfo, givenMemoryInfoWithRegionsAndPrivateBOSupportWhenCreatingGemExt
ASSERT_NE(nullptr, memoryInfo);
uint32_t handle = 0;
auto ret = memoryInfo->createGemExtWithSingleRegion(1, 1024, handle, 0, -1);
auto ret = memoryInfo->createGemExtWithSingleRegion(1, 1024, handle, 0, -1, false, nullptr);
EXPECT_EQ(1u, handle);
EXPECT_EQ(0, ret);
EXPECT_EQ(1u, drm->ioctlCallsCount);
@@ -541,7 +837,7 @@ TEST(MemoryInfo, givenMemoryInfoWithRegionsAndNoPrivateBOSupportWhenCreatingGemE
ASSERT_NE(nullptr, memoryInfo);
uint32_t handle = 0;
auto ret = memoryInfo->createGemExtWithSingleRegion(1, 1024, handle, 0, -1);
auto ret = memoryInfo->createGemExtWithSingleRegion(1, 1024, handle, 0, -1, false, nullptr);
EXPECT_EQ(1u, handle);
EXPECT_EQ(0, ret);
EXPECT_EQ(1u, drm->ioctlCallsCount);
@@ -570,7 +866,7 @@ TEST(MemoryInfo, givenMemoryInfoWithRegionsAndPrivateBOSupportedAndIsPerContextV
ASSERT_NE(nullptr, memoryInfo);
uint32_t handle = 0;
auto ret = memoryInfo->createGemExtWithSingleRegion(1, 1024, handle, 0, -1);
auto ret = memoryInfo->createGemExtWithSingleRegion(1, 1024, handle, 0, -1, false, nullptr);
EXPECT_EQ(1u, handle);
EXPECT_EQ(0, ret);
EXPECT_EQ(1u, drm->ioctlCallsCount);
@@ -603,7 +899,7 @@ TEST(MemoryInfo, givenMemoryInfoWithRegionsWhenCreatingGemExtWithMultipleRegions
ASSERT_NE(nullptr, memoryInfo);
uint32_t handle = 0;
uint32_t memoryRegions = 0b1011;
auto ret = memoryInfo->createGemExtWithMultipleRegions(memoryRegions, 1024, handle, 0);
auto ret = memoryInfo->createGemExtWithMultipleRegions(memoryRegions, 1024, handle, 0, false, nullptr);
EXPECT_EQ(1u, handle);
EXPECT_EQ(0, ret);
EXPECT_EQ(1u, drm->ioctlCallsCount);
@@ -644,7 +940,7 @@ TEST(MemoryInfo, givenMemoryInfoWithRegionsWhenCallingCreatingGemExtWithMultiple
uint32_t handle = 0;
uint32_t memoryRegions = 0b1011;
uint32_t numOfChunks = 2;
EXPECT_THROW(memoryInfo->createGemExtWithMultipleRegions(memoryRegions, MemoryConstants::chunkThreshold / (numOfChunks * 2), handle, 0, -1, true, numOfChunks), std::runtime_error);
EXPECT_THROW(memoryInfo->createGemExtWithMultipleRegions(memoryRegions, MemoryConstants::chunkThreshold / (numOfChunks * 2), handle, 0, -1, true, numOfChunks, false, nullptr), std::runtime_error);
}
TEST(MemoryInfo, givenMemoryInfoWithRegionsWhenCallingCreatingGemExtWithMultipleRegionsAndChunkingThenReturnCorrectValues) {
@@ -672,7 +968,7 @@ TEST(MemoryInfo, givenMemoryInfoWithRegionsWhenCallingCreatingGemExtWithMultiple
uint32_t memoryRegions = 0b1011;
uint32_t numOfChunks = 2;
size_t size = MemoryConstants::chunkThreshold * numOfChunks;
auto ret = memoryInfo->createGemExtWithMultipleRegions(memoryRegions, size, handle, 0, -1, true, numOfChunks);
auto ret = memoryInfo->createGemExtWithMultipleRegions(memoryRegions, size, handle, 0, -1, true, numOfChunks, false, nullptr);
EXPECT_EQ(1u, handle);
EXPECT_EQ(0, ret);
EXPECT_EQ(1u, drm->ioctlCallsCount);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2023 Intel Corporation
* Copyright (C) 2019-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -236,7 +236,7 @@ HWTEST2_F(MemoryInfoTest, givenMemoryInfoWithRegionsWhenCreatingGemWithExtension
uint32_t handle = 0;
MemRegionsVec memClassInstance = {regionInfo[0].region, regionInfo[1].region};
uint32_t numOfChunks = 0;
auto ret = memoryInfo->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks);
auto ret = memoryInfo->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks, false, nullptr);
EXPECT_EQ(1u, handle);
EXPECT_EQ(0, ret);
EXPECT_EQ(1u, drm->ioctlCallsCount);
@@ -259,7 +259,7 @@ HWTEST2_F(MemoryInfoTest, givenMemoryInfoWithRegionsWhenCreatingGemExtWithSingle
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo, *drm);
ASSERT_NE(nullptr, memoryInfo);
auto ret = memoryInfo->createGemExtWithSingleRegion(1, 1024, handle, 0, -1);
auto ret = memoryInfo->createGemExtWithSingleRegion(1, 1024, handle, 0, -1, false, nullptr);
EXPECT_EQ(1u, handle);
EXPECT_EQ(0, ret);
EXPECT_EQ(1u, drm->ioctlCallsCount);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Intel Corporation
* Copyright (C) 2022-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -62,6 +62,7 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenDrmMemoryManagerWithPrelimSup
(1 << (MemoryBanks::getBankForLocalMemory(0) - 1)),
1,
-1,
false,
false));
ASSERT_NE(nullptr, bo);
@@ -1982,6 +1983,7 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenPrintBOCreateDestroyResultFla
(1 << (MemoryBanks::getBankForLocalMemory(0) - 1)),
1,
-1,
false,
false));
EXPECT_NE(nullptr, bo);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -54,7 +54,7 @@ class DrmMemoryManagerFixtureImpl : public DrmMemoryManagerFixture {
std::unique_ptr<VariableBackup<UltHwConfig>> backup;
};
BufferObject *createBufferObjectInMemoryRegion(Drm *drm, Gmm *gmm, AllocationType allocationType, uint64_t gpuAddress, size_t size, uint32_t memoryBanks, size_t maxOsContextCount, bool isSystemMemoryPool);
BufferObject *createBufferObjectInMemoryRegion(Drm *drm, Gmm *gmm, AllocationType allocationType, uint64_t gpuAddress, size_t size, uint32_t memoryBanks, size_t maxOsContextCount, bool isSystemMemoryPool, bool isHostUSMAllocation);
class DrmMemoryManagerLocalMemoryTest : public ::testing::Test {
public:
@@ -127,6 +127,7 @@ HWTEST2_F(DrmMemoryManagerLocalMemoryTest, givenDrmMemoryManagerWhenCreateBuffer
(1 << (MemoryBanks::getBankForLocalMemory(0) - 1)),
1,
-1,
false,
false));
ASSERT_NE(nullptr, bo);
EXPECT_EQ(1u, mock->ioctlCallsCount);
@@ -449,7 +450,7 @@ class DrmMemoryManagerLocalMemoryMemoryBankMock : public TestedDrmMemoryManager
uint32_t memoryBanks,
size_t maxOsContextCount,
int32_t pairHandle,
bool isSystemMemoryPool) override {
bool isSystemMemoryPool, bool isUSMHostAllocation) override {
memoryBankIsOne = (memoryBanks == 1) ? true : false;
return nullptr;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Intel Corporation
* Copyright (C) 2022-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -5459,7 +5459,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenDrmMemor
auto gpuAddress = 0x1234u;
auto size = MemoryConstants::pageSize;
auto bo = std::unique_ptr<BufferObject>(memoryManager->createBufferObjectInMemoryRegion(rootDeviceIndex, nullptr, AllocationType::buffer, gpuAddress, size, MemoryBanks::mainBank, 1, -1, false));
auto bo = std::unique_ptr<BufferObject>(memoryManager->createBufferObjectInMemoryRegion(rootDeviceIndex, nullptr, AllocationType::buffer, gpuAddress, size, MemoryBanks::mainBank, 1, -1, false, false));
EXPECT_EQ(nullptr, bo);
}
@@ -5467,7 +5467,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenDrmMemor
auto gpuAddress = 0x1234u;
auto size = 0u;
auto bo = std::unique_ptr<BufferObject>(memoryManager->createBufferObjectInMemoryRegion(rootDeviceIndex, nullptr, AllocationType::buffer, gpuAddress, size, MemoryBanks::mainBank, 1, -1, false));
auto bo = std::unique_ptr<BufferObject>(memoryManager->createBufferObjectInMemoryRegion(rootDeviceIndex, nullptr, AllocationType::buffer, gpuAddress, size, MemoryBanks::mainBank, 1, -1, false, false));
EXPECT_EQ(nullptr, bo);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2023 Intel Corporation
* Copyright (C) 2021-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -137,7 +137,7 @@ TEST_F(IoctlHelperPrelimFixture, givenPrelimsWhenCreateGemExtThenReturnSuccess)
uint32_t handle = 0;
MemRegionsVec memClassInstance = {{drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0}};
uint32_t numOfChunks = 0;
auto ret = ioctlHelper->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks);
auto ret = ioctlHelper->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks, std::nullopt, std::nullopt);
EXPECT_EQ(1u, handle);
EXPECT_EQ(0, ret);
@@ -161,7 +161,7 @@ TEST_F(IoctlHelperPrelimFixture, givenPrelimsWhenCreateGemExtWithChunkingThenGet
uint32_t handle = 0;
uint32_t getNumOfChunks = 2;
MemRegionsVec memClassInstance = {{drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0}};
ioctlHelper->createGemExt(memClassInstance, allocSize, handle, 0, {}, -1, true, getNumOfChunks);
ioctlHelper->createGemExt(memClassInstance, allocSize, handle, 0, {}, -1, true, getNumOfChunks, std::nullopt, std::nullopt);
std::string output = testing::internal::GetCapturedStdout();
std::string expectedOutput("GEM_CREATE_EXT BO-1 with BOChunkingSize 65536, chunkingParamRegion.param.data 65536, numOfChunks 2\n");
EXPECT_EQ(expectedOutput, output);
@@ -178,7 +178,7 @@ TEST_F(IoctlHelperPrelimFixture, givenPrelimsWhenCreateGemExtWithChunkingAndAllo
uint32_t handle = 0;
uint32_t getNumOfChunks = 2;
MemRegionsVec memClassInstance = {{drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0}};
EXPECT_THROW(ioctlHelper->createGemExt(memClassInstance, allocSize, handle, 0, {}, -1, true, getNumOfChunks), std::runtime_error);
EXPECT_THROW(ioctlHelper->createGemExt(memClassInstance, allocSize, handle, 0, {}, -1, true, getNumOfChunks, std::nullopt, std::nullopt), std::runtime_error);
}
TEST_F(IoctlHelperPrelimFixture, givenPrelimsWhenCreateGemExtWithDebugFlagThenPrintDebugInfo) {
@@ -190,7 +190,7 @@ TEST_F(IoctlHelperPrelimFixture, givenPrelimsWhenCreateGemExtWithDebugFlagThenPr
uint32_t handle = 0;
MemRegionsVec memClassInstance = {{drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0}};
uint32_t numOfChunks = 0;
ioctlHelper->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks);
ioctlHelper->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks, std::nullopt, std::nullopt);
std::string output = testing::internal::GetCapturedStdout();
std::string expectedOutput("Performing GEM_CREATE_EXT with { size: 1024, param: 0x1000000010001, memory class: 1, memory instance: 0 }\nGEM_CREATE_EXT has returned: 0 BO-1 with size: 1024\n");

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2023 Intel Corporation
* Copyright (C) 2021-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -28,7 +28,7 @@ DG1TEST_F(IoctlHelperTestsDg1, givenDg1WhenCreateGemExtThenReturnCorrectValue) {
uint32_t handle = 0;
MemRegionsVec memClassInstance = {{drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0}};
uint32_t numOfChunks = 0;
auto ret = ioctlHelper->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks);
auto ret = ioctlHelper->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks, std::nullopt, std::nullopt);
EXPECT_EQ(0, ret);
EXPECT_EQ(1u, handle);
@@ -50,7 +50,7 @@ DG1TEST_F(IoctlHelperTestsDg1, givenDg1WithDrmTipWhenCreateGemExtWithDebugFlagTh
uint32_t handle = 0;
MemRegionsVec memClassInstance = {{drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0}};
uint32_t numOfChunks = 0;
auto ret = ioctlHelper->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks);
auto ret = ioctlHelper->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks, std::nullopt, std::nullopt);
std::string output = testing::internal::GetCapturedStdout();
std::string expectedOutput("Performing GEM_CREATE_EXT with { size: 1024, memory class: 1, memory instance: 0 }\nGEM_CREATE_EXT with EXT_MEMORY_REGIONS has returned: 0 BO-1 with size: 1024\n");
@@ -72,7 +72,7 @@ DG1TEST_F(IoctlHelperTestsDg1, givenDg1WhenCreateGemExtWithDebugFlagThenPrintDeb
uint32_t handle = 0;
MemRegionsVec memClassInstance = {{drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0}};
uint32_t numOfChunks = 0;
auto ret = ioctlHelper->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks);
auto ret = ioctlHelper->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks, std::nullopt, std::nullopt);
std::string output = testing::internal::GetCapturedStdout();
std::string expectedOutput("Performing GEM_CREATE_EXT with { size: 1024, memory class: 1, memory instance: 0 }\nGEM_CREATE_EXT with EXT_MEMORY_REGIONS has returned: -1 BO-0 with size: 1024\nGEM_CREATE_EXT with EXT_SETPARAM has returned: 0 BO-1 with size: 1024\n");

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2023 Intel Corporation
* Copyright (C) 2021-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -366,8 +366,7 @@ TEST_F(IoctlPrelimHelperTests, givenPrelimWhenGettingEuStallPropertiesThenCorrec
EXPECT_EQ(properties[6], prelim_drm_i915_eu_stall_property_id::PRELIM_DRM_I915_EU_STALL_PROP_ENGINE_CLASS);
EXPECT_EQ(properties[7], prelim_drm_i915_gem_engine_class::PRELIM_I915_ENGINE_CLASS_COMPUTE);
EXPECT_EQ(properties[8], prelim_drm_i915_eu_stall_property_id::PRELIM_DRM_I915_EU_STALL_PROP_ENGINE_INSTANCE);
EXPECT_EQ(properties[9], 1u);
EXPECT_EQ(properties[10], prelim_drm_i915_eu_stall_property_id::PRELIM_DRM_I915_EU_STALL_PROP_EVENT_REPORT_COUNT);
EXPECT_EQ(properties[11], 20u);
}
@@ -375,6 +374,98 @@ TEST_F(IoctlPrelimHelperTests, givenPrelimWhenGettingEuStallFdParameterThenCorre
EXPECT_EQ(static_cast<uint32_t>(PRELIM_I915_PERF_FLAG_FD_EU_STALL), ioctlHelper.getEuStallFdParameter());
}
struct MockIoctlHelperPrelim20 : IoctlHelperPrelim20 {
using IoctlHelperPrelim20::createGemExt;
using IoctlHelperPrelim20::IoctlHelperPrelim20;
int ioctl(DrmIoctl request, void *arg) override {
ioctlCallCount++;
if (request == DrmIoctl::gemCreateExt) {
lastGemCreateContainedMemPolicy = checkWhetherGemCreateExtContainsMemPolicy(arg);
if (overrideGemCreateExtReturnValue.has_value()) {
return *overrideGemCreateExtReturnValue;
}
}
return IoctlHelperPrelim20::ioctl(request, arg);
}
bool checkWhetherGemCreateExtContainsMemPolicy(void *arg) {
auto &gemCreateExt = *reinterpret_cast<prelim_drm_i915_gem_create_ext *>(arg);
auto pExtensionBase = reinterpret_cast<i915_user_extension *>(gemCreateExt.extensions);
while (pExtensionBase != nullptr) {
if (pExtensionBase->name == PRELIM_I915_GEM_CREATE_EXT_MEMORY_POLICY) {
auto lastPolicy = reinterpret_cast<prelim_drm_i915_gem_create_ext_memory_policy *>(pExtensionBase);
lastPolicyMode = lastPolicy->mode;
lastPolicyFlags = lastPolicy->flags;
lastPolicyNodeMask.clear();
auto nodeMaskPtr = reinterpret_cast<unsigned long *>(lastPolicy->nodemask_ptr);
for (auto i = 0u; i < lastPolicy->nodemask_max; i++) {
lastPolicyNodeMask.push_back(nodeMaskPtr[i]);
}
return true;
}
pExtensionBase = reinterpret_cast<i915_user_extension *>(pExtensionBase->next_extension);
}
return false;
}
size_t ioctlCallCount = 0;
bool lastGemCreateContainedMemPolicy = false;
std::optional<int> overrideGemCreateExtReturnValue{};
uint32_t lastPolicyMode = 0;
uint32_t lastPolicyFlags = 0;
std::vector<unsigned long> lastPolicyNodeMask{};
};
TEST(IoctlPrelimHelperCreateGemExtTests, givenPrelimWhenCreateGemExtWithMemPolicyThenMemPolicyExtensionsIsAdded) {
DebugManagerStateRestore stateRestore;
debugManager.flags.PrintBOCreateDestroyResult.set(true);
testing::internal::CaptureStdout();
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto drm = std::make_unique<DrmMock>(*executionEnvironment->rootDeviceEnvironments[0]);
MockIoctlHelperPrelim20 mockIoctlHelper{*drm};
uint32_t handle = 0;
MemRegionsVec memClassInstance = {{drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 0}};
uint32_t numOfChunks = 0;
std::vector<unsigned long> memPolicy;
memPolicy.push_back(1);
uint32_t memPolicyMode = 0;
mockIoctlHelper.overrideGemCreateExtReturnValue = 0;
mockIoctlHelper.initialize();
auto ret = mockIoctlHelper.createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks, memPolicyMode, memPolicy);
std::string output = testing::internal::GetCapturedStdout();
std::string expectedSubstring("memory policy:");
EXPECT_EQ(0, ret);
EXPECT_TRUE(mockIoctlHelper.lastGemCreateContainedMemPolicy);
EXPECT_EQ(0u, mockIoctlHelper.lastPolicyFlags);
EXPECT_EQ(memPolicyMode, mockIoctlHelper.lastPolicyMode);
EXPECT_EQ(memPolicy, mockIoctlHelper.lastPolicyNodeMask);
EXPECT_TRUE(output.find(expectedSubstring) != std::string::npos);
}
TEST(IoctlPrelimHelperCreateGemExtTests, givenPrelimWhenCreateGemExtWithMemPolicyAndChunkingThenMemPolicyExtensionsIsAdded) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto drm = std::make_unique<DrmMock>(*executionEnvironment->rootDeviceEnvironments[0]);
MockIoctlHelperPrelim20 mockIoctlHelper{*drm};
uint32_t handle = 0;
MemRegionsVec memClassInstance = {{drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 0}};
uint32_t numOfChunks = 2;
size_t size = 4 * MemoryConstants::pageSize64k;
std::vector<unsigned long> memPolicy;
memPolicy.push_back(1);
uint32_t memPolicyMode = 0;
mockIoctlHelper.overrideGemCreateExtReturnValue = 0;
mockIoctlHelper.initialize();
auto ret = mockIoctlHelper.createGemExt(memClassInstance, size, handle, 0, {}, -1, true, numOfChunks, memPolicyMode, memPolicy);
EXPECT_EQ(0, ret);
EXPECT_TRUE(mockIoctlHelper.lastGemCreateContainedMemPolicy);
EXPECT_EQ(0u, mockIoctlHelper.lastPolicyFlags);
EXPECT_EQ(memPolicyMode, mockIoctlHelper.lastPolicyMode);
EXPECT_EQ(memPolicy, mockIoctlHelper.lastPolicyNodeMask);
}
class DrmMockIoctl : public DrmMock {
public:
DrmMockIoctl(RootDeviceEnvironment &rootDeviceEnvironment) : DrmMock(rootDeviceEnvironment) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2023 Intel Corporation
* Copyright (C) 2021-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -328,7 +328,7 @@ TEST(IoctlHelperTestsUpstream, givenUpstreamWhenCreateGemExtThenReturnCorrectVal
uint32_t handle = 0;
MemRegionsVec memClassInstance = {{drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0}};
uint32_t numOfChunks = 0;
auto ret = ioctlHelper->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks);
auto ret = ioctlHelper->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks, std::nullopt, std::nullopt);
EXPECT_EQ(0, ret);
EXPECT_EQ(1u, handle);
@@ -350,7 +350,7 @@ TEST(IoctlHelperTestsUpstream, givenUpstreamWhenCreateGemExtWithDebugFlagThenPri
uint32_t handle = 0;
MemRegionsVec memClassInstance = {{drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0}};
uint32_t numOfChunks = 0;
ioctlHelper->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks);
ioctlHelper->createGemExt(memClassInstance, 1024, handle, 0, {}, -1, false, numOfChunks, std::nullopt, std::nullopt);
std::string output = testing::internal::GetCapturedStdout();
std::string expectedOutput("Performing GEM_CREATE_EXT with { size: 1024, memory class: 1, memory instance: 0 }\nGEM_CREATE_EXT with EXT_MEMORY_REGIONS has returned: 0 BO-1 with size: 1024\n");
@@ -365,13 +365,13 @@ TEST(IoctlHelperTestsUpstream, givenSetPatSupportedWhenCreateGemExtThenSetPatExt
uint32_t handle = 0;
MemRegionsVec memClassInstance = {{drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0}};
mockIoctlHelper.isSetPatSupported = false;
auto ret = mockIoctlHelper.createGemExt(memClassInstance, 1, handle, 0, {}, -1, false, 0);
auto ret = mockIoctlHelper.createGemExt(memClassInstance, 1, handle, 0, {}, -1, false, 0, std::nullopt, std::nullopt);
EXPECT_EQ(0, ret);
EXPECT_EQ(1u, mockIoctlHelper.ioctlCallCount);
EXPECT_FALSE(mockIoctlHelper.lastGemCreateContainedSetPat);
mockIoctlHelper.isSetPatSupported = true;
ret = mockIoctlHelper.createGemExt(memClassInstance, 1, handle, 0, {}, -1, false, 0);
ret = mockIoctlHelper.createGemExt(memClassInstance, 1, handle, 0, {}, -1, false, 0, std::nullopt, std::nullopt);
EXPECT_EQ(0, ret);
EXPECT_EQ(2u, mockIoctlHelper.ioctlCallCount);
EXPECT_TRUE(mockIoctlHelper.lastGemCreateContainedSetPat);
@@ -386,13 +386,13 @@ TEST(IoctlHelperTestsUpstream, givenInvalidPatIndexWhenCreateGemExtThenSetPatExt
mockIoctlHelper.isSetPatSupported = true;
uint64_t invalidPatIndex = CommonConstants::unsupportedPatIndex;
MemRegionsVec memClassInstance = {{drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0}};
auto ret = mockIoctlHelper.createGemExt(memClassInstance, 1, handle, invalidPatIndex, {}, -1, false, 0);
auto ret = mockIoctlHelper.createGemExt(memClassInstance, 1, handle, invalidPatIndex, {}, -1, false, 0, std::nullopt, std::nullopt);
EXPECT_EQ(0, ret);
EXPECT_EQ(1u, mockIoctlHelper.ioctlCallCount);
EXPECT_FALSE(mockIoctlHelper.lastGemCreateContainedSetPat);
invalidPatIndex = static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()) + 1;
ret = mockIoctlHelper.createGemExt(memClassInstance, 1, handle, invalidPatIndex, {}, -1, false, 0);
ret = mockIoctlHelper.createGemExt(memClassInstance, 1, handle, invalidPatIndex, {}, -1, false, 0, std::nullopt, std::nullopt);
EXPECT_EQ(0, ret);
EXPECT_EQ(2u, mockIoctlHelper.ioctlCallCount);
EXPECT_FALSE(mockIoctlHelper.lastGemCreateContainedSetPat);
@@ -414,7 +414,7 @@ TEST(IoctlHelperTestsUpstream, givenSetPatSupportedWhenCreateGemExtWithDebugFlag
MemRegionsVec memClassInstance = {{drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0}};
uint32_t numOfChunks = 0;
uint64_t patIndex = 5;
mockIoctlHelper.createGemExt(memClassInstance, 1024, handle, patIndex, {}, -1, false, numOfChunks);
mockIoctlHelper.createGemExt(memClassInstance, 1024, handle, patIndex, {}, -1, false, numOfChunks, std::nullopt, std::nullopt);
std::string output = testing::internal::GetCapturedStdout();
std::string expectedOutput("Performing GEM_CREATE_EXT with { size: 1024, memory class: 1, memory instance: 0, pat index: 5 }\nGEM_CREATE_EXT with EXT_MEMORY_REGIONS with EXT_SET_PAT has returned: 0 BO-1 with size: 1024\n");

View File

@@ -0,0 +1,144 @@
/*
* Copyright (C) 2023-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/string.h"
#include "shared/source/os_interface/linux/numa_library.h"
#include "shared/test/common/mocks/mock_os_library.h"
#include "shared/test/common/test_macros/test.h"
#include <fcntl.h>
using namespace NEO;
using namespace NEO::Linux;
struct WhiteBoxNumaLibrary : NumaLibrary {
public:
using NumaLibrary::numaLibNameStr;
using NumaLibrary::procGetMemPolicyStr;
using NumaLibrary::procNumaAvailableStr;
using NumaLibrary::procNumaMaxNodeStr;
using OsLibraryLoadPtr = NumaLibrary::OsLibraryLoadPtr;
using GetMemPolicyPtr = NumaLibrary::GetMemPolicyPtr;
using NumaAvailablePtr = NumaLibrary::NumaAvailablePtr;
using NumaMaxNodePtr = NumaLibrary::NumaMaxNodePtr;
using NumaLibrary::getMemPolicyFunction;
using NumaLibrary::osLibrary;
using NumaLibrary::osLibraryLoadFunction;
};
TEST(NumaLibraryTests, givenNumaLibraryWithValidMockOsLibraryWhenCallingGetMemPolicyThenZeroIsReturned) {
WhiteBoxNumaLibrary::GetMemPolicyPtr memPolicyHandler =
[](int *, unsigned long[], unsigned long, void *, unsigned long) -> long { return 0; };
WhiteBoxNumaLibrary::NumaAvailablePtr numaAvailableHandler =
[](void) -> int { return 0; };
WhiteBoxNumaLibrary::NumaMaxNodePtr numaMaxNodeHandler =
[](void) -> int { return 4; };
MockOsLibrary::loadLibraryNewObject = new MockOsLibraryCustom(nullptr, true);
MockOsLibraryCustom *osLibrary = static_cast<MockOsLibraryCustom *>(MockOsLibrary::loadLibraryNewObject);
// register proc pointers
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procGetMemPolicyStr)] = reinterpret_cast<void *>(memPolicyHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaAvailableStr)] = reinterpret_cast<void *>(numaAvailableHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaMaxNodeStr)] = reinterpret_cast<void *>(numaMaxNodeHandler);
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibraryCustom::load;
EXPECT_TRUE(WhiteBoxNumaLibrary::init());
EXPECT_TRUE(WhiteBoxNumaLibrary::isLoaded());
EXPECT_EQ(reinterpret_cast<WhiteBoxNumaLibrary::GetMemPolicyPtr>(memPolicyHandler), WhiteBoxNumaLibrary::getMemPolicyFunction);
std::vector<unsigned long> memPolicyNodeMask;
int mode = -1;
EXPECT_EQ(true, WhiteBoxNumaLibrary::getMemPolicy(&mode, memPolicyNodeMask, nullptr));
MockOsLibrary::loadLibraryNewObject = nullptr;
WhiteBoxNumaLibrary::osLibrary.reset();
}
TEST(NumaLibraryTests, givenNumaLibraryWithInvalidMockOsLibraryWhenCallingLoadThenFalseIsReturned) {
WhiteBoxNumaLibrary::GetMemPolicyPtr memPolicyHandler =
[](int *, unsigned long[], unsigned long, void *, unsigned long) -> long { return 0; };
WhiteBoxNumaLibrary::NumaAvailablePtr numaAvailableHandler =
[](void) -> int { return -1; };
WhiteBoxNumaLibrary::NumaAvailablePtr numaAvailableHandler2 =
[](void) -> int { return 0; };
WhiteBoxNumaLibrary::NumaMaxNodePtr numaMaxNodeHandler =
[](void) -> int { return 0; };
MockOsLibrary::loadLibraryNewObject = new MockOsLibraryCustom(nullptr, true);
MockOsLibraryCustom *osLibrary = static_cast<MockOsLibraryCustom *>(MockOsLibrary::loadLibraryNewObject);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaAvailableStr)] = nullptr;
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaMaxNodeStr)] = nullptr;
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procGetMemPolicyStr)] = nullptr;
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibraryCustom::load;
EXPECT_FALSE(WhiteBoxNumaLibrary::init());
EXPECT_FALSE(WhiteBoxNumaLibrary::isLoaded());
EXPECT_EQ(nullptr, MockOsLibrary::loadLibraryNewObject);
MockOsLibrary::loadLibraryNewObject = new MockOsLibraryCustom(nullptr, true);
osLibrary = static_cast<MockOsLibraryCustom *>(MockOsLibrary::loadLibraryNewObject);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaAvailableStr)] = reinterpret_cast<void *>(numaAvailableHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaMaxNodeStr)] = nullptr;
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procGetMemPolicyStr)] = nullptr;
EXPECT_FALSE(WhiteBoxNumaLibrary::init());
EXPECT_FALSE(WhiteBoxNumaLibrary::isLoaded());
EXPECT_EQ(nullptr, MockOsLibrary::loadLibraryNewObject);
MockOsLibrary::loadLibraryNewObject = new MockOsLibraryCustom(nullptr, true);
osLibrary = static_cast<MockOsLibraryCustom *>(MockOsLibrary::loadLibraryNewObject);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaAvailableStr)] = reinterpret_cast<void *>(numaAvailableHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaMaxNodeStr)] = reinterpret_cast<void *>(numaMaxNodeHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procGetMemPolicyStr)] = nullptr;
EXPECT_FALSE(WhiteBoxNumaLibrary::init());
EXPECT_FALSE(WhiteBoxNumaLibrary::isLoaded());
EXPECT_EQ(nullptr, MockOsLibrary::loadLibraryNewObject);
MockOsLibrary::loadLibraryNewObject = new MockOsLibraryCustom(nullptr, true);
osLibrary = static_cast<MockOsLibraryCustom *>(MockOsLibrary::loadLibraryNewObject);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaAvailableStr)] = reinterpret_cast<void *>(numaAvailableHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaMaxNodeStr)] = reinterpret_cast<void *>(numaMaxNodeHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procGetMemPolicyStr)] = reinterpret_cast<void *>(memPolicyHandler);
EXPECT_FALSE(WhiteBoxNumaLibrary::init());
EXPECT_FALSE(WhiteBoxNumaLibrary::isLoaded());
EXPECT_EQ(nullptr, MockOsLibrary::loadLibraryNewObject);
MockOsLibrary::loadLibraryNewObject = new MockOsLibraryCustom(nullptr, true);
osLibrary = static_cast<MockOsLibraryCustom *>(MockOsLibrary::loadLibraryNewObject);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaAvailableStr)] = reinterpret_cast<void *>(numaAvailableHandler2);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procNumaMaxNodeStr)] = reinterpret_cast<void *>(numaMaxNodeHandler);
osLibrary->procMap[std::string(WhiteBoxNumaLibrary::procGetMemPolicyStr)] = reinterpret_cast<void *>(memPolicyHandler);
EXPECT_FALSE(WhiteBoxNumaLibrary::init());
EXPECT_FALSE(WhiteBoxNumaLibrary::isLoaded());
EXPECT_EQ(nullptr, MockOsLibrary::loadLibraryNewObject);
MockOsLibrary::loadLibraryNewObject = nullptr;
EXPECT_FALSE(WhiteBoxNumaLibrary::init());
EXPECT_FALSE(WhiteBoxNumaLibrary::isLoaded());
EXPECT_EQ(nullptr, WhiteBoxNumaLibrary::osLibrary.get());
WhiteBoxNumaLibrary::osLibrary.reset();
}
TEST(NumaLibraryTests, givenNumaLibraryWithInvalidOsLibraryWhenCallingGetMemPolicyThenErrorIsReturned) {
MockOsLibrary::loadLibraryNewObject = new MockOsLibrary(nullptr, false);
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibrary::load;
EXPECT_FALSE(WhiteBoxNumaLibrary::init());
EXPECT_FALSE(WhiteBoxNumaLibrary::isLoaded());
MockOsLibrary::loadLibraryNewObject = nullptr;
WhiteBoxNumaLibrary::osLibrary.reset();
}
TEST(NumaLibraryTests, givenNumaLibraryWithInvalidGetMemPolicyWhenCallingGetMemPolicyThenErrorIsReturned) {
MockOsLibrary::loadLibraryNewObject = new MockOsLibrary(nullptr, true);
WhiteBoxNumaLibrary::osLibraryLoadFunction = MockOsLibrary::load;
EXPECT_FALSE(WhiteBoxNumaLibrary::init());
EXPECT_FALSE(WhiteBoxNumaLibrary::isLoaded());
EXPECT_EQ(nullptr, WhiteBoxNumaLibrary::getMemPolicyFunction);
std::vector<unsigned long> memPolicyNodeMask;
int mode = -1;
EXPECT_EQ(false, WhiteBoxNumaLibrary::getMemPolicy(&mode, memPolicyNodeMask, nullptr));
MockOsLibrary::loadLibraryNewObject = nullptr;
WhiteBoxNumaLibrary::osLibrary.reset();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 Intel Corporation
* Copyright (C) 2023-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -60,7 +60,7 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingGemCreateExtWithRegionsThen
uint32_t numOfChunks = 0;
EXPECT_TRUE(xeIoctlHelper->bindInfo.empty());
EXPECT_NE(0, xeIoctlHelper->createGemExt(memRegions, 0u, handle, 0, {}, -1, false, numOfChunks));
EXPECT_NE(0, xeIoctlHelper->createGemExt(memRegions, 0u, handle, 0, {}, -1, false, numOfChunks, std::nullopt, std::nullopt));
EXPECT_FALSE(xeIoctlHelper->bindInfo.empty());
EXPECT_EQ(DRM_XE_GEM_CPU_CACHING_WC, drm.createParamsCpuCaching);
}
@@ -83,7 +83,7 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingGemCreateExtWithRegionsAndV
GemVmControl test = {};
EXPECT_TRUE(xeIoctlHelper->bindInfo.empty());
EXPECT_NE(0, xeIoctlHelper->createGemExt(memRegions, 0u, handle, 0, test.vmId, -1, false, numOfChunks));
EXPECT_NE(0, xeIoctlHelper->createGemExt(memRegions, 0u, handle, 0, test.vmId, -1, false, numOfChunks, std::nullopt, std::nullopt));
EXPECT_FALSE(xeIoctlHelper->bindInfo.empty());
EXPECT_EQ(DRM_XE_GEM_CPU_CACHING_WC, drm.createParamsCpuCaching);
}
@@ -221,7 +221,7 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingAnyMethodThenDummyValueIsRe
MemRegionsVec memRegions{};
uint32_t handle = 0u;
uint32_t numOfChunks = 0;
EXPECT_NE(0, xeIoctlHelper->createGemExt(memRegions, 0u, handle, 0, {}, -1, false, numOfChunks));
EXPECT_NE(0, xeIoctlHelper->createGemExt(memRegions, 0u, handle, 0, {}, -1, false, numOfChunks, std::nullopt, std::nullopt));
EXPECT_TRUE(xeIoctlHelper->isVmBindAvailable());