Skip to content

Commit 004618b

Browse files
mitjapaxsaucedo
andauthored
Fix compilation error when using Algorithm::setPushConstants(const std::vector<T> &) (#466)
* add test for Algorithm::setPushConstants(const std::vector<T> &) Signed-off-by: Mitja Puzigaća <mitjap@gmail.com> * fix incorrect function signature Signed-off-by: Mitja Puzigaća <mitjap@gmail.com> * remove unintended empty line Signed-off-by: Mitja Puzigaća <mitjap@gmail.com> --------- Signed-off-by: Mitja Puzigaća <mitjap@gmail.com> Co-authored-by: Alejandro Saucedo <axsauze@gmail.com>
1 parent 49ca4b9 commit 004618b

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

‎src/include/kompute/Algorithm.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class Algorithm
226226
* @param size The number of data elements provided in the data
227227
* @param memorySize The memory size of each of the data elements in bytes.
228228
*/
229-
void setPushConstants(void* data, uint32_t size, uint32_t memorySize)
229+
void setPushConstants(const void* data, uint32_t size, uint32_t memorySize)
230230
{
231231

232232
uint32_t totalSize = memorySize * size;

‎test/TestPushConstant.cpp‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,53 @@ TEST(TestPushConstants, TestConstantsAlgoDispatchOverride)
5454
}
5555
}
5656

57+
TEST(TestPushConstants, TestConstantsAlgoSetPushConstants)
58+
{
59+
{
60+
std::string shader(R"(
61+
#version 450
62+
layout(push_constant) uniform PushConstants {
63+
float x;
64+
float y;
65+
float z;
66+
} pcs;
67+
layout (local_size_x = 1) in;
68+
layout(set = 0, binding = 0) buffer a { float pa[]; };
69+
void main() {
70+
pa[0] += pcs.x;
71+
pa[1] += pcs.y;
72+
pa[2] += pcs.z;
73+
})");
74+
75+
std::vector<uint32_t> spirv = compileSource(shader);
76+
77+
std::shared_ptr<kp::Sequence> sq = nullptr;
78+
79+
{
80+
kp::Manager mgr;
81+
82+
std::shared_ptr<kp::TensorT<float>> tensor =
83+
mgr.tensor({ 0, 0, 0 });
84+
85+
std::shared_ptr<kp::Algorithm> algo = mgr.algorithm(
86+
{ tensor }, spirv, kp::Workgroup({ 1 }), {}, { 0.0, 0.0, 0.0 });
87+
88+
sq = mgr.sequence()->eval<kp::OpSyncDevice>({ tensor });
89+
90+
// We need to run this in sequence to avoid race condition
91+
// We can't use atomicAdd as swiftshader doesn't support it for
92+
// float
93+
algo->setPushConstants(std::vector<float>{ 0.1, 0.2, 0.3 });
94+
sq->eval<kp::OpAlgoDispatch>(algo);
95+
algo->setPushConstants(std::vector<float>{ 0.3, 0.2, 0.1 });
96+
sq->eval<kp::OpAlgoDispatch>(algo);
97+
sq->eval<kp::OpSyncLocal>({ tensor });
98+
99+
EXPECT_EQ(tensor->vector(), std::vector<float>({ 0.4, 0.4, 0.4 }));
100+
}
101+
}
102+
}
103+
57104
TEST(TestPushConstants, TestConstantsAlgoDispatchNoOverride)
58105
{
59106
{

0 commit comments

Comments
 (0)