From 13575499008d3b8994e0b12f9501a58f9559563b Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Tue, 20 Jul 2021 19:22:51 +0100 Subject: [PATCH] Updated glslang as core dependency --- .ccls | 1 + CHANGELOG.md | 2 +- CMakeLists.txt | 19 ++--- README.md | 2 +- docs/overview/advanced-examples.rst | 8 +-- docs/overview/reference.rst | 4 +- docs/overview/shaders-to-headers.rst | 16 ----- examples/array_multiplication/src/Main.cpp | 2 +- .../kompute_summator/KomputeSummatorNode.cpp | 2 +- .../gdnative_shared/src/KomputeSummator.cpp | 2 +- python/src/main.cpp | 28 -------- python/test/test_kompute.py | 17 +++-- python/test/test_tensor_types.py | 11 +-- single_include/AggregateHeaders.cpp | 1 - single_include/kompute/Kompute.hpp | 72 ------------------- src/CMakeLists.txt | 35 --------- test/CMakeLists.txt | 40 ++++++++++- test/TestAsyncOperations.cpp | 6 +- test/TestDestroy.cpp | 8 ++- test/TestMultipleAlgoExecutions.cpp | 12 ++-- test/TestOpShadersFromStringAndFile.cpp | 4 +- test/TestOpTensorCopy.cpp | 2 + test/TestPushConstant.cpp | 8 ++- test/TestSequence.cpp | 6 +- test/TestShaderResources.cpp | 10 +-- test/TestSpecializationConstant.cpp | 4 +- {src => test/utils/kompute_test}/Shader.cpp | 8 +-- .../utils/kompute_test}/Shader.hpp | 6 +- 28 files changed, 119 insertions(+), 217 deletions(-) rename {src => test/utils/kompute_test}/Shader.cpp (97%) rename {src/include/kompute => test/utils/kompute_test}/Shader.hpp (94%) diff --git a/.ccls b/.ccls index da06a9763..dd11e052f 100644 --- a/.ccls +++ b/.ccls @@ -24,4 +24,5 @@ -I./single_include/ -I./vk_ndk_wrapper_include/ -I./test/compiled_shaders_include/ +-I./test/utils/ diff --git a/CHANGELOG.md b/CHANGELOG.md index b85f4e1de..3a48d1fa1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,7 @@ **Closed issues:** - Update memory barriers to align with tensor staging/primary memory revamp [\#181](https://github.com/EthicalML/vulkan-kompute/issues/181) -- Move shader defaultResource inside kp::Shader class [\#175](https://github.com/EthicalML/vulkan-kompute/issues/175) +- Move shader defaultResource inside kp_test_utils::Shader class [\#175](https://github.com/EthicalML/vulkan-kompute/issues/175) - Reach at least 90% code coverage on tests [\#170](https://github.com/EthicalML/vulkan-kompute/issues/170) - Add functionality to re-record sequence as now it's possible to update the underlying algorithm [\#169](https://github.com/EthicalML/vulkan-kompute/issues/169) - Use numpy arrays as default return value [\#166](https://github.com/EthicalML/vulkan-kompute/issues/166) diff --git a/CMakeLists.txt b/CMakeLists.txt index 37162eb9c..3a9c5b2c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,6 @@ option(KOMPUTE_OPT_ENABLE_SPDLOG "Extra compile flags for Kompute, see docs for option(KOMPUTE_OPT_REPO_SUBMODULE_BUILD "Use the submodule repos instead of external package manager" 0) option(KOMPUTE_OPT_ANDROID_BUILD "Enable android compilation flags required" 0) option(KOMPUTE_OPT_DISABLE_VK_DEBUG_LAYERS "Explicitly disable debug layers even on debug" 0) -option(KOMPUTE_OPT_DISABLE_SHADER_UTILS "Remove shader util code and dependencies including glslang" 0) option(KOMPUTE_OPT_DEPENDENCIES_SHARED_LIBS "Whether to use shared libraries for dependencies for install" 0) option(KOMPUTE_OPT_BUILD_AS_SHARED_LIB "Whether to build kompute as shared library" 0) # Build flags @@ -55,19 +54,15 @@ if(KOMPUTE_OPT_DISABLE_VK_DEBUG_LAYERS) set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DKOMPUTE_DISABLE_VK_DEBUG_LAYERS=1") endif() -if(NOT KOMPUTE_OPT_DISABLE_SHADER_UTILS) - if(KOMPUTE_OPT_INSTALL) - # Enable install parameters for glslang (overrides parameters passed) - # When install is enabled the glslang libraries become shared - set(ENABLE_GLSLANG_INSTALL ON CACHE BOOL "Enables install of glslang" FORCE) +if(KOMPUTE_OPT_INSTALL) + # Enable install parameters for glslang (overrides parameters passed) + # When install is enabled the glslang libraries become shared + set(ENABLE_GLSLANG_INSTALL ON CACHE BOOL "Enables install of glslang" FORCE) - # By default we enable shared library based installation - if(KOMPUTE_OPT_DEPENDENCIES_SHARED_LIBS) - set(BUILD_SHARED_LIBS ON CACHE BOOL "Enables build of shared libraries" FORCE) - endif() + # By default we enable shared library based installation + if(KOMPUTE_OPT_DEPENDENCIES_SHARED_LIBS) + set(BUILD_SHARED_LIBS ON CACHE BOOL "Enables build of shared libraries" FORCE) endif() -else() - set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DKOMPUTE_DISABLE_SHADER_UTILS=1") endif() set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG=1 ${KOMPUTE_EXTRA_CXX_FLAGS} -DUSE_DEBUG_EXTENTIONS") diff --git a/README.md b/README.md index aed87c9f3..699928ea4 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ void kompute(const std::string& shader) { kp::Constants pushConstsB({ 3.0 }); auto algorithm = mgr.algorithm(params, - kp::Shader::compileSource(shader), + kp_test_utils::Shader::compileSource(shader), workgroup, specConsts, pushConstsA); diff --git a/docs/overview/advanced-examples.rst b/docs/overview/advanced-examples.rst index e4cc83049..f2fbe219c 100644 --- a/docs/overview/advanced-examples.rst +++ b/docs/overview/advanced-examples.rst @@ -55,7 +55,7 @@ The example below shows how you can enable the "VK_EXT_shader_atomic_float" exte atomicAdd(pa[2], pcs.z); })"); - std::vector spirv = kp::Shader::compileSource(shader); + std::vector spirv = kp_test_utils::Shader::compileSource(shader); std::shared_ptr sq = nullptr; @@ -102,7 +102,7 @@ We also provide tools that allow you to `convert shaders into C++ headers spirv = kp::Shader::compileSource(R"( + std::vector spirv = kp_test_utils::Shader::compileSource(R"( #version 450 layout(set = 0, binding = 0) buffer tensorLhs { @@ -215,7 +215,7 @@ In this case we create a shader that should take a couple of milliseconds to run } )"); - auto algo = mgr.algorithm({tensor}, kp::Shader::compileSource(shader)); + auto algo = mgr.algorithm({tensor}, kp_test_utils::Shader::compileSource(shader)); Now we are able to run the await function on the default sequence. @@ -361,7 +361,7 @@ Similar to the asyncrhonous usecase above, we can still run synchronous commands } )"); - std::vector spirv = kp::Shader::compileSource(shader); + std::vector spirv = kp_test_utils::Shader::compileSource(shader); std::shared_ptr algo = mgr.algorithm({tensorA, tenssorB}, spirv); diff --git a/docs/overview/reference.rst b/docs/overview/reference.rst index 76d165147..7ea805186 100644 --- a/docs/overview/reference.rst +++ b/docs/overview/reference.rst @@ -122,9 +122,9 @@ The :class:`kp::OpMemoryBarrier` is a tensor only operation which adds memory ba Shader -------- -The :class:`kp::Shader` class contains a set of utilities to compile and process shaders. +The :class:`kp_test_utils::Shader` class contains a set of utilities to compile and process shaders. -.. doxygenclass:: kp::Shader +.. doxygenclass:: kp_test_utils::Shader :members: diff --git a/docs/overview/shaders-to-headers.rst b/docs/overview/shaders-to-headers.rst index 531e7495c..0b36777be 100644 --- a/docs/overview/shaders-to-headers.rst +++ b/docs/overview/shaders-to-headers.rst @@ -3,22 +3,6 @@ Processing Shaders with Kompute ===================== -Kompute allows for two main ways of interacting with shaders - namely: - -* Integration with [glslang](https://github.com/KhronosGroup/glslang) for online/runtime shader compilation -* A CLI that coverts shaders into C++ header files - -Processing Shaders Online via Kompute Shader Utils ---------------- - -Kompute provides a set of helper functions that expose the C++ functionality of the glslang Khronos framework to process shader sources online during runtime. - -It's worth emphasising that the suggested approach is to process shaders offline, so the section below is suggested to convert shaders to either their respective SPV format, or convert them into C++ sources that would be embedded as part of the resulting binary. - -The Shader utility function can be skipped on build time through compiler flags - for more information on this you should read the `build section `_. - -More details on the shader utils can be found in the :class:`kp::Shader` section of the `C++ reference page `_. - Converting Shaders into C / C++ Header Files ---------------------------------- diff --git a/examples/array_multiplication/src/Main.cpp b/examples/array_multiplication/src/Main.cpp index 95e0781ad..3dd48c392 100755 --- a/examples/array_multiplication/src/Main.cpp +++ b/examples/array_multiplication/src/Main.cpp @@ -39,7 +39,7 @@ int main() std::vector> params = { tensorInA, tensorInB, tensorOut }; - std::shared_ptr algo = mgr.algorithm(params, kp::Shader::compileSource(shader)); + std::shared_ptr algo = mgr.algorithm(params, kp_test_utils::Shader::compileSource(shader)); mgr.sequence() ->record(params) diff --git a/examples/godot_examples/custom_module/kompute_summator/KomputeSummatorNode.cpp b/examples/godot_examples/custom_module/kompute_summator/KomputeSummatorNode.cpp index e901ef816..1a42761bf 100644 --- a/examples/godot_examples/custom_module/kompute_summator/KomputeSummatorNode.cpp +++ b/examples/godot_examples/custom_module/kompute_summator/KomputeSummatorNode.cpp @@ -54,7 +54,7 @@ void KomputeSummatorNode::_init() { std::shared_ptr algo = mgr.algorithm( { this->mPrimaryTensor, this->mSecondaryTensor }, - kp::Shader::compileSource(shader)); + kp_test_utils::Shader::compileSource(shader)); // First we ensure secondary tensor loads to GPU diff --git a/examples/godot_examples/gdnative_shared/src/KomputeSummator.cpp b/examples/godot_examples/gdnative_shared/src/KomputeSummator.cpp index 99aabb338..ffca61dcf 100644 --- a/examples/godot_examples/gdnative_shared/src/KomputeSummator.cpp +++ b/examples/godot_examples/gdnative_shared/src/KomputeSummator.cpp @@ -58,7 +58,7 @@ void KomputeSummator::_init() { // Then we run the operation with both tensors this->mSequence->record( { this->mPrimaryTensor, this->mSecondaryTensor }, - kp::Shader::compileSource(shader)); + kp_test_utils::Shader::compileSource(shader)); // We map the result back to local this->mSequence->record( diff --git a/python/src/main.cpp b/python/src/main.cpp index d9f87e93a..846576adb 100644 --- a/python/src/main.cpp +++ b/python/src/main.cpp @@ -33,34 +33,6 @@ PYBIND11_MODULE(kp, m) { .value("storage", kp::Tensor::TensorTypes::eStorage, DOC(kp, Tensor, TensorTypes, eStorage)) .export_values(); -#if !defined(KOMPUTE_DISABLE_SHADER_UTILS) || !KOMPUTE_DISABLE_SHADER_UTILS - py::class_(m, "Shader", "Shader class") - .def_static("compile_source", []( - const std::string& source, - const std::string& entryPoint, - const std::vector>& definitions) { - std::vector spirv = kp::Shader::compileSource(source, entryPoint, definitions); - return py::bytes((const char*)spirv.data(), spirv.size() * sizeof(uint32_t)); - }, - DOC(kp, Shader, compileSource), - py::arg("source"), - py::arg("entryPoint") = "main", - py::arg("definitions") = std::vector>() ) - .def_static("compile_sources", []( - const std::vector& source, - const std::vector& files, - const std::string& entryPoint, - const std::vector>& definitions) { - std::vector spirv = kp::Shader::compileSources(source, files, entryPoint, definitions); - return py::bytes((const char*)spirv.data(), spirv.size() * sizeof(uint32_t)); - }, - DOC(kp, Shader, compileSources), - py::arg("sources"), - py::arg("files") = std::vector(), - py::arg("entryPoint") = "main", - py::arg("definitions") = std::vector>() ); -#endif // KOMPUTE_DISABLE_SHADER_UTILS - py::class_>(m, "OpBase", DOC(kp, OpBase)); py::class_>( diff --git a/python/test/test_kompute.py b/python/test/test_kompute.py index 8c2c1ac55..9dd8040df 100644 --- a/python/test/test_kompute.py +++ b/python/test/test_kompute.py @@ -5,10 +5,13 @@ import numpy as np import logging import pyshader as ps +import pyshaderc + DIRNAME = os.path.dirname(os.path.abspath(__file__)) kp_log = logging.getLogger("kp") + def test_end_to_end(): mgr = kp.Manager() @@ -52,7 +55,7 @@ def test_end_to_end(): push_consts_a = [2] push_consts_b = [3] - algo = mgr.algorithm(params, kp.Shader.compile_source(shader), workgroup, spec_consts, push_consts_a) + algo = mgr.algorithm(params, pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp"), workgroup, spec_consts, push_consts_a) (mgr.sequence() .record(kp.OpTensorSyncDevice(params)) @@ -88,7 +91,7 @@ void main() } """ - spirv = kp.Shader.compile_source(shader) + spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp") mgr = kp.Manager() @@ -108,6 +111,7 @@ void main() assert tensor_out.data().tolist() == [2.0, 4.0, 6.0] + def test_sequence(): """ Test basic OpAlgoBase operation @@ -127,7 +131,7 @@ def test_sequence(): } """ - spirv = kp.Shader.compile_source(shader) + spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp") mgr = kp.Manager(0) @@ -164,9 +168,10 @@ def test_sequence(): assert tensor_in_b.is_init() == False assert tensor_out.is_init() == False + def test_pushconsts(): - spirv = kp.Shader.compile_source(""" + spirv = pyshaderc.compile_into_spirv(""" #version 450 layout(push_constant) uniform PushConstants { float x; @@ -180,7 +185,7 @@ def test_pushconsts(): pa[1] += pcs.y; pa[2] += pcs.z; } - """) + """.encode("utf-8"), "comp", "shader.comp") mgr = kp.Manager() @@ -197,6 +202,7 @@ def test_pushconsts(): assert np.all(tensor.data() == np.array([0.4, 0.4, 0.4], dtype=np.float32)) + def test_workgroup(): mgr = kp.Manager(0) @@ -227,6 +233,7 @@ def test_workgroup(): assert np.all(tensor_a.data() == np.stack([np.arange(16)]*8, axis=1).ravel()) assert np.all(tensor_b.data() == np.stack([np.arange(8)]*16, axis=0).ravel()) + def test_mgr_utils(): mgr = kp.Manager() diff --git a/python/test/test_tensor_types.py b/python/test/test_tensor_types.py index ee645d850..e2a71250a 100644 --- a/python/test/test_tensor_types.py +++ b/python/test/test_tensor_types.py @@ -1,4 +1,5 @@ import pyshader as ps +import pyshaderc import os import pytest import kp @@ -22,7 +23,7 @@ def test_type_float(): } """ - spirv = kp.Shader.compile_source(shader) + spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp") arr_in_a = np.array([123., 153., 231.], dtype=np.float32) arr_in_b = np.array([9482, 1208, 1238], dtype=np.float32) @@ -61,7 +62,7 @@ def test_type_float_double_incorrect(): } """ - spirv = kp.Shader.compile_source(shader) + spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp") arr_in_a = np.array([123., 153., 231.], dtype=np.float32) arr_in_b = np.array([9482, 1208, 1238], dtype=np.uint32) @@ -103,7 +104,7 @@ def test_type_double(): } """ - spirv = kp.Shader.compile_source(shader) + spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp") arr_in_a = np.array([123., 153., 231.], dtype=np.float64) arr_in_b = np.array([9482, 1208, 1238], dtype=np.float64) @@ -143,7 +144,7 @@ def test_type_int(): } """ - spirv = kp.Shader.compile_source(shader) + spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp") arr_in_a = np.array([123, 153, 231], dtype=np.int32) arr_in_b = np.array([9482, 1208, 1238], dtype=np.int32) @@ -183,7 +184,7 @@ def test_type_unsigned_int(): } """ - spirv = kp.Shader.compile_source(shader) + spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp") arr_in_a = np.array([123, 153, 231], dtype=np.uint32) arr_in_b = np.array([9482, 1208, 1238], dtype=np.uint32) diff --git a/single_include/AggregateHeaders.cpp b/single_include/AggregateHeaders.cpp index e4d1014e9..e1c7f4afb 100644 --- a/single_include/AggregateHeaders.cpp +++ b/single_include/AggregateHeaders.cpp @@ -2,7 +2,6 @@ #include "kompute/shaders/shaderopmult.hpp" #include "kompute/shaders/shaderlogisticregression.hpp" #include "kompute/Core.hpp" -#include "kompute/Shader.hpp" #include "kompute/Tensor.hpp" #include "kompute/Algorithm.hpp" #include "kompute/operations/OpBase.hpp" diff --git a/single_include/kompute/Kompute.hpp b/single_include/kompute/Kompute.hpp index a1be47655..4d252f519 100755 --- a/single_include/kompute/Kompute.hpp +++ b/single_include/kompute/Kompute.hpp @@ -725,78 +725,6 @@ extern py::object kp_debug, kp_info, kp_warning, kp_error; #endif // KOMPUTE_SPDLOG_ENABLED #endif // KOMPUTE_LOG_OVERRIDE -#if !defined(KOMPUTE_DISABLE_SHADER_UTILS) || !KOMPUTE_DISABLE_SHADER_UTILS -#include -#include - -#ifdef USE_EXTERNAL_GLSLANG -#include -#else -#include -#endif - -#include -#include - -namespace kp { - -/** - Shader utily class with functions to compile and process glsl files. -*/ -class Shader -{ - public: - // The default resource limit for the GLSL compiler, can be overwritten - // Has been adopted by: - // https://github.com/KhronosGroup/glslang/blob/master/StandAlone/ResourceLimits.cpp - const static TBuiltInResource defaultResource; - - /** - * Compile multiple sources with optional filenames. Currently this function - * uses the glslang C++ interface which is not thread safe so this funciton - * should not be called from multiple threads concurrently. If you have a - * online shader processing multithreading use-case that can't use offline - * compilation please open an issue. - * - * @param sources A list of raw glsl shaders in string format - * @param files A list of file names respective to each of the sources - * @param entryPoint The function name to use as entry point - * @param definitions List of pairs containing key value definitions - * @param resourcesLimit A list that contains the resource limits for the - * GLSL compiler - * @return The compiled SPIR-V binary in unsigned int32 format - */ - static std::vector compileSources( - const std::vector& sources, - const std::vector& files = {}, - const std::string& entryPoint = "main", - std::vector> definitions = {}, - const TBuiltInResource& resources = Shader::defaultResource); - - /** - * Compile a single glslang source from string value. Currently this - * function uses the glslang C++ interface which is not thread safe so this - * funciton should not be called from multiple threads concurrently. If you - * have a online shader processing multithreading use-case that can't use - * offline compilation please open an issue. - * - * @param source An individual raw glsl shader in string format - * @param entryPoint The function name to use as entry point - * @param definitions List of pairs containing key value definitions - * @param resourcesLimit A list that contains the resource limits for the - * GLSL compiler - * @return The compiled SPIR-V binary in unsigned int32 format - */ - static std::vector compileSource( - const std::string& source, - const std::string& entryPoint = "main", - std::vector> definitions = {}, - const TBuiltInResource& resources = Shader::defaultResource); -}; - -} -#endif // DKOMPUTE_DISABLE_SHADER_UTILS - namespace kp { /** diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 26bf47e66..5adfddc2e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -141,41 +141,6 @@ if(KOMPUTE_OPT_BUILD_SINGLE_HEADER) build_single_header) endif() -##################################################### -#################### GLSLANG ####################### -##################################################### - -if(NOT KOMPUTE_OPT_DISABLE_SHADER_UTILS) - if(KOMPUTE_OPT_REPO_SUBMODULE_BUILD) - add_subdirectory(${PROJECT_SOURCE_DIR}/external/glslang - ${CMAKE_CURRENT_BINARY_DIR}/kompute_glslang) - - target_include_directories( - kompute PRIVATE - ${PROJECT_SOURCE_DIR}/external/glslang) - - target_link_libraries(kompute - # Not including hlsl support - # HLSL - # glslang includes OGLCompiler, OSDependent, MachineIndependent - glslang - SPIRV) - else() - find_package(glslang CONFIG REQUIRED) - - target_include_directories( - kompute PRIVATE - ${GLSLANG_GENERATED_INCLUDEDIR}) - - target_link_libraries(kompute - # Not including hlsl support - # glslang::HLSL - # Adding explicit dependencies to match above - glslang::glslang - glslang::SPIRV) - endif() -endif() - add_library(kompute::kompute ALIAS kompute) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a30792aad..8c4731a7e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,6 +12,7 @@ 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}) @@ -20,6 +21,7 @@ target_include_directories( test_kompute PUBLIC $ $ + $ ) if(KOMPUTE_OPT_REPO_SUBMODULE_BUILD) @@ -27,17 +29,51 @@ if(KOMPUTE_OPT_REPO_SUBMODULE_BUILD) test_kompute PRIVATE ${gtest_SOURCE_DIR}/include) - target_link_libraries(test_kompute PRIVATE + target_link_libraries(test_kompute gtest_main) else() target_link_libraries(test_kompute PRIVATE GTest::gtest) endif() -target_link_libraries(test_kompute PRIVATE kompute) +target_link_libraries(test_kompute kompute) add_test(NAME test_kompute COMMAND test_kompute) +##################################################### +#################### GLSLANG ####################### +##################################################### + +if(KOMPUTE_OPT_REPO_SUBMODULE_BUILD) + add_subdirectory(${PROJECT_SOURCE_DIR}/external/glslang + ${CMAKE_CURRENT_BINARY_DIR}/kompute_glslang) + + target_include_directories( + test_kompute PRIVATE + ${PROJECT_SOURCE_DIR}/external/glslang) + + target_link_libraries(test_kompute + # Not including hlsl support + # HLSL + # glslang includes OGLCompiler, OSDependent, MachineIndependent + glslang + SPIRV) +else() + find_package(glslang CONFIG REQUIRED) + + target_include_directories( + test_kompute PRIVATE + ${GLSLANG_GENERATED_INCLUDEDIR}) + + target_link_libraries(test_kompute + # Not including hlsl support + # glslang::HLSL + # Adding explicit dependencies to match above + glslang::glslang + glslang::SPIRV) +endif() + + ##################################################### #################### CODECOV ####################### ##################################################### diff --git a/test/TestAsyncOperations.cpp b/test/TestAsyncOperations.cpp index 2e3edcd32..1c5fe277e 100644 --- a/test/TestAsyncOperations.cpp +++ b/test/TestAsyncOperations.cpp @@ -5,6 +5,8 @@ #include "kompute/Kompute.hpp" +#include "kompute_test/Shader.hpp" + TEST(TestAsyncOperations, TestManagerParallelExecution) { // This test is built for NVIDIA 1650. It assumes: @@ -37,7 +39,7 @@ TEST(TestAsyncOperations, TestManagerParallelExecution) } )"); - std::vector spirv = kp::Shader::compileSource(shader); + std::vector spirv = kp_test_utils::Shader::compileSource(shader); std::vector data(size, 0.0); std::vector resultSync(size, 100000000); @@ -145,7 +147,7 @@ TEST(TestAsyncOperations, TestManagerAsyncExecution) } )"); - std::vector spirv = kp::Shader::compileSource(shader); + std::vector spirv = kp_test_utils::Shader::compileSource(shader); std::vector data(size, 0.0); std::vector resultAsync(size, 100000000); diff --git a/test/TestDestroy.cpp b/test/TestDestroy.cpp index 36127f84e..72225f9ce 100644 --- a/test/TestDestroy.cpp +++ b/test/TestDestroy.cpp @@ -3,6 +3,8 @@ #include "kompute/Kompute.hpp" +#include "kompute_test/Shader.hpp" + TEST(TestDestroy, TestDestroyTensorSingle) { std::shared_ptr> tensorA = nullptr; @@ -16,7 +18,7 @@ TEST(TestDestroy, TestDestroyTensorSingle) pa[index] = pa[index] + 1; })"); - std::vector spirv = kp::Shader::compileSource(shader); + std::vector spirv = kp_test_utils::Shader::compileSource(shader); { std::shared_ptr sq = nullptr; @@ -58,7 +60,7 @@ TEST(TestDestroy, TestDestroyTensorVector) pa[index] = pa[index] + 1; pb[index] = pb[index] + 2; })"); - std::vector spirv = kp::Shader::compileSource(shader); + std::vector spirv = kp_test_utils::Shader::compileSource(shader); { std::shared_ptr sq = nullptr; @@ -103,7 +105,7 @@ TEST(TestDestroy, TestDestroySequenceSingle) pa[index] = pa[index] + 1; })"); - std::vector spirv = kp::Shader::compileSource(shader); + std::vector spirv = kp_test_utils::Shader::compileSource(shader); { std::shared_ptr sq = nullptr; diff --git a/test/TestMultipleAlgoExecutions.cpp b/test/TestMultipleAlgoExecutions.cpp index df4af2f08..2206e1269 100644 --- a/test/TestMultipleAlgoExecutions.cpp +++ b/test/TestMultipleAlgoExecutions.cpp @@ -3,6 +3,8 @@ #include "kompute/Kompute.hpp" +#include "kompute_test/Shader.hpp" + TEST(TestMultipleAlgoExecutions, TestEndToEndFunctionality) { @@ -51,7 +53,7 @@ TEST(TestMultipleAlgoExecutions, TestEndToEndFunctionality) kp::Constants pushConstsB({ 3.0 }); auto algorithm = mgr.algorithm(params, - kp::Shader::compileSource(shader), + kp_test_utils::Shader::compileSource(shader), workgroup, specConsts, pushConstsA); @@ -89,7 +91,7 @@ TEST(TestMultipleAlgoExecutions, SingleSequenceRecord) pa[index] = pa[index] + 1; })"); - std::vector spirv = kp::Shader::compileSource(shader); + std::vector spirv = kp_test_utils::Shader::compileSource(shader); { // A sharedMemoryBarrier is required as the shader is not thread-safe:w @@ -130,7 +132,7 @@ TEST(TestMultipleAlgoExecutions, MultipleCmdBufRecords) pa[index] = pa[index] + 1; })"); - std::vector spirv = kp::Shader::compileSource(shader); + std::vector spirv = kp_test_utils::Shader::compileSource(shader); std::shared_ptr algorithm = mgr.algorithm({ tensorA }, spirv); @@ -166,7 +168,7 @@ TEST(TestMultipleAlgoExecutions, MultipleSequences) pa[index] = pa[index] + 1; })"); - std::vector spirv = kp::Shader::compileSource(shader); + std::vector spirv = kp_test_utils::Shader::compileSource(shader); std::shared_ptr algorithm = mgr.algorithm({ tensorA }, spirv); @@ -201,7 +203,7 @@ TEST(TestMultipleAlgoExecutions, SingleRecordMultipleEval) pa[index] = pa[index] + 1; })"); - std::vector spirv = kp::Shader::compileSource(shader); + std::vector spirv = kp_test_utils::Shader::compileSource(shader); std::shared_ptr algorithm = mgr.algorithm({ tensorA }, spirv); diff --git a/test/TestOpShadersFromStringAndFile.cpp b/test/TestOpShadersFromStringAndFile.cpp index bf2ed8587..cfbd9b00d 100644 --- a/test/TestOpShadersFromStringAndFile.cpp +++ b/test/TestOpShadersFromStringAndFile.cpp @@ -5,6 +5,8 @@ #include "kompute_test/shaders/shadertest_op_custom_shader.hpp" +#include "kompute_test/Shader.hpp" + TEST(TestOpAlgoCreate, ShaderRawDataFromConstructor) { kp::Manager mgr; @@ -27,7 +29,7 @@ TEST(TestOpAlgoCreate, ShaderRawDataFromConstructor) } )"); - std::vector spirv = kp::Shader::compileSource(shader); + std::vector spirv = kp_test_utils::Shader::compileSource(shader); std::vector> params = { tensorA, tensorB }; diff --git a/test/TestOpTensorCopy.cpp b/test/TestOpTensorCopy.cpp index 6978eeeea..1cd87fc75 100644 --- a/test/TestOpTensorCopy.cpp +++ b/test/TestOpTensorCopy.cpp @@ -3,6 +3,8 @@ #include "kompute/Kompute.hpp" +#include "kompute_test/Shader.hpp" + TEST(TestOpTensorCopy, CopyDeviceToDeviceTensor) { diff --git a/test/TestPushConstant.cpp b/test/TestPushConstant.cpp index 66f798afe..51985ef1f 100644 --- a/test/TestPushConstant.cpp +++ b/test/TestPushConstant.cpp @@ -2,6 +2,8 @@ #include "kompute/Kompute.hpp" +#include "kompute_test/Shader.hpp" + #include "fmt/ranges.h" TEST(TestPushConstants, TestConstantsAlgoDispatchOverride) @@ -22,7 +24,7 @@ TEST(TestPushConstants, TestConstantsAlgoDispatchOverride) pa[2] += pcs.z; })"); - std::vector spirv = kp::Shader::compileSource(shader); + std::vector spirv = kp_test_utils::Shader::compileSource(shader); std::shared_ptr sq = nullptr; @@ -67,7 +69,7 @@ TEST(TestPushConstants, TestConstantsAlgoDispatchNoOverride) pa[2] += pcs.z; })"); - std::vector spirv = kp::Shader::compileSource(shader); + std::vector spirv = kp_test_utils::Shader::compileSource(shader); std::shared_ptr sq = nullptr; @@ -112,7 +114,7 @@ TEST(TestPushConstants, TestConstantsWrongSize) pa[2] += pcs.z; })"); - std::vector spirv = kp::Shader::compileSource(shader); + std::vector spirv = kp_test_utils::Shader::compileSource(shader); std::shared_ptr sq = nullptr; diff --git a/test/TestSequence.cpp b/test/TestSequence.cpp index 19d96c893..c1f5734d4 100644 --- a/test/TestSequence.cpp +++ b/test/TestSequence.cpp @@ -3,6 +3,8 @@ #include "kompute/Kompute.hpp" +#include "kompute_test/Shader.hpp" + TEST(TestSequence, SequenceDestructorViaManager) { std::shared_ptr sq = nullptr; @@ -66,7 +68,7 @@ TEST(TestSequence, RerecordSequence) sq->eval({ tensorA, tensorB, tensorOut }); - std::vector spirv = kp::Shader::compileSource(R"( + std::vector spirv = kp_test_utils::Shader::compileSource(R"( #version 450 layout (local_size_x = 1) in; @@ -116,7 +118,7 @@ TEST(TestSequence, SequenceTimestamps) pa[index] = pa[index] + 1; })"); - std::vector spirv = kp::Shader::compileSource(shader); + std::vector spirv = kp_test_utils::Shader::compileSource(shader); auto seq = mgr.sequence(0, 100); // 100 timestamps seq->record({ tensorA }) diff --git a/test/TestShaderResources.cpp b/test/TestShaderResources.cpp index 6faddb39e..41a979f6a 100644 --- a/test/TestShaderResources.cpp +++ b/test/TestShaderResources.cpp @@ -2,6 +2,8 @@ #include "kompute/Kompute.hpp" +#include "kompute_test/Shader.hpp" + static const std::string shaderString = (R"( #version 450 @@ -28,7 +30,7 @@ void compileShaderWithGivenResources(const std::string shaderString, const TBuiltInResource resources) { - kp::Shader::compileSource( + kp_test_utils::Shader::compileSource( shaderString, std::string("main"), std::vector>({}), @@ -37,7 +39,7 @@ compileShaderWithGivenResources(const std::string shaderString, TEST(TestShaderResources, TestNoMaxLight) { - TBuiltInResource noMaxLightResources = kp::Shader::defaultResource; + TBuiltInResource noMaxLightResources = kp_test_utils::Shader::defaultResource; noMaxLightResources.maxLights = 0; EXPECT_NO_THROW( @@ -47,7 +49,7 @@ TEST(TestShaderResources, TestNoMaxLight) TEST(TestShaderResources, TestSmallComputeWorkGroupSizeX) { TBuiltInResource smallComputeWorkGroupSizeXResources = - kp::Shader::defaultResource; + kp_test_utils::Shader::defaultResource; smallComputeWorkGroupSizeXResources.maxComputeWorkGroupSizeX = 0; ASSERT_THROW(compileShaderWithGivenResources( @@ -57,7 +59,7 @@ TEST(TestShaderResources, TestSmallComputeWorkGroupSizeX) TEST(TestShaderResources, TestNoWhileLoopLimit) { - TBuiltInResource noWhileLoopLimitResources = kp::Shader::defaultResource; + TBuiltInResource noWhileLoopLimitResources = kp_test_utils::Shader::defaultResource; noWhileLoopLimitResources.limits.whileLoops = 0; ASSERT_THROW( diff --git a/test/TestSpecializationConstant.cpp b/test/TestSpecializationConstant.cpp index 7654c8aaf..2279b46b4 100644 --- a/test/TestSpecializationConstant.cpp +++ b/test/TestSpecializationConstant.cpp @@ -2,6 +2,8 @@ #include "kompute/Kompute.hpp" +#include "kompute_test/Shader.hpp" + TEST(TestSpecializationConstants, TestTwoConstants) { { @@ -18,7 +20,7 @@ TEST(TestSpecializationConstants, TestTwoConstants) pb[index] = cTwo; })"); - std::vector spirv = kp::Shader::compileSource(shader); + std::vector spirv = kp_test_utils::Shader::compileSource(shader); std::shared_ptr sq = nullptr; diff --git a/src/Shader.cpp b/test/utils/kompute_test/Shader.cpp similarity index 97% rename from src/Shader.cpp rename to test/utils/kompute_test/Shader.cpp index 293752a9a..2fb9209a7 100644 --- a/src/Shader.cpp +++ b/test/utils/kompute_test/Shader.cpp @@ -1,8 +1,9 @@ -#if !defined(KOMPUTE_DISABLE_SHADER_UTILS) || !KOMPUTE_DISABLE_SHADER_UTILS -#include "kompute/Shader.hpp" +#include "kompute/Kompute.hpp" -namespace kp { +#include "kompute_test/Shader.hpp" + +namespace kp_test_utils { std::vector Shader::compileSources( @@ -215,4 +216,3 @@ const TBuiltInResource Shader::defaultResource = { }; } -#endif // DKOMPUTE_DISABLE_SHADER_UTILS diff --git a/src/include/kompute/Shader.hpp b/test/utils/kompute_test/Shader.hpp similarity index 94% rename from src/include/kompute/Shader.hpp rename to test/utils/kompute_test/Shader.hpp index d670d63a7..a24234e30 100644 --- a/src/include/kompute/Shader.hpp +++ b/test/utils/kompute_test/Shader.hpp @@ -1,6 +1,5 @@ #pragma once -#if !defined(KOMPUTE_DISABLE_SHADER_UTILS) || !KOMPUTE_DISABLE_SHADER_UTILS #include #include @@ -13,9 +12,7 @@ #include #include -#include "kompute/Core.hpp" - -namespace kp { +namespace kp_test_utils { /** Shader utily class with functions to compile and process glsl files. @@ -72,4 +69,3 @@ class Shader }; } -#endif // DKOMPUTE_DISABLE_SHADER_UTILS