Updated python
This commit is contained in:
parent
c211c22a78
commit
647f2f1e62
3 changed files with 52 additions and 8 deletions
|
|
@ -151,15 +151,16 @@ PYBIND11_MODULE(kp, m) {
|
|||
const std::vector<std::shared_ptr<kp::Tensor>>& 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<const char *>(info.ptr);
|
||||
size_t length = static_cast<size_t>(info.size);
|
||||
std::vector<uint32_t> 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;
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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<uint32_t> spirv = kp::Shader::compile_source(shader);
|
||||
|
||||
std::shared_ptr<kp::Sequence> sq = nullptr;
|
||||
|
||||
{
|
||||
kp::Manager mgr;
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensor = mgr.tensor({ 0, 0, 0 });
|
||||
|
||||
std::shared_ptr<kp::Algorithm> algo =
|
||||
mgr.algorithm({ tensor }, spirv, kp::Workgroup({ 1 }), {}, { 0.1, 0.2, 0.3 });
|
||||
|
||||
sq = mgr.sequence()
|
||||
->record<kp::OpTensorSyncDevice>({ tensor })
|
||||
->record<kp::OpAlgoDispatch>(algo)
|
||||
->record<kp::OpAlgoDispatch>(algo,
|
||||
kp::Constants{ 0.3, 0.2, 0.1 })
|
||||
->record<kp::OpTensorSyncLocal>({ tensor })
|
||||
->eval();
|
||||
|
||||
EXPECT_EQ(tensor->data(), kp::Constants({ 0.4, 0.4, 0.4 }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(TestPushConstants, TestConstantsWrongSize)
|
||||
{
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue