Skip to content

Commit f23fd66

Browse files
authored
Merge branch 'master' into fix/conda-packageing
2 parents 09c4286 + 7f81331 commit f23fd66

117 files changed

Lines changed: 8160 additions & 2789 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/cpp_examples.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
configure-options: -DKOMPUTE_OPT_USE_BUILT_IN_VULKAN_HEADER=ON -DKOMPUTE_OPT_FROM_SOURCE=ON
3131
build-options: --parallel # Given we don't build too many resources we can leverage parallel
3232
- name: Run tests
33-
run: ./examples/array_multiplication/build/src/kompute_array_mult
33+
run: ./examples/array_multiplication/build/kompute_array_mult
3434

3535
logistc-regression-example:
3636
runs-on: ubuntu-latest
@@ -55,4 +55,4 @@ jobs:
5555
configure-options: -DKOMPUTE_OPT_USE_BUILT_IN_VULKAN_HEADER=ON -DKOMPUTE_OPT_FROM_SOURCE=ON
5656
build-options: --parallel # Given we don't build too many resources we can leverage parallel
5757
- name: Run tests
58-
run: ./examples/logistic_regression/build/src/kompute_logistic_regression
58+
run: ./examples/logistic_regression/build/kompute_logistic_regression

.github/workflows/cpp_tests.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ on:
77
branches: [ master ]
88

99
jobs:
10+
cpp-tests-1-4-debug-with-debug-layers:
11+
runs-on: ubuntu-latest
12+
container: axsauze/kompute-builder:0.4
13+
env:
14+
VK_ICD_FILENAMES: "/swiftshader/vk_swiftshader_icd.json"
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
with:
19+
submodules: false
20+
- name: "[Release g++] Build & Test"
21+
uses: KomputeProject/action-cmake-build@master
22+
with:
23+
build-dir: ${{github.workspace}}/build
24+
source-dir: ${{github.workspace}}
25+
cc: gcc
26+
cxx: g++
27+
build-type: Debug
28+
run-test: false
29+
ctest-options: -V
30+
configure-options: -DKOMPUTE_OPT_BUILD_TESTS=ON -DKOMPUTE_OPT_DISABLE_VK_DEBUG_LAYERS=OFF -DKOMPUTE_OPT_USE_BUILT_IN_VULKAN_HEADER=ON -DKOMPUTE_OPT_BUILT_IN_VULKAN_HEADER_TAG=v1.4.304 -DKOMPUTE_OPT_DISABLE_VULKAN_VERSION_CHECK=ON
31+
- name: Run tests
32+
run: make mk_run_tests
33+
1034
cpp-tests-debug-with-debug-layers:
1135
runs-on: ubuntu-latest
1236
container: axsauze/kompute-builder:0.4

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ vk_swiftshader_icd.json
192192
tmp_kp_shader.comp.spv
193193
tmp_kp_shader.comp
194194

195+
# Shaders
196+
test/shaders/glsl/*.hpp
197+
compiled_shaders_include/
198+
195199
# Docs
196200
_build/
197201

202+

CMakeLists.txt

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ message(STATUS "=======================================================")
8888

8989
# Enable or disable targets
9090
kompute_option(KOMPUTE_OPT_BUILD_TESTS "Enable if you want to build tests." OFF)
91+
kompute_option(KOMPUTE_OPT_ENABLE_BENCHMARK "Enable if you want to build and enable benchmark." OFF)
9192
kompute_option(KOMPUTE_OPT_CODE_COVERAGE "Enable if you want code coverage." OFF)
9293
kompute_option(KOMPUTE_OPT_BUILD_DOCS "Enable if you want to build documentation." OFF)
9394
kompute_option(KOMPUTE_OPT_INSTALL "Enable if you want to enable installation." ${kompute_opt_install_default_val})
@@ -123,13 +124,20 @@ include(cmake/vulkan_shader_compiler.cmake)
123124
include(cmake/check_vulkan_version.cmake)
124125
include(FetchContent)
125126

127+
# Set -fPIC so that ../lib/kp.cpython-310-x86_64-linux-gnu.so links correctly
128+
if(KOMPUTE_OPT_BUILD_PYTHON)
129+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
130+
endif()
131+
126132
# Vulkan Header
127133
# We don't import Vulkan library if Android build as it is built dynamically
128134
# Otherwise it is expected that the Vulkan SDK and dependencies are installed
129135
# Has to happen AFTER using the build-in Vulkan headers to prevent multiple targets with the name Vulkan::Headers
130136
if(KOMPUTE_OPT_ANDROID_BUILD)
131137
add_library(vulkanAndroid INTERFACE)
132-
set(VULKAN_INCLUDE_DIR ${ANDROID_NDK}/sources/third_party/vulkan/src/include)
138+
if(NOT DEFINED VULKAN_INCLUDE_DIR)
139+
message(FATAL_ERROR "VULKAN_INCLUDE_DIR is not set. Please set it to the Vulkan SDK include directory.")
140+
endif()
133141
target_sources(vulkanAndroid INTERFACE ${VULKAN_INCLUDE_DIR}/vulkan/vulkan.hpp)
134142
target_include_directories(vulkanAndroid INTERFACE ${VULKAN_INCLUDE_DIR})
135143

@@ -138,7 +146,8 @@ if(KOMPUTE_OPT_ANDROID_BUILD)
138146
else()
139147
if(KOMPUTE_OPT_USE_BUILT_IN_VULKAN_HEADER)
140148
FetchContent_Declare(vulkan_header GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Headers.git
141-
GIT_TAG ${KOMPUTE_OPT_BUILT_IN_VULKAN_HEADER_TAG}) # Source: https://github.com/KhronosGroup/Vulkan-Headers/tags
149+
GIT_TAG ${KOMPUTE_OPT_BUILT_IN_VULKAN_HEADER_TAG}
150+
GIT_SHALLOW 1) # Source: https://github.com/KhronosGroup/Vulkan-Headers/tags
142151
FetchContent_MakeAvailable(vulkan_header)
143152

144153
if(NOT KOMPUTE_OPT_DISABLE_VULKAN_VERSION_CHECK)
@@ -162,38 +171,38 @@ else()
162171
endif()
163172

164173
# Spdlog
165-
if(KOMPUTE_OPT_USE_SPDLOG)
174+
if(NOT KOMPUTE_OPT_LOG_LEVEL_DISABLED AND KOMPUTE_OPT_USE_SPDLOG)
166175
add_compile_definitions(KOMPUTE_OPT_USE_SPDLOG=1)
167176

168-
if(NOT KOMPUTE_OPT_LOG_LEVEL_DISABLED)
169-
if(KOMPUTE_OPT_USE_BUILT_IN_SPDLOG)
170-
set(SPDLOG_INSTALL ${KOMPUTE_OPT_INSTALL})
171-
set(SPDLOG_BUILD_SHARED ${BUILD_SHARED_LIBS})
177+
if(KOMPUTE_OPT_USE_BUILT_IN_SPDLOG)
178+
set(SPDLOG_INSTALL ${KOMPUTE_OPT_INSTALL})
179+
set(SPDLOG_BUILD_SHARED ${BUILD_SHARED_LIBS})
172180

173-
FetchContent_Declare(spdlog GIT_REPOSITORY https://github.com/gabime/spdlog.git
174-
GIT_TAG v1.10.0) # Source: https://github.com/gabime/spdlog/releases
175-
FetchContent_MakeAvailable(spdlog)
176-
else()
177-
find_package(spdlog REQUIRED)
178-
endif()
181+
FetchContent_Declare(spdlog GIT_REPOSITORY https://github.com/gabime/spdlog.git
182+
GIT_TAG v1.10.0
183+
GIT_SHALLOW 1) # Source: https://github.com/gabime/spdlog/releases
184+
FetchContent_MakeAvailable(spdlog)
185+
else()
186+
find_package(spdlog REQUIRED)
179187
endif()
180-
endif()
181-
182-
# fmt
183-
if(KOMPUTE_OPT_USE_BUILT_IN_FMT)
184-
set(FMT_INSTALL ${KOMPUTE_OPT_INSTALL})
185-
FetchContent_Declare(fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git
186-
GIT_TAG 10.1.1) # Source: https://github.com/fmtlib/fmt/releases
187-
FetchContent_MakeAvailable(fmt)
188188
else()
189-
find_package(fmt REQUIRED)
189+
# fmt
190+
if(KOMPUTE_OPT_USE_BUILT_IN_FMT)
191+
set(FMT_INSTALL ${KOMPUTE_OPT_INSTALL})
192+
FetchContent_Declare(fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git
193+
GIT_TAG 11.0.0
194+
GIT_SHALLOW 1) # Source: https://github.com/fmtlib/fmt/releases
195+
FetchContent_MakeAvailable(fmt)
196+
else()
197+
find_package(fmt REQUIRED)
198+
endif()
190199
endif()
191200

192201
# GoogleTest
193-
if(KOMPUTE_OPT_BUILD_TESTS)
202+
if(KOMPUTE_OPT_BUILD_TESTS OR KOMPUTE_OPT_ENABLE_BENCHMARK)
194203
if(KOMPUTE_OPT_USE_BUILT_IN_GOOGLE_TEST)
195204
FetchContent_Declare(googletest GIT_REPOSITORY https://github.com/google/googletest.git
196-
GIT_TAG release-1.11.0) # Source: https://github.com/google/googletest/releases
205+
GIT_TAG v1.17.0) # Source: https://github.com/google/googletest/releases
197206

198207
# Use a shared C runtime in case we build shared
199208
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
@@ -217,7 +226,8 @@ endif()
217226
if(KOMPUTE_OPT_BUILD_PYTHON)
218227
if(KOMPUTE_OPT_USE_BUILT_IN_PYBIND11)
219228
FetchContent_Declare(pybind GIT_REPOSITORY https://github.com/pybind/pybind11.git
220-
GIT_TAG v2.9.2) # Source: https://github.com/pybind/pybind11/releases
229+
GIT_TAG v3.0.0
230+
GIT_SHALLOW 1) # Source: https://github.com/pybind/pybind11/releases
221231
FetchContent_MakeAvailable(pybind)
222232
else()
223233
find_package(pybind11 REQUIRED)
@@ -266,11 +276,18 @@ endfunction()
266276

267277
add_subdirectory(src)
268278

269-
if(KOMPUTE_OPT_BUILD_TESTS)
279+
if(KOMPUTE_OPT_BUILD_TESTS OR KOMPUTE_OPT_ENABLE_BENCHMARK)
270280
enable_testing()
281+
endif()
282+
283+
if(KOMPUTE_OPT_BUILD_TESTS)
271284
add_subdirectory(test)
272285
endif()
273286

287+
if(KOMPUTE_OPT_ENABLE_BENCHMARK)
288+
add_subdirectory(benchmark)
289+
endif()
290+
274291
if(KOMPUTE_OPT_CODE_COVERAGE)
275292
if(NOT UNIX)
276293
message(FATAL_ERROR "KOMPUTE_OPT_CODE_COVERAGE can only be enabled in unix based systems due to limitation on gcov.")
@@ -295,6 +312,13 @@ if(KOMPUTE_OPT_INSTALL)
295312
FILE komputeTargets.cmake
296313
NAMESPACE kompute::
297314
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kompute)
315+
316+
# Copy CMake files needed to `vulkan_compile_shader`
317+
install(FILES
318+
cmake/vulkan_shader_compiler.cmake
319+
cmake/bin_file_to_header.cmake
320+
cmake/bin2h.cmake
321+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kompute)
298322
endif()
299323

300324

Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,15 @@ mk_cmake:
6161
-DCMAKE_INSTALL_PREFIX=$(MK_INSTALL_PATH) \
6262
-DKOMPUTE_OPT_INSTALL=ON \
6363
-DKOMPUTE_OPT_BUILD_TESTS=ON \
64+
-DKOMPUTE_OPT_ENABLE_BENCHMARK=ON \
65+
-DKOMPUTE_OPT_BUILT_IN_VULKAN_HEADER_TAG="v1.3.275" \
6466
-DKOMPUTE_OPT_BUILD_DOCS=ON \
65-
-DKOMPUTE_OPT_BUILD_SHADERS=ON \
6667
-DKOMPUTE_OPT_CODE_COVERAGE=ON \
67-
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
68+
-DKOMPUTE_OPT_USE_SPDLOG=1 \
6869
-DKOMPUTE_OPT_LOG_LEVEL=Debug \
70+
-DKOMPUTE_OPT_DISABLE_VK_DEBUG_LAYERS=ON \
71+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
72+
-DKOMPUTE_OPT_DISABLE_VULKAN_VERSION_CHECK=ON \
6973
$(MK_CMAKE_EXTRA_FLAGS) \
7074
-G "Unix Makefiles"
7175

@@ -81,6 +85,9 @@ mk_build_kompute:
8185
mk_build_tests:
8286
cmake --build build/. --target kompute_tests --parallel
8387

88+
mk_build_benchmark:
89+
cmake --build build/. --target kompute_benchmark --parallel
90+
8491
mk_run_docs: mk_build_docs mk_run_docs_only
8592

8693
mk_run_docs_only:
@@ -92,6 +99,9 @@ mk_run_docs_only:
9299
mk_run_tests: mk_build_tests
93100
./build/bin/kompute_tests --gtest_filter=$(FILTER_TESTS)
94101

102+
mk_run_benchmark: mk_build_benchmark
103+
./build/bin/kompute_benchmark --gtest_filter=$(FILTER_TESTS)
104+
95105
mk_build_swiftshader_library:
96106
git clone https://github.com/google/swiftshader || echo "Assuming already cloned"
97107
# GCC 8 or above is required otherwise error on "filesystem" lib will appear

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@
6060

6161
![](https://raw.githubusercontent.com/KomputeProject/kompute/master/docs/images/komputer-logos.gif)
6262

63+
## Projects using Kompute ❤️ 🤖
64+
65+
* [GPT4ALL](https://github.com/nomic-ai/gpt4all) ![](https://img.shields.io/github/stars/nomic-ai/gpt4all.svg?style=social) - An ecosystem of open-source on-edge large language models that run locally on your CPU and nearly any GPU.
66+
* [llama.cpp](https://github.com/ggerganov/llama.cpp) ![](https://img.shields.io/github/stars/ggerganov/llama.cpp.svg?style=social) - Port of Facebook's LLaMA model in C/C++ (now decomissioned).
67+
* [tpoisonooo/how-to-optimize-gemm](https://github.com/tpoisonooo/how-to-optimize-gemm) ![](https://img.shields.io/github/stars/tpoisonooo/how-to-optimize-gemm.svg?style=social) - row-major matmul optimization.
68+
* [vkJAX](https://github.com/alexander-g/vkJAX) ![](https://img.shields.io/github/stars/alexander-g/vkJAX.svg?style=social) - JAX interpreter for Vulkan.
69+
6370
## Getting Started
6471

6572
Below you can find a GPU multiplication example using the C++ and Python Kompute interfaces.
@@ -86,7 +93,7 @@ void kompute(const std::string& shader) {
8693
auto tensorOutA = mgr.tensorT<uint32_t>({ 0, 0, 0 });
8794
auto tensorOutB = mgr.tensorT<uint32_t>({ 0, 0, 0 });
8895

89-
std::vector<std::shared_ptr<kp::Tensor>> params = {tensorInA, tensorInB, tensorOutA, tensorOutB};
96+
std::vector<std::shared_ptr<kp::Memory>> params = {tensorInA, tensorInB, tensorOutA, tensorOutB};
9097

9198
// 3. Create algorithm based on shader (supports buffers & push/spec constants)
9299
kp::Workgroup workgroup({3, 1, 1});
@@ -103,15 +110,15 @@ void kompute(const std::string& shader) {
103110

104111
// 4. Run operation synchronously using sequence
105112
mgr.sequence()
106-
->record<kp::OpTensorSyncDevice>(params)
113+
->record<kp::OpSyncDevice>(params)
107114
->record<kp::OpAlgoDispatch>(algorithm) // Binds default push consts
108115
->eval() // Evaluates the two recorded operations
109116
->record<kp::OpAlgoDispatch>(algorithm, pushConstsB) // Overrides push consts
110117
->eval(); // Evaluates only last recorded operation
111118

112119
// 5. Sync results from the GPU asynchronously
113120
auto sq = mgr.sequence();
114-
sq->evalAsync<kp::OpTensorSyncLocal>(params);
121+
sq->evalAsync<kp::OpSyncLocal>(params);
115122

116123
// ... Do other work asynchronously whilst GPU finishes
117124

@@ -180,6 +187,7 @@ def kompute(shader):
180187
# Explicit type constructor supports uint32, int32, double, float and bool
181188
tensor_out_a = mgr.tensor_t(np.array([0, 0, 0], dtype=np.uint32))
182189
tensor_out_b = mgr.tensor_t(np.array([0, 0, 0], dtype=np.uint32))
190+
assert(t_data.data_type() == kp.DataTypes.uint)
183191
184192
params = [tensor_in_a, tensor_in_b, tensor_out_a, tensor_out_b]
185193

benchmark/CMakeLists.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# ######################
3+
cmake_minimum_required(VERSION 3.20)
4+
5+
# ####################################################
6+
# Shaders
7+
# ####################################################
8+
add_subdirectory(shaders)
9+
10+
# ####################################################
11+
# Tests
12+
# ####################################################
13+
add_executable(kompute_benchmark
14+
TestBenchmark.cpp)
15+
16+
target_link_libraries(kompute_benchmark PRIVATE GTest::gtest_main
17+
kompute::kompute
18+
kp_logger
19+
test_benchmark_shaders)
20+
add_test(NAME kompute_benchmark COMMAND kompute_benchmark)
21+
22+
# Group under the "tests" project folder in IDEs such as Visual Studio.
23+
set_property(TARGET kompute_benchmark PROPERTY FOLDER "tests")
24+
25+
if(WIN32 AND BUILD_SHARED_LIBS) # Install dlls in the same directory as the executable on Windows so one can simply double click them
26+
add_custom_command(TARGET kompute_benchmark POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:test_shaders> $<TARGET_FILE_DIR:kompute_benchmark>)
27+
add_custom_command(TARGET kompute_benchmark POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:kompute::kompute> $<TARGET_FILE_DIR:kompute_benchmark>)
28+
add_custom_command(TARGET kompute_benchmark POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:spdlog> $<TARGET_FILE_DIR:kompute_benchmark>)
29+
add_custom_command(TARGET kompute_benchmark POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:kp_logger> $<TARGET_FILE_DIR:kompute_benchmark>)
30+
endif()
31+
32+

0 commit comments

Comments
 (0)