Updated tests to run synchronous

This commit is contained in:
Alejandro Saucedo 2021-03-05 08:33:53 +00:00
parent 71129392c2
commit 33a0ef933b
3 changed files with 33 additions and 36 deletions

View file

@ -1753,7 +1753,8 @@ class Manager
* @param totalQueues The total number of compute queues to create. * @param totalQueues The total number of compute queues to create.
*/ */
Manager(uint32_t physicalDeviceIndex, Manager(uint32_t physicalDeviceIndex,
const std::vector<uint32_t>& familyQueueIndices = {}); const std::vector<uint32_t>& familyQueueIndices = {},
const std::vector<std::string>& desiredExtensions = {});
/** /**
* Manager constructor which allows your own vulkan application to integrate * Manager constructor which allows your own vulkan application to integrate
@ -1839,7 +1840,8 @@ class Manager
// Create functions // Create functions
void createInstance(); void createInstance();
void createDevice(const std::vector<uint32_t>& familyQueueIndices = {}, void createDevice(const std::vector<uint32_t>& familyQueueIndices = {},
uint32_t hysicalDeviceIndex = 0); uint32_t hysicalDeviceIndex = 0,
const std::vector<std::string>& desiredExtensions = {});
}; };
} // End namespace kp } // End namespace kp

View file

@ -16,8 +16,6 @@ TEST(TestMultipleAlgoExecutions, TestEndToEndFunctionality)
std::string shader = (R"( std::string shader = (R"(
#version 450 #version 450
#extension GL_EXT_shader_atomic_float: enable
layout (local_size_x = 1) in; layout (local_size_x = 1) in;
// The input tensors bind index is relative to index in parameter passed // The input tensors bind index is relative to index in parameter passed
@ -36,8 +34,8 @@ TEST(TestMultipleAlgoExecutions, TestEndToEndFunctionality)
void main() { void main() {
uint index = gl_GlobalInvocationID.x; uint index = gl_GlobalInvocationID.x;
atomicAdd(out_a[index], in_a[index] * in_b[index]); out_a[index] += in_a[index] * in_b[index];
atomicAdd(out_b[index], const_one * push_const.val); out_b[index] += const_one * push_const.val;
} }
)"); )");
@ -57,6 +55,7 @@ TEST(TestMultipleAlgoExecutions, TestEndToEndFunctionality)
mgr.sequence() mgr.sequence()
->record<kp::OpTensorSyncDevice>(params) ->record<kp::OpTensorSyncDevice>(params)
->record<kp::OpAlgoDispatch>(algorithm) ->record<kp::OpAlgoDispatch>(algorithm)
->eval()
->record<kp::OpAlgoDispatch>(algorithm, pushConstsB) ->record<kp::OpAlgoDispatch>(algorithm, pushConstsB)
->eval(); ->eval();

View file

@ -9,7 +9,6 @@ TEST(TestPushConstants, TestConstantsAlgoDispatchOverride)
{ {
std::string shader(R"( std::string shader(R"(
#version 450 #version 450
#extension GL_EXT_shader_atomic_float: enable
layout(push_constant) uniform PushConstants { layout(push_constant) uniform PushConstants {
float x; float x;
float y; float y;
@ -18,9 +17,9 @@ TEST(TestPushConstants, TestConstantsAlgoDispatchOverride)
layout (local_size_x = 1) in; layout (local_size_x = 1) in;
layout(set = 0, binding = 0) buffer a { float pa[]; }; layout(set = 0, binding = 0) buffer a { float pa[]; };
void main() { void main() {
atomicAdd(pa[0], pcs.x); pa[0] += pcs.x;
atomicAdd(pa[1], pcs.y); pa[1] += pcs.y;
atomicAdd(pa[2], pcs.z); pa[2] += pcs.z;
})"); })");
std::vector<uint32_t> spirv = kp::Shader::compile_source(shader); std::vector<uint32_t> spirv = kp::Shader::compile_source(shader);
@ -28,21 +27,20 @@ TEST(TestPushConstants, TestConstantsAlgoDispatchOverride)
std::shared_ptr<kp::Sequence> sq = nullptr; std::shared_ptr<kp::Sequence> sq = nullptr;
{ {
kp::Manager mgr(0, {}, { "VK_EXT_shader_atomic_float", "SPV_EXT_shader_atomic_float_add" }); kp::Manager mgr;
std::shared_ptr<kp::Tensor> tensor = mgr.tensor({ 0, 0, 0 }); std::shared_ptr<kp::Tensor> tensor = mgr.tensor({ 0, 0, 0 });
std::shared_ptr<kp::Algorithm> algo = std::shared_ptr<kp::Algorithm> algo =
mgr.algorithm({ tensor }, spirv, kp::Workgroup({ 1 }), {}, { 0.0, 0.0, 0.0 }); mgr.algorithm({ tensor }, spirv, kp::Workgroup({ 1 }), {}, { 0.0, 0.0, 0.0 });
sq = mgr.sequence() sq = mgr.sequence()->eval<kp::OpTensorSyncDevice>({ tensor });
->record<kp::OpTensorSyncDevice>({ tensor })
->record<kp::OpAlgoDispatch>(algo, // We need to run this in sequence to avoid race condition
kp::Constants{ 0.1, 0.2, 0.3 }) // We can't use atomicAdd as swiftshader doesn't support it for float
->record<kp::OpAlgoDispatch>(algo, sq->eval<kp::OpAlgoDispatch>(algo, kp::Constants{ 0.1, 0.2, 0.3 });
kp::Constants{ 0.3, 0.2, 0.1 }) sq->eval<kp::OpAlgoDispatch>(algo, kp::Constants{ 0.3, 0.2, 0.1 });
->record<kp::OpTensorSyncLocal>({ tensor }) sq->eval<kp::OpTensorSyncLocal>({ tensor });
->eval();
EXPECT_EQ(tensor->data(), kp::Constants({ 0.4, 0.4, 0.4 })); EXPECT_EQ(tensor->data(), kp::Constants({ 0.4, 0.4, 0.4 }));
} }
@ -54,7 +52,6 @@ TEST(TestPushConstants, TestConstantsAlgoDispatchNoOverride)
{ {
std::string shader(R"( std::string shader(R"(
#version 450 #version 450
#extension GL_EXT_shader_atomic_float: enable
layout(push_constant) uniform PushConstants { layout(push_constant) uniform PushConstants {
float x; float x;
float y; float y;
@ -63,9 +60,9 @@ TEST(TestPushConstants, TestConstantsAlgoDispatchNoOverride)
layout (local_size_x = 1) in; layout (local_size_x = 1) in;
layout(set = 0, binding = 0) buffer a { float pa[]; }; layout(set = 0, binding = 0) buffer a { float pa[]; };
void main() { void main() {
atomicAdd(pa[0], pcs.x); pa[0] += pcs.x;
atomicAdd(pa[1], pcs.y); pa[1] += pcs.y;
atomicAdd(pa[2], pcs.z); pa[2] += pcs.z;
})"); })");
std::vector<uint32_t> spirv = kp::Shader::compile_source(shader); std::vector<uint32_t> spirv = kp::Shader::compile_source(shader);
@ -73,20 +70,20 @@ TEST(TestPushConstants, TestConstantsAlgoDispatchNoOverride)
std::shared_ptr<kp::Sequence> sq = nullptr; std::shared_ptr<kp::Sequence> sq = nullptr;
{ {
kp::Manager mgr(0, {}, { "VK_EXT_shader_atomic_float", "SPV_EXT_shader_atomic_float_add" }); kp::Manager mgr;
std::shared_ptr<kp::Tensor> tensor = mgr.tensor({ 0, 0, 0 }); std::shared_ptr<kp::Tensor> tensor = mgr.tensor({ 0, 0, 0 });
std::shared_ptr<kp::Algorithm> algo = std::shared_ptr<kp::Algorithm> algo =
mgr.algorithm({ tensor }, spirv, kp::Workgroup({ 1 }), {}, { 0.1, 0.2, 0.3 }); mgr.algorithm({ tensor }, spirv, kp::Workgroup({ 1 }), {}, { 0.1, 0.2, 0.3 });
sq = mgr.sequence() sq = mgr.sequence()->eval<kp::OpTensorSyncDevice>({ tensor });
->record<kp::OpTensorSyncDevice>({ tensor })
->record<kp::OpAlgoDispatch>(algo) // We need to run this in sequence to avoid race condition
->record<kp::OpAlgoDispatch>(algo, // We can't use atomicAdd as swiftshader doesn't support it for float
kp::Constants{ 0.3, 0.2, 0.1 }) sq->eval<kp::OpAlgoDispatch>(algo);
->record<kp::OpTensorSyncLocal>({ tensor }) sq->eval<kp::OpAlgoDispatch>(algo, kp::Constants{ 0.3, 0.2, 0.1 });
->eval(); sq->eval<kp::OpTensorSyncLocal>({ tensor });
EXPECT_EQ(tensor->data(), kp::Constants({ 0.4, 0.4, 0.4 })); EXPECT_EQ(tensor->data(), kp::Constants({ 0.4, 0.4, 0.4 }));
} }
@ -98,7 +95,6 @@ TEST(TestPushConstants, TestConstantsWrongSize)
{ {
std::string shader(R"( std::string shader(R"(
#version 450 #version 450
#extension GL_EXT_shader_atomic_float: enable
layout(push_constant) uniform PushConstants { layout(push_constant) uniform PushConstants {
float x; float x;
float y; float y;
@ -107,9 +103,9 @@ TEST(TestPushConstants, TestConstantsWrongSize)
layout (local_size_x = 1) in; layout (local_size_x = 1) in;
layout(set = 0, binding = 0) buffer a { float pa[]; }; layout(set = 0, binding = 0) buffer a { float pa[]; };
void main() { void main() {
atomicAdd(pa[0], pcs.x); pa[0] += pcs.x;
atomicAdd(pa[1], pcs.y); pa[1] += pcs.y;
atomicAdd(pa[2], pcs.z); pa[2] += pcs.z;
})"); })");
std::vector<uint32_t> spirv = kp::Shader::compile_source(shader); std::vector<uint32_t> spirv = kp::Shader::compile_source(shader);
@ -117,7 +113,7 @@ TEST(TestPushConstants, TestConstantsWrongSize)
std::shared_ptr<kp::Sequence> sq = nullptr; std::shared_ptr<kp::Sequence> sq = nullptr;
{ {
kp::Manager mgr(0, {}, { "VK_EXT_shader_atomic_float", "SPV_EXT_shader_atomic_float_add" }); kp::Manager mgr;
std::shared_ptr<kp::Tensor> tensor = mgr.tensor({ 0, 0, 0 }); std::shared_ptr<kp::Tensor> tensor = mgr.tensor({ 0, 0, 0 });