Updated to use cpp raw literal strings

This commit is contained in:
Alejandro Saucedo 2020-09-05 08:15:52 +01:00
parent c15a14d2b2
commit 1449c858ee
8 changed files with 34 additions and 33 deletions

View file

@ -64,14 +64,12 @@ int main() {
auto tensorRhs = std::make_shared<kp::Tensor>(kp::Tensor({ 2., 4., 6. }));
auto tensorOut = std::make_shared<kp::Tensor>(kp::Tensor({ 0., 0., 0. }));
// Create tensor data in GPU
// Create tensors data in GPU
mgr.evalOpDefault<kp::OpCreateTensor>({ tensorLhs, tensorRhs, tensorOut });
// Run Kompute operation on the parameters provided with dispatch layout
mgr.evalOpDefault<kp::OpMult<3, 1, 1>>(
{ tensorLhs, tensorRhs, tensorOut },
true, // Whether to retrieve the output from GPU memory
std::vector<char>(shader.begin(), shader.end()));
{ tensorLhs, tensorRhs, tensorOut });
// Prints the output which is { 0, 4, 12 }
std::cout << fmt::format("Output: {}", tensorOutput.data()) << std::endl;
@ -89,17 +87,20 @@ int main() {
auto tensorRhs = std::make_shared<kp::Tensor>(kp::Tensor({ 2, 4, 6 }));
// Define your shader as a string, or directly pass the compiled bytes
std::string shader(
"#version 450\n"
"layout (local_size_x = 1) in;\n"
"layout(set = 0, binding = 0) buffer bufa { uint a[]; };\n"
"layout(set = 0, binding = 1) buffer bufb { uint b[]; };\n"
"void main() {\n"
" uint index = gl_GlobalInvocationID.x;\n"
" b[index] = a[index];\n"
" a[index] = index;\n"
"}\n"
);
std::string shader(R"(
#version 450
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;
pb[index] = pa[index];
pa[index] = index;
}
)");
// Create tensor data in GPU
mgr.evalOpDefault<kp::OpCreateTensor>({ tensorA, tensorB });

View file

@ -4,10 +4,10 @@
// SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import
#if !defined(SPDLOG_ACTIVE_LEVEL)
#if RELEASE
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
#else
#if DEBUG
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
#else
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
#endif
#endif
@ -1137,7 +1137,7 @@ OpAlgoBase<tX, tY, tZ>::record()
if (this->mCopyOutputData) {
// Barrier to ensure the shader code is executed before buffer read
for (std::shared_ptr<Tensor> tensor : this->mTensors) {
for (const std::shared_ptr<Tensor>& tensor : this->mTensors) {
tensor->recordBufferMemoryBarrier(
vk::AccessFlagBits::eShaderWrite,
vk::AccessFlagBits::eTransferRead,

View file

@ -44,7 +44,6 @@ add_dependencies(kompute
build_shaders
build_single_header)
add_library(kompute::kompute ALIAS kompute)

View file

@ -293,7 +293,7 @@ OpAlgoBase<tX, tY, tZ>::record()
if (this->mCopyOutputData) {
// Barrier to ensure the shader code is executed before buffer read
for (std::shared_ptr<Tensor> tensor : this->mTensors) {
for (const std::shared_ptr<Tensor>& tensor : this->mTensors) {
tensor->recordBufferMemoryBarrier(
vk::AccessFlagBits::eShaderWrite,
vk::AccessFlagBits::eTransferRead,

View file

@ -71,6 +71,7 @@ TEST(LogisticRegressionAlgorithm, TestMainLogisticRegression) {
// * wi < 0.01
// * wj > 1.0
// * b < 0
// TODO: Add EXPECT_DOUBLE_EQ instead
EXPECT_LT(wIn->data()[0], 0.01);
EXPECT_GT(wIn->data()[1], 1.0);
EXPECT_LT(bIn->data()[0], 0.0);

View file

@ -9,7 +9,6 @@ int main(int argc, char *argv[]) {
#if KOMPUTE_ENABLE_SPDLOG
spdlog::set_level(static_cast<spdlog::level::level_enum>(SPDLOG_ACTIVE_LEVEL));
spdlog::error("default active level {}", SPDLOG_ACTIVE_LEVEL);
#endif
return RUN_ALL_TESTS();

View file

@ -12,17 +12,17 @@ TEST(TestOpAlgoBase, ShaderRawDataFromConstructor) {
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 })};
mgr.evalOpDefault<kp::OpCreateTensor>({ tensorA, tensorB });
std::string shader(
"#version 450\n"
"layout (local_size_x = 1) in;\n"
"layout(set = 0, binding = 0) buffer a { float pa[]; };\n"
"layout(set = 0, binding = 1) buffer b { float pb[]; };\n"
"void main() {\n"
" uint index = gl_GlobalInvocationID.x;\n"
" pb[index] = pa[index];\n"
" pa[index] = index;\n"
"}\n"
);
std::string shader(R"(
#version 450
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;
pb[index] = pa[index];
pa[index] = index;
}
)");
mgr.evalOpDefault<kp::OpAlgoBase<>>(
{ tensorA, tensorB },

View file

@ -4,6 +4,7 @@
"dependencies": [
"spdlog",
"vulkan",
"vulkan-hpp",
"gtest"
]
}