diff --git a/python/src/main.cpp b/python/src/main.cpp index 8aac68c98..594d9f45b 100644 --- a/python/src/main.cpp +++ b/python/src/main.cpp @@ -151,15 +151,16 @@ PYBIND11_MODULE(kp, m) { const std::vector>& tensors, const py::bytes& spirv, const kp::Workgroup& workgroup, - const kp::Constants& spec_consts) { + const kp::Constants& spec_consts, + const kp::Constants& push_consts) { py::buffer_info info(py::buffer(spirv).request()); const char *data = reinterpret_cast(info.ptr); size_t length = static_cast(info.size); std::vector spirvVec((uint32_t*)data, (uint32_t*)(data + length)); - return self.algorithm(tensors, spirvVec, workgroup, spec_consts); + return self.algorithm(tensors, spirvVec, workgroup, spec_consts, push_consts); }, "Algorithm initialisation function", - py::arg("tensors"), py::arg("spirv"), py::arg("workgroup") = kp::Workgroup(), py::arg("spec_consts") = kp::Constants()); + py::arg("tensors"), py::arg("spirv"), py::arg("workgroup") = kp::Workgroup(), py::arg("spec_consts") = kp::Constants(), py::arg("push_consts") = kp::Constants()); #ifdef VERSION_INFO m.attr("__version__") = VERSION_INFO; diff --git a/python/test/test_kompute.py b/python/test/test_kompute.py index 865f72d92..47887930a 100644 --- a/python/test/test_kompute.py +++ b/python/test/test_kompute.py @@ -72,11 +72,11 @@ def test_end_to_end(): push_consts_a = [2] push_consts_b = [3] - algo = mgr.algorithm(params, kp.Shader.compile_source(shader), workgroup, spec_consts) + algo = mgr.algorithm(params, kp.Shader.compile_source(shader), workgroup, spec_consts, push_consts_a) (mgr.sequence() .record(kp.OpTensorSyncDevice(params)) - .record(kp.OpAlgoDispatch(algo, push_consts_a)) + .record(kp.OpAlgoDispatch(algo)) .record(kp.OpAlgoDispatch(algo, push_consts_b)) .eval()) @@ -206,11 +206,11 @@ def test_pushconsts(): tensor = mgr.tensor([0, 0, 0]) - algo = mgr.algorithm([tensor], spirv, (1, 1, 1)) + algo = mgr.algorithm([tensor], spirv, (1, 1, 1), [], [0.1, 0.2, 0.3]) (mgr.sequence() .record(kp.OpTensorSyncDevice([tensor])) - .record(kp.OpAlgoDispatch(algo, [0.1, 0.2, 0.3])) + .record(kp.OpAlgoDispatch(algo)) .record(kp.OpAlgoDispatch(algo, [0.3, 0.2, 0.1])) .record(kp.OpTensorSyncLocal([tensor])) .eval()) diff --git a/test/TestPushConstant.cpp b/test/TestPushConstant.cpp index 8c3357b33..6b37ab015 100644 --- a/test/TestPushConstant.cpp +++ b/test/TestPushConstant.cpp @@ -4,7 +4,7 @@ #include "fmt/ranges.h" -TEST(TestPushConstants, TestConstants) +TEST(TestPushConstants, TestConstantsAlgoDispatchOverride) { { std::string shader(R"( @@ -48,6 +48,49 @@ TEST(TestPushConstants, TestConstants) } } +TEST(TestPushConstants, TestConstantsAlgoDispatchNoOverride) +{ + { + 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 = kp::Shader::compile_source(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.1, 0.2, 0.3 }); + + sq = mgr.sequence() + ->record({ tensor }) + ->record(algo) + ->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 })); + } + } +} + TEST(TestPushConstants, TestConstantsWrongSize) { {