Skip to content

Commit d605234

Browse files
Add function to check if kernel has indirect stateless access to host memory
Signed-off-by: Slawomir Milczarek <[email protected]>
1 parent d1d81c1 commit d605234

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

opencl/source/kernel/kernel.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2615,6 +2615,19 @@ bool Kernel::hasDirectStatelessAccessToHostMemory() const {
26152615
return false;
26162616
}
26172617

2618+
bool Kernel::hasIndirectStatelessAccessToHostMemory() const {
2619+
if (!getDefaultKernelInfo().hasIndirectStatelessAccess) {
2620+
return false;
2621+
}
2622+
2623+
for (auto gfxAllocation : kernelUnifiedMemoryGfxAllocations) {
2624+
if (gfxAllocation->getAllocationType() == GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY) {
2625+
return true;
2626+
}
2627+
}
2628+
return false;
2629+
}
2630+
26182631
void Kernel::getAllocationsForCacheFlush(CacheFlushAllocationsVec &out, uint32_t rootDeviceIndex) const {
26192632
if (false == HwHelper::cacheFlushAfterWalkerSupported(getHardwareInfo(rootDeviceIndex))) {
26202633
return;

opencl/source/kernel/kernel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ class Kernel : public BaseObject<_cl_kernel> {
501501

502502
void reconfigureKernel(uint32_t rootDeviceIndex);
503503
bool hasDirectStatelessAccessToHostMemory() const;
504+
bool hasIndirectStatelessAccessToHostMemory() const;
504505

505506
void addAllocationToCacheFlushVector(uint32_t argIndex, GraphicsAllocation *argAllocation);
506507
bool allocationForCacheFlush(GraphicsAllocation *argAllocation) const;

opencl/test/unit_test/kernel/kernel_arg_buffer_tests.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,36 @@ TEST_F(KernelArgBufferTest, givenInvalidKernelObjWhenHasDirectStatelessAccessToH
432432
EXPECT_FALSE(pKernel->hasDirectStatelessAccessToHostMemory());
433433
}
434434

435+
TEST_F(KernelArgBufferTest, givenKernelWithIndirectStatelessAccessWhenHasIndirectStatelessAccessToHostMemoryIsCalledThenReturnTrueForHostMemoryAllocations) {
436+
KernelInfo kernelInfo;
437+
EXPECT_FALSE(kernelInfo.hasIndirectStatelessAccess);
438+
439+
MockKernel kernelWithNoIndirectStatelessAccess(pProgram, MockKernel::toKernelInfoContainer(kernelInfo, 0));
440+
EXPECT_FALSE(kernelWithNoIndirectStatelessAccess.hasIndirectStatelessAccessToHostMemory());
441+
442+
kernelInfo.hasIndirectStatelessAccess = true;
443+
444+
MockKernel kernelWithNoIndirectHostAllocations(pProgram, MockKernel::toKernelInfoContainer(kernelInfo, 0));
445+
EXPECT_FALSE(kernelWithNoIndirectHostAllocations.hasIndirectStatelessAccessToHostMemory());
446+
447+
const auto allocationTypes = {GraphicsAllocation::AllocationType::BUFFER,
448+
GraphicsAllocation::AllocationType::BUFFER_COMPRESSED,
449+
GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY};
450+
451+
MockKernel kernelWithIndirectUnifiedMemoryAllocation(pProgram, MockKernel::toKernelInfoContainer(kernelInfo, 0));
452+
MockGraphicsAllocation gfxAllocation;
453+
for (const auto type : allocationTypes) {
454+
gfxAllocation.setAllocationType(type);
455+
kernelWithIndirectUnifiedMemoryAllocation.setUnifiedMemoryExecInfo(&gfxAllocation);
456+
if (type == GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY) {
457+
EXPECT_TRUE(kernelWithIndirectUnifiedMemoryAllocation.hasIndirectStatelessAccessToHostMemory());
458+
} else {
459+
EXPECT_FALSE(kernelWithIndirectUnifiedMemoryAllocation.hasIndirectStatelessAccessToHostMemory());
460+
}
461+
kernelWithIndirectUnifiedMemoryAllocation.clearUnifiedMemoryExecInfo();
462+
}
463+
}
464+
435465
TEST_F(KernelArgBufferTest, whenSettingAuxTranslationRequiredThenIsAuxTranslationRequiredReturnsCorrectValue) {
436466
for (auto auxTranslationRequired : {false, true}) {
437467
pKernel->setAuxTranslationRequired(auxTranslationRequired);

opencl/test/unit_test/mocks/mock_kernel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class MockKernel : public Kernel {
6363
using Kernel::containsStatelessWrites;
6464
using Kernel::executionType;
6565
using Kernel::hasDirectStatelessAccessToHostMemory;
66+
using Kernel::hasIndirectStatelessAccessToHostMemory;
6667
using Kernel::isSchedulerKernel;
6768
using Kernel::kernelArgHandlers;
6869
using Kernel::kernelArgRequiresCacheFlush;

0 commit comments

Comments
 (0)