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

Function TEST

test/TestMultipleAlgoExecutions.cpp:10–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#include "shaders/Utils.hpp"
9
10TEST(TestMultipleAlgoExecutions, TestEndToEndFunctionality)
11{
12
13 kp::Manager mgr;
14
15 // Default tensor constructor simplifies creation of float values
16 auto tensorInA = mgr.tensor({ 2., 2., 2. });
17 auto tensorInB = mgr.tensor({ 1., 2., 3. });
18 // Explicit type constructor supports int, in32, double, float and int
19 auto tensorOutA = mgr.tensorT<uint32_t>({ 0, 0, 0 });
20 auto tensorOutB = mgr.tensorT<uint32_t>({ 0, 0, 0 });
21
22 std::string shader = (R"(
23 #version 450
24
25 layout (local_size_x = 1) in;
26
27 // The input tensors bind index is relative to index in parameter passed
28 layout(set = 0, binding = 0) buffer buf_in_a { float in_a[]; };
29 layout(set = 0, binding = 1) buffer buf_in_b { float in_b[]; };
30 layout(set = 0, binding = 2) buffer buf_out_a { uint out_a[]; };
31 layout(set = 0, binding = 3) buffer buf_out_b { uint out_b[]; };
32
33 // Kompute supports push constants updated on dispatch
34 layout(push_constant) uniform PushConstants {
35 float val;
36 } push_const;
37
38 // Kompute also supports spec constants on initalization
39 layout(constant_id = 0) const float const_one = 0;
40
41 void main() {
42 uint index = gl_GlobalInvocationID.x;
43 out_a[index] += uint( in_a[index] * in_b[index] );
44 out_b[index] += uint( const_one * push_const.val );
45 }
46 )");
47
48 std::vector<std::shared_ptr<kp::Tensor>> params = {
49 tensorInA, tensorInB, tensorOutA, tensorOutB
50 };
51
52 kp::Workgroup workgroup({ 3, 1, 1 });
53 std::vector<float> specConsts({ 2 });
54 std::vector<float> pushConstsA({ 2.0 });
55 std::vector<float> pushConstsB({ 3.0 });
56
57 auto algorithm = mgr.algorithm(
58 params, compileSource(shader), workgroup, specConsts, pushConstsA);
59
60 // 3. Run operation with string shader synchronously
61 mgr.sequence()
62 ->record<kp::OpTensorSyncDevice>(params)
63 ->record<kp::OpAlgoDispatch>(algorithm)
64 ->eval()
65 ->record<kp::OpAlgoDispatch>(algorithm, pushConstsB)
66 ->eval();
67

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected