Skip to content

Commit 52ae228

Browse files
Add missing unit test
Missing ult for isDebuggerActive Move inline function to .inl file Related-To: NEO-7003 Signed-off-by: Dominik Dabek <dominik.dabek@intel.com>
1 parent b7a7808 commit 52ae228

File tree

4 files changed

+183
-42
lines changed

4 files changed

+183
-42
lines changed

level_zero/core/source/kernel/kernel_imp.cpp

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <memory>
4545

4646
namespace L0 {
47+
#include "level_zero/core/source/kernel/patch_with_implicit_surface.inl"
4748

4849
KernelImmutableData::KernelImmutableData(L0::Device *l0device) : device(l0device) {}
4950

@@ -57,39 +58,6 @@ KernelImmutableData::~KernelImmutableData() {
5758
dynamicStateHeapTemplate.reset();
5859
}
5960

60-
inline void patchWithImplicitSurface(ArrayRef<uint8_t> crossThreadData, ArrayRef<uint8_t> surfaceStateHeap,
61-
uintptr_t ptrToPatchInCrossThreadData, NEO::GraphicsAllocation &allocation,
62-
const NEO::ArgDescPointer &ptr, const NEO::Device &device, bool useGlobalAtomics,
63-
bool implicitScaling) {
64-
if (false == crossThreadData.empty()) {
65-
NEO::patchPointer(crossThreadData, ptr, ptrToPatchInCrossThreadData);
66-
}
67-
68-
if ((false == surfaceStateHeap.empty()) && (NEO::isValidOffset(ptr.bindful))) {
69-
auto surfaceState = surfaceStateHeap.begin() + ptr.bindful;
70-
auto addressToPatch = allocation.getGpuAddress();
71-
size_t sizeToPatch = allocation.getUnderlyingBufferSize();
72-
73-
auto &hwInfo = device.getHardwareInfo();
74-
auto &hwHelper = NEO::HwHelper::get(hwInfo.platform.eRenderCoreFamily);
75-
auto isDebuggerActive = device.isDebuggerActive() || device.getDebugger() != nullptr;
76-
NEO::EncodeSurfaceStateArgs args;
77-
args.outMemory = surfaceState;
78-
args.size = sizeToPatch;
79-
args.graphicsAddress = addressToPatch;
80-
args.gmmHelper = device.getGmmHelper();
81-
args.allocation = &allocation;
82-
args.useGlobalAtomics = useGlobalAtomics;
83-
args.numAvailableDevices = device.getNumGenericSubDevices();
84-
args.areMultipleSubDevicesInContext = args.numAvailableDevices > 1;
85-
args.mocs = hwHelper.getMocsIndex(*args.gmmHelper, true, false) << 1;
86-
args.implicitScaling = implicitScaling;
87-
args.isDebuggerActive = isDebuggerActive;
88-
89-
hwHelper.encodeBufferSurfaceState(args);
90-
}
91-
}
92-
9361
void KernelImmutableData::initialize(NEO::KernelInfo *kernelInfo, Device *device,
9462
uint32_t computeUnitsUsedForSratch,
9563
NEO::GraphicsAllocation *globalConstBuffer,
@@ -120,7 +88,7 @@ void KernelImmutableData::initialize(NEO::KernelInfo *kernelInfo, Device *device
12088

12189
this->crossThreadDataSize = this->kernelDescriptor->kernelAttributes.crossThreadDataSize;
12290

123-
ArrayRef<uint8_t> crossThredDataArrayRef;
91+
ArrayRef<uint8_t> crossThreadDataArrayRef;
12492
if (crossThreadDataSize != 0) {
12593
crossThreadDataTemplate.reset(new uint8_t[crossThreadDataSize]);
12694

@@ -131,9 +99,9 @@ void KernelImmutableData::initialize(NEO::KernelInfo *kernelInfo, Device *device
13199
memset(crossThreadDataTemplate.get(), 0x00, crossThreadDataSize);
132100
}
133101

134-
crossThredDataArrayRef = ArrayRef<uint8_t>(this->crossThreadDataTemplate.get(), this->crossThreadDataSize);
102+
crossThreadDataArrayRef = ArrayRef<uint8_t>(this->crossThreadDataTemplate.get(), this->crossThreadDataSize);
135103

136-
NEO::patchNonPointer<uint32_t>(crossThredDataArrayRef,
104+
NEO::patchNonPointer<uint32_t>(crossThreadDataArrayRef,
137105
kernelDescriptor->payloadMappings.implicitArgs.simdSize, kernelDescriptor->kernelAttributes.simdSize);
138106
}
139107

@@ -158,7 +126,7 @@ void KernelImmutableData::initialize(NEO::KernelInfo *kernelInfo, Device *device
158126
if (NEO::isValidOffset(kernelDescriptor->payloadMappings.implicitArgs.globalConstantsSurfaceAddress.stateless)) {
159127
UNRECOVERABLE_IF(nullptr == globalConstBuffer);
160128

161-
patchWithImplicitSurface(crossThredDataArrayRef, surfaceStateHeapArrayRef,
129+
patchWithImplicitSurface(crossThreadDataArrayRef, surfaceStateHeapArrayRef,
162130
static_cast<uintptr_t>(globalConstBuffer->getGpuAddressToPatch()),
163131
*globalConstBuffer, kernelDescriptor->payloadMappings.implicitArgs.globalConstantsSurfaceAddress,
164132
*neoDevice, kernelDescriptor->kernelAttributes.flags.useGlobalAtomics, deviceImp->isImplicitScalingCapable());
@@ -170,7 +138,7 @@ void KernelImmutableData::initialize(NEO::KernelInfo *kernelInfo, Device *device
170138
if (NEO::isValidOffset(kernelDescriptor->payloadMappings.implicitArgs.globalVariablesSurfaceAddress.stateless)) {
171139
UNRECOVERABLE_IF(globalVarBuffer == nullptr);
172140

173-
patchWithImplicitSurface(crossThredDataArrayRef, surfaceStateHeapArrayRef,
141+
patchWithImplicitSurface(crossThreadDataArrayRef, surfaceStateHeapArrayRef,
174142
static_cast<uintptr_t>(globalVarBuffer->getGpuAddressToPatch()),
175143
*globalVarBuffer, kernelDescriptor->payloadMappings.implicitArgs.globalVariablesSurfaceAddress,
176144
*neoDevice, kernelDescriptor->kernelAttributes.flags.useGlobalAtomics, deviceImp->isImplicitScalingCapable());
@@ -785,10 +753,10 @@ void KernelImp::patchCrossthreadDataWithPrivateAllocation(NEO::GraphicsAllocatio
785753
auto &kernelAttributes = kernelImmData->getDescriptor().kernelAttributes;
786754
auto device = module->getDevice();
787755

788-
ArrayRef<uint8_t> crossThredDataArrayRef = ArrayRef<uint8_t>(this->crossThreadData.get(), this->crossThreadDataSize);
756+
ArrayRef<uint8_t> crossThreadDataArrayRef = ArrayRef<uint8_t>(this->crossThreadData.get(), this->crossThreadDataSize);
789757
ArrayRef<uint8_t> surfaceStateHeapArrayRef = ArrayRef<uint8_t>(this->surfaceStateHeapData.get(), this->surfaceStateHeapDataSize);
790758

791-
patchWithImplicitSurface(crossThredDataArrayRef, surfaceStateHeapArrayRef,
759+
patchWithImplicitSurface(crossThreadDataArrayRef, surfaceStateHeapArrayRef,
792760
static_cast<uintptr_t>(privateAllocation->getGpuAddressToPatch()),
793761
*privateAllocation, kernelImmData->getDescriptor().payloadMappings.implicitArgs.privateMemoryAddress,
794762
*device->getNEODevice(), kernelAttributes.flags.useGlobalAtomics, device->isImplicitScalingCapable());
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (C) 2022 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
inline void patchWithImplicitSurface(ArrayRef<uint8_t> crossThreadData, ArrayRef<uint8_t> surfaceStateHeap,
9+
uintptr_t ptrToPatchInCrossThreadData, NEO::GraphicsAllocation &allocation,
10+
const NEO::ArgDescPointer &ptr, const NEO::Device &device, bool useGlobalAtomics,
11+
bool implicitScaling) {
12+
if (false == crossThreadData.empty()) {
13+
NEO::patchPointer(crossThreadData, ptr, ptrToPatchInCrossThreadData);
14+
}
15+
16+
if ((false == surfaceStateHeap.empty()) && (NEO::isValidOffset(ptr.bindful))) {
17+
auto surfaceState = surfaceStateHeap.begin() + ptr.bindful;
18+
auto addressToPatch = allocation.getGpuAddress();
19+
size_t sizeToPatch = allocation.getUnderlyingBufferSize();
20+
21+
auto &hwInfo = device.getHardwareInfo();
22+
auto &hwHelper = NEO::HwHelper::get(hwInfo.platform.eRenderCoreFamily);
23+
auto isDebuggerActive = device.isDebuggerActive() || device.getDebugger() != nullptr;
24+
NEO::EncodeSurfaceStateArgs args;
25+
args.outMemory = surfaceState;
26+
args.size = sizeToPatch;
27+
args.graphicsAddress = addressToPatch;
28+
args.gmmHelper = device.getGmmHelper();
29+
args.allocation = &allocation;
30+
args.useGlobalAtomics = useGlobalAtomics;
31+
args.numAvailableDevices = device.getNumGenericSubDevices();
32+
args.areMultipleSubDevicesInContext = args.numAvailableDevices > 1;
33+
args.mocs = hwHelper.getMocsIndex(*args.gmmHelper, true, false) << 1;
34+
args.implicitScaling = implicitScaling;
35+
args.isDebuggerActive = isDebuggerActive;
36+
37+
hwHelper.encodeBufferSurfaceState(args);
38+
}
39+
}

level_zero/core/test/unit_tests/sources/kernel/test_kernel_2.cpp

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
*
66
*/
77

8+
#include "shared/test/common/mocks/mock_l0_debugger.h"
9+
#include "shared/test/common/test_macros/hw_test.h"
810
#include "shared/test/common/test_macros/test.h"
911

1012
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
1113
#include "level_zero/core/test/unit_tests/mocks/mock_kernel.h"
1214
#include "level_zero/core/test/unit_tests/mocks/mock_module.h"
13-
15+
namespace NEO {
16+
extern HwHelper *hwHelperFactory[IGFX_MAX_CORE];
17+
}
1418
namespace L0 {
19+
#include "level_zero/core/source/kernel/patch_with_implicit_surface.inl"
1520
namespace ult {
1621

1722
using KernelImp = Test<DeviceFixture>;
@@ -232,6 +237,67 @@ TEST_F(KernelImp, GivenNumChannelsZeroWhenSettingGroupSizeThenLocalIdsNotGenerat
232237
EXPECT_EQ(memAfter, memBefore);
233238
}
234239

240+
HWTEST_F(KernelImp, givenSurfaceStateHeapWhenPatchWithImplicitSurfaceCalledThenIsDebuggerActiveIsSetCorrectly) {
241+
struct MockHwHelper : NEO::HwHelperHw<FamilyType> {
242+
void encodeBufferSurfaceState(EncodeSurfaceStateArgs &args) override {
243+
savedSurfaceStateArgs = args;
244+
++encodeBufferSurfaceStateCalled;
245+
}
246+
EncodeSurfaceStateArgs savedSurfaceStateArgs;
247+
size_t encodeBufferSurfaceStateCalled{0};
248+
};
249+
MockHwHelper hwHelper{};
250+
auto hwInfo = *defaultHwInfo.get();
251+
VariableBackup<HwHelper *> hwHelperFactoryBackup{&NEO::hwHelperFactory[static_cast<size_t>(hwInfo.platform.eRenderCoreFamily)]};
252+
hwHelperFactoryBackup = &hwHelper;
253+
254+
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
255+
256+
auto surfaceStateHeap = std::make_unique<uint8_t[]>(2 * sizeof(RENDER_SURFACE_STATE));
257+
auto crossThreadDataArrayRef = ArrayRef<uint8_t>();
258+
auto surfaceStateHeapArrayRef = ArrayRef<uint8_t>(surfaceStateHeap.get(), 2 * sizeof(RENDER_SURFACE_STATE));
259+
uintptr_t ptrToPatchInCrossThreadData = 0;
260+
NEO::MockGraphicsAllocation globalBuffer;
261+
ArgDescPointer ptr;
262+
ASSERT_EQ(hwHelper.encodeBufferSurfaceStateCalled, 0u);
263+
{
264+
patchWithImplicitSurface(crossThreadDataArrayRef, surfaceStateHeapArrayRef,
265+
ptrToPatchInCrossThreadData,
266+
globalBuffer, ptr,
267+
*neoDevice, false, false);
268+
EXPECT_EQ(hwHelper.encodeBufferSurfaceStateCalled, 0u);
269+
}
270+
{
271+
ptr.bindful = 1;
272+
patchWithImplicitSurface(crossThreadDataArrayRef, surfaceStateHeapArrayRef,
273+
ptrToPatchInCrossThreadData,
274+
globalBuffer, ptr,
275+
*neoDevice, false, false);
276+
ASSERT_EQ(hwHelper.encodeBufferSurfaceStateCalled, 1u);
277+
EXPECT_FALSE(hwHelper.savedSurfaceStateArgs.isDebuggerActive);
278+
}
279+
{
280+
neoDevice->setDebuggerActive(true);
281+
patchWithImplicitSurface(crossThreadDataArrayRef, surfaceStateHeapArrayRef,
282+
ptrToPatchInCrossThreadData,
283+
globalBuffer, ptr,
284+
*neoDevice, false, false);
285+
ASSERT_EQ(hwHelper.encodeBufferSurfaceStateCalled, 2u);
286+
EXPECT_TRUE(hwHelper.savedSurfaceStateArgs.isDebuggerActive);
287+
}
288+
{
289+
neoDevice->setDebuggerActive(false);
290+
auto debugger = MockDebuggerL0Hw<FamilyType>::allocate(neoDevice);
291+
neoDevice->getRootDeviceEnvironmentRef().debugger.reset(debugger);
292+
patchWithImplicitSurface(crossThreadDataArrayRef, surfaceStateHeapArrayRef,
293+
ptrToPatchInCrossThreadData,
294+
globalBuffer, ptr,
295+
*neoDevice, false, false);
296+
ASSERT_EQ(hwHelper.encodeBufferSurfaceStateCalled, 3u);
297+
EXPECT_TRUE(hwHelper.savedSurfaceStateArgs.isDebuggerActive);
298+
}
299+
}
300+
235301
TEST(zeKernelGetProperties, WhenGettingKernelPropertiesThenSuccessIsReturned) {
236302
Mock<Kernel> kernel;
237303

level_zero/core/test/unit_tests/xe_hpg_core/dg2/test_module_dg2.cpp

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,78 @@
55
*
66
*/
77

8+
#include "shared/source/kernel/kernel_arg_descriptor.h"
89
#include "shared/test/common/mocks/mock_compilers.h"
910
#include "shared/test/common/mocks/mock_l0_debugger.h"
1011
#include "shared/test/common/test_macros/hw_test.h"
1112

1213
#include "level_zero/core/test/unit_tests/fixtures/module_fixture.h"
1314
#include "level_zero/core/test/unit_tests/mocks/mock_module.h"
1415

16+
#include "encode_surface_state_args.h"
17+
1518
namespace L0 {
19+
#include "level_zero/core/source/kernel/patch_with_implicit_surface.inl"
1620
namespace ult {
1721
using KernelDebugSurfaceDG2Test = Test<ModuleFixture>;
1822

19-
HWTEST2_F(KernelDebugSurfaceDG2Test, givenDebuggerAndBindfulKernelWhenAppendingKernelToCommandListThenCachePolicyIsWBP, IsDG2) {
23+
HWTEST2_F(KernelDebugSurfaceDG2Test, givenDebuggerWhenKernelInitializeCalledThenCachePolicyIsWBP, IsDG2) {
24+
NEO::MockCompilerEnableGuard mock(true);
25+
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
26+
27+
auto debugger = MockDebuggerL0Hw<FamilyType>::allocate(neoDevice);
28+
29+
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->debugger.reset(debugger);
30+
auto &hwInfo = *NEO::defaultHwInfo.get();
31+
auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
32+
auto maxDbgSurfaceSize = hwHelper.getSipKernelMaxDbgSurfaceSize(hwInfo);
33+
auto debugSurface = neoDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(
34+
{device->getRootDeviceIndex(), true,
35+
maxDbgSurfaceSize,
36+
NEO::AllocationType::DEBUG_CONTEXT_SAVE_AREA,
37+
false,
38+
false,
39+
device->getNEODevice()->getDeviceBitfield()});
40+
static_cast<L0::DeviceImp *>(device)->setDebugSurface(debugSurface);
41+
42+
uint8_t binary[10];
43+
ze_module_desc_t moduleDesc = {};
44+
moduleDesc.format = ZE_MODULE_FORMAT_NATIVE;
45+
moduleDesc.pInputModule = binary;
46+
moduleDesc.inputSize = 10;
47+
ModuleBuildLog *moduleBuildLog = nullptr;
48+
49+
std::unique_ptr<MockModule> module = std::make_unique<MockModule>(device,
50+
moduleBuildLog,
51+
ModuleType::User);
52+
53+
module->debugEnabled = true;
54+
55+
uint32_t kernelHeap = 0;
56+
KernelInfo kernelInfo;
57+
kernelInfo.heapInfo.KernelHeapSize = 1;
58+
kernelInfo.heapInfo.pKernelHeap = &kernelHeap;
59+
60+
Mock<::L0::Kernel> kernel;
61+
kernel.module = module.get();
62+
kernel.immutableData.kernelInfo = &kernelInfo;
63+
64+
ze_kernel_desc_t desc = {};
65+
66+
kernel.immutableData.kernelDescriptor->payloadMappings.implicitArgs.systemThreadSurfaceAddress.bindful = sizeof(RENDER_SURFACE_STATE);
67+
kernel.immutableData.surfaceStateHeapSize = 2 * sizeof(RENDER_SURFACE_STATE);
68+
kernel.immutableData.surfaceStateHeapTemplate.reset(new uint8_t[2 * sizeof(RENDER_SURFACE_STATE)]);
69+
module->kernelImmData = &kernel.immutableData;
70+
71+
kernel.initialize(&desc);
72+
73+
auto debugSurfaceState = reinterpret_cast<RENDER_SURFACE_STATE *>(kernel.surfaceStateHeapData.get());
74+
debugSurfaceState = ptrOffset(debugSurfaceState, sizeof(RENDER_SURFACE_STATE));
75+
76+
EXPECT_EQ(RENDER_SURFACE_STATE::L1_CACHE_POLICY_WBP, debugSurfaceState->getL1CachePolicyL1CacheControl());
77+
}
78+
79+
HWTEST2_F(KernelDebugSurfaceDG2Test, givenNoDebuggerButDebuggerActiveSetWhenPatchWithImplicitSurfaceCalledThenCachePolicyIsWBP, IsDG2) {
2080
NEO::MockCompilerEnableGuard mock(true);
2181
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
2282

@@ -67,10 +127,18 @@ HWTEST2_F(KernelDebugSurfaceDG2Test, givenDebuggerAndBindfulKernelWhenAppendingK
67127

68128
kernel.initialize(&desc);
69129

130+
auto surfaceStateHeapRef = ArrayRef<uint8_t>(kernel.surfaceStateHeapData.get(), kernel.immutableData.surfaceStateHeapSize);
131+
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->debugger.reset(nullptr);
132+
patchWithImplicitSurface(ArrayRef<uint8_t>(), surfaceStateHeapRef,
133+
0,
134+
*device->getDebugSurface(), kernel.immutableData.kernelDescriptor->payloadMappings.implicitArgs.systemThreadSurfaceAddress,
135+
*device->getNEODevice(), kernel.immutableData.kernelDescriptor->kernelAttributes.flags.useGlobalAtomics, device->isImplicitScalingCapable());
136+
70137
auto debugSurfaceState = reinterpret_cast<RENDER_SURFACE_STATE *>(kernel.surfaceStateHeapData.get());
71138
debugSurfaceState = ptrOffset(debugSurfaceState, sizeof(RENDER_SURFACE_STATE));
72139

73140
EXPECT_EQ(RENDER_SURFACE_STATE::L1_CACHE_POLICY_WBP, debugSurfaceState->getL1CachePolicyL1CacheControl());
74141
}
142+
75143
} // namespace ult
76144
} // namespace L0

0 commit comments

Comments
 (0)