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

Function main

examples/array_multiplication/src/main.cpp:9–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7#include <kompute/Kompute.hpp>
8
9int
10main()
11{
12 kp::Manager mgr;
13
14 std::shared_ptr<kp::TensorT<float>> tensorInA =
15 mgr.tensor({ 2.0, 4.0, 6.0 });
16 std::shared_ptr<kp::TensorT<float>> tensorInB =
17 mgr.tensor({ 0.0, 1.0, 2.0 });
18 std::shared_ptr<kp::TensorT<float>> tensorOut =
19 mgr.tensor({ 0.0, 0.0, 0.0 });
20
21 const std::vector<std::shared_ptr<kp::Tensor>> params = { tensorInA,
22 tensorInB,
23 tensorOut };
24
25 const std::vector<uint32_t> shader = std::vector<uint32_t>(
26 shader::MY_SHADER_COMP_SPV.begin(), shader::MY_SHADER_COMP_SPV.end());
27 std::shared_ptr<kp::Algorithm> algo = mgr.algorithm(params, shader);
28
29 mgr.sequence()
30 ->record<kp::OpTensorSyncDevice>(params)
31 ->record<kp::OpAlgoDispatch>(algo)
32 ->record<kp::OpTensorSyncLocal>(params)
33 ->eval();
34
35 // prints "Output { 0 4 12 }"
36 std::cout << "Output: { ";
37 for (const float& elem : tensorOut->vector()) {
38 std::cout << elem << " ";
39 }
40 std::cout << "}" << std::endl;
41
42 if (tensorOut->vector() != std::vector<float>{ 0, 4, 12 }) {
43 throw std::runtime_error("Result does not match");
44 }
45}

Callers

nothing calls this directly

Calls 7

tensorMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
algorithmMethod · 0.80
sequenceMethod · 0.80
evalMethod · 0.45
vectorMethod · 0.45

Tested by

no test coverage detected