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

Function TEST

test/TestPushConstant.cpp:10–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#include "shaders/Utils.hpp"
9
10TEST(TestPushConstants, TestConstantsAlgoDispatchOverride)
11{
12 {
13 std::string shader(R"(
14 #version 450
15 layout(push_constant) uniform PushConstants {
16 float x;
17 float y;
18 float z;
19 } pcs;
20 layout (local_size_x = 1) in;
21 layout(set = 0, binding = 0) buffer a { float pa[]; };
22 void main() {
23 pa[0] += pcs.x;
24 pa[1] += pcs.y;
25 pa[2] += pcs.z;
26 })");
27
28 std::vector<uint32_t> spirv = compileSource(shader);
29
30 std::shared_ptr<kp::Sequence> sq = nullptr;
31
32 {
33 kp::Manager mgr;
34
35 std::shared_ptr<kp::TensorT<float>> tensor =
36 mgr.tensor({ 0, 0, 0 });
37
38 std::shared_ptr<kp::Algorithm> algo = mgr.algorithm(
39 { tensor }, spirv, kp::Workgroup({ 1 }), {}, { 0.0, 0.0, 0.0 });
40
41 sq = mgr.sequence()->eval<kp::OpTensorSyncDevice>({ tensor });
42
43 // We need to run this in sequence to avoid race condition
44 // We can't use atomicAdd as swiftshader doesn't support it for
45 // float
46 sq->eval<kp::OpAlgoDispatch>(algo,
47 std::vector<float>{ 0.1, 0.2, 0.3 });
48 sq->eval<kp::OpAlgoDispatch>(algo,
49 std::vector<float>{ 0.3, 0.2, 0.1 });
50 sq->eval<kp::OpTensorSyncLocal>({ tensor });
51
52 EXPECT_EQ(tensor->vector(), std::vector<float>({ 0.4, 0.4, 0.4 }));
53 }
54 }
55}
56
57TEST(TestPushConstants, TestConstantsAlgoDispatchNoOverride)
58{

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected