Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/plugins/intel_gpu/tests/common/random_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,29 @@

#pragma once

#include <cstdint>
#include <random>
#include <set>
#include <string>
#include <string_view>
Comment thread
yuanxion marked this conversation as resolved.
#include <vector>

#define GET_SUITE_NAME (std::string(::testing::UnitTest::GetInstance()->current_test_info()->test_suite_name()) + \
std::string(::testing::UnitTest::GetInstance()->current_test_info()->name()))

namespace tests {
static const uint32_t DEFAULT_SEED = 0;

// Use a deterministic FNV-1a hash instead of std::hash algorithm
inline uint32_t stable_string_seed(std::string_view seed) {
uint32_t hash = 2166136261u;
for (unsigned char ch : seed) {
hash ^= ch;
hash *= 16777619u;
}
return hash;
Comment thread
yuanxion marked this conversation as resolved.
}

class random_generator {
public:
random_generator() = default;
Expand All @@ -26,8 +40,7 @@ class random_generator {
}

void set_seed(const std::string& seed) {
auto seed_hash = std::hash<std::string>{}(seed);
set_seed(static_cast<uint32_t>(seed_hash));
set_seed(stable_string_seed(seed));
}

void set_seed(const uint32_t seed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
using namespace cldnn;
using namespace ::tests;

TEST(random_generator, stable_string_seed_regression) {
EXPECT_EQ(stable_string_seed("stable_seed_smoke"), 2193642732u);
EXPECT_EQ(stable_string_seed("fully_connected_gpu_testcompressed_int4_scale"), 3127160893u);
EXPECT_EQ(stable_string_seed("fully_connected_gpu_testcompressed_int4_scale_dynamic"), 2450867795u);
EXPECT_NE(stable_string_seed("stable_seed_smoke"),
stable_string_seed("stable_seed_smoke_cached"));
}

/* Basic test to show how the program can be build and run within internal tests
in similar way as it is done in tests utilizing clDNN API */
TEST(basic, test1) {
Expand Down
Loading