| 8 | #include "shaders/Utils.hpp" |
| 9 | |
| 10 | TEST(TestDestroy, TestDestroyTensorSingle) |
| 11 | { |
| 12 | std::shared_ptr<kp::TensorT<float>> tensorA = nullptr; |
| 13 | |
| 14 | std::string shader(R"( |
| 15 | #version 450 |
| 16 | layout (local_size_x = 1) in; |
| 17 | layout(set = 0, binding = 0) buffer a { float pa[]; }; |
| 18 | void main() { |
| 19 | uint index = gl_GlobalInvocationID.x; |
| 20 | pa[index] = pa[index] + 1; |
| 21 | })"); |
| 22 | |
| 23 | std::vector<uint32_t> spirv = compileSource(shader); |
| 24 | |
| 25 | { |
| 26 | std::shared_ptr<kp::Sequence> sq = nullptr; |
| 27 | |
| 28 | { |
| 29 | kp::Manager mgr; |
| 30 | |
| 31 | const std::vector<float> initialValues = { 0.0f, 0.0f, 0.0f }; |
| 32 | |
| 33 | tensorA = mgr.tensor(initialValues); |
| 34 | |
| 35 | std::shared_ptr<kp::Algorithm> algo = |
| 36 | mgr.algorithm({ tensorA }, spirv); |
| 37 | |
| 38 | // Sync values to and from device |
| 39 | mgr.sequence()->eval<kp::OpTensorSyncDevice>(algo->getTensors()); |
| 40 | |
| 41 | EXPECT_EQ(tensorA->vector(), initialValues); |
| 42 | |
| 43 | mgr.sequence() |
| 44 | ->record<kp::OpAlgoDispatch>(algo) |
| 45 | ->eval() |
| 46 | ->eval<kp::OpTensorSyncLocal>(algo->getTensors()); |
| 47 | |
| 48 | const std::vector<float> expectedFinalValues = { 1.0f, 1.0f, 1.0f }; |
| 49 | EXPECT_EQ(tensorA->vector(), expectedFinalValues); |
| 50 | |
| 51 | tensorA->destroy(); |
| 52 | EXPECT_FALSE(tensorA->isInit()); |
| 53 | } |
| 54 | EXPECT_FALSE(tensorA->isInit()); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | TEST(TestDestroy, TestDestroyTensorVector) |
| 59 | { |