Update Context::blitMemoryToAllocation function

Change-Id: I5f81cb023b75e82bd3aff8e393f6b9463c767112
Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
This commit is contained in:
Filip Hazubski
2020-07-10 17:04:42 +02:00
parent f3f464801c
commit 2912cebbd4
20 changed files with 158 additions and 85 deletions

View File

@@ -28,12 +28,6 @@ class SharingFunctions;
class SVMAllocsManager;
class SchedulerKernel;
enum class BlitOperationResult {
Unsupported,
Fail,
Success
};
template <>
struct OpenCLObjectMapper<_cl_context> {
typedef class Context DerivedType;
@@ -136,8 +130,6 @@ class Context : public BaseObject<_cl_context> {
ContextType peekContextType() const { return contextType; }
MOCKABLE_VIRTUAL BlitOperationResult blitMemoryToAllocation(MemObj &memObj, GraphicsAllocation *memory, void *hostPtr, Vec3<size_t> size) const;
SchedulerKernel &getSchedulerKernel();
bool isDeviceAssociated(const ClDevice &clDevice) const;

View File

@@ -16,7 +16,4 @@ cl_int Context::processExtraProperties(cl_context_properties propertyType, cl_co
return CL_INVALID_PROPERTY;
}
BlitOperationResult Context::blitMemoryToAllocation(MemObj &memObj, GraphicsAllocation *memory, void *hostPtr, Vec3<size_t> size) const {
return BlitOperationResult::Unsupported;
}
} // namespace NEO

View File

@@ -340,7 +340,7 @@ Buffer *Buffer::create(Context *context,
bool gpuCopyRequired = (gmm && gmm->isRenderCompressed) || !MemoryPool::isSystemMemoryPool(memory->getMemoryPool());
if (gpuCopyRequired) {
auto blitMemoryToAllocationResult = context->blitMemoryToAllocation(*pBuffer, memory, hostPtr, {size, 1, 1});
auto blitMemoryToAllocationResult = BlitHelperFunctions::blitMemoryToAllocation(pBuffer->getContext()->getDevice(0)->getDevice(), memory, pBuffer->getOffset(), hostPtr, {size, 1, 1});
if (blitMemoryToAllocationResult != BlitOperationResult::Success) {
auto cmdQ = context->getSpecialQueue();

View File

@@ -35,9 +35,9 @@ struct BlitEnqueueTests : public ::testing::Test {
bcsCsr.reset(createCommandStream(*device->getExecutionEnvironment(), device->getRootDeviceIndex()));
bcsCsr->setupContext(*bcsOsContext);
bcsCsr->initializeTagAllocation();
}
BlitOperationResult blitMemoryToAllocation(MemObj &memObj, GraphicsAllocation *memory, void *hostPtr, Vec3<size_t> size) const override {
auto mockBlitMemoryToAllocation = [this](Device &device, GraphicsAllocation *memory, size_t offset, const void *hostPtr,
Vec3<size_t> size) -> BlitOperationResult {
auto blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection::HostPtrToBuffer,
*bcsCsr, memory, nullptr,
hostPtr,
@@ -49,9 +49,14 @@ struct BlitEnqueueTests : public ::testing::Test {
bcsCsr->blitBuffer(container, true, false);
return BlitOperationResult::Success;
};
blitMemoryToAllocationFuncBackup = mockBlitMemoryToAllocation;
}
std::unique_ptr<OsContext> bcsOsContext;
std::unique_ptr<CommandStreamReceiver> bcsCsr;
VariableBackup<BlitHelperFunctions::BlitMemoryToAllocationFunc> blitMemoryToAllocationFuncBackup{
&BlitHelperFunctions::blitMemoryToAllocation};
};
template <typename FamilyType>

View File

@@ -243,6 +243,11 @@ GEN12LPTEST_F(HwHelperTestGen12Lp, whenGettingComputeEngineIndexByOrdinalThenCor
}
}
GEN12LPTEST_F(HwHelperTestGen12Lp, givenDefaultHwHelperHwWhenGettingIsBlitCopyRequiredForLocalMemoryThenFalseIsReturned) {
auto &helper = HwHelper::get(renderCoreFamily);
EXPECT_FALSE(helper.isBlitCopyRequiredForLocalMemory(*defaultHwInfo));
}
class HwHelperTestsGen12LpBuffer : public ::testing::Test {
public:
void SetUp() override {
@@ -335,7 +340,7 @@ GEN12LPTEST_F(HwHelperTestGen12Lp, givenRevisionEnumAndPlatformFamilyTypeThenPro
EXPECT_TRUE(hwHelper.isWorkaroundRequired(REVISION_A0, REVISION_B, hardwareInfo));
EXPECT_FALSE(hwHelper.isWorkaroundRequired(REVISION_B, REVISION_A0, hardwareInfo));
} else if (stepping == 0x1) {
EXPECT_FALSE(hwHelper.isWorkaroundRequired(REVISION_A0, REVISION_C, hardwareInfo));
EXPECT_TRUE(hwHelper.isWorkaroundRequired(REVISION_A0, REVISION_C, hardwareInfo));
} else if (stepping == 0x3) {
EXPECT_FALSE(hwHelper.isWorkaroundRequired(REVISION_A0, REVISION_D, hardwareInfo));
}

View File

@@ -906,12 +906,16 @@ HWTEST_F(HwHelperTest, givenDefaultHwHelperHwWhenMinimalSIMDSizeIsQueriedThen8Is
EXPECT_EQ(8u, helper.getMinimalSIMDSize());
}
using isAtMostGen11 = IsAtMostGfxCore<IGFX_GEN11LP_CORE>;
HWTEST2_F(HwHelperTest, givenSingleEnginePlatformWhenGettingComputeEngineIndexByOrdinalThenZeroIndexIsReturned, isAtMostGen11) {
HWTEST2_F(HwHelperTest, givenSingleEnginePlatformWhenGettingComputeEngineIndexByOrdinalThenZeroIndexIsReturned, IsAtMostGen11) {
auto &helper = HwHelper::get(renderCoreFamily);
EXPECT_EQ(0u, helper.getComputeEngineIndexByOrdinal(*defaultHwInfo, 0));
}
HWTEST2_F(HwHelperTest, givenDefaultHwHelperHwWhenGettingIsBlitCopyRequiredForLocalMemoryThenFalseIsReturned, IsAtMostGen11) {
auto &helper = HwHelper::get(renderCoreFamily);
EXPECT_FALSE(helper.isBlitCopyRequiredForLocalMemory(*defaultHwInfo));
}
HWCMDTEST_F(IGFX_GEN8_CORE, HwHelperTest, WhenIsFusedEuDispatchEnabledIsCalledThenFalseIsReturned) {
if (hardwareInfo.platform.eRenderCoreFamily == IGFX_GEN12LP_CORE) {
GTEST_SKIP();

View File

@@ -693,9 +693,9 @@ struct BcsBufferTests : public ::testing::Test {
bcsCsr->setupContext(*bcsOsContext);
bcsCsr->initializeTagAllocation();
bcsCsr->createGlobalFenceAllocation();
}
BlitOperationResult blitMemoryToAllocation(MemObj &memObj, GraphicsAllocation *memory, void *hostPtr, Vec3<size_t> size) const override {
auto mockBlitMemoryToAllocation = [this](Device &device, GraphicsAllocation *memory, size_t offset, const void *hostPtr,
Vec3<size_t> size) -> BlitOperationResult {
auto blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection::HostPtrToBuffer,
*bcsCsr, memory, nullptr,
hostPtr,
@@ -707,9 +707,14 @@ struct BcsBufferTests : public ::testing::Test {
bcsCsr->blitBuffer(container, true, false);
return BlitOperationResult::Success;
};
blitMemoryToAllocationFuncBackup = mockBlitMemoryToAllocation;
}
std::unique_ptr<OsContext> bcsOsContext;
std::unique_ptr<CommandStreamReceiver> bcsCsr;
VariableBackup<BlitHelperFunctions::BlitMemoryToAllocationFunc> blitMemoryToAllocationFuncBackup{
&BlitHelperFunctions::blitMemoryToAllocation};
};
template <typename FamilyType>

View File

@@ -2198,6 +2198,7 @@ TEST(MemoryManagerTest, givenMemoryManagerWhenGetReservedMemoryIsCalledManyTimes
class MemoryManagerWithFailure : public MockMemoryManager {
public:
using MockMemoryManager::MockMemoryManager;
GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) override {
recentlyPassedDeviceBitfield = properties.subDevicesBitfield;
return nullptr;
@@ -2207,7 +2208,7 @@ class MemoryManagerWithFailure : public MockMemoryManager {
TEST(MemoryManagerTest, whenMemoryManagerReturnsNullptrThenAllocateGlobalsSurfaceAlsoReturnsNullptr) {
MockClDevice device{new MockDevice};
auto deviceBitfield = device.getDeviceBitfield();
auto memoryManager = new MemoryManagerWithFailure();
auto memoryManager = new MemoryManagerWithFailure{*device.getExecutionEnvironment()};
device.injectMemoryManager(memoryManager);
WhiteBox<NEO::LinkerInput> linkerInput;

View File

@@ -93,7 +93,7 @@ bool HwHelperHw<Family>::isWorkaroundRequired(uint32_t lowestSteppingWithBug, ui
return false;
}
}
return (lowestSteppingWithBug >= hwInfo.platform.usRevId && hwInfo.platform.usRevId < steppingWithFix);
return (lowestSteppingWithBug <= hwInfo.platform.usRevId && hwInfo.platform.usRevId < steppingWithFix);
} else if (hwInfo.platform.eProductFamily == PRODUCT_FAMILY::IGFX_DG1) {
for (auto stepping : {&lowestSteppingWithBug, &steppingWithFix}) {
switch (*stepping) {
@@ -108,7 +108,7 @@ bool HwHelperHw<Family>::isWorkaroundRequired(uint32_t lowestSteppingWithBug, ui
return false;
}
}
return (lowestSteppingWithBug >= hwInfo.platform.usRevId && hwInfo.platform.usRevId < steppingWithFix);
return (lowestSteppingWithBug <= hwInfo.platform.usRevId && hwInfo.platform.usRevId < steppingWithFix);
}
return Gen12LPHelpers::workaroundRequired(lowestSteppingWithBug, steppingWithFix, hwInfo);

View File

@@ -15,6 +15,7 @@ set(NEO_CORE_HELPERS
${CMAKE_CURRENT_SOURCE_DIR}/bit_helpers.h
${CMAKE_CURRENT_SOURCE_DIR}/blit_commands_helper_base.inl
${CMAKE_CURRENT_SOURCE_DIR}/blit_commands_helper_bdw_plus.inl
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/blit_commands_helper_extra.cpp
${CMAKE_CURRENT_SOURCE_DIR}/blit_commands_helper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/blit_commands_helper.h
${CMAKE_CURRENT_SOURCE_DIR}/cache_policy.cpp

View File

@@ -11,11 +11,16 @@
#include "shared/source/memory_manager/surface.h"
namespace NEO {
namespace BlitHelperFunctions {
BlitMemoryToAllocationFunc blitMemoryToAllocation = BlitHelper::blitMemoryToAllocation;
} // namespace BlitHelperFunctions
BlitProperties BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection blitDirection,
CommandStreamReceiver &commandStreamReceiver,
GraphicsAllocation *memObjAllocation,
GraphicsAllocation *preallocatedHostAllocation,
void *hostPtr, uint64_t memObjGpuVa,
const void *hostPtr, uint64_t memObjGpuVa,
uint64_t hostAllocGpuVa, Vec3<size_t> hostPtrOffset,
Vec3<size_t> copyOffset, Vec3<size_t> copySize,
size_t hostRowPitch, size_t hostSlicePitch,

View File

@@ -15,9 +15,11 @@
#include "shared/source/utilities/stackvec.h"
#include <cstdint>
#include <functional>
namespace NEO {
class CommandStreamReceiver;
class Device;
class GraphicsAllocation;
class LinearStream;
struct TimestampPacketStorage;
@@ -36,7 +38,7 @@ struct BlitProperties {
CommandStreamReceiver &commandStreamReceiver,
GraphicsAllocation *memObjAllocation,
GraphicsAllocation *preallocatedHostAllocation,
void *hostPtr, uint64_t memObjGpuVa,
const void *hostPtr, uint64_t memObjGpuVa,
uint64_t hostAllocGpuVa, Vec3<size_t> hostPtrOffset,
Vec3<size_t> copyOffset, Vec3<size_t> copySize,
size_t hostRowPitch, size_t hostSlicePitch,
@@ -77,6 +79,26 @@ struct BlitProperties {
Vec3<uint32_t> srcSize = 0;
};
enum class BlitOperationResult {
Unsupported,
Fail,
Success
};
namespace BlitHelperFunctions {
using BlitMemoryToAllocationFunc = std::function<BlitOperationResult(Device &device,
GraphicsAllocation *memory,
size_t offset,
const void *hostPtr,
Vec3<size_t> size)>;
extern BlitMemoryToAllocationFunc blitMemoryToAllocation;
} // namespace BlitHelperFunctions
struct BlitHelper {
static BlitOperationResult blitMemoryToAllocation(Device &device, GraphicsAllocation *memory, size_t offset, const void *hostPtr,
Vec3<size_t> size);
};
template <typename GfxFamily>
struct BlitCommandsHelper {
using COLOR_DEPTH = typename GfxFamily::XY_COLOR_BLT::COLOR_DEPTH;

View File

@@ -0,0 +1,17 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/blit_commands_helper.h"
namespace NEO {
BlitOperationResult BlitHelper::blitMemoryToAllocation(Device &device, GraphicsAllocation *memory, size_t offset, const void *hostPtr,
Vec3<size_t> size) {
return BlitOperationResult::Unsupported;
}
} // namespace NEO

View File

@@ -56,6 +56,7 @@ class HwHelper {
virtual bool obtainBlitterPreference(const HardwareInfo &hwInfo) const = 0;
virtual bool checkResourceCompatibility(GraphicsAllocation &graphicsAllocation) = 0;
virtual bool allowRenderCompression(const HardwareInfo &hwInfo) const = 0;
virtual bool isBlitCopyRequiredForLocalMemory(const HardwareInfo &hwInfo) const = 0;
static bool renderCompressedBuffersSupported(const HardwareInfo &hwInfo);
static bool renderCompressedImagesSupported(const HardwareInfo &hwInfo);
static bool cacheFlushAfterWalkerSupported(const HardwareInfo &hwInfo);
@@ -270,6 +271,8 @@ class HwHelperHw : public HwHelper {
bool allowRenderCompression(const HardwareInfo &hwInfo) const override;
bool isBlitCopyRequiredForLocalMemory(const HardwareInfo &hwInfo) const override;
protected:
static const AuxTranslationMode defaultAuxTranslationMode;
HwHelperHw() = default;

View File

@@ -379,6 +379,11 @@ inline bool HwHelperHw<GfxFamily>::allowRenderCompression(const HardwareInfo &hw
return true;
}
template <typename GfxFamily>
inline bool HwHelperHw<GfxFamily>::isBlitCopyRequiredForLocalMemory(const HardwareInfo &hwInfo) const {
return false;
}
template <typename GfxFamily>
size_t MemorySynchronizationCommands<GfxFamily>::getSizeForFullCacheFlush() {
return sizeof(typename GfxFamily::PIPE_CONTROL);

View File

@@ -33,16 +33,16 @@ class NullSurface : public Surface {
class HostPtrSurface : public Surface {
public:
HostPtrSurface(void *ptr, size_t size) : memoryPointer(ptr), surfaceSize(size) {
HostPtrSurface(const void *ptr, size_t size) : memoryPointer(ptr), surfaceSize(size) {
UNRECOVERABLE_IF(!ptr);
gfxAllocation = nullptr;
}
HostPtrSurface(void *ptr, size_t size, bool copyAllowed) : HostPtrSurface(ptr, size) {
HostPtrSurface(const void *ptr, size_t size, bool copyAllowed) : HostPtrSurface(ptr, size) {
isPtrCopyAllowed = copyAllowed;
}
HostPtrSurface(void *ptr, size_t size, GraphicsAllocation *allocation) : memoryPointer(ptr), surfaceSize(size), gfxAllocation(allocation) {
HostPtrSurface(const void *ptr, size_t size, GraphicsAllocation *allocation) : memoryPointer(ptr), surfaceSize(size), gfxAllocation(allocation) {
DEBUG_BREAK_IF(!ptr);
}
~HostPtrSurface() override = default;
@@ -55,7 +55,7 @@ class HostPtrSurface : public Surface {
return new HostPtrSurface(this->memoryPointer, this->surfaceSize, this->gfxAllocation);
};
void *getMemoryPointer() const {
const void *getMemoryPointer() const {
return memoryPointer;
}
size_t getSurfaceSize() const {
@@ -79,7 +79,7 @@ class HostPtrSurface : public Surface {
}
protected:
void *memoryPointer;
const void *memoryPointer;
size_t surfaceSize;
GraphicsAllocation *gfxAllocation;
bool isPtrCopyAllowed = false;

View File

@@ -9,6 +9,8 @@
#include "shared/source/compiler_interface/linker.h"
#include "shared/source/device/device.h"
#include "shared/source/helpers/blit_commands_helper.h"
#include "shared/source/helpers/hw_helper.h"
#include "shared/source/helpers/string.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/memory_manager/unified_memory_manager.h"
@@ -16,7 +18,8 @@
namespace NEO {
GraphicsAllocation *allocateGlobalsSurface(NEO::SVMAllocsManager *const svmAllocManager, NEO::Device &device, size_t size, bool constant, LinkerInput *const linkerInput, const void *const initData) {
GraphicsAllocation *allocateGlobalsSurface(NEO::SVMAllocsManager *const svmAllocManager, NEO::Device &device, size_t size, bool constant,
LinkerInput *const linkerInput, const void *initData) {
bool globalsAreExported = false;
if (linkerInput != nullptr) {
globalsAreExported = constant ? linkerInput->getTraits().exportsGlobalConstants : linkerInput->getTraits().exportsGlobalVariables;
@@ -49,7 +52,13 @@ GraphicsAllocation *allocateGlobalsSurface(NEO::SVMAllocsManager *const svmAlloc
if (gpuAlloc == nullptr) {
return nullptr;
}
auto &hwInfo = device.getHardwareInfo();
auto &helper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
if (gpuAlloc->isAllocatedInLocalMemoryPool() && helper.isBlitCopyRequiredForLocalMemory(hwInfo)) {
BlitHelperFunctions::blitMemoryToAllocation(device, gpuAlloc, 0, initData, {size, 1, 1});
} else {
memcpy_s(gpuAlloc->getUnderlyingBuffer(), gpuAlloc->getUnderlyingBufferSize(), initData, size);
}
return gpuAlloc;
}
}

View File

@@ -18,6 +18,6 @@ struct LinkerInput;
GraphicsAllocation *allocateGlobalsSurface(SVMAllocsManager *const svmAllocManager, Device &device,
size_t size, bool constant,
LinkerInput *const linkerInput, const void *const initData);
LinkerInput *const linkerInput, const void *initData);
} // namespace NEO

View File

@@ -8,6 +8,7 @@
#include "shared/source/program/program_initialization.h"
#include "shared/test/unit_test/compiler_interface/linker_mock.h"
#include "shared/test/unit_test/mocks/mock_device.h"
#include "shared/test/unit_test/test_macros/test_checks_shared.h"
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
@@ -22,10 +23,8 @@ using namespace NEO;
TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreNotExportedThenMemoryIsAllocatedAsNonSvmAllocation) {
auto &device = *(new MockDevice);
REQUIRE_SVM_OR_SKIP(&device);
MockClDevice clDevice{&device};
if (0 == clDevice.getDeviceInfo().svmCapabilities) {
return;
}
MockSVMAllocsManager svmAllocsManager(device.getMemoryManager());
WhiteBox<LinkerInput> emptyLinkerInput;
std::vector<uint8_t> initData;
@@ -67,10 +66,8 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreNotExportedTh
TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenMemoryIsAllocatedAsSvmAllocation) {
auto &device = *(new MockDevice);
REQUIRE_SVM_OR_SKIP(&device);
MockClDevice clDevice{&device};
if (0 == clDevice.getDeviceInfo().svmCapabilities) {
return;
}
MockMemoryManager memoryManager;
MockSVMAllocsManager svmAllocsManager(&memoryManager);
WhiteBox<LinkerInput> linkerInputExportGlobalVariables;
@@ -113,7 +110,8 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenM
}
TEST(AllocateGlobalSurfaceTest, GivenNullSvmAllocsManagerWhenGlobalsAreExportedThenMemoryIsAllocatedAsNonSvmAllocation) {
MockDevice device;
auto pDevice = new MockDevice{};
MockClDevice clDevice{pDevice};
WhiteBox<LinkerInput> linkerInputExportGlobalVariables;
WhiteBox<LinkerInput> linkerInputExportGlobalConstants;
linkerInputExportGlobalVariables.traits.exportsGlobalVariables = true;
@@ -122,74 +120,76 @@ TEST(AllocateGlobalSurfaceTest, GivenNullSvmAllocsManagerWhenGlobalsAreExportedT
initData.resize(64, 7U);
GraphicsAllocation *alloc = nullptr;
alloc = allocateGlobalsSurface(nullptr, device, initData.size(), true /* constant */, &linkerInputExportGlobalConstants, initData.data());
alloc = allocateGlobalsSurface(nullptr, *pDevice, initData.size(), true /* constant */, &linkerInputExportGlobalConstants, initData.data());
ASSERT_NE(nullptr, alloc);
ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize());
EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size()));
EXPECT_EQ(GraphicsAllocation::AllocationType::CONSTANT_SURFACE, alloc->getAllocationType());
device.getMemoryManager()->freeGraphicsMemory(alloc);
pDevice->getMemoryManager()->freeGraphicsMemory(alloc);
alloc = allocateGlobalsSurface(nullptr, device, initData.size(), true /* constant */, &linkerInputExportGlobalVariables, initData.data());
alloc = allocateGlobalsSurface(nullptr, *pDevice, initData.size(), true /* constant */, &linkerInputExportGlobalVariables, initData.data());
ASSERT_NE(nullptr, alloc);
ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize());
EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size()));
EXPECT_EQ(GraphicsAllocation::AllocationType::CONSTANT_SURFACE, alloc->getAllocationType());
device.getMemoryManager()->freeGraphicsMemory(alloc);
pDevice->getMemoryManager()->freeGraphicsMemory(alloc);
alloc = allocateGlobalsSurface(nullptr, device, initData.size(), false /* constant */, &linkerInputExportGlobalConstants, initData.data());
alloc = allocateGlobalsSurface(nullptr, *pDevice, initData.size(), false /* constant */, &linkerInputExportGlobalConstants, initData.data());
ASSERT_NE(nullptr, alloc);
ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize());
EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size()));
EXPECT_EQ(GraphicsAllocation::AllocationType::GLOBAL_SURFACE, alloc->getAllocationType());
device.getMemoryManager()->freeGraphicsMemory(alloc);
pDevice->getMemoryManager()->freeGraphicsMemory(alloc);
alloc = allocateGlobalsSurface(nullptr, device, initData.size(), false /* constant */, &linkerInputExportGlobalVariables, initData.data());
alloc = allocateGlobalsSurface(nullptr, *pDevice, initData.size(), false /* constant */, &linkerInputExportGlobalVariables, initData.data());
ASSERT_NE(nullptr, alloc);
ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize());
EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size()));
EXPECT_EQ(GraphicsAllocation::AllocationType::GLOBAL_SURFACE, alloc->getAllocationType());
device.getMemoryManager()->freeGraphicsMemory(alloc);
pDevice->getMemoryManager()->freeGraphicsMemory(alloc);
}
TEST(AllocateGlobalSurfaceTest, WhenGlobalsAreNotExportedAndAllocationFailsThenGracefullyReturnsNullptr) {
MockDevice device;
auto memoryManager = std::make_unique<MockMemoryManager>();
auto pDevice = new MockDevice{};
MockClDevice clDevice{pDevice};
auto memoryManager = std::make_unique<MockMemoryManager>(*clDevice.getExecutionEnvironment());
memoryManager->failInAllocateWithSizeAndAlignment = true;
device.injectMemoryManager(memoryManager.release());
MockSVMAllocsManager mockSvmAllocsManager(device.getMemoryManager());
clDevice.injectMemoryManager(memoryManager.release());
MockSVMAllocsManager mockSvmAllocsManager(clDevice.getMemoryManager());
WhiteBox<LinkerInput> emptyLinkerInput;
std::vector<uint8_t> initData;
initData.resize(64, 7U);
GraphicsAllocation *alloc = nullptr;
alloc = allocateGlobalsSurface(&mockSvmAllocsManager, device, initData.size(), true /* constant */, nullptr /* linker input */, initData.data());
alloc = allocateGlobalsSurface(&mockSvmAllocsManager, *pDevice, initData.size(), true /* constant */, nullptr /* linker input */, initData.data());
EXPECT_EQ(nullptr, alloc);
alloc = allocateGlobalsSurface(&mockSvmAllocsManager, device, initData.size(), false /* constant */, nullptr /* linker input */, initData.data());
alloc = allocateGlobalsSurface(&mockSvmAllocsManager, *pDevice, initData.size(), false /* constant */, nullptr /* linker input */, initData.data());
EXPECT_EQ(nullptr, alloc);
alloc = allocateGlobalsSurface(&mockSvmAllocsManager, device, initData.size(), true /* constant */, &emptyLinkerInput, initData.data());
alloc = allocateGlobalsSurface(&mockSvmAllocsManager, *pDevice, initData.size(), true /* constant */, &emptyLinkerInput, initData.data());
EXPECT_EQ(nullptr, alloc);
alloc = allocateGlobalsSurface(&mockSvmAllocsManager, device, initData.size(), false /* constant */, &emptyLinkerInput, initData.data());
alloc = allocateGlobalsSurface(&mockSvmAllocsManager, *pDevice, initData.size(), false /* constant */, &emptyLinkerInput, initData.data());
EXPECT_EQ(nullptr, alloc);
alloc = allocateGlobalsSurface(nullptr /* svmAllocsManager */, device, initData.size(), true /* constant */, nullptr /* linker input */, initData.data());
alloc = allocateGlobalsSurface(nullptr /* svmAllocsManager */, *pDevice, initData.size(), true /* constant */, nullptr /* linker input */, initData.data());
EXPECT_EQ(nullptr, alloc);
alloc = allocateGlobalsSurface(nullptr /* svmAllocsManager */, device, initData.size(), false /* constant */, nullptr /* linker input */, initData.data());
alloc = allocateGlobalsSurface(nullptr /* svmAllocsManager */, *pDevice, initData.size(), false /* constant */, nullptr /* linker input */, initData.data());
EXPECT_EQ(nullptr, alloc);
alloc = allocateGlobalsSurface(nullptr /* svmAllocsManager */, device, initData.size(), true /* constant */, &emptyLinkerInput, initData.data());
alloc = allocateGlobalsSurface(nullptr /* svmAllocsManager */, *pDevice, initData.size(), true /* constant */, &emptyLinkerInput, initData.data());
EXPECT_EQ(nullptr, alloc);
alloc = allocateGlobalsSurface(nullptr /* svmAllocsManager */, device, initData.size(), false /* constant */, &emptyLinkerInput, initData.data());
alloc = allocateGlobalsSurface(nullptr /* svmAllocsManager */, *pDevice, initData.size(), false /* constant */, &emptyLinkerInput, initData.data());
EXPECT_EQ(nullptr, alloc);
}
TEST(AllocateGlobalSurfaceTest, WhenGlobalsAreExportedAndAllocationFailsThenGracefullyReturnsNullptr) {
MockDevice device;
MockMemoryManager memoryManager;
auto pDevice = new MockDevice{};
MockClDevice clDevice{pDevice};
MockMemoryManager memoryManager{*clDevice.getExecutionEnvironment()};
MockSVMAllocsManager svmAllocsManager(&memoryManager);
memoryManager.failInAllocateWithSizeAndAlignment = true;
WhiteBox<LinkerInput> linkerInputExportGlobalVariables;
@@ -200,9 +200,9 @@ TEST(AllocateGlobalSurfaceTest, WhenGlobalsAreExportedAndAllocationFailsThenGrac
initData.resize(64, 7U);
GraphicsAllocation *alloc = nullptr;
alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), true /* constant */, &linkerInputExportGlobalConstants, initData.data());
alloc = allocateGlobalsSurface(&svmAllocsManager, *pDevice, initData.size(), true /* constant */, &linkerInputExportGlobalConstants, initData.data());
EXPECT_EQ(nullptr, alloc);
alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), false /* constant */, &linkerInputExportGlobalVariables, initData.data());
alloc = allocateGlobalsSurface(&svmAllocsManager, *pDevice, initData.size(), false /* constant */, &linkerInputExportGlobalVariables, initData.data());
EXPECT_EQ(nullptr, alloc);
}

View File

@@ -1038,6 +1038,8 @@ using IsGen11HP = IsGfxCore<IGFX_GEN11_CORE>;
using IsGen11LP = IsGfxCore<IGFX_GEN11LP_CORE>;
using IsGen12LP = IsGfxCore<IGFX_GEN12LP_CORE>;
using IsAtMostGen11 = IsAtMostGfxCore<IGFX_GEN11LP_CORE>;
using IsBXT = IsProduct<IGFX_BROXTON>;
using IsCFL = IsProduct<IGFX_COFFEELAKE>;
using IsEHL = IsProduct<IGFX_ELKHARTLAKE>;