diff --git a/README.md b/README.md index 301572a09..41596cb00 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ The C++ interface provides low level access to the native components of Kompute void kompute(const std::string& shader) { - // 1. Create Kompute Manager with default settings (device 0 and first compute compatible queue) + // 1. Create Kompute Manager with default settings (device 0, first queue and no extensions) kp::Manager mgr; // 2. Create and initialise Kompute Tensors through manager @@ -140,7 +140,7 @@ The [Python package](https://kompute.cc/overview/python-package.html) provides a ```python def kompute(shader): - # 1. Create Kompute Manager with default settings (device 0 and first compute compatible queue) + # 1. Create Kompute Manager with default settings (device 0, first queue and no extensions) mgr = kp.Manager() # 2. Create and initialise Kompute Tensors through manager diff --git a/docs/overview/advanced-examples.rst b/docs/overview/advanced-examples.rst index 80df20e42..90066e8cc 100644 --- a/docs/overview/advanced-examples.rst +++ b/docs/overview/advanced-examples.rst @@ -23,6 +23,63 @@ End-to-end examples * `Android NDK Mobile Kompute ML Application `_ * `Game Development Kompute ML in Godot Engine `_ +Add Vulkan Extensions +^^^^^^^^^^^^^^^^^^^^ + +Kompute provides a simple way to add Vulkan extensions through kp::Manager initialisation. When debug is enabled you will be able to see logs that show what are the desired extensions requested and the ones that are added based on the available extensions on the current driver. + +The example below shows how you can enable the "VK_EXT_shader_atomic_float" extension so we can use the adomicAdd for floats in the shaders. + +.. code-block:: cpp + :linenos: + + int main() { + std::string shader(R"( + #version 450 + + #extension GL_EXT_shader_atomic_float: enable + + layout(push_constant) uniform PushConstants { + float x; + float y; + float z; + } pcs; + + layout (local_size_x = 1) in; + + layout(set = 0, binding = 0) buffer a { float pa[]; }; + + void main() { + atomicAdd(pa[0], pcs.x); + atomicAdd(pa[1], pcs.y); + atomicAdd(pa[2], pcs.z); + })"); + + std::vector spirv = kp::Shader::compile_source(shader); + + std::shared_ptr sq = nullptr; + + { + kp::Manager mgr(0, {}, { "VK_EXT_shader_atomic_float" }); + + std::shared_ptr tensor = mgr.tensor({ 0, 0, 0 }); + + std::shared_ptr algo = + mgr.algorithm({ tensor }, spirv, kp::Workgroup({ 1 }), {}, { 0.0, 0.0, 0.0 }); + + sq = mgr.sequence() + ->record({ tensor }) + ->record(algo, + kp::Constants{ 0.1, 0.2, 0.3 }) + ->record(algo, + kp::Constants{ 0.3, 0.2, 0.1 }) + ->record({ tensor }) + ->eval(); + + EXPECT_EQ(tensor->data(), kp::Constants({ 0.4, 0.4, 0.4 })); + } + } + Your Custom Kompute Operation ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^