From 84b4bb467321e96131b88f1e12fa35444502f687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mitja=20Puziga=C4=87a?= Date: Thu, 16 Jul 2026 17:14:06 +0200 Subject: [PATCH 1/3] add test for Algorithm::setPushConstants(const std::vector &) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mitja Puzigaća --- test/TestPushConstant.cpp | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/test/TestPushConstant.cpp b/test/TestPushConstant.cpp index d575a62f..47c8461a 100644 --- a/test/TestPushConstant.cpp +++ b/test/TestPushConstant.cpp @@ -54,6 +54,54 @@ TEST(TestPushConstants, TestConstantsAlgoDispatchOverride) } } +TEST(TestPushConstants, TestConstantsAlgoSetPushConstants) +{ + { + std::string shader(R"( + #version 450 + 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() { + pa[0] += pcs.x; + pa[1] += pcs.y; + pa[2] += pcs.z; + })"); + + std::vector spirv = compileSource(shader); + + std::shared_ptr sq = nullptr; + + { + kp::Manager mgr; + + 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()->eval({ tensor }); + + // We need to run this in sequence to avoid race condition + // We can't use atomicAdd as swiftshader doesn't support it for + // float + algo->setPushConstants(std::vector{ 0.1, 0.2, 0.3 }); + sq->eval(algo); + algo->setPushConstants(std::vector{ 0.3, 0.2, 0.1 }); + sq->eval(algo); + sq->eval({ tensor }); + + EXPECT_EQ(tensor->vector(), std::vector({ 0.4, 0.4, 0.4 })); + } + } +} + + TEST(TestPushConstants, TestConstantsAlgoDispatchNoOverride) { { From 090cc26dde566bf9f9ab05b1e4e3ad75efffec1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mitja=20Puziga=C4=87a?= Date: Thu, 16 Jul 2026 17:17:43 +0200 Subject: [PATCH 2/3] fix incorrect function signature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mitja Puzigaća --- src/include/kompute/Algorithm.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/kompute/Algorithm.hpp b/src/include/kompute/Algorithm.hpp index 650d8a46..cb416bde 100644 --- a/src/include/kompute/Algorithm.hpp +++ b/src/include/kompute/Algorithm.hpp @@ -226,7 +226,7 @@ class Algorithm * @param size The number of data elements provided in the data * @param memorySize The memory size of each of the data elements in bytes. */ - void setPushConstants(void* data, uint32_t size, uint32_t memorySize) + void setPushConstants(const void* data, uint32_t size, uint32_t memorySize) { uint32_t totalSize = memorySize * size; From 1163efeffa650854490a1b298f3205fa9f990479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mitja=20Puziga=C4=87a?= Date: Thu, 16 Jul 2026 18:45:40 +0200 Subject: [PATCH 3/3] remove unintended empty line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mitja Puzigaća --- test/TestPushConstant.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/TestPushConstant.cpp b/test/TestPushConstant.cpp index 47c8461a..d0d85ee4 100644 --- a/test/TestPushConstant.cpp +++ b/test/TestPushConstant.cpp @@ -101,7 +101,6 @@ TEST(TestPushConstants, TestConstantsAlgoSetPushConstants) } } - TEST(TestPushConstants, TestConstantsAlgoDispatchNoOverride) { {