| 7 | #include <kompute/Kompute.hpp> |
| 8 | |
| 9 | int |
| 10 | main() |
| 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 | } |