First pass for rewriting the build system
* Refactored all CMake files * Started working on compiling shaders to header files in CMake Signed-off-by: Fabian Sauter <sauter.fabian@mailbox.org>
This commit is contained in:
parent
c6a2b022f9
commit
b95df8d0a0
33 changed files with 559 additions and 2712 deletions
|
|
@ -1,81 +1,42 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
#######################
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
#####################################################
|
||||
#################### GOOGLETEST #####################
|
||||
# Shaders
|
||||
#####################################################
|
||||
enable_testing()
|
||||
|
||||
file(GLOB test_kompute_CPP
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
)
|
||||
|
||||
add_executable(test_kompute ${test_kompute_CPP})
|
||||
|
||||
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>
|
||||
)
|
||||
target_link_libraries(test_kompute kompute GTest::GTest)
|
||||
|
||||
add_test(NAME test_kompute COMMAND test_kompute)
|
||||
|
||||
add_subdirectory(shaders)
|
||||
|
||||
#####################################################
|
||||
#################### CODECOV #######################
|
||||
# Tests
|
||||
#####################################################
|
||||
|
||||
if (KOMPUTE_OPT_CODE_COVERAGE)
|
||||
if(NOT UNIX)
|
||||
message(
|
||||
FATAL_ERROR
|
||||
"KOMPUTE_OPT_CODE_COVERAGE can only be enabled in unix based systems due to limitation on gcov")
|
||||
macro(add_kompute_test _TEST_NAME)
|
||||
add_executable("${_TEST_NAME}_tests" "Test${_TEST_NAME}.cpp"
|
||||
${ARGN})
|
||||
target_link_libraries("${_TEST_NAME}_tests" PRIVATE GTest::GTest
|
||||
kompute::kompute
|
||||
test_shaders
|
||||
test_shaders_glsl)
|
||||
add_test(NAME "kompute_${_TEST_NAME}_tests" COMMAND "${_TEST_NAME}_tests")
|
||||
# Group under the "tests" project folder in IDEs such as Visual Studio.
|
||||
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
|
||||
if(WIN32 AND BUILD_SHARED_LIBS)
|
||||
add_custom_command(TARGET ${_TEST_NAME}_tests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:libcurl> $<TARGET_FILE_DIR:${_TEST_NAME}_tests>)
|
||||
add_custom_command(TARGET ${_TEST_NAME}_tests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:kompute> $<TARGET_FILE_DIR:${_TEST_NAME}_tests>)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
add_custom_target(codecov_run_tests
|
||||
COMMAND make -C ${PROJECT_SOURCE_DIR} mk_run_tests
|
||||
DEPENDS test_kompute)
|
||||
|
||||
add_custom_target(codecov_copy_files
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-E copy_directory
|
||||
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_kompute.dir/
|
||||
${CODECOV_DIR}
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-E copy_directory
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../src/CMakeFiles/kompute.dir/
|
||||
${CODECOV_DIR}
|
||||
DEPENDS test_kompute codecov_run_tests)
|
||||
|
||||
add_custom_target(codecov_gcov
|
||||
COMMAND gcov
|
||||
-b -c "*.gcno"
|
||||
WORKING_DIRECTORY ${CODECOV_DIR}
|
||||
DEPENDS codecov_copy_files)
|
||||
|
||||
add_custom_target(codecov_lcov_capture
|
||||
COMMAND lcov
|
||||
--capture
|
||||
-o ${CODECOV_FILENAME_LCOV_INFO_FULL}
|
||||
-d .
|
||||
WORKING_DIRECTORY ${CODECOV_DIR}
|
||||
DEPENDS codecov_gcov)
|
||||
add_custom_target(codecov_lcov_extract
|
||||
COMMAND lcov
|
||||
--extract
|
||||
${CODECOV_FILENAME_LCOV_INFO_FULL}
|
||||
-o ${CODECOV_FILENAME_LCOV_INFO}
|
||||
-d .
|
||||
"*/src/*"
|
||||
WORKING_DIRECTORY ${CODECOV_DIR}
|
||||
DEPENDS codecov_lcov_capture)
|
||||
|
||||
add_custom_target(codecov_genhtml
|
||||
COMMAND genhtml
|
||||
${CODECOV_FILENAME_LCOV_INFO}
|
||||
--output-directory ${CODECOV_DIR_HTML}
|
||||
WORKING_DIRECTORY ${CODECOV_DIR}
|
||||
DEPENDS codecov_lcov_extract)
|
||||
endif()
|
||||
|
||||
add_kompute_test(AsyncOperations)
|
||||
add_kompute_test(Destroy)
|
||||
add_kompute_test(LogisticRegression)
|
||||
add_kompute_test(Main)
|
||||
add_kompute_test(Manager)
|
||||
add_kompute_test(MultipleAlgoExecutions)
|
||||
add_kompute_test(OpShadersFromStringAndFile)
|
||||
add_kompute_test(OpTensorCopy)
|
||||
add_kompute_test(OpTensorCreate)
|
||||
add_kompute_test(PushConstant)
|
||||
add_kompute_test(Sequence)
|
||||
add_kompute_test(SpecializationConstant)
|
||||
add_kompute_test(Workgroup)
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
#include "kompute_test/Shader.hpp"
|
||||
|
||||
TEST(TestAsyncOperations, TestManagerParallelExecution)
|
||||
{
|
||||
// This test is built for NVIDIA 1650. It assumes:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
#include "kompute_test/Shader.hpp"
|
||||
#include "shaders/Utils.hpp"
|
||||
|
||||
TEST(TestDestroy, TestDestroyTensorSingle)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
#include "kompute_test/shaders/shadertest_logistic_regression.hpp"
|
||||
#include "test_logistic_regression.hpp"
|
||||
|
||||
TEST(TestLogisticRegression, TestMainLogisticRegression)
|
||||
{
|
||||
|
|
@ -40,12 +40,11 @@ TEST(TestLogisticRegression, TestMainLogisticRegression)
|
|||
mgr.sequence()->eval<kp::OpTensorSyncDevice>(params);
|
||||
|
||||
std::vector<uint32_t> spirv = std::vector<uint32_t>(
|
||||
(uint32_t*)kp::shader_data::
|
||||
test_shaders_glsl_test_logistic_regression_comp_spv,
|
||||
(uint32_t*)(kp::shader_data::
|
||||
test_shaders_glsl_test_logistic_regression_comp_spv +
|
||||
kp::shader_data::
|
||||
test_shaders_glsl_test_logistic_regression_comp_spv_len));
|
||||
(const uint32_t*)kp::TEST_LOGISTIC_REGRESSION_COMP_SPV.data(),
|
||||
(const uint32_t*)(kp::shader_data::
|
||||
test_shaders_glsl_test_logistic_regression_comp_spv +
|
||||
kp::shader_data::
|
||||
test_shaders_glsl_test_logistic_regression_comp_spv_len));
|
||||
|
||||
std::shared_ptr<kp::Algorithm> algorithm = mgr.algorithm(
|
||||
params, spirv, kp::Workgroup({ 5 }), std::vector<float>({ 5.0 }));
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
#include "kompute_test/Shader.hpp"
|
||||
#include "shaders/Utils.hpp"
|
||||
|
||||
TEST(TestMultipleAlgoExecutions, TestEndToEndFunctionality)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "kompute_test/shaders/shadertest_op_custom_shader.hpp"
|
||||
|
||||
#include "kompute_test/Shader.hpp"
|
||||
#include "shaders/Utils.hpp"
|
||||
|
||||
TEST(TestOpAlgoCreate, ShaderRawDataFromConstructor)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
#include "kompute_test/Shader.hpp"
|
||||
#include "shaders/Utils.hpp"
|
||||
|
||||
TEST(TestOpTensorCopy, CopyDeviceToDeviceTensor)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
#include "kompute_test/Shader.hpp"
|
||||
#include "shaders/Utils.hpp"
|
||||
|
||||
#include "fmt/ranges.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
#include "kompute_test/Shader.hpp"
|
||||
#include "shaders/Utils.hpp"
|
||||
|
||||
TEST(TestSequence, SequenceDestructorViaManager)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
#include "kompute_test/Shader.hpp"
|
||||
#include "shaders/Utils.hpp"
|
||||
|
||||
TEST(TestSpecializationConstants, TestTwoConstants)
|
||||
{
|
||||
|
|
|
|||
8
test/shaders/CMakeLists.txt
Normal file
8
test/shaders/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
#######################
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
add_library(test_shaders "Utils.cpp"
|
||||
"Utils.hpp")
|
||||
|
||||
add_subdirectory(glsl)
|
||||
|
|
@ -1,21 +1,13 @@
|
|||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Utils.hpp"
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* 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/KomputeProject/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<uint32_t>
|
||||
std::vector<uint32_t>
|
||||
compileSource(const std::string& source)
|
||||
{
|
||||
std::ofstream fileOut("tmp_kp_shader.comp");
|
||||
|
|
@ -24,12 +16,13 @@ compileSource(const std::string& source)
|
|||
if (system(
|
||||
std::string(
|
||||
"glslangValidator -V tmp_kp_shader.comp -o tmp_kp_shader.comp.spv")
|
||||
.c_str()))
|
||||
.c_str())) {
|
||||
throw std::runtime_error("Error running glslangValidator command");
|
||||
}
|
||||
std::ifstream fileStream("tmp_kp_shader.comp.spv", std::ios::binary);
|
||||
std::vector<char> buffer;
|
||||
buffer.insert(
|
||||
buffer.begin(), std::istreambuf_iterator<char>(fileStream), {});
|
||||
return { (uint32_t*)buffer.data(),
|
||||
(uint32_t*)(buffer.data() + buffer.size()) };
|
||||
return { reinterpret_cast<uint32_t*>(buffer.data()),
|
||||
reinterpret_cast<uint32_t*>(buffer.data() + buffer.size()) };
|
||||
}
|
||||
19
test/shaders/Utils.hpp
Normal file
19
test/shaders/Utils.hpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* 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/KomputeProject/kompute/pull/235
|
||||
*
|
||||
* @param source An individual raw glsl shader in string format
|
||||
* @return The compiled SPIR-V binary in unsigned int32 format
|
||||
*/
|
||||
std::vector<uint32_t>
|
||||
compileSource(const std::string& source);
|
||||
22
test/shaders/glsl/CMakeLists.txt
Normal file
22
test/shaders/glsl/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
#######################
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
vulkan_compile_shader(INFILE test_logistic_regression.comp
|
||||
OUTFILE test_logistic_regression.hpp
|
||||
NAMESPACE "kp")
|
||||
|
||||
vulkan_compile_shader(INFILE test_op_custom_shader.comp
|
||||
OUTFILE test_op_custom_shader.hpp
|
||||
NAMESPACE "kp")
|
||||
|
||||
vulkan_compile_shader(INFILE test_workgroup.comp
|
||||
OUTFILE test_workgroup.hpp
|
||||
NAMESPACE "kp")
|
||||
|
||||
add_library(test_shaders_glsl "${CMAKE_CURRENT_BINARY_DIR}/test_logistic_regression.hpp"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/test_op_custom_shader.hpp"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/test_workgroup.hpp")
|
||||
|
||||
set_target_properties(test_shaders_glsl PROPERTIES LINKER_LANGUAGE CXX)
|
||||
target_include_directories(test_shaders_glsl PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue