diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ebe565b1a..b97e549b5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,7 +12,6 @@ endif() file(GLOB test_kompute_CPP "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/utils/kompute_test/*.cpp" ) add_executable(test_kompute ${test_kompute_CPP}) diff --git a/test/TestAsyncOperations.cpp b/test/TestAsyncOperations.cpp index 1c5fe277e..7bda7a100 100644 --- a/test/TestAsyncOperations.cpp +++ b/test/TestAsyncOperations.cpp @@ -39,7 +39,7 @@ TEST(TestAsyncOperations, TestManagerParallelExecution) } )"); - std::vector spirv = kp_test_utils::Shader::compileSource(shader); + std::vector spirv = compileSource(shader); std::vector data(size, 0.0); std::vector resultSync(size, 100000000); @@ -147,7 +147,7 @@ TEST(TestAsyncOperations, TestManagerAsyncExecution) } )"); - std::vector spirv = kp_test_utils::Shader::compileSource(shader); + std::vector spirv = compileSource(shader); std::vector data(size, 0.0); std::vector resultAsync(size, 100000000); diff --git a/test/TestDestroy.cpp b/test/TestDestroy.cpp index 72225f9ce..b415024e6 100644 --- a/test/TestDestroy.cpp +++ b/test/TestDestroy.cpp @@ -18,7 +18,7 @@ TEST(TestDestroy, TestDestroyTensorSingle) pa[index] = pa[index] + 1; })"); - std::vector spirv = kp_test_utils::Shader::compileSource(shader); + std::vector spirv = compileSource(shader); { std::shared_ptr sq = nullptr; @@ -60,7 +60,7 @@ TEST(TestDestroy, TestDestroyTensorVector) pa[index] = pa[index] + 1; pb[index] = pb[index] + 2; })"); - std::vector spirv = kp_test_utils::Shader::compileSource(shader); + std::vector spirv = compileSource(shader); { std::shared_ptr sq = nullptr; @@ -105,7 +105,7 @@ TEST(TestDestroy, TestDestroySequenceSingle) pa[index] = pa[index] + 1; })"); - std::vector spirv = kp_test_utils::Shader::compileSource(shader); + std::vector spirv = compileSource(shader); { std::shared_ptr sq = nullptr; diff --git a/test/TestMultipleAlgoExecutions.cpp b/test/TestMultipleAlgoExecutions.cpp index 2206e1269..c364d0846 100644 --- a/test/TestMultipleAlgoExecutions.cpp +++ b/test/TestMultipleAlgoExecutions.cpp @@ -53,7 +53,7 @@ TEST(TestMultipleAlgoExecutions, TestEndToEndFunctionality) kp::Constants pushConstsB({ 3.0 }); auto algorithm = mgr.algorithm(params, - kp_test_utils::Shader::compileSource(shader), + compileSource(shader), workgroup, specConsts, pushConstsA); @@ -91,7 +91,7 @@ TEST(TestMultipleAlgoExecutions, SingleSequenceRecord) pa[index] = pa[index] + 1; })"); - std::vector spirv = kp_test_utils::Shader::compileSource(shader); + std::vector spirv = compileSource(shader); { // A sharedMemoryBarrier is required as the shader is not thread-safe:w @@ -132,7 +132,7 @@ TEST(TestMultipleAlgoExecutions, MultipleCmdBufRecords) pa[index] = pa[index] + 1; })"); - std::vector spirv = kp_test_utils::Shader::compileSource(shader); + std::vector spirv = compileSource(shader); std::shared_ptr algorithm = mgr.algorithm({ tensorA }, spirv); @@ -168,7 +168,7 @@ TEST(TestMultipleAlgoExecutions, MultipleSequences) pa[index] = pa[index] + 1; })"); - std::vector spirv = kp_test_utils::Shader::compileSource(shader); + std::vector spirv = compileSource(shader); std::shared_ptr algorithm = mgr.algorithm({ tensorA }, spirv); @@ -203,7 +203,7 @@ TEST(TestMultipleAlgoExecutions, SingleRecordMultipleEval) pa[index] = pa[index] + 1; })"); - std::vector spirv = kp_test_utils::Shader::compileSource(shader); + std::vector spirv = compileSource(shader); std::shared_ptr algorithm = mgr.algorithm({ tensorA }, spirv); diff --git a/test/TestOpShadersFromStringAndFile.cpp b/test/TestOpShadersFromStringAndFile.cpp index cfbd9b00d..09b354cc6 100644 --- a/test/TestOpShadersFromStringAndFile.cpp +++ b/test/TestOpShadersFromStringAndFile.cpp @@ -29,7 +29,7 @@ TEST(TestOpAlgoCreate, ShaderRawDataFromConstructor) } )"); - std::vector spirv = kp_test_utils::Shader::compileSource(shader); + std::vector spirv = compileSource(shader); std::vector> params = { tensorA, tensorB }; diff --git a/test/TestPushConstant.cpp b/test/TestPushConstant.cpp index 51985ef1f..df0980654 100644 --- a/test/TestPushConstant.cpp +++ b/test/TestPushConstant.cpp @@ -24,7 +24,7 @@ TEST(TestPushConstants, TestConstantsAlgoDispatchOverride) pa[2] += pcs.z; })"); - std::vector spirv = kp_test_utils::Shader::compileSource(shader); + std::vector spirv = compileSource(shader); std::shared_ptr sq = nullptr; @@ -69,7 +69,7 @@ TEST(TestPushConstants, TestConstantsAlgoDispatchNoOverride) pa[2] += pcs.z; })"); - std::vector spirv = kp_test_utils::Shader::compileSource(shader); + std::vector spirv = compileSource(shader); std::shared_ptr sq = nullptr; @@ -114,7 +114,7 @@ TEST(TestPushConstants, TestConstantsWrongSize) pa[2] += pcs.z; })"); - std::vector spirv = kp_test_utils::Shader::compileSource(shader); + std::vector spirv = compileSource(shader); std::shared_ptr sq = nullptr; diff --git a/test/TestSequence.cpp b/test/TestSequence.cpp index c1f5734d4..3e8291591 100644 --- a/test/TestSequence.cpp +++ b/test/TestSequence.cpp @@ -68,7 +68,7 @@ TEST(TestSequence, RerecordSequence) sq->eval({ tensorA, tensorB, tensorOut }); - std::vector spirv = kp_test_utils::Shader::compileSource(R"( + std::vector spirv = compileSource(R"( #version 450 layout (local_size_x = 1) in; @@ -118,7 +118,7 @@ TEST(TestSequence, SequenceTimestamps) pa[index] = pa[index] + 1; })"); - std::vector spirv = kp_test_utils::Shader::compileSource(shader); + std::vector spirv = compileSource(shader); auto seq = mgr.sequence(0, 100); // 100 timestamps seq->record({ tensorA }) diff --git a/test/TestSpecializationConstant.cpp b/test/TestSpecializationConstant.cpp index 2279b46b4..79e829f5b 100644 --- a/test/TestSpecializationConstant.cpp +++ b/test/TestSpecializationConstant.cpp @@ -20,7 +20,7 @@ TEST(TestSpecializationConstants, TestTwoConstants) pb[index] = cTwo; })"); - std::vector spirv = kp_test_utils::Shader::compileSource(shader); + std::vector spirv = compileSource(shader); std::shared_ptr sq = nullptr; diff --git a/test/utils/kompute_test/Shader.cpp b/test/utils/kompute_test/Shader.cpp deleted file mode 100644 index 691c9715a..000000000 --- a/test/utils/kompute_test/Shader.cpp +++ /dev/null @@ -1,20 +0,0 @@ - -#include "kompute/Kompute.hpp" - -#include "kompute_test/Shader.hpp" - -namespace kp_test_utils { - -std::vector -Shader::compileSource( - const std::string& source) -{ - if (system(std::string("glslangValidator --stdin -S comp -V -o tmp_kp_shader.comp.spv << END\n" + source + "\nEND").c_str())) - throw std::runtime_error("Error running glslangValidator command"); - std::ifstream fileStream("tmp_kp_shader.comp.spv", std::ios::binary); - std::vector buffer; - buffer.insert(buffer.begin(), std::istreambuf_iterator(fileStream), {}); - return {(uint32_t*)buffer.data(), (uint32_t*)(buffer.data() + buffer.size())}; -} - -} diff --git a/test/utils/kompute_test/Shader.hpp b/test/utils/kompute_test/Shader.hpp index b6df40dce..884efe5f9 100644 --- a/test/utils/kompute_test/Shader.hpp +++ b/test/utils/kompute_test/Shader.hpp @@ -2,26 +2,26 @@ #include #include - -namespace kp_test_utils { +#include /** - Shader utily class with functions to compile and process glsl files. -*/ -class Shader + * Compile a single glslang source from string value. This is only meant + * to be used for testing as it's non threadsafe, and it had to be removed + * from the glslang dependency and now can only run the CLI directly due to + * license issues: see https://github.com/EthicalML/vulkan-kompute/pull/235 + * + * @param source An individual raw glsl shader in string format + * @return The compiled SPIR-V binary in unsigned int32 format + */ +static +std::vector +compileSource( + const std::string& source) { - public: - /** - * Compile a single glslang source from string value. This is only meant - * to be used for testing as it's non threadsafe, and it had to be removed - * from the glslang dependency and now can only run the CLI directly due to - * license issues: see https://github.com/EthicalML/vulkan-kompute/pull/235 - * - * @param source An individual raw glsl shader in string format - * @return The compiled SPIR-V binary in unsigned int32 format - */ - static std::vector compileSource( - const std::string& source); -}; - + if (system(std::string("glslangValidator --stdin -S comp -V -o tmp_kp_shader.comp.spv << END\n" + source + "\nEND").c_str())) + throw std::runtime_error("Error running glslangValidator command"); + std::ifstream fileStream("tmp_kp_shader.comp.spv", std::ios::binary); + std::vector buffer; + buffer.insert(buffer.begin(), std::istreambuf_iterator(fileStream), {}); + return {(uint32_t*)buffer.data(), (uint32_t*)(buffer.data() + buffer.size())}; }