Updated glslang as core dependency
This commit is contained in:
parent
03bea35fce
commit
1357549900
28 changed files with 119 additions and 217 deletions
1
.ccls
1
.ccls
|
|
@ -24,4 +24,5 @@
|
|||
-I./single_include/
|
||||
-I./vk_ndk_wrapper_include/
|
||||
-I./test/compiled_shaders_include/
|
||||
-I./test/utils/
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<uint32_t> spirv = kp::Shader::compileSource(shader);
|
||||
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
|
||||
|
||||
std::shared_ptr<kp::Sequence> sq = nullptr;
|
||||
|
||||
|
|
@ -102,7 +102,7 @@ We also provide tools that allow you to `convert shaders into C++ headers <https
|
|||
throw std::runtime_error("Kompute OpMult expected 3 tensors but got " + tensors.size());
|
||||
}
|
||||
|
||||
std::vector<uint32_t> spirv = kp::Shader::compileSource(R"(
|
||||
std::vector<uint32_t> 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<uint32_t> spirv = kp::Shader::compileSource(shader);
|
||||
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
|
||||
|
||||
std::shared_ptr<kp::Algorithm> algo = mgr.algorithm({tensorA, tenssorB}, spirv);
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <build-system.rst>`_.
|
||||
|
||||
More details on the shader utils can be found in the :class:`kp::Shader` section of the `C++ reference page <reference.rst>`_.
|
||||
|
||||
Converting Shaders into C / C++ Header Files
|
||||
----------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ int main()
|
|||
|
||||
std::vector<std::shared_ptr<kp::Tensor>> params = { tensorInA, tensorInB, tensorOut };
|
||||
|
||||
std::shared_ptr<kp::Algorithm> algo = mgr.algorithm(params, kp::Shader::compileSource(shader));
|
||||
std::shared_ptr<kp::Algorithm> algo = mgr.algorithm(params, kp_test_utils::Shader::compileSource(shader));
|
||||
|
||||
mgr.sequence()
|
||||
->record<kp::OpTensorSyncDevice>(params)
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ void KomputeSummatorNode::_init() {
|
|||
std::shared_ptr<kp::Algorithm> 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
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ void KomputeSummator::_init() {
|
|||
// Then we run the operation with both tensors
|
||||
this->mSequence->record<kp::OpAlgoCreate>(
|
||||
{ this->mPrimaryTensor, this->mSecondaryTensor },
|
||||
kp::Shader::compileSource(shader));
|
||||
kp_test_utils::Shader::compileSource(shader));
|
||||
|
||||
// We map the result back to local
|
||||
this->mSequence->record<kp::OpTensorSyncLocal>(
|
||||
|
|
|
|||
|
|
@ -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_<kp::Shader>(m, "Shader", "Shader class")
|
||||
.def_static("compile_source", [](
|
||||
const std::string& source,
|
||||
const std::string& entryPoint,
|
||||
const std::vector<std::pair<std::string,std::string>>& definitions) {
|
||||
std::vector<uint32_t> 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<std::pair<std::string,std::string>>() )
|
||||
.def_static("compile_sources", [](
|
||||
const std::vector<std::string>& source,
|
||||
const std::vector<std::string>& files,
|
||||
const std::string& entryPoint,
|
||||
const std::vector<std::pair<std::string,std::string>>& definitions) {
|
||||
std::vector<uint32_t> 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<std::string>(),
|
||||
py::arg("entryPoint") = "main",
|
||||
py::arg("definitions") = std::vector<std::pair<std::string,std::string>>() );
|
||||
#endif // KOMPUTE_DISABLE_SHADER_UTILS
|
||||
|
||||
py::class_<kp::OpBase, std::shared_ptr<kp::OpBase>>(m, "OpBase", DOC(kp, OpBase));
|
||||
|
||||
py::class_<kp::OpTensorSyncDevice, std::shared_ptr<kp::OpTensorSyncDevice>>(
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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 <iostream>
|
||||
#include <vector>
|
||||
|
||||
#ifdef USE_EXTERNAL_GLSLANG
|
||||
#include <SPIRV/GlslangToSpv.h>
|
||||
#else
|
||||
#include <glslang/SPIRV/GlslangToSpv.h>
|
||||
#endif
|
||||
|
||||
#include <glslang/Include/ResourceLimits.h>
|
||||
#include <glslang/Public/ShaderLang.h>
|
||||
|
||||
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<uint32_t> compileSources(
|
||||
const std::vector<std::string>& sources,
|
||||
const std::vector<std::string>& files = {},
|
||||
const std::string& entryPoint = "main",
|
||||
std::vector<std::pair<std::string, std::string>> 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<uint32_t> compileSource(
|
||||
const std::string& source,
|
||||
const std::string& entryPoint = "main",
|
||||
std::vector<std::pair<std::string, std::string>> definitions = {},
|
||||
const TBuiltInResource& resources = Shader::defaultResource);
|
||||
};
|
||||
|
||||
}
|
||||
#endif // DKOMPUTE_DISABLE_SHADER_UTILS
|
||||
|
||||
namespace kp {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/single_include>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/compiled_shaders_include>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/utils>
|
||||
)
|
||||
|
||||
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 #######################
|
||||
#####################################################
|
||||
|
|
|
|||
|
|
@ -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<uint32_t> spirv = kp::Shader::compileSource(shader);
|
||||
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
|
||||
|
||||
std::vector<float> data(size, 0.0);
|
||||
std::vector<float> resultSync(size, 100000000);
|
||||
|
|
@ -145,7 +147,7 @@ TEST(TestAsyncOperations, TestManagerAsyncExecution)
|
|||
}
|
||||
)");
|
||||
|
||||
std::vector<uint32_t> spirv = kp::Shader::compileSource(shader);
|
||||
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
|
||||
|
||||
std::vector<float> data(size, 0.0);
|
||||
std::vector<float> resultAsync(size, 100000000);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
#include "kompute_test/Shader.hpp"
|
||||
|
||||
TEST(TestDestroy, TestDestroyTensorSingle)
|
||||
{
|
||||
std::shared_ptr<kp::TensorT<float>> tensorA = nullptr;
|
||||
|
|
@ -16,7 +18,7 @@ TEST(TestDestroy, TestDestroyTensorSingle)
|
|||
pa[index] = pa[index] + 1;
|
||||
})");
|
||||
|
||||
std::vector<uint32_t> spirv = kp::Shader::compileSource(shader);
|
||||
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
|
||||
|
||||
{
|
||||
std::shared_ptr<kp::Sequence> sq = nullptr;
|
||||
|
|
@ -58,7 +60,7 @@ TEST(TestDestroy, TestDestroyTensorVector)
|
|||
pa[index] = pa[index] + 1;
|
||||
pb[index] = pb[index] + 2;
|
||||
})");
|
||||
std::vector<uint32_t> spirv = kp::Shader::compileSource(shader);
|
||||
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
|
||||
|
||||
{
|
||||
std::shared_ptr<kp::Sequence> sq = nullptr;
|
||||
|
|
@ -103,7 +105,7 @@ TEST(TestDestroy, TestDestroySequenceSingle)
|
|||
pa[index] = pa[index] + 1;
|
||||
})");
|
||||
|
||||
std::vector<uint32_t> spirv = kp::Shader::compileSource(shader);
|
||||
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
|
||||
|
||||
{
|
||||
std::shared_ptr<kp::Sequence> sq = nullptr;
|
||||
|
|
|
|||
|
|
@ -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<uint32_t> spirv = kp::Shader::compileSource(shader);
|
||||
std::vector<uint32_t> 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<uint32_t> spirv = kp::Shader::compileSource(shader);
|
||||
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
|
||||
|
||||
std::shared_ptr<kp::Algorithm> algorithm =
|
||||
mgr.algorithm({ tensorA }, spirv);
|
||||
|
|
@ -166,7 +168,7 @@ TEST(TestMultipleAlgoExecutions, MultipleSequences)
|
|||
pa[index] = pa[index] + 1;
|
||||
})");
|
||||
|
||||
std::vector<uint32_t> spirv = kp::Shader::compileSource(shader);
|
||||
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
|
||||
|
||||
std::shared_ptr<kp::Algorithm> algorithm =
|
||||
mgr.algorithm({ tensorA }, spirv);
|
||||
|
|
@ -201,7 +203,7 @@ TEST(TestMultipleAlgoExecutions, SingleRecordMultipleEval)
|
|||
pa[index] = pa[index] + 1;
|
||||
})");
|
||||
|
||||
std::vector<uint32_t> spirv = kp::Shader::compileSource(shader);
|
||||
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
|
||||
|
||||
std::shared_ptr<kp::Algorithm> algorithm =
|
||||
mgr.algorithm({ tensorA }, spirv);
|
||||
|
|
|
|||
|
|
@ -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<uint32_t> spirv = kp::Shader::compileSource(shader);
|
||||
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
|
||||
|
||||
std::vector<std::shared_ptr<kp::Tensor>> params = { tensorA, tensorB };
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
#include "kompute_test/Shader.hpp"
|
||||
|
||||
TEST(TestOpTensorCopy, CopyDeviceToDeviceTensor)
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -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<uint32_t> spirv = kp::Shader::compileSource(shader);
|
||||
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
|
||||
|
||||
std::shared_ptr<kp::Sequence> sq = nullptr;
|
||||
|
||||
|
|
@ -67,7 +69,7 @@ TEST(TestPushConstants, TestConstantsAlgoDispatchNoOverride)
|
|||
pa[2] += pcs.z;
|
||||
})");
|
||||
|
||||
std::vector<uint32_t> spirv = kp::Shader::compileSource(shader);
|
||||
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
|
||||
|
||||
std::shared_ptr<kp::Sequence> sq = nullptr;
|
||||
|
||||
|
|
@ -112,7 +114,7 @@ TEST(TestPushConstants, TestConstantsWrongSize)
|
|||
pa[2] += pcs.z;
|
||||
})");
|
||||
|
||||
std::vector<uint32_t> spirv = kp::Shader::compileSource(shader);
|
||||
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
|
||||
|
||||
std::shared_ptr<kp::Sequence> sq = nullptr;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
#include "kompute_test/Shader.hpp"
|
||||
|
||||
TEST(TestSequence, SequenceDestructorViaManager)
|
||||
{
|
||||
std::shared_ptr<kp::Sequence> sq = nullptr;
|
||||
|
|
@ -66,7 +68,7 @@ TEST(TestSequence, RerecordSequence)
|
|||
|
||||
sq->eval<kp::OpTensorSyncDevice>({ tensorA, tensorB, tensorOut });
|
||||
|
||||
std::vector<uint32_t> spirv = kp::Shader::compileSource(R"(
|
||||
std::vector<uint32_t> 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<uint32_t> spirv = kp::Shader::compileSource(shader);
|
||||
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
|
||||
|
||||
auto seq = mgr.sequence(0, 100); // 100 timestamps
|
||||
seq->record<kp::OpTensorSyncDevice>({ tensorA })
|
||||
|
|
|
|||
|
|
@ -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<std::pair<std::string, std::string>>({}),
|
||||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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<uint32_t> spirv = kp::Shader::compileSource(shader);
|
||||
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
|
||||
|
||||
std::shared_ptr<kp::Sequence> sq = nullptr;
|
||||
|
||||
|
|
|
|||
|
|
@ -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<uint32_t>
|
||||
Shader::compileSources(
|
||||
|
|
@ -215,4 +216,3 @@ const TBuiltInResource Shader::defaultResource = {
|
|||
};
|
||||
|
||||
}
|
||||
#endif // DKOMPUTE_DISABLE_SHADER_UTILS
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#if !defined(KOMPUTE_DISABLE_SHADER_UTILS) || !KOMPUTE_DISABLE_SHADER_UTILS
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -13,9 +12,7 @@
|
|||
#include <glslang/Include/ResourceLimits.h>
|
||||
#include <glslang/Public/ShaderLang.h>
|
||||
|
||||
#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
|
||||
Loading…
Add table
Add a link
Reference in a new issue