Add hash function for AUB dump handle

Change-Id: I3f53f187a31ca47e7cf2717f328c216469171f90
This commit is contained in:
Milczarek, Slawomir
2018-10-30 16:25:33 -07:00
parent b051528258
commit 4a8f4aa47b
4 changed files with 47 additions and 1 deletions

View File

@@ -16,6 +16,7 @@
#include "runtime/gmm_helper/resource_info.h"
#include "runtime/helpers/aligned_memory.h"
#include "runtime/helpers/debug_helpers.h"
#include "runtime/helpers/hash.h"
#include "runtime/helpers/ptr_math.h"
#include "runtime/helpers/string.h"
#include "runtime/memory_manager/graphics_allocation.h"
@@ -737,7 +738,7 @@ void AUBCommandStreamReceiverHw<GfxFamily>::activateAubSubCapture(const MultiDis
template <typename GfxFamily>
uint32_t AUBCommandStreamReceiverHw<GfxFamily>::getDumpHandle() {
return static_cast<uint32_t>(reinterpret_cast<uintptr_t>(this));
return hashPtrToU32(this);
}
template <typename GfxFamily>

View File

@@ -104,4 +104,13 @@ class Hash {
protected:
uint32_t a, hi, lo;
};
template <typename T>
uint32_t hashPtrToU32(const T *src) {
auto asInt = reinterpret_cast<uintptr_t>(src);
constexpr auto m = sizeof(uintptr_t) / 8;
asInt = asInt ^ ((asInt & ~(m - 1)) >> (m * 32));
return static_cast<uint32_t>(asInt);
}
} // namespace OCLRT

View File

@@ -22,6 +22,7 @@ set(IGDRCL_SRCS_tests_helpers
${CMAKE_CURRENT_SOURCE_DIR}/flush_stamp_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/get_info_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gtest_helpers.h
${CMAKE_CURRENT_SOURCE_DIR}/hash_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hw_helper_default_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hw_helper_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hw_helper_tests.h

View File

@@ -0,0 +1,35 @@
/*
* Copyright (C) 2018 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "runtime/helpers/hash.h"
#include "gtest/gtest.h"
using namespace OCLRT;
TEST(HashTests, givenSamePointersWhenHashIsCalculatedThenSame32BitValuesAreGenerated) {
uintptr_t ptr1UI = 1;
uintptr_t ptr2UI = 1;
void *ptr1 = reinterpret_cast<void *>(ptr1UI);
void *ptr2 = reinterpret_cast<void *>(ptr2UI);
uint32_t hash1 = hashPtrToU32(ptr1);
uint32_t hash2 = hashPtrToU32(ptr2);
EXPECT_EQ(hash1, hash2);
}
TEST(HashTests, givenDifferentPointersWhenHashIsCalculatedThenUnique32BitValuesAreGenerated) {
uintptr_t ptr1UI = 1;
uintptr_t ptr2UI = ptr1UI | (ptr1UI << ((sizeof(uintptr_t) / 2) * 8));
void *ptr1 = reinterpret_cast<void *>(ptr1UI);
void *ptr2 = reinterpret_cast<void *>(ptr2UI);
uint32_t hash1 = hashPtrToU32(ptr1);
uint32_t hash2 = hashPtrToU32(ptr2);
EXPECT_NE(hash1, hash2);
}