[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 <michal.mrozek@intel.com>
This commit is contained in:
Michal Mrozek
2023-03-02 11:09:24 +00:00
committed by Compute-Runtime-Automation
parent 49424eb859
commit c77d954900
2 changed files with 7 additions and 16 deletions

View File

@@ -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<uint8_t> buffer, CrossThreadDataOffset loca
if (undefined<CrossThreadDataOffset> == location) {
return false;
}
UNRECOVERABLE_IF(location + sizeof(DstT) > buffer.size());
DEBUG_BREAK_IF(location + sizeof(DstT) > buffer.size());
*reinterpret_cast<DstT *>(buffer.begin() + location) = static_cast<DstT>(value);
return true;
}
template <uint32_t VecSize, typename T>
inline uint32_t patchVecNonPointer(ArrayRef<uint8_t> buffer, const CrossThreadDataOffset (&location)[VecSize], const T (&value)[VecSize]) {
uint32_t numPatched = 0;
inline void patchVecNonPointer(ArrayRef<uint8_t> buffer, const CrossThreadDataOffset (&location)[VecSize], const T (&value)[VecSize]) {
for (uint32_t i = 0; i < VecSize; ++i) {
numPatched += patchNonPointer<T, T>(buffer, location[i], value[i]) ? 1 : 0;
patchNonPointer<T, T>(buffer, location[i], value[i]);
}
return numPatched;
return;
}
inline bool patchPointer(ArrayRef<uint8_t> buffer, const ArgDescPointer &arg, uintptr_t value) {

View File

@@ -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<uint32_t, uint32_t>(buffer, NEO::undefined<NEO::CrossThreadDataOffset>, value)));
}
TEST(PatchNonPointer, GivenOutOfBoundsOffsetThenAbort) {
uint8_t buffer[64];
uint32_t value = 7;
EXPECT_THROW((NEO::patchNonPointer<uint32_t, uint32_t>(buffer, sizeof(buffer), value)), std::exception);
EXPECT_THROW((NEO::patchNonPointer<uint32_t, uint32_t>(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<NEO::CrossThreadDataOffset>};
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<uint32_t *>(expected) = 7;