Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/include/kompute/Algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
47 changes: 47 additions & 0 deletions test/TestPushConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,53 @@ 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<uint32_t> spirv = compileSource(shader);

std::shared_ptr<kp::Sequence> sq = nullptr;

{
kp::Manager mgr;

std::shared_ptr<kp::TensorT<float>> tensor =
mgr.tensor({ 0, 0, 0 });

std::shared_ptr<kp::Algorithm> algo = mgr.algorithm(
{ tensor }, spirv, kp::Workgroup({ 1 }), {}, { 0.0, 0.0, 0.0 });

sq = mgr.sequence()->eval<kp::OpSyncDevice>({ 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<float>{ 0.1, 0.2, 0.3 });
sq->eval<kp::OpAlgoDispatch>(algo);
algo->setPushConstants(std::vector<float>{ 0.3, 0.2, 0.1 });
sq->eval<kp::OpAlgoDispatch>(algo);
sq->eval<kp::OpSyncLocal>({ tensor });

EXPECT_EQ(tensor->vector(), std::vector<float>({ 0.4, 0.4, 0.4 }));
}
}
}

TEST(TestPushConstants, TestConstantsAlgoDispatchNoOverride)
{
{
Expand Down
Loading