From c77d95490066e78c2559a6bec81a1f40155ff080 Mon Sep 17 00:00:00 2001 From: Michal Mrozek Date: Thu, 2 Mar 2023 11:09:24 +0000 Subject: [PATCH] [perf] simplify setting constant buffer and improve performance - no need to count parameters - remove unrecoverable which requires fetching additional fields. Related-To: NEO-5170 Signed-off-by: Michal Mrozek --- shared/source/kernel/kernel_arg_descriptor.h | 11 +++++------ .../unit_test/kernel/kernel_arg_descriptor_tests.cpp | 12 ++---------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/shared/source/kernel/kernel_arg_descriptor.h b/shared/source/kernel/kernel_arg_descriptor.h index 1c882e69b7..a8db84347b 100644 --- a/shared/source/kernel/kernel_arg_descriptor.h +++ b/shared/source/kernel/kernel_arg_descriptor.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -282,18 +282,17 @@ inline bool patchNonPointer(ArrayRef buffer, CrossThreadDataOffset loca if (undefined == location) { return false; } - UNRECOVERABLE_IF(location + sizeof(DstT) > buffer.size()); + DEBUG_BREAK_IF(location + sizeof(DstT) > buffer.size()); *reinterpret_cast(buffer.begin() + location) = static_cast(value); return true; } template -inline uint32_t patchVecNonPointer(ArrayRef buffer, const CrossThreadDataOffset (&location)[VecSize], const T (&value)[VecSize]) { - uint32_t numPatched = 0; +inline void patchVecNonPointer(ArrayRef buffer, const CrossThreadDataOffset (&location)[VecSize], const T (&value)[VecSize]) { for (uint32_t i = 0; i < VecSize; ++i) { - numPatched += patchNonPointer(buffer, location[i], value[i]) ? 1 : 0; + patchNonPointer(buffer, location[i], value[i]); } - return numPatched; + return; } inline bool patchPointer(ArrayRef buffer, const ArgDescPointer &arg, uintptr_t value) { 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 ce5c67db14..c6cf709015 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-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -446,13 +446,6 @@ TEST(PatchNonPointer, GivenUndefinedOffsetThenReturnsFalse) { EXPECT_FALSE((NEO::patchNonPointer(buffer, NEO::undefined, value))); } -TEST(PatchNonPointer, GivenOutOfBoundsOffsetThenAbort) { - uint8_t buffer[64]; - uint32_t value = 7; - EXPECT_THROW((NEO::patchNonPointer(buffer, sizeof(buffer), value)), std::exception); - EXPECT_THROW((NEO::patchNonPointer(buffer, sizeof(buffer) - sizeof(value) + 1, value)), std::exception); -} - TEST(PatchNonPointer, GivenValidOffsetThenPatchProperly) { alignas(8) uint8_t buffer[64]; memset(buffer, 3, sizeof(buffer)); @@ -475,8 +468,7 @@ TEST(PatchVecNonPointer, GivenArrayOfOffsetsThenReturnsNumberOfValuesProperlyPat memset(buffer, 3, sizeof(buffer)); NEO::CrossThreadDataOffset offsets[] = {0, 4, sizeof(buffer) - sizeof(uint32_t), NEO::undefined}; uint32_t values[] = {7, 11, 13, 17}; - auto numPatched = NEO::patchVecNonPointer(buffer, offsets, values); - EXPECT_EQ(3U, numPatched); + NEO::patchVecNonPointer(buffer, offsets, values); alignas(8) uint8_t expected[64]; memset(expected, 3, sizeof(expected)); *reinterpret_cast(expected) = 7;