mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-20 08:53:55 +08:00
Add hash function for AUB dump handle
Change-Id: I3f53f187a31ca47e7cf2717f328c216469171f90
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
35
unit_tests/helpers/hash_tests.cpp
Normal file
35
unit_tests/helpers/hash_tests.cpp
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user