Skip to content

Commit d07362c

Browse files
Use blitter to initialize Global surface if required
Change-Id: I53cc532a5b5edd16a32deaf987f85db4224b9945 Signed-off-by: Bartosz Dunajski <[email protected]>
1 parent 2b3d45b commit d07362c

File tree

3 files changed

+54
-18
lines changed

3 files changed

+54
-18
lines changed

opencl/test/unit_test/command_queue/blit_enqueue_tests.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
#include "shared/source/helpers/pause_on_gpu_properties.h"
99
#include "shared/source/helpers/vec.h"
10+
#include "shared/source/memory_manager/unified_memory_manager.h"
1011
#include "shared/test/unit_test/cmd_parse/hw_parse.h"
12+
#include "shared/test/unit_test/compiler_interface/linker_mock.h"
1113
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
1214
#include "shared/test/unit_test/helpers/variable_backup.h"
1315
#include "shared/test/unit_test/mocks/mock_device.h"
@@ -19,6 +21,7 @@
1921
#include "opencl/test/unit_test/mocks/mock_command_queue.h"
2022
#include "opencl/test/unit_test/mocks/mock_context.h"
2123
#include "opencl/test/unit_test/mocks/mock_kernel.h"
24+
#include "opencl/test/unit_test/mocks/mock_program.h"
2225
#include "opencl/test/unit_test/mocks/mock_timestamp_container.h"
2326
#include "opencl/test/unit_test/test_macros/test_checks_ocl.h"
2427
#include "test.h"
@@ -1671,4 +1674,31 @@ HWTEST_TEMPLATED_F(BlitCopyTests, givenKernelAllocationInLocalMemoryWhenCreating
16711674
device->getMemoryManager()->freeGraphicsMemory(kernelInfo.kernelAllocation);
16721675
}
16731676

1677+
HWTEST_TEMPLATED_F(BlitCopyTests, givenLocalMemoryAccessNotAllowedWhenGlobalConstantsAreExportedThenUseBlitter) {
1678+
DebugManager.flags.EnableLocalMemory.set(1);
1679+
DebugManager.flags.ForceLocalMemoryAccessMode.set(static_cast<int32_t>(LocalMemoryAccessMode::CpuAccessDisallowed));
1680+
1681+
char constantData[128] = {};
1682+
ProgramInfo programInfo;
1683+
programInfo.globalConstants.initData = constantData;
1684+
programInfo.globalConstants.size = sizeof(constantData);
1685+
auto mockLinkerInput = std::make_unique<WhiteBox<LinkerInput>>();
1686+
mockLinkerInput->traits.exportsGlobalConstants = true;
1687+
programInfo.linkerInput = std::move(mockLinkerInput);
1688+
1689+
MockProgram program(*device->getExecutionEnvironment(), bcsMockContext.get(), false, &device->getDevice());
1690+
1691+
EXPECT_EQ(0u, bcsMockContext->bcsCsr->peekTaskCount());
1692+
1693+
program.processProgramInfo(programInfo);
1694+
1695+
EXPECT_EQ(1u, bcsMockContext->bcsCsr->peekTaskCount());
1696+
1697+
auto rootDeviceIndex = device->getRootDeviceIndex();
1698+
1699+
ASSERT_NE(nullptr, program.getConstantSurface(rootDeviceIndex));
1700+
auto gpuAddress = reinterpret_cast<const void *>(program.getConstantSurface(rootDeviceIndex)->getGpuAddress());
1701+
EXPECT_NE(nullptr, bcsMockContext->getSVMAllocsManager()->getSVMAlloc(gpuAddress));
1702+
}
1703+
16741704
} // namespace NEO

shared/source/helpers/hw_helper_base.inl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ inline bool HwHelperHw<GfxFamily>::allowRenderCompression(const HardwareInfo &hw
422422
template <typename GfxFamily>
423423
inline bool HwHelperHw<GfxFamily>::isBlitCopyRequiredForLocalMemory(const HardwareInfo &hwInfo) const {
424424
HwHelper &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
425-
return (hwHelper.getLocalMemoryAccessMode(hwInfo) == LocalMemoryAccessMode::CpuAccessDisallowed) && hwInfo.capabilityTable.blitterOperationsSupported;
425+
return (hwHelper.getLocalMemoryAccessMode(hwInfo) == LocalMemoryAccessMode::CpuAccessDisallowed) &&
426+
hwInfo.capabilityTable.blitterOperationsSupported;
426427
}
427428

428429
template <typename GfxFamily>

shared/source/program/program_initialization.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace NEO {
2121
GraphicsAllocation *allocateGlobalsSurface(NEO::SVMAllocsManager *const svmAllocManager, NEO::Device &device, size_t size, bool constant,
2222
LinkerInput *const linkerInput, const void *initData) {
2323
bool globalsAreExported = false;
24+
GraphicsAllocation *gpuAllocation = nullptr;
25+
2426
if (linkerInput != nullptr) {
2527
globalsAreExported = constant ? linkerInput->getTraits().exportsGlobalConstants : linkerInput->getTraits().exportsGlobalVariables;
2628
}
@@ -37,30 +39,33 @@ GraphicsAllocation *allocateGlobalsSurface(NEO::SVMAllocsManager *const svmAlloc
3739
}
3840
auto svmAlloc = svmAllocManager->getSVMAlloc(ptr);
3941
UNRECOVERABLE_IF(svmAlloc == nullptr);
40-
auto gpuAlloc = svmAlloc->gpuAllocations.getGraphicsAllocation(device.getRootDeviceIndex());
41-
UNRECOVERABLE_IF(gpuAlloc == nullptr);
42-
device.getMemoryManager()->copyMemoryToAllocation(gpuAlloc, initData, static_cast<uint32_t>(size));
43-
return gpuAlloc;
42+
gpuAllocation = svmAlloc->gpuAllocations.getGraphicsAllocation(device.getRootDeviceIndex());
4443
} else {
4544
auto allocationType = constant ? GraphicsAllocation::AllocationType::CONSTANT_SURFACE : GraphicsAllocation::AllocationType::GLOBAL_SURFACE;
46-
auto gpuAlloc = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({device.getRootDeviceIndex(),
45+
gpuAllocation = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({device.getRootDeviceIndex(),
4746
true, // allocateMemory
4847
size, allocationType,
4948
false, // isMultiStorageAllocation
5049
device.getDeviceBitfield()});
51-
DEBUG_BREAK_IF(gpuAlloc == nullptr);
52-
if (gpuAlloc == nullptr) {
53-
return nullptr;
54-
}
55-
auto &hwInfo = device.getHardwareInfo();
56-
auto &helper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
57-
if (gpuAlloc->isAllocatedInLocalMemoryPool() && helper.isBlitCopyRequiredForLocalMemory(hwInfo)) {
58-
BlitHelperFunctions::blitMemoryToAllocation(device, gpuAlloc, 0, initData, {size, 1, 1});
59-
} else {
60-
memcpy_s(gpuAlloc->getUnderlyingBuffer(), gpuAlloc->getUnderlyingBufferSize(), initData, size);
61-
}
62-
return gpuAlloc;
6350
}
51+
52+
if (!gpuAllocation) {
53+
return nullptr;
54+
}
55+
56+
auto &hwInfo = device.getHardwareInfo();
57+
auto &helper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
58+
59+
bool success = false;
60+
if (gpuAllocation->isAllocatedInLocalMemoryPool() && helper.isBlitCopyRequiredForLocalMemory(hwInfo)) {
61+
success = (BlitHelperFunctions::blitMemoryToAllocation(device, gpuAllocation, 0, initData, {size, 1, 1}) == BlitOperationResult::Success);
62+
} else {
63+
success = device.getMemoryManager()->copyMemoryToAllocation(gpuAllocation, initData, static_cast<uint32_t>(size));
64+
}
65+
66+
UNRECOVERABLE_IF(!success);
67+
68+
return gpuAllocation;
6469
}
6570

6671
} // namespace NEO

0 commit comments

Comments
 (0)