Added test and updated LR tests to confirm works

This commit is contained in:
Alejandro Saucedo 2021-02-13 19:38:15 +00:00
parent 0b84876c95
commit 6b62990dbc
2 changed files with 55 additions and 4 deletions

View file

@ -350,3 +350,50 @@ TEST(TestMultipleAlgoExecutions, SequenceAlgoDestroyOutsideManagerScope)
}
EXPECT_EQ(tensorA->data(), std::vector<float>({ 1, 1, 1 }));
}
TEST(TestMultipleAlgoExecutions, TestAlgorithmSpecialized)
{
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 uint 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::shared_ptr<kp::Sequence> sq = nullptr;
{
kp::Manager mgr;
mgr.rebuild({ tensorA, tensorB });
sq = mgr.sequence();
auto spec = kp::Algorithm::SpecializationContainer({{(uint32_t)5}, {(float)0.3f}});
sq->begin();
sq->record<kp::OpAlgoBase>(
{ tensorA, tensorB },
std::vector<char>(shader.begin(), shader.end()),
kp::OpAlgoBase::KomputeWorkgroup(), spec);
sq->end();
sq->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 }));
}
}
}