Initial base set of tests aligned with new interface
This commit is contained in:
parent
6378583a23
commit
fb617d1722
16 changed files with 908 additions and 1071 deletions
|
|
@ -4,46 +4,44 @@
|
|||
|
||||
TEST(TestSpecializationConstants, TestTwoConstants)
|
||||
{
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
|
||||
std::string shader(R"(
|
||||
#version 450
|
||||
layout (constant_id = 0) const float cOne = 1;
|
||||
layout (constant_id = 1) const float cTwo = 1;
|
||||
layout (local_size_x = 1) in;
|
||||
layout(set = 0, binding = 0) buffer a { float pa[]; };
|
||||
layout(set = 0, binding = 1) buffer b { float pb[]; };
|
||||
void main() {
|
||||
uint index = gl_GlobalInvocationID.x;
|
||||
pa[index] = cOne;
|
||||
pb[index] = cTwo;
|
||||
})");
|
||||
|
||||
{
|
||||
std::string shader(R"(
|
||||
#version 450
|
||||
layout (constant_id = 0) const float cOne = 1;
|
||||
layout (constant_id = 1) const float cTwo = 1;
|
||||
layout (local_size_x = 1) in;
|
||||
layout(set = 0, binding = 0) buffer a { float pa[]; };
|
||||
layout(set = 0, binding = 1) buffer b { float pb[]; };
|
||||
void main() {
|
||||
uint index = gl_GlobalInvocationID.x;
|
||||
pa[index] = cOne;
|
||||
pb[index] = cTwo;
|
||||
})");
|
||||
|
||||
std::vector<uint32_t> spirv = kp::Shader::compile_source(shader);
|
||||
|
||||
std::shared_ptr<kp::Sequence> sq = nullptr;
|
||||
|
||||
{
|
||||
kp::Manager mgr;
|
||||
|
||||
mgr.rebuild({ tensorA, tensorB });
|
||||
std::shared_ptr<kp::Tensor> tensorA = mgr.tensor({ 0, 0, 0 });
|
||||
std::shared_ptr<kp::Tensor> tensorB = mgr.tensor({ 0, 0, 0 });
|
||||
|
||||
sq = mgr.sequence();
|
||||
std::vector<std::shared_ptr<kp::Tensor>> params = {tensorA, tensorB};
|
||||
|
||||
auto spec = kp::Constants({5.0, 0.3});
|
||||
kp::Constants spec = kp::Constants({5.0, 0.3});
|
||||
|
||||
sq->begin();
|
||||
sq->record<kp::OpAlgoCreate>(
|
||||
{ tensorA, tensorB },
|
||||
kp::Shader::compile_source(shader),
|
||||
kp::Workgroup(), spec);
|
||||
sq->end();
|
||||
std::shared_ptr<kp::Algorithm> algo = mgr.algorithm(params, spirv, {}, spec);
|
||||
|
||||
sq->eval();
|
||||
sq = mgr.sequence()
|
||||
->record<kp::OpTensorSyncDevice>(params)
|
||||
->record<kp::OpAlgoDispatch>(algo)
|
||||
->record<kp::OpTensorSyncLocal>(params)
|
||||
->eval();
|
||||
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({ tensorA, tensorB });
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({ 5, 5, 5 }));
|
||||
EXPECT_EQ(tensorB->data(), std::vector<float>({ 0.3, 0.3, 0.3 }));
|
||||
}
|
||||
}
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({ 5, 5, 5 }));
|
||||
EXPECT_EQ(tensorB->data(), std::vector<float>({ 0.3, 0.3, 0.3 }));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue