mirror of
https://github.com/nomic-ai/kompute.git
synced 2026-04-22 16:08:52 +00:00
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:
169
CMakeLists.txt
169
CMakeLists.txt
@@ -1,51 +1,103 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.4.1)
|
||||
project(kompute VERSION 0.8.1)
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
project(kompute VERSION 1.8.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(CMAKE_VERBOSE_MAKEFILE on)
|
||||
# Only change the folder behaviour if kompute is not a subproject
|
||||
if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake")
|
||||
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
|
||||
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
|
||||
endif()
|
||||
|
||||
# Avoid the dll boilerplate code for windows
|
||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")
|
||||
|
||||
set(KOMPUTE_LIBRARIES kompute CACHE INTERNAL "")
|
||||
|
||||
#####################################################
|
||||
# Options
|
||||
#####################################################
|
||||
|
||||
macro(kompute_option OPTION_NAME OPTION_TEXT OPTION_DEFAULT)
|
||||
option(${OPTION_NAME} ${OPTION_TEXT} ${OPTION_DEFAULT})
|
||||
if(DEFINED ENV{${OPTION_NAME}})
|
||||
# Allow overriding the option through an environment variable
|
||||
set(${OPTION_NAME} $ENV{${OPTION_NAME}})
|
||||
endif()
|
||||
if(${OPTION_NAME})
|
||||
add_definitions(-D${OPTION_NAME})
|
||||
endif()
|
||||
message(STATUS " ${OPTION_NAME}: ${${OPTION_NAME}}")
|
||||
endmacro()
|
||||
|
||||
macro(kompute_log_level OPTION_NAME OPTION_TEXT OPTION_DEFAULT)
|
||||
set(${OPTION_NAME} ${OPTION_DEFAULT} CACHE STRING ${OPTION_TEXT})
|
||||
set_property(CACHE ${OPTION_NAME} PROPERTY STRINGS "Trace" "Debug" "Info" "Warn" "Error" "Critical")
|
||||
if(DEFINED ENV{${OPTION_NAME}})
|
||||
# Allow setting the option through an environment variable
|
||||
set(${OPTION_NAME} $ENV{${OPTION_NAME}})
|
||||
endif()
|
||||
if(${OPTION_NAME})
|
||||
add_definitions(-D${OPTION_NAME})
|
||||
endif()
|
||||
message(STATUS " ${OPTION_NAME}: ${${OPTION_NAME}}")
|
||||
endmacro()
|
||||
|
||||
macro(kompute_option_string OPTION_NAME OPTION_TEXT OPTION_DEFAULT)
|
||||
set(${OPTION_NAME} ${OPTION_DEFAULT} CACHE STRING ${OPTION_TEXT})
|
||||
if(DEFINED ENV{${OPTION_NAME}})
|
||||
# Allow setting the option through an environment variable
|
||||
set(${OPTION_NAME} $ENV{${OPTION_NAME}})
|
||||
endif()
|
||||
if(${OPTION_NAME})
|
||||
add_definitions(-D${OPTION_NAME})
|
||||
endif()
|
||||
message(STATUS " ${OPTION_NAME}: ${${OPTION_NAME}}")
|
||||
endmacro()
|
||||
|
||||
option(BUILD_SHARED_LIBS "Build libraries as shared libraries" ON)
|
||||
message(STATUS "General purpose GPU compute framework built on Vulkan")
|
||||
message(STATUS "=======================================================")
|
||||
# Enable or disable targets
|
||||
option(KOMPUTE_OPT_BUILD_TESTS "Enable if you want to build tests" OFF)
|
||||
option(KOMPUTE_OPT_CODE_COVERAGE "Enable if you want code coverage" OFF)
|
||||
option(KOMPUTE_OPT_BUILD_DOCS "Enable if you want to build documentation" OFF)
|
||||
option(KOMPUTE_OPT_BUILD_SHADERS "Enable if you want to re-build all shader files" OFF)
|
||||
option(KOMPUTE_OPT_BUILD_SINGLE_HEADER "Enable if you want to build the single header file" OFF)
|
||||
option(KOMPUTE_OPT_INSTALL "Enable if you want to enable installation" OFF)
|
||||
kompute_option(KOMPUTE_OPT_BUILD_TESTS "Enable if you want to build tests" ON)
|
||||
kompute_option(KOMPUTE_OPT_CODE_COVERAGE "Enable if you want code coverage" OFF)
|
||||
kompute_option(KOMPUTE_OPT_BUILD_DOCS "Enable if you want to build documentation" OFF)
|
||||
kompute_option(KOMPUTE_OPT_INSTALL "Enable if you want to enable installation" OFF)
|
||||
|
||||
# Build options
|
||||
option(KOMPUTE_OPT_BUILD_PYTHON "Enable if you want to build python bindings" OFF)
|
||||
option(KOMPUTE_OPT_ENABLE_SPDLOG "Enable to compile with spdlog as the internal logging framework" OFF)
|
||||
option(KOMPUTE_OPT_ANDROID_BUILD "Enable android compilation flags required" OFF)
|
||||
option(KOMPUTE_OPT_DISABLE_VK_DEBUG_LAYERS "Explicitly disable debug layers even on debug" OFF)
|
||||
option(KOMPUTE_OPT_DEPENDENCIES_SHARED_LIBS "Whether to use shared libraries for dependencies for install" OFF)
|
||||
option(KOMPUTE_OPT_BUILD_AS_SHARED_LIB "Whether to build kompute as shared library" OFF)
|
||||
option(KOMPUTE_OPT_DISABLE_VULKAN_VERSION_CHECK "Whether to check if your driver supports the Vulkan Header version you are linking against. This might be useful in case you build shared on a different system than you run later." OFF)
|
||||
kompute_option(KOMPUTE_OPT_BUILD_PYTHON "Enable if you want to build python bindings" OFF)
|
||||
kompute_option(KOMPUTE_OPT_ENABLE_LOGGING "Internally we use spdlog for logging. The log output can be either enabled or disabled." OFF)
|
||||
kompute_log_level(KOMPUTE_OPT_LOG_LEVEL "Internally we use spdlog for logging. The log level used can be changed here." "Debug")
|
||||
kompute_option(KOMPUTE_OPT_ANDROID_BUILD "Enable android compilation flags required" OFF)
|
||||
kompute_option(KOMPUTE_OPT_DISABLE_VK_DEBUG_LAYERS "Explicitly disable debug layers even on debug" OFF)
|
||||
kompute_option(KOMPUTE_OPT_DISABLE_VULKAN_VERSION_CHECK "Whether to check if your driver supports the Vulkan Header version you are linking against. This might be useful in case you build shared on a different system than you run later." OFF)
|
||||
|
||||
# External komponents
|
||||
# External components
|
||||
option(KOMPUTE_OPT_USE_BUILD_IN_SPDLOG "Use the build in version of Spdlog" ON)
|
||||
option(KOMPUTE_OPT_USE_BUILD_IN_FMT "Use the build in version of fmt" ON)
|
||||
option(KOMPUTE_OPT_USE_BUILD_IN_GOOGLE_TEST "Use the build in version of GoogleTest" ON)
|
||||
option(KOMPUTE_OPT_USE_BUILD_IN_PYBIND11 "Use the build in version of pybind11" ON)
|
||||
option(KOMPUTE_OPT_USE_BUILD_IN_VULKAN_HEADER "Use the build in version of Vulkan Headers. This could be helpful in case your system Vulkan Headers are to new for your driver. If you set this to false, please make sure your system Vulkan Header are supported by your driver." ON)
|
||||
set(KOMPUTE_OPT_BUILD_IN_VULKAN_HEADER_TAG "v1.2.203" CACHE STRING "The git tag used for the build in Vulkan Headers when 'KOMPUTE_OPT_USE_BUILD_IN_VULKAN_HEADER' is enabled. A list of tags can be found here: https://github.com/KhronosGroup/Vulkan-Headers/tags")
|
||||
|
||||
# Build flags
|
||||
set(KOMPUTE_EXTRA_CXX_FLAGS "" CACHE STRING "Extra compile flags for Kompute, see docs for full list")
|
||||
kompute_option_string(KOMPUTE_OPT_BUILD_IN_VULKAN_HEADER_TAG "The git tag used for the build in Vulkan Headers when 'KOMPUTE_OPT_USE_BUILD_IN_VULKAN_HEADER' is enabled. A list of tags can be found here: https://github.com/KhronosGroup/Vulkan-Headers/tags" "v1.2.203")
|
||||
message(STATUS "=======================================================")
|
||||
|
||||
#####################################################
|
||||
#################### Deprecated Options #############
|
||||
# Deprecated Options
|
||||
#####################################################
|
||||
if(KOMPUTE_OPT_REPO_SUBMODULE_BUILD)
|
||||
message(FATAL_ERROR "'KOMPUTE_OPT_REPO_SUBMODULE_BUILD' got replaced by 'KOMPUTE_OPT_USE_BUILD_IN_SPDLOG', 'KOMPUTE_OPT_USE_BUILD_IN_FMT', 'KOMPUTE_OPT_USE_BUILD_IN_GOOGLE_TEST', 'KOMPUTE_OPT_USE_BUILD_IN_PYBIND11' and 'KOMPUTE_OPT_USE_BUILD_IN_VULKAN_HEADER'. Please use them instead.")
|
||||
endif()
|
||||
include(cmake/deprecation_warnings.cmake)
|
||||
|
||||
#####################################################
|
||||
#################### Dependencies ###################
|
||||
# Dependencies
|
||||
#####################################################
|
||||
include(cmake/vulkan_shader_compiler.cmake)
|
||||
include(FetchContent)
|
||||
include(cmake/check_vulkan_version.cmake)
|
||||
|
||||
@@ -72,16 +124,18 @@ else()
|
||||
endif()
|
||||
|
||||
# Spdlog
|
||||
if(KOMPUTE_OPT_ENABLE_SPDLOG)
|
||||
if(KOMPUTE_OPT_USE_BUILD_IN_SPDLOG)
|
||||
set(SPDLOG_INSTALL ${KOMPUTE_OPT_INSTALL})
|
||||
set(SPDLOG_BUILD_SHARED ${KOMPUTE_OPT_DEPENDENCIES_SHARED_LIBS})
|
||||
if(KOMPUTE_OPT_ENABLE_LOGGING)
|
||||
if(KOMPUTE_OPT_ENABLE_SPDLOG)
|
||||
if(KOMPUTE_OPT_USE_BUILD_IN_SPDLOG)
|
||||
set(SPDLOG_INSTALL ${KOMPUTE_OPT_INSTALL})
|
||||
set(SPDLOG_BUILD_SHARED ${KOMPUTE_OPT_DEPENDENCIES_SHARED_LIBS})
|
||||
|
||||
FetchContent_Declare(spdlog GIT_REPOSITORY https://github.com/gabime/spdlog.git
|
||||
GIT_TAG v1.10.0) # Source: https://github.com/gabime/spdlog/releases
|
||||
FetchContent_MakeAvailable(spdlog)
|
||||
else()
|
||||
find_package(spdlog REQUIRED)
|
||||
FetchContent_Declare(spdlog GIT_REPOSITORY https://github.com/gabime/spdlog.git
|
||||
GIT_TAG v1.10.0) # Source: https://github.com/gabime/spdlog/releases
|
||||
FetchContent_MakeAvailable(spdlog)
|
||||
else()
|
||||
find_package(spdlog REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -132,48 +186,43 @@ if(KOMPUTE_OPT_BUILD_PYTHON)
|
||||
endif()
|
||||
|
||||
#####################################################
|
||||
#################### Other Options ##################
|
||||
# Preprocessor Macros
|
||||
#####################################################
|
||||
|
||||
if(KOMPUTE_OPT_ANDROID_BUILD)
|
||||
set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DVK_USE_PLATFORM_ANDROID_KHR")
|
||||
add_compile_definitions(VK_USE_PLATFORM_ANDROID_KHR=1)
|
||||
endif()
|
||||
|
||||
if(KOMPUTE_OPT_BUILD_PYTHON)
|
||||
set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DKOMPUTE_BUILD_PYTHON")
|
||||
add_compile_definitions(KOMPUTE_BUILD_PYTHON=1)
|
||||
endif()
|
||||
|
||||
if(KOMPUTE_OPT_DISABLE_VK_DEBUG_LAYERS)
|
||||
set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DKOMPUTE_DISABLE_VK_DEBUG_LAYERS=1")
|
||||
add_compile_definitions(KOMPUTE_DISABLE_VK_DEBUG_LAYERS=1)
|
||||
endif()
|
||||
|
||||
if(KOMPUTE_OPT_ENABLE_LOGGING)
|
||||
add_compile_definitions(KOMPUTE_OPT_ENABLE_LOGGING=1)
|
||||
endif()
|
||||
|
||||
#####################################################
|
||||
# Misc Options
|
||||
#####################################################
|
||||
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()
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG=1 ${KOMPUTE_EXTRA_CXX_FLAGS} -DUSE_DEBUG_EXTENTIONS")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DRELEASE=1 ${KOMPUTE_EXTRA_CXX_FLAGS}")
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Werror")
|
||||
endif()
|
||||
|
||||
if(KOMPUTE_OPT_CODE_COVERAGE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage --coverage")
|
||||
|
||||
set(CODECOV_DIR
|
||||
${CMAKE_CURRENT_BINARY_DIR}/codecov/)
|
||||
set(CODECOV_DIR_LCOV
|
||||
${CODECOV_DIR}lcov/)
|
||||
set(CODECOV_FILENAME_LCOV_INFO
|
||||
lcov.info)
|
||||
set(CODECOV_FILENAME_LCOV_INFO_FULL
|
||||
lcov_full.info)
|
||||
set(CODECOV_DIR_HTML
|
||||
${CODECOV_DIR}html/)
|
||||
if(NOT UNIX)
|
||||
message(FATAL_ERROR "KOMPUTE_OPT_CODE_COVERAGE can only be enabled in unix based systems due to limitation on gcov.")
|
||||
endif()
|
||||
include(cmake/code_coverage.cmake)
|
||||
endif()
|
||||
|
||||
# If glslang is cloned, then SPIRV/GlslangToSpv.h will be used instead of glslang/SPIRV/GlslangToSpv.h
|
||||
|
||||
4
Makefile
4
Makefile
@@ -63,7 +63,6 @@ mk_cmake:
|
||||
-DKOMPUTE_OPT_BUILD_TESTS=1 \
|
||||
-DKOMPUTE_OPT_BUILD_DOCS=1 \
|
||||
-DKOMPUTE_OPT_BUILD_SHADERS=1 \
|
||||
-DKOMPUTE_OPT_BUILD_SINGLE_HEADER=1 \
|
||||
-DKOMPUTE_OPT_ENABLE_SPDLOG=1 \
|
||||
-DKOMPUTE_OPT_CODE_COVERAGE=1 \
|
||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
||||
@@ -116,7 +115,6 @@ vs_cmake:
|
||||
-DKOMPUTE_OPT_INSTALL=1 \
|
||||
-DKOMPUTE_OPT_BUILD_TESTS=1 \
|
||||
-DKOMPUTE_OPT_BUILD_SHADERS=1 \
|
||||
-DKOMPUTE_OPT_BUILD_SINGLE_HEADER=1 \
|
||||
-DKOMPUTE_OPT_ENABLE_SPDLOG=1 \
|
||||
-DKOMPUTE_OPT_CODE_COVERAGE=0 \
|
||||
-DKOMPUTE_OPT_BUILD_DOCS=0 \
|
||||
@@ -161,7 +159,7 @@ run_ci:
|
||||
generate_python_docstrings:
|
||||
python -m pybind11_mkdoc \
|
||||
-o python/src/docstrings.hpp \
|
||||
single_include/kompute/Kompute.hpp \
|
||||
kompute/Kompute.hpp \
|
||||
-Iexternal/fmt/include/ \
|
||||
-Iexternal/spdlog/include/ \
|
||||
-Iexternal/glslang/ \
|
||||
|
||||
98
cmake/bin2h.cmake
Normal file
98
cmake/bin2h.cmake
Normal file
@@ -0,0 +1,98 @@
|
||||
##################################################################################
|
||||
# Based on: https://github.com/sivachandran/cmake-bin2h
|
||||
#
|
||||
# Copyright 2020 Sivachandran Paramasivam
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
##################################################################################
|
||||
|
||||
include(CMakeParseArguments)
|
||||
|
||||
# Function to wrap a given string into multiple lines at the given column position.
|
||||
# Parameters:
|
||||
# VARIABLE - The name of the CMake variable holding the string.
|
||||
# AT_COLUMN - The column position at which string will be wrapped.
|
||||
function(WRAP_STRING)
|
||||
set(oneValueArgs VARIABLE AT_COLUMN)
|
||||
cmake_parse_arguments(WRAP_STRING "${options}" "${oneValueArgs}" "" ${ARGN})
|
||||
|
||||
string(LENGTH ${${WRAP_STRING_VARIABLE}} stringLength)
|
||||
math(EXPR offset "0")
|
||||
|
||||
while(stringLength GREATER 0)
|
||||
|
||||
if(stringLength GREATER ${WRAP_STRING_AT_COLUMN})
|
||||
math(EXPR length "${WRAP_STRING_AT_COLUMN}")
|
||||
else()
|
||||
math(EXPR length "${stringLength}")
|
||||
endif()
|
||||
|
||||
string(SUBSTRING ${${WRAP_STRING_VARIABLE}} ${offset} ${length} line)
|
||||
set(lines "${lines}\n${line}")
|
||||
|
||||
math(EXPR stringLength "${stringLength} - ${length}")
|
||||
math(EXPR offset "${offset} + ${length}")
|
||||
endwhile()
|
||||
|
||||
set(${WRAP_STRING_VARIABLE} "${lines}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Function to embed contents of a file as byte array in C/C++ header file(.h). The header file
|
||||
# will contain a byte array and integer variable holding the size of the array.
|
||||
# Parameters
|
||||
# SOURCE_FILE - The path of source file whose contents will be embedded in the header file.
|
||||
# VARIABLE_NAME - The name of the variable for the byte array. The string "_SIZE" will be append
|
||||
# to this name and will be used a variable name for size variable.
|
||||
# HEADER_FILE - The path of header file.
|
||||
# APPEND - If specified appends to the header file instead of overwriting it
|
||||
# NULL_TERMINATE - If specified a null byte(zero) will be append to the byte array. This will be
|
||||
# useful if the source file is a text file and we want to use the file contents
|
||||
# as string. But the size variable holds size of the byte array without this
|
||||
# null byte.
|
||||
# HEADER_NAMESPACE - The namespace, where the array should be located in.
|
||||
# Usage:
|
||||
# bin2h(SOURCE_FILE "Logo.png" HEADER_FILE "Logo.h" VARIABLE_NAME "LOGO_PNG")
|
||||
function(BIN2H)
|
||||
set(options APPEND NULL_TERMINATE)
|
||||
set(oneValueArgs SOURCE_FILE VARIABLE_NAME HEADER_FILE)
|
||||
cmake_parse_arguments(BIN2H "${options}" "${oneValueArgs}" "" ${ARGN})
|
||||
|
||||
# reads source file contents as hex string
|
||||
file(READ ${BIN2H_SOURCE_FILE} hexString HEX)
|
||||
string(LENGTH ${hexString} hexStringLength)
|
||||
|
||||
# appends null byte if asked
|
||||
if(BIN2H_NULL_TERMINATE)
|
||||
set(hexString "${hexString}00")
|
||||
endif()
|
||||
|
||||
# wraps the hex string into multiple lines at column 32(i.e. 16 bytes per line)
|
||||
wrap_string(VARIABLE hexString AT_COLUMN 32)
|
||||
math(EXPR arraySize "${hexStringLength} / 2")
|
||||
|
||||
# adds '0x' prefix and comma suffix before and after every byte respectively
|
||||
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1, " arrayValues ${hexString})
|
||||
# removes trailing comma
|
||||
string(REGEX REPLACE ", $" "" arrayValues ${arrayValues})
|
||||
|
||||
# converts the variable name into proper C identifier
|
||||
string(MAKE_C_IDENTIFIER "${BIN2H_VARIABLE_NAME}" BIN2H_VARIABLE_NAME)
|
||||
string(TOUPPER "${BIN2H_VARIABLE_NAME}" BIN2H_VARIABLE_NAME)
|
||||
|
||||
# declares byte array and the length variables
|
||||
set(namespaceStart "namespace ${HEADER_NAMESPACE} {")
|
||||
set(namespaceEnd "} // ${HEADER_NAMESPACE}")
|
||||
set(arrayIncludes "#pragma once\n#include <array>\n#include <cstdint>")
|
||||
set(arrayDefinition "const std::array<uint8_t, ${arraySize}> ${BIN2H_VARIABLE_NAME} = { ${arrayValues} };")
|
||||
|
||||
set(declarations "${arrayIncludes}\n\n${namespaceStart}\n${arrayDefinition}\n${namespaceEnd}\n\n")
|
||||
if(BIN2H_APPEND)
|
||||
file(APPEND ${BIN2H_HEADER_FILE} "${declarations}")
|
||||
else()
|
||||
file(WRITE ${BIN2H_HEADER_FILE} "${declarations}")
|
||||
endif()
|
||||
endfunction()
|
||||
19
cmake/bin_file_to_header.cmake
Normal file
19
cmake/bin_file_to_header.cmake
Normal file
@@ -0,0 +1,19 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
if(${INPUT_SHADER_FILE} STREQUAL "")
|
||||
message(FATAL_ERROR "No input file path provided via 'INPUT_SHADER_FILE'.")
|
||||
endif()
|
||||
|
||||
if(${OUTPUT_HEADER_FILE} STREQUAL "")
|
||||
message(FATAL_ERROR "No output file path provided via 'OUTPUT_HEADER_FILE'.")
|
||||
endif()
|
||||
|
||||
if(${HEADER_NAMESPACE} STREQUAL "")
|
||||
message(FATAL_ERROR "No header namespace provided via 'HEADER_NAMESPACE'.")
|
||||
endif()
|
||||
|
||||
include(bin2h.cmake)
|
||||
|
||||
get_filename_component(BINARY_FILE_CONTENT ${INPUT_SHADER_FILE} NAME)
|
||||
bin2h(SOURCE_FILE ${INPUT_SHADER_FILE} HEADER_FILE ${OUTPUT_HEADER_FILE} VARIABLE_NAME ${BINARY_FILE_CONTENT} HEADER_NAMESPACE ${HEADER_NAMESPACE})
|
||||
file(APPEND ${OUTPUT_HEADER_FILE} "\n")
|
||||
34
cmake/code_coverage.cmake
Normal file
34
cmake/code_coverage.cmake
Normal file
@@ -0,0 +1,34 @@
|
||||
# Code coverage
|
||||
set(CMAKE_BUILD_TYPE COVERAGE CACHE INTERNAL "Coverage build enabled")
|
||||
message(STATUS "Enabling gcov support")
|
||||
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
set(COVERAGE_FLAG "--coverage")
|
||||
endif()
|
||||
set(CMAKE_CXX_FLAGS_COVERAGE
|
||||
"-g -O0 ${COVERAGE_FLAG} -fprofile-arcs -ftest-coverage"
|
||||
CACHE STRING "Flags used by the C++ compiler during coverage builds."
|
||||
FORCE)
|
||||
set(CMAKE_C_FLAGS_COVERAGE
|
||||
"-g -O0 ${COVERAGE_FLAG} -fprofile-arcs -ftest-coverage"
|
||||
CACHE STRING "Flags used by the C compiler during coverage builds."
|
||||
FORCE)
|
||||
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
|
||||
""
|
||||
CACHE STRING "Flags used for linking binaries during coverage builds."
|
||||
FORCE)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
|
||||
""
|
||||
CACHE STRING "Flags used by the shared libraries linker during coverage builds."
|
||||
FORCE)
|
||||
|
||||
set(CODECOV_DIR ${CMAKE_CURRENT_BINARY_DIR}/codecov/)
|
||||
set(CODECOV_DIR_LCOV ${CODECOV_DIR}lcov/)
|
||||
set(CODECOV_FILENAME_LCOV_INFO lcov.info)
|
||||
set(CODECOV_FILENAME_LCOV_INFO_FULL lcov_full.info)
|
||||
set(CODECOV_DIR_HTML ${CODECOV_DIR}html/)
|
||||
|
||||
mark_as_advanced(CMAKE_CXX_FLAGS_COVERAGE
|
||||
CMAKE_C_FLAGS_COVERAGE
|
||||
CMAKE_EXE_LINKER_FLAGS_COVERAGE
|
||||
CMAKE_SHARED_LINKER_FLAGS_COVERAGE)
|
||||
endif()
|
||||
3
cmake/deprecation_warnings.cmake
Normal file
3
cmake/deprecation_warnings.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
if(KOMPUTE_OPT_REPO_SUBMODULE_BUILD)
|
||||
message(FATAL_ERROR "'KOMPUTE_OPT_REPO_SUBMODULE_BUILD' got replaced by 'KOMPUTE_OPT_USE_BUILD_IN_SPDLOG', 'KOMPUTE_OPT_USE_BUILD_IN_FMT', 'KOMPUTE_OPT_USE_BUILD_IN_GOOGLE_TEST', 'KOMPUTE_OPT_USE_BUILD_IN_PYBIND11' and 'KOMPUTE_OPT_USE_BUILD_IN_VULKAN_HEADER'. Please use them instead.")
|
||||
endif()
|
||||
8
cmake/komputeConfig.cmake.in
Normal file
8
cmake/komputeConfig.cmake.in
Normal file
@@ -0,0 +1,8 @@
|
||||
include(CMakeFindDependencyMacro)
|
||||
@PACKAGE_INIT@
|
||||
|
||||
find_dependency(VULKAN REQUIRED)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/komputeTargets.cmake)
|
||||
|
||||
check_required_components(kompute)
|
||||
36
cmake/vulkan_shader_compiler.cmake
Normal file
36
cmake/vulkan_shader_compiler.cmake
Normal file
@@ -0,0 +1,36 @@
|
||||
function(vulkan_compile_shader)
|
||||
find_program(GLS_LANG_VALIDATOR_PATH NAMES glslangValidator)
|
||||
if(${GLS_LANG_VALIDATOR_PATH})
|
||||
message(FATAL_ERROR "glslangValidator not found.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
cmake_parse_arguments(SHADER_COMPILE "" "INFILE;OUTFILE;NAMESPACE" "" ${ARGN})
|
||||
set(SHADER_COMPILE_INFILE_FULL "${CMAKE_CURRENT_SOURCE_DIR}/${SHADER_COMPILE_INFILE}")
|
||||
set(SHADER_COMPILE_SPV_FILE_FULL "${CMAKE_CURRENT_BINARY_DIR}/${SHADER_COMPILE_INFILE}.spv")
|
||||
set(SHADER_COMPILE_HEADER_FILE_FULL "${CMAKE_CURRENT_BINARY_DIR}/${SHADER_COMPILE_OUTFILE}")
|
||||
|
||||
# .comp -> .spv
|
||||
add_custom_command(OUTPUT "${SHADER_COMPILE_SPV_FILE_FULL}"
|
||||
COMMAND "${GLS_LANG_VALIDATOR_PATH}"
|
||||
ARGS "-V"
|
||||
"-o"
|
||||
"${SHADER_COMPILE_SPV_FILE_FULL}"
|
||||
"--target-env"
|
||||
"vulkan1.2"
|
||||
"${SHADER_COMPILE_INFILE_FULL}"
|
||||
COMMENT "Compile vulkan compute shader from file '${SHADER_COMPILE_INFILE_FULL}' to '${SHADER_COMPILE_SPV_FILE_FULL}'."
|
||||
MAIN_DEPENDENCY "${SHADER_COMPILE_INFILE_FULL}")
|
||||
|
||||
# .spv -> .hpp
|
||||
add_custom_command(OUTPUT "${SHADER_COMPILE_HEADER_FILE_FULL}"
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
ARGS "-DINPUT_SHADER_FILE=${SHADER_COMPILE_SPV_FILE_FULL}"
|
||||
"-DOUTPUT_HEADER_FILE=${SHADER_COMPILE_HEADER_FILE_FULL}"
|
||||
"-DHEADER_NAMESPACE=${SHADER_COMPILE_NAMESPACE}"
|
||||
"-P"
|
||||
"${CMAKE_SOURCE_DIR}/cmake/bin_file_to_header.cmake"
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/cmake"
|
||||
COMMENT "Converting compiled shader '${SHADER_COMPILE_SPV_FILE_FULL}' to header file '${SHADER_COMPILE_HEADER_FILE_FULL}'."
|
||||
MAIN_DEPENDENCY "${SHADER_COMPILE_SPV_FILE_FULL}")
|
||||
endfunction()
|
||||
@@ -28,8 +28,6 @@ This by default configures without any of the extra build tasks (such as buildin
|
||||
* - -DKOMPUTE_OPT_BUILD_DOCS=ON
|
||||
- Enable if you wish to build the docs (must have docs deps installed)
|
||||
* - -DKOMPUTE_OPT_BUILD_SHADERS=ON
|
||||
- Enable if you wish to build the shaders into header files (must have docs deps installed)
|
||||
* - -DKOMPUTE_OPT_BUILD_SINGLE_HEADER=ON
|
||||
- Option to build the single header file using "quom" utility
|
||||
* - -DKOMPUTE_OPT_INSTALL=OFF
|
||||
- Disables the install step in the cmake file (useful for android build)
|
||||
|
||||
@@ -20,7 +20,6 @@ android {
|
||||
'-DKOMPUTE_OPT_ANDROID_BUILD=1',
|
||||
'-DKOMPUTE_OPT_INSTALL=0',
|
||||
'-DKOMPUTE_OPT_ENABLE_SPDLOG=0',
|
||||
'-DKOMPUTE_OPT_BUILD_SINGLE_HEADER=0',
|
||||
'-DKOMPUTE_OPT_DISABLE_VK_DEBUG_LAYERS=1',
|
||||
'-DKOMPUTE_EXTRA_CXX_FLAGS=-DKOMPUTE_VK_API_MINOR_VERSION=0'
|
||||
}
|
||||
|
||||
28
kompute-config.cmake
Normal file
28
kompute-config.cmake
Normal file
@@ -0,0 +1,28 @@
|
||||
# General purpose GPU compute framework built on Vulkan to
|
||||
# support 1000s of cross vendor graphics cards
|
||||
# (AMD, Qualcomm, NVIDIA & friends). Blazing fast, mobile-enabled,
|
||||
# asynchronous and optimized for advanced GPU data processing use cases.
|
||||
# Backed by the Linux Foundation.
|
||||
#
|
||||
# Finding this module will define the following variables:
|
||||
# KOMPUTE_FOUND - True if the core library has been found
|
||||
# KOMPUTE_LIBRARIES - Path to the core library archive
|
||||
# KOMPUTE_INCLUDE_DIRS - Path to the include directories. Gives access
|
||||
# to kompute.h, as a single include which must be included in every
|
||||
# file that uses this interface. Else it also points to the
|
||||
# directory for individual includes.
|
||||
|
||||
find_path(KOMPUTE_INCLUDE_DIR
|
||||
NAMES kompute.h)
|
||||
|
||||
find_library(KOMPUTE_LIBRARY
|
||||
NAMES kompute
|
||||
HINTS ${KOMPUTE_LIBRARY_ROOT})
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(KOMPUTE REQUIRED_VARS KOMPUTE_LIBRARY KOMPUTE_INCLUDE_DIR)
|
||||
|
||||
if(KOMPUTE_FOUND)
|
||||
set(KOMPUTE_LIBRARIES ${KOMPUTE_LIBRARY})
|
||||
set(KOMPUTE_INCLUDE_DIRS ${KOMPUTE_INCLUDE_DIR})
|
||||
endif()
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
#include "kompute/Algorithm.hpp"
|
||||
#include "kompute/Core.hpp"
|
||||
#include "kompute/Manager.hpp"
|
||||
#include "kompute/Sequence.hpp"
|
||||
#include "kompute/Tensor.hpp"
|
||||
#include "kompute/operations/OpAlgoDispatch.hpp"
|
||||
#include "kompute/operations/OpBase.hpp"
|
||||
#include "kompute/operations/OpMemoryBarrier.hpp"
|
||||
#include "kompute/operations/OpMult.hpp"
|
||||
#include "kompute/operations/OpTensorCopy.hpp"
|
||||
#include "kompute/operations/OpTensorSyncDevice.hpp"
|
||||
#include "kompute/operations/OpTensorSyncLocal.hpp"
|
||||
#include "kompute/shaders/shaderlogisticregression.hpp"
|
||||
#include "kompute/shaders/shaderopmult.hpp"
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,124 +1,103 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
if(KOMPUTE_OPT_ANDROID_BUILD)
|
||||
find_library(android android)
|
||||
endif()
|
||||
|
||||
if(KOMPUTE_OPT_BUILD_SHADERS)
|
||||
# all shaders are compiled into cpp files
|
||||
kompute_make(build_shaders
|
||||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
add_library(kompute Algorithm.cpp
|
||||
Manager.cpp
|
||||
OpAlgoDispatch.cpp
|
||||
OpMemoryBarrier.cpp
|
||||
OpTensorCopy.cpp
|
||||
OpTensorSyncDevice.cpp
|
||||
OpTensorSyncLocal.cpp
|
||||
Sequence.cpp
|
||||
Tensor.cpp)
|
||||
|
||||
add_library(kompute::kompute ALIAS kompute)
|
||||
|
||||
# Set version for shared libraries.
|
||||
set_target_properties(kompute
|
||||
PROPERTIES
|
||||
VERSION ${${PROJECT_NAME}_VERSION}
|
||||
SOVERSION ${${PROJECT_NAME}_VERSION_MAJOR})
|
||||
|
||||
# Import GNU common install directory variables
|
||||
include(GNUInstallDirs)
|
||||
|
||||
if(CPR_FORCE_USE_SYSTEM_CURL)
|
||||
install(TARGETS kompute
|
||||
EXPORT komputeTargets
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
# Include CMake helpers for package config files
|
||||
# Follow this installation guideline: https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/komputeConfig.cmake.in
|
||||
"${PROJECT_BINARY_DIR}/kompute/komputeConfig.cmake"
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kompute)
|
||||
|
||||
install(EXPORT komputeTargets
|
||||
FILE komputeTargets.cmake
|
||||
NAMESPACE kompute::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kompute)
|
||||
|
||||
install(FILES ${PROJECT_BINARY_DIR}/kompute/komputeConfig.cmake
|
||||
${PROJECT_BINARY_DIR}/kompute/komputeConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kompute)
|
||||
|
||||
else()
|
||||
install(TARGETS kompute
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
if(KOMPUTE_OPT_BUILD_SINGLE_HEADER)
|
||||
# all headers are compiled into a single header
|
||||
kompute_make(build_single_header
|
||||
OUTPUT ${PROJECT_SOURCE_DIR}/single_include)
|
||||
endif()
|
||||
|
||||
file(GLOB kompute_CPP
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
)
|
||||
#####################################################
|
||||
# Android
|
||||
#####################################################
|
||||
|
||||
if(KOMPUTE_OPT_ANDROID_BUILD)
|
||||
set(VK_ANDROID_COMMON_DIR ${ANDROID_NDK}/sources/third_party/vulkan/src/common)
|
||||
set(VK_ANDROID_PATCH_DIR ${PROJECT_SOURCE_DIR}/vk_ndk_wrapper_include/)
|
||||
set(VK_ANDROID_INCLUDE_DIR ${ANDROID_NDK}/sources/third_party/vulkan/src/include)
|
||||
|
||||
include_directories(
|
||||
${VK_ANDROID_COMMON_DIR}
|
||||
${VK_ANDROID_PATCH_DIR}
|
||||
${VK_ANDROID_INCLUDE_DIR})
|
||||
include_directories(${VK_ANDROID_COMMON_DIR}
|
||||
${VK_ANDROID_PATCH_DIR}
|
||||
${VK_ANDROID_INCLUDE_DIR})
|
||||
|
||||
add_library(kompute_vk_ndk_wrapper STATIC
|
||||
${PROJECT_SOURCE_DIR}/vk_ndk_wrapper_include/kompute_vk_ndk_wrapper.cpp)
|
||||
add_library(kompute_vk_ndk_wrapper STATIC ${PROJECT_SOURCE_DIR}/vk_ndk_wrapper_include/kompute_vk_ndk_wrapper.cpp)
|
||||
endif()
|
||||
|
||||
if(NOT KOMPUTE_OPT_BUILD_AS_SHARED_LIB)
|
||||
add_library(
|
||||
kompute STATIC
|
||||
${kompute_CPP})
|
||||
else()
|
||||
add_library(
|
||||
kompute SHARED
|
||||
${kompute_CPP})
|
||||
endif()
|
||||
|
||||
target_include_directories(
|
||||
kompute PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/single_include>
|
||||
)
|
||||
#####################################################
|
||||
# Linking
|
||||
#####################################################
|
||||
|
||||
if(KOMPUTE_OPT_ANDROID_BUILD)
|
||||
target_link_libraries(kompute
|
||||
fmt::fmt)
|
||||
target_link_libraries(kompute PRIVATE fmt::fmt
|
||||
kompute_vk_ndk_wrapper
|
||||
log
|
||||
android)
|
||||
else()
|
||||
target_link_libraries(kompute
|
||||
Vulkan::Vulkan
|
||||
fmt::fmt)
|
||||
target_link_libraries(kompute PRIVATE Vulkan::Vulkan
|
||||
fmt::fmt)
|
||||
endif()
|
||||
|
||||
if(KOMPUTE_OPT_USE_BUILD_IN_VULKAN_HEADER)
|
||||
target_link_libraries(kompute
|
||||
Vulkan-Headers)
|
||||
target_link_libraries(kompute PUBLIC Vulkan-Headers)
|
||||
endif()
|
||||
|
||||
if(KOMPUTE_OPT_ENABLE_LOGGING)
|
||||
target_link_libraries(kompute PRIVATE spdlog::spdlog)
|
||||
endif()
|
||||
|
||||
#####################################################
|
||||
#################### SPDLOG #########################
|
||||
# Misc
|
||||
#####################################################
|
||||
|
||||
if(KOMPUTE_OPT_ENABLE_SPDLOG)
|
||||
target_link_libraries(kompute spdlog::spdlog)
|
||||
endif()
|
||||
|
||||
#####################################################
|
||||
#################### Android ########################
|
||||
#####################################################
|
||||
|
||||
if(KOMPUTE_OPT_ANDROID_BUILD)
|
||||
target_link_libraries(kompute
|
||||
kompute_vk_ndk_wrapper
|
||||
log
|
||||
android)
|
||||
endif()
|
||||
|
||||
#####################################################
|
||||
########## Built C++ Header SHADERS #################
|
||||
#####################################################
|
||||
|
||||
if(KOMPUTE_OPT_BUILD_SHADERS)
|
||||
add_dependencies(kompute
|
||||
build_shaders)
|
||||
endif()
|
||||
|
||||
#####################################################
|
||||
#################### Single Header ##################
|
||||
#####################################################
|
||||
|
||||
if(KOMPUTE_OPT_BUILD_SINGLE_HEADER)
|
||||
add_dependencies(kompute
|
||||
build_single_header)
|
||||
endif()
|
||||
|
||||
|
||||
add_library(kompute::kompute ALIAS kompute)
|
||||
|
||||
if(KOMPUTE_OPT_INSTALL)
|
||||
install(TARGETS kompute EXPORT KomputeTargets
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib
|
||||
INCLUDES DESTINATION include)
|
||||
|
||||
target_include_directories(kompute PUBLIC $<INSTALL_INTERFACE:include>)
|
||||
|
||||
install(DIRECTORY include/ DESTINATION include)
|
||||
|
||||
install(DIRECTORY ${PROJECT_SOURCE_DIR}/single_include/
|
||||
DESTINATION include)
|
||||
|
||||
install(EXPORT KomputeTargets
|
||||
FILE komputeConfig.cmake
|
||||
NAMESPACE kompute::
|
||||
DESTINATION lib/cmake/kompute)
|
||||
endif()
|
||||
add_subdirectory(include)
|
||||
|
||||
27
src/include/CMakeLists.txt
Normal file
27
src/include/CMakeLists.txt
Normal file
@@ -0,0 +1,27 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
target_include_directories(kompute PUBLIC $<INSTALL_INTERFACE:include>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
|
||||
|
||||
target_sources(kompute PRIVATE
|
||||
# Header files (useful in IDEs)
|
||||
kompute/Algorithm.hpp
|
||||
kompute/Core.hpp
|
||||
kompute/Kompute.hpp
|
||||
kompute/Manager.hpp
|
||||
kompute/Sequence.hpp
|
||||
kompute/Tensor.hpp
|
||||
|
||||
kompute/operations/OpAlgoDispatch.hpp
|
||||
kompute/operations/OpBase.hpp
|
||||
kompute/operations/OpMemoryBarrier.hpp
|
||||
kompute/operations/OpMult.hpp
|
||||
kompute/operations/OpTensorCopy.hpp
|
||||
kompute/operations/OpTensorSyncDevice.hpp
|
||||
kompute/operations/OpTensorSyncLocal.hpp
|
||||
|
||||
kompute/shaders/shaderlogisticregression.hpp
|
||||
kompute/shaders/shaderopmult.hpp
|
||||
)
|
||||
|
||||
install(DIRECTORY kompute DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
18
src/include/kompute/Kompute.hpp
Normal file
18
src/include/kompute/Kompute.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "Algorithm.hpp"
|
||||
#include "Core.hpp"
|
||||
#include "Manager.hpp"
|
||||
#include "Sequence.hpp"
|
||||
#include "Tensor.hpp"
|
||||
|
||||
#include "operations/OpAlgoDispatch.hpp"
|
||||
#include "operations/OpBase.hpp"
|
||||
#include "operations/OpMemoryBarrier.hpp"
|
||||
#include "operations/OpMult.hpp"
|
||||
#include "operations/OpTensorCopy.hpp"
|
||||
#include "operations/OpTensorSyncDevice.hpp"
|
||||
#include "operations/OpTensorSyncLocal.hpp"
|
||||
|
||||
#include "shaders/shaderlogisticregression.hpp"
|
||||
#include "shaders/shaderopmult.hpp"
|
||||
@@ -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.
Reference in New Issue
Block a user