From c5880d074fbb0462cc7a11c8822b29eca860bdc6 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Wed, 1 Sep 2021 07:07:15 +0100 Subject: [PATCH] Added testseqquence tests Signed-off-by: Alejandro Saucedo --- test/TestSequence.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/test/TestSequence.cpp b/test/TestSequence.cpp index 7b432aebd..631632ad1 100644 --- a/test/TestSequence.cpp +++ b/test/TestSequence.cpp @@ -133,3 +133,55 @@ TEST(TestSequence, SequenceTimestamps) EXPECT_EQ(timestamps.size(), 6); // 1 timestamp at start + 1 after each operation } + +TEST(TestSequence, UtilsClearRecordingRunning) +{ + kp::Manager mgr; + + std::shared_ptr sq = mgr.sequence(); + + std::shared_ptr> tensorA = mgr.tensor({ 1, 2, 3 }); + std::shared_ptr> tensorB = mgr.tensor({ 2, 2, 2 }); + std::shared_ptr> tensorOut = mgr.tensor({ 0, 0, 0 }); + + sq->eval({ tensorA, tensorB, tensorOut }); + + std::vector spirv = compileSource(R"( + #version 450 + + layout (local_size_x = 1) in; + + // The input tensors bind index is relative to index in parameter passed + layout(set = 0, binding = 0) buffer bina { float tina[]; }; + layout(set = 0, binding = 1) buffer binb { float tinb[]; }; + layout(set = 0, binding = 2) buffer bout { float tout[]; }; + + void main() { + uint index = gl_GlobalInvocationID.x; + tout[index] = tina[index] * tinb[index]; + } + )"); + + std::shared_ptr algo = + mgr.algorithm({ tensorA, tensorB, tensorOut }, spirv); + + sq->record(algo)->record( + { tensorA, tensorB, tensorOut }); + + EXPECT_TRUE(sq->isRecording()); + + // Running clear to confirm it clears + sq->clear(); + + EXPECT_FALSE(sq->isRecording()); + + sq->evalAsync(); + + EXPECT_TRUE(sq->isRunning()); + + sq->evalAwait(); + + EXPECT_FALSE(sq->isRunning()); + + EXPECT_EQ(tensorOut->vector(), std::vector({ 2, 4, 6 })); +}