Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include <string>
 
#include "gtest/gtest.h"
 
#include "core/providers/webgpu/nn/fuse_utils.h"
 
namespace onnxruntime {
namespace test {
namespace {
 
webgpu::Activation MakeActivation(webgpu::ActivationKind kind, float value0, float value1 = 0.0f) {
  webgpu::Activation activation;
  activation.activation_kind_ = kind;
  activation.activation_params_.values_[0] = value0;
  activation.activation_params_.values_[1] = value1;
  return activation;
}
 
}  // namespace
 
TEST(ActivationCacheKeyTest, ParametersDoNotAffectTheKey) {
  const auto leaky_a = MakeActivation(webgpu::ActivationKind::LeakyRelu, 0.01f);
  const auto leaky_b = MakeActivation(webgpu::ActivationKind::LeakyRelu, 0.2f);
  EXPECT_EQ(leaky_a.CacheKey(), leaky_b.CacheKey())
      << "LeakyRelu alpha is a uniform, so it must not fork the pipeline cache";
 
  const auto clip_a = MakeActivation(webgpu::ActivationKind::Clip, 0.0f, 6.0f);
  const auto clip_b = MakeActivation(webgpu::ActivationKind::Clip, -1.0f, 1.0f);
  EXPECT_EQ(clip_a.CacheKey(), clip_b.CacheKey())
      << "Clip bounds are uniforms, so they must not fork the pipeline cache";
}
 
TEST(ActivationCacheKeyTest, QuickGeluUnitAlphaIsKeyedSeparately) {
  const auto unit_alpha = MakeActivation(webgpu::ActivationKind::QuickGelu, 1.0f);
  const auto other_alpha = MakeActivation(webgpu::ActivationKind::QuickGelu, 1.702f);
 
  EXPECT_NE(unit_alpha.CacheKey(), other_alpha.CacheKey())
      << "QuickGelu drops the multiply at alpha == 1, which is different shader text";
 
  const auto another_alpha = MakeActivation(webgpu::ActivationKind::QuickGelu, 0.5f);
  EXPECT_EQ(other_alpha.CacheKey(), another_alpha.CacheKey());
}
 
TEST(ActivationCacheKeyTest, IdenticalActivationsProduceIdenticalKeys) {
  const auto activation_a = MakeActivation(webgpu::ActivationKind::LeakyRelu, 0.01f);
  const auto activation_b = MakeActivation(webgpu::ActivationKind::LeakyRelu, 0.01f);
 
  EXPECT_EQ(activation_a.CacheKey(), activation_b.CacheKey())
      << "identical activations must share a cache entry";
}
 
TEST(ActivationCacheKeyTest, DistinctActivationKindsProduceDistinctKeys) {
  const auto relu = MakeActivation(webgpu::ActivationKind::Relu, 0.0f);
  const auto sigmoid = MakeActivation(webgpu::ActivationKind::Sigmoid, 0.0f);
 
  EXPECT_NE(relu.CacheKey(), sigmoid.CacheKey());
}
 
}  // namespace test
}  // namespace onnxruntime