Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
798ba17
add datatype enum to python module (#404)
koubaa Dec 10, 2024
82bc222
Add noexcept to all constructors to explicitly state no exception thr…
ThePseudo Feb 11, 2025
08a5261
Remove copy operations from classes in Kompute (#412)
ThePseudo Feb 18, 2025
fcf0f34
Fix noexcept missing from OpMemoryBarrier (#413)
axsaucedo Mar 6, 2025
9fb1876
414 support for 1 4 headers (#415)
axsaucedo Mar 6, 2025
b4f74cb
Fix syntax error (MSVC) in Manager.cpp (#418)
jsrgb Mar 19, 2025
63b84b3
Fix compile error in android (#423)
zlaazlaa May 25, 2025
5ad7972
Make spdlog and fmt mutually exclusive and support -Werror=missing-br…
zfergus May 30, 2025
9dd9c71
Add missing eDeviceAndHost MemoryType to the Python Bindings (#424)
robquill Jun 10, 2025
1304c0f
feat: Add log library linking to Android build (#428)
zlaazlaa Jul 12, 2025
3160b6a
Fix python SpecConst and PushConst bugs (#430)
axsaucedo Jul 12, 2025
d76e86b
Update Python Matmul examples (#434)
n-jay Oct 5, 2025
77a0a0d
update internal gtest to v1.17.0 (#437)
TinyTinni Dec 5, 2025
2488e92
Fix incorrect creation of python arrays in Tensor.data (#440)
robquill Jan 12, 2026
ad03e3b
Updated to pybind 3.0.0 (#431)
axsaucedo Jan 12, 2026
38a1a81
Clarify status of llama.cpp in README (#446)
axsaucedo Jan 12, 2026
7f1edae
adding kompute example using debug printf
Jan 21, 2026
67a0a84
adding link to the draft article
Jan 21, 2026
9cc8eca
Updating the readme for the debug statement example
Feb 3, 2026
d2e316b
Adding in the example shader, gitignore targets it so needed to force in
Feb 3, 2026
2d69587
Modifying the comment to include bytes in the comment on message length
Feb 3, 2026
1030b8b
Correcting the readme for spelling mistakes in vulkan_ext_printf
Feb 3, 2026
19caffe
Fix family queue selection in tests (#448)
TinyTinni Jan 29, 2026
8fbcef0
removes compile definition defining for spdlog target (#449)
TinyTinni Jan 30, 2026
958a55e
adding kompute example using debug printf
Jan 21, 2026
fb328f7
adding link to the draft article
Jan 21, 2026
4d5f5b1
Updating the readme for the debug statement example
Feb 3, 2026
466aaed
Merge branch 'master' into master
eokeeffe Feb 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions examples/vulkan_ext_printf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.20)
project(kompute_vulkan_extensions_printf)

set(CMAKE_CXX_STANDARD 14)

# Options
option(KOMPUTE_OPT_GIT_TAG "The tag of the repo to use for the example" v0.9.0)
option(KOMPUTE_OPT_FROM_SOURCE "Whether to build example from source or from git fetch repo" ON)

if(KOMPUTE_OPT_FROM_SOURCE)
add_subdirectory(../../ ${CMAKE_CURRENT_BINARY_DIR}/kompute_build)
else()
include(FetchContent)
FetchContent_Declare(kompute GIT_REPOSITORY https://github.com/KomputeProject/kompute.git
GIT_TAG ${KOMPUTE_OPT_GIT_TAG})
FetchContent_MakeAvailable(kompute)
include_directories(${kompute_SOURCE_DIR}/src/include)
endif()

# Compiling shader
# To add more shaders simply copy the vulkan_compile_shader command and replace it with your new shader
vulkan_compile_shader(
INFILE shader/example_shader.comp
OUTFILE shader/example_shader.hpp
NAMESPACE "shader")

# Then add it to the library, so you can access it later in your code
add_library(shader INTERFACE "shader/example_shader.hpp")
target_include_directories(shader INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)

# Setting up main example code
add_executable(example_shader_printf src/main.cpp)
target_link_libraries(example_shader_printf PRIVATE shader kompute::kompute)

53 changes: 53 additions & 0 deletions examples/vulkan_ext_printf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Kompute Debugging GLSL Shader using DebugPrint

This folder contains an end to end Kompute Example that implements a GLSL with a debug print statement.
This example is structured such that you will be able to extend it for your project.
It contains a CMake build configuration that can be used in your production applications.

## Further information
Debugging Vulkan shaders, especially compute shaders, can be very difficult to do even with the aid
of a powerful debugging tool like RenderDoc. Debug Printf is a recent Vulkan feature that allows
developers to debug their shaders by inserting Debug Print statements. This debug print statement operates
quite like the C printf statement, only that it is executed in multiple compute cores at the same time, so it needs some logic to allow semantic usage of the debug statement otherwise you can easily be overwelmed by debug messages.
<br>

This feature is now supported within RenderDoc in a way that allows for per-invocation inspection of values in a shader.
This article describes how to instrument your GLSL or HLSL shaders with Debug Printf and how to
inspect and debug with them in the terminal, using vkconfig, or with environment variables.

For a full walkthrough of the process please see my article at https://medium.com/@evanokeeffe/using-debug-printf-in-vulkan-kompute-shaders-2aaf30bdb96c

## Building the example

You will notice that it's a standalone project, so you can re-use it for your application.
It uses CMake's [`fetch_content`](https://cmake.org/cmake/help/latest/module/FetchContent.html) to consume Kompute as a dependency.
To build you just need to run the CMake command in this folder as follows:

```bash
git clone https://github.com/KomputeProject/kompute.git
cd kompute/examples/vulkan_ext_printf
mkdir build
cd build
cmake ..
cmake --build .
```

## Executing

From inside the `build/` directory run:

### Linux

```bash
./example_shader_printf
```

## Pre-requisites

In order to run this example, you will need the following dependencies:

* REQUIRED
+ The Vulkan SDK must be installed

For the Vulkan SDK, the simplest way to install it is through [their website](https://vulkan.lunarg.com/sdk/home). You just have to follow the instructions for the relevant platform.

23 changes: 23 additions & 0 deletions examples/vulkan_ext_printf/shader/example_shader.comp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#version 450
// To use Debug Printf in GLSL shaders, you need to enable the GL_EXT_debug_printf extension.
// Then add debugPrintfEXT calls at the locations in your shader where you want to print
// messages and/or values
#extension GL_EXT_debug_printf : enable

// The execution structure
layout (local_size_x = 1) in;

// The buffers are provided via the tensors
layout(binding = 0) buffer bufA { float a[]; };
layout(binding = 1) buffer bufB { float b[]; };
layout(binding = 2) buffer bufOut { float o[]; };

void main() {
uint index = gl_GlobalInvocationID.x;
o[index] = a[index] * b[index];

// the debug statement operates much the same as printf in C
// do be wary of the size of each line as the default debug message size is
// 1024 bytes
debugPrintfEXT("The result of %f x %f = %f \n", a[index], b[index], o[index]);
}
76 changes: 76 additions & 0 deletions examples/vulkan_ext_printf/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <iostream>
#include <memory>
#include <vector>
#include <string>
#include <random>
#include <bits/stdc++.h>
#include <functional> // std::multiplies
#include <algorithm> // std::transform

#include <kompute/Kompute.hpp>
#include <shader/example_shader.hpp>

std::vector<float> generate_random_floats(int n, float min_val, float max_val) {
// create std::vector and pre-allocate the vector with n floats
std::vector<float> vectorF = std::vector<float>(n);
// 1. Obtain a random seed from the hardware
std::random_device rd;
// 2. Initialize the generator with the seed
std::mt19937 gen(rd());
// 3. Define the distribution range [0, n)
std::uniform_real_distribution<float> dis(min_val, max_val);
//fill the vector with randomly distributed floats
for (int i = 0; i < n; i++) {vectorF[i] = dis(gen);}
//return the filled vector
return vectorF;
}

int main(int argc, char *argv[])
{
int device_id = 0;

if(argc>1){
device_id = atoi(argv[1]);
}else{
std::cout<<"Using device 0"<<std::endl;
}

// make sure to add the extension, check vulkan_info to see if your GPU vulkan driver supports the extension
// vulkaninfo | grep VK_KHR_shader_non_semantic_info
const std::vector<std::string> desiredExtensions = std::vector<std::string>({
"VK_KHR_shader_non_semantic_info",
});
const std::vector<uint32_t> familyQueueIndices = std::vector<uint32_t>({});

kp::Manager mgr(device_id, familyQueueIndices, desiredExtensions);

int vector_length = 10;

const std::vector<float> A = generate_random_floats(vector_length, 1.0, 10.0);
const std::vector<float> B = generate_random_floats(vector_length, 1.0, 10.0);
const std::vector<float> C = generate_random_floats(vector_length, 0.0, 0.0);

std::shared_ptr<kp::TensorT<float>> tensorInA = mgr.tensorT<float>(A);
std::shared_ptr<kp::TensorT<float>> tensorInB = mgr.tensorT<float>(B);
std::shared_ptr<kp::TensorT<float>> tensorOut = mgr.tensorT<float>(C);

const std::vector<std::shared_ptr<kp::Memory>> params = { tensorInA,
tensorInB,
tensorOut };

kp::Workgroup workgroup = { vector_length, 1, 1 };

const std::vector<uint32_t> shader = std::vector<uint32_t>(
shader::EXAMPLE_SHADER_COMP_SPV.begin(), shader::EXAMPLE_SHADER_COMP_SPV.end());
std::shared_ptr<kp::Algorithm> algo = mgr.algorithm(params, shader, workgroup);

mgr.sequence()
->record<kp::OpSyncDevice>(params)
->record<kp::OpAlgoDispatch>(algo)
->record<kp::OpSyncLocal>(params)
->eval();

std::cout << "Output: { ";
for (const float& elem : tensorOut->vector()) { std::cout << elem << " ";}
std::cout << "}" << std::endl;
}