From 4c50a9e147f7fdb7d6bffdc575b6c17b5d544685 Mon Sep 17 00:00:00 2001 From: Jaroslaw Chodor Date: Thu, 7 Jan 2021 11:30:05 +0100 Subject: [PATCH] Zebin - Improving binding table generation Allowing N:1 kernel_arg:bti mappings Signed-off-by: Jaroslaw Chodor --- .../source/device_binary_format/zebin_decoder.cpp | 8 ++++++-- shared/source/kernel/kernel_arg_descriptor.h | 4 ++-- .../device_binary_format/zebin_decoder_tests.cpp | 4 ++-- .../kernel/kernel_arg_descriptor_tests.cpp | 13 ++++++++++++- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/shared/source/device_binary_format/zebin_decoder.cpp b/shared/source/device_binary_format/zebin_decoder.cpp index 22fe2ffbc9..49b2f131cc 100644 --- a/shared/source/device_binary_format/zebin_decoder.cpp +++ b/shared/source/device_binary_format/zebin_decoder.cpp @@ -878,10 +878,14 @@ NEO::DecodeError populateKernelDescriptor(NEO::ProgramInfo &dst, NEO::Elf::Elf(kernelDescriptor.generatedHeaps.data() + generatedBindingTablePos); - for (auto &bti : bindingTableIndices) { - *bindingTableIt = bti.btiValue * 64U; + for (int i = 0; i < numEntries; ++i) { + *bindingTableIt = i * maxSurfaceStateSize; ++bindingTableIt; + } + + for (auto &bti : bindingTableIndices) { auto &explicitArg = kernelDescriptor.payloadMappings.explicitArgs[bti.argIndex]; switch (explicitArg.type) { default: diff --git a/shared/source/kernel/kernel_arg_descriptor.h b/shared/source/kernel/kernel_arg_descriptor.h index a1a4a255b4..bff2fa7dfe 100644 --- a/shared/source/kernel/kernel_arg_descriptor.h +++ b/shared/source/kernel/kernel_arg_descriptor.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -282,7 +282,7 @@ inline bool patchPointer(ArrayRef buffer, const ArgDescPointer &arg, ui if (arg.pointerSize == 8) { return patchNonPointer(buffer, arg.stateless, static_cast(value)); } else { - UNRECOVERABLE_IF(arg.pointerSize != 4); + UNRECOVERABLE_IF((arg.pointerSize != 4) && isValidOffset(arg.stateless)); return patchNonPointer(buffer, arg.stateless, static_cast(value)); } } diff --git a/shared/test/unit_test/device_binary_format/zebin_decoder_tests.cpp b/shared/test/unit_test/device_binary_format/zebin_decoder_tests.cpp index c27c1c79ab..2f40069d59 100644 --- a/shared/test/unit_test/device_binary_format/zebin_decoder_tests.cpp +++ b/shared/test/unit_test/device_binary_format/zebin_decoder_tests.cpp @@ -2362,8 +2362,8 @@ kernels: EXPECT_EQ(512U, programInfo.kernelInfos[0]->kernelDescriptor.payloadMappings.bindingTable.tableOffset); ASSERT_EQ(576U, programInfo.kernelInfos[0]->heapInfo.SurfaceStateHeapSize); ASSERT_NE(nullptr, programInfo.kernelInfos[0]->heapInfo.pSsh); - EXPECT_EQ(128U, reinterpret_cast(ptrOffset(programInfo.kernelInfos[0]->heapInfo.pSsh, 512U))[0]); - EXPECT_EQ(448U, reinterpret_cast(ptrOffset(programInfo.kernelInfos[0]->heapInfo.pSsh, 512U))[1]); + EXPECT_EQ(128U, reinterpret_cast(ptrOffset(programInfo.kernelInfos[0]->heapInfo.pSsh, 512U))[2]); + EXPECT_EQ(448U, reinterpret_cast(ptrOffset(programInfo.kernelInfos[0]->heapInfo.pSsh, 512U))[7]); } TEST(PopulateKernelDescriptor, GivenBtiEntryForWrongArgTypeThenFail) { diff --git a/shared/test/unit_test/kernel/kernel_arg_descriptor_tests.cpp b/shared/test/unit_test/kernel/kernel_arg_descriptor_tests.cpp index a423ca2fa7..f6b8de3d2e 100644 --- a/shared/test/unit_test/kernel/kernel_arg_descriptor_tests.cpp +++ b/shared/test/unit_test/kernel/kernel_arg_descriptor_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -486,9 +486,20 @@ TEST(PatchPointer, GivenUnhandledPointerSizeThenAborts) { NEO::ArgDescPointer ptrArg; uintptr_t ptrValue = reinterpret_cast(&ptrArg); ptrArg.pointerSize = 5; + ptrArg.stateless = 0U; EXPECT_THROW(patchPointer(buffer, ptrArg, ptrValue), std::exception); } +TEST(PatchPointer, GivenUnhandledPointerSizeWhenStatelessOffsetIsUndefinedThenIgnoresPointerSize) { + alignas(8) uint8_t buffer[64]; + memset(buffer, 3, sizeof(buffer)); + NEO::ArgDescPointer ptrArg; + uintptr_t ptrValue = reinterpret_cast(&ptrArg); + ptrArg.pointerSize = 5; + ptrArg.stateless = NEO::undefined; + EXPECT_NO_THROW(patchPointer(buffer, ptrArg, ptrValue)); +} + TEST(PatchPointer, Given32bitPointerSizeThenPatchesOnly32bits) { alignas(8) uint8_t buffer[64]; memset(buffer, 3, sizeof(buffer));