From 7db6f8c46f906cbf7a12bf4502fac9d702701939 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sat, 11 Sep 2021 17:53:54 +0100 Subject: [PATCH] Added test for timeouts Signed-off-by: Alejandro Saucedo --- test/TestAsyncOperations.cpp | 72 ++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/test/TestAsyncOperations.cpp b/test/TestAsyncOperations.cpp index 50402cbd1..36179375b 100644 --- a/test/TestAsyncOperations.cpp +++ b/test/TestAsyncOperations.cpp @@ -182,3 +182,75 @@ TEST(TestAsyncOperations, TestManagerAsyncExecution) EXPECT_EQ(tensorA->vector(), resultAsync); EXPECT_EQ(tensorB->vector(), resultAsync); } + +TEST(TestAsyncOperations, TestManagerAsyncExecutionTimeout) +{ + uint32_t size = 10; + + std::string shader(R"( + #version 450 + + layout (local_size_x = 1) in; + + layout(set = 0, binding = 0) buffer b { float pb[]; }; + + shared uint sharedTotal[1]; + + void main() { + uint index = gl_GlobalInvocationID.x; + + sharedTotal[0] = 0; + + for (int i = 0; i < 100000000; i++) + { + atomicAdd(sharedTotal[0], 1); + } + + pb[index] = sharedTotal[0]; + } + )"); + + std::vector spirv = compileSource(shader); + + std::vector data(size, 0.0); + std::vector resultAsync(size, 100000000); + + kp::Manager mgr; + + std::shared_ptr> tensorA = mgr.tensor(data); + std::shared_ptr> tensorB = mgr.tensor(data); + + std::shared_ptr sq1 = mgr.sequence(); + std::shared_ptr sq2 = mgr.sequence(); + + sq1->eval({ tensorA, tensorB }); + + std::shared_ptr algo1 = mgr.algorithm({ tensorA }, spirv); + std::shared_ptr algo2 = mgr.algorithm({ tensorB }, spirv); + + auto startSync = std::chrono::high_resolution_clock::now(); + + // AMD Drivers in Windows may see an error in this line due to timeout. + // In order to fix this, it requires a change on Windows registries. + // More details on this can be found here: https://docs.substance3d.com/spdoc/gpu-drivers-crash-with-long-computations-128745489.html + // Context on solution discussed in github: https://github.com/KomputeProject/kompute/issues/196#issuecomment-808866505 + sq1->evalAsync(algo1); + sq2->evalAsync(algo2); + + sq1->evalAwait(1); + sq2->evalAwait(1); + + auto endSync = std::chrono::high_resolution_clock::now(); + auto duration = + std::chrono::duration_cast(endSync - startSync) + .count(); + + // The time should several orders of magnitude smaller (in this 10k instead of 1m ns) + EXPECT_LT(duration, 10000); + + sq1->evalAsync({ tensorA, tensorB }); + sq1->evalAwait(); + + EXPECT_EQ(tensorA->vector(), resultAsync); + EXPECT_EQ(tensorB->vector(), resultAsync); +}