MCPcopy Create free account
hub / github.com/KomputeProject/kompute / TEST

Function TEST

test/TestSpecializationConstant.cpp:10–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#include "shaders/Utils.hpp"
9
10TEST(TestSpecializationConstants, TestTwoConstants)
11{
12 {
13 std::string shader(R"(
14 #version 450
15 layout (constant_id = 0) const float cOne = 1;
16 layout (constant_id = 1) const float cTwo = 1;
17 layout (local_size_x = 1) in;
18 layout(set = 0, binding = 0) buffer a { float pa[]; };
19 layout(set = 0, binding = 1) buffer b { float pb[]; };
20 void main() {
21 uint index = gl_GlobalInvocationID.x;
22 pa[index] = cOne;
23 pb[index] = cTwo;
24 })");
25
26 std::vector<uint32_t> spirv = compileSource(shader);
27
28 std::shared_ptr<kp::Sequence> sq = nullptr;
29
30 {
31 kp::Manager mgr;
32
33 std::shared_ptr<kp::TensorT<float>> tensorA =
34 mgr.tensor({ 0, 0, 0 });
35 std::shared_ptr<kp::TensorT<float>> tensorB =
36 mgr.tensor({ 0, 0, 0 });
37
38 std::vector<std::shared_ptr<kp::Tensor>> params = { tensorA,
39 tensorB };
40
41 std::vector<float> spec = std::vector<float>({ 5.0, 0.3 });
42
43 std::shared_ptr<kp::Algorithm> algo =
44 mgr.algorithm(params, spirv, {}, spec);
45
46 sq = mgr.sequence()
47 ->record<kp::OpTensorSyncDevice>(params)
48 ->record<kp::OpAlgoDispatch>(algo)
49 ->record<kp::OpTensorSyncLocal>(params)
50 ->eval();
51
52 EXPECT_EQ(tensorA->vector(), std::vector<float>({ 5, 5, 5 }));
53 EXPECT_EQ(tensorB->vector(), std::vector<float>({ 0.3, 0.3, 0.3 }));
54 }
55 }
56}
57
58TEST(TestSpecializationConstants, TestConstantsInt)
59{

Callers

nothing calls this directly

Calls 6

tensorMethod · 0.80
algorithmMethod · 0.80
sequenceMethod · 0.80
compileSourceFunction · 0.50
evalMethod · 0.45
vectorMethod · 0.45

Tested by

no test coverage detected