Merge pull request #38 from axsaucedo/migrating_to_gtest
Migrating to gtest
This commit is contained in:
commit
6e3c6a1f75
17 changed files with 163 additions and 154 deletions
|
|
@ -35,8 +35,6 @@ if(KOMPUTE_OPT_BUILD_DOCS)
|
|||
endif()
|
||||
|
||||
if(KOMPUTE_OPT_BUILD_TESTS)
|
||||
include(CTest)
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
|
|
|
|||
38
README.md
38
README.md
|
|
@ -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;
|
||||
|
|
@ -88,18 +86,22 @@ int main() {
|
|||
auto tensorA = std::make_shared<kp::Tensor>(kp::Tensor({ 0, 1, 2 }));
|
||||
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"
|
||||
);
|
||||
// Define your shader as a string (using string literals for simplicity)
|
||||
// Or pass the raw bytes of the compiled shader as uint32_t
|
||||
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 });
|
||||
|
|
@ -208,6 +210,8 @@ SPDLOG is the preferred logging library, however by default Vulkan Kompute runs
|
|||
|
||||
You can choose to build with or without SPDLOG by using the cmake flag `KOMPUTE_OPT_ENABLE_SPDLOG`.
|
||||
|
||||
Finally, remember that you will still need to set both the compile time log level with `SPDLOG_ACTIVE_LEVEL`, and the runtime log level with `spdlog::set_level(spdlog::level::debug);`.
|
||||
|
||||
|
||||
## Motivations
|
||||
|
||||
|
|
@ -267,7 +271,7 @@ We appreciate PRs and Issues. If you want to contribute try checking the "Good f
|
|||
#### Dev Dependencies
|
||||
|
||||
* Testing
|
||||
+ Catch2
|
||||
+ GTest
|
||||
* Documentation
|
||||
+ Doxygen (with Dot)
|
||||
+ Sphynx
|
||||
|
|
|
|||
|
|
@ -3,11 +3,13 @@
|
|||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
// SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import
|
||||
#if !defined(SPDLOG_ACTIVE_LEVEL)
|
||||
#if DEBUG
|
||||
#ifndef SPDLOG_ACTIVE_LEVEL
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
|
||||
#endif
|
||||
#else
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef KOMPUTE_LOG_OVERRIDE
|
||||
#if KOMPUTE_ENABLE_SPDLOG
|
||||
|
|
@ -1135,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,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
|
||||
find_package(spdlog REQUIRED)
|
||||
|
||||
if(KOMPUTE_OPT_ENABLE_SPDLOG)
|
||||
find_package(spdlog REQUIRED)
|
||||
find_package(fmt REQUIRED)
|
||||
endif()
|
||||
|
||||
find_package(Vulkan REQUIRED)
|
||||
|
||||
# In production builds all shaders are compiled into cpp files
|
||||
|
|
@ -30,6 +35,7 @@ target_link_libraries(
|
|||
if(KOMPUTE_OPT_ENABLE_SPDLOG)
|
||||
target_link_libraries(
|
||||
kompute
|
||||
fmt::fmt
|
||||
spdlog::spdlog
|
||||
)
|
||||
endif()
|
||||
|
|
@ -38,7 +44,6 @@ add_dependencies(kompute
|
|||
build_shaders
|
||||
build_single_header)
|
||||
|
||||
|
||||
add_library(kompute::kompute ALIAS kompute)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
#if DEBUG
|
||||
#if KOMPUTE_SPDLOG_ENABLED
|
||||
#if KOMPUTE_ENABLE_SPDLOG
|
||||
// Only enabled if spdlog is enabled
|
||||
#include <spdlog/fmt/ranges.h>
|
||||
#include <fmt/ranges.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
@ -18,8 +18,10 @@ Tensor::Tensor()
|
|||
|
||||
Tensor::Tensor(std::vector<float> data, TensorTypes tensorType)
|
||||
{
|
||||
#if DEBUG
|
||||
SPDLOG_DEBUG(
|
||||
"Kompute Tensor constructor data: {}, and type: {}", data, tensorType);
|
||||
#endif
|
||||
|
||||
this->mData = data;
|
||||
this->mShape = { static_cast<uint32_t>(data.size()) };
|
||||
|
|
|
|||
|
|
@ -3,11 +3,13 @@
|
|||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
// SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import
|
||||
#if !defined(SPDLOG_ACTIVE_LEVEL)
|
||||
#if DEBUG
|
||||
#ifndef SPDLOG_ACTIVE_LEVEL
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
|
||||
#endif
|
||||
#else
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef KOMPUTE_LOG_OVERRIDE
|
||||
#if KOMPUTE_ENABLE_SPDLOG
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
find_package(Catch2 REQUIRED)
|
||||
enable_testing()
|
||||
find_package(GTest CONFIG REQUIRED)
|
||||
|
||||
file(GLOB test_kompute_CPP
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
|
|
@ -13,7 +14,10 @@ target_include_directories(
|
|||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/compiled_shaders_include>
|
||||
)
|
||||
|
||||
target_link_libraries(test_kompute PRIVATE Catch2::Catch2)
|
||||
target_link_libraries(test_kompute PRIVATE
|
||||
GTest::gtest
|
||||
GTest::gmock)
|
||||
|
||||
target_link_libraries(test_kompute PRIVATE kompute)
|
||||
|
||||
add_test(NAME test_kompute COMMAND test_kompute)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
#include "catch2/catch.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
TEST_CASE("test_logistic_regression") {
|
||||
TEST(LogisticRegressionAlgorithm, TestMainLogisticRegression) {
|
||||
|
||||
uint32_t ITERATIONS = 100;
|
||||
|
||||
|
|
@ -71,9 +71,10 @@ TEST_CASE("test_logistic_regression") {
|
|||
// * wi < 0.01
|
||||
// * wj > 1.0
|
||||
// * b < 0
|
||||
REQUIRE(wIn->data()[0] < 0.01);
|
||||
REQUIRE(wIn->data()[1] > 1.0);
|
||||
REQUIRE(bIn->data()[0] < 0.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);
|
||||
|
||||
//SPDLOG_DEBUG("Result wIn: {}, bIn: {}",
|
||||
// wIn->data(), bIn->data());
|
||||
|
|
|
|||
|
|
@ -1,24 +1,15 @@
|
|||
#define CATCH_CONFIG_RUNNER
|
||||
|
||||
// clang-format: SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import
|
||||
#if DEBUG
|
||||
#ifndef SPDLOG_ACTIVE_LEVEL
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
|
||||
#endif
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include <kompute/Kompute.hpp>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
#if KOMPUTE_ENABLE_SPDLOG
|
||||
spdlog::set_level(static_cast<spdlog::level::level_enum>(SPDLOG_ACTIVE_LEVEL));
|
||||
#endif
|
||||
|
||||
//#include <spdlog/spdlog.h>
|
||||
//// clang-format: ranges.h must come after spdlog.h
|
||||
//#include <fmt/ranges.h>
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
|
||||
int main( int argc, char* argv[] ) {
|
||||
|
||||
int result = Catch::Session().run( argc, argv );
|
||||
|
||||
// global clean-up...
|
||||
|
||||
return result;
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
#include "catch2/catch.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
TEST_CASE("End to end OpMult Flow should execute correctly from manager")
|
||||
TEST(TestManager, EndToEndOpMultFlow)
|
||||
{
|
||||
kp::Manager mgr;
|
||||
|
||||
|
|
@ -20,10 +20,10 @@ TEST_CASE("End to end OpMult Flow should execute correctly from manager")
|
|||
|
||||
mgr.evalOp<kp::OpMult<>>({ tensorLHS, tensorRHS, tensorOutput });
|
||||
|
||||
REQUIRE(tensorOutput->data() == std::vector<float>{0, 4, 12});
|
||||
EXPECT_EQ(tensorOutput->data(), std::vector<float>({0, 4, 12}));
|
||||
}
|
||||
|
||||
TEST_CASE("End to end OpMult Flow should execute correctly from sequence") {
|
||||
TEST(TestManager, OpMultSequenceFlow) {
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorLHS{ new kp::Tensor(
|
||||
{ 0, 1, 2 }) };
|
||||
|
|
@ -51,10 +51,10 @@ TEST_CASE("End to end OpMult Flow should execute correctly from sequence") {
|
|||
}
|
||||
sqWeakPtr.reset();
|
||||
|
||||
REQUIRE(tensorOutput->data() == std::vector<float>{0, 4, 12});
|
||||
EXPECT_EQ(tensorOutput->data(), std::vector<float>({0, 4, 12}));
|
||||
}
|
||||
|
||||
TEST_CASE("Test manager get create functionality for sequences") {
|
||||
TEST(TestManager, TestMultipleSequences) {
|
||||
kp::Manager mgr;
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtrOne =
|
||||
|
|
@ -69,13 +69,13 @@ TEST_CASE("Test manager get create functionality for sequences") {
|
|||
std::weak_ptr<kp::Sequence> sqWeakPtrTwoRef =
|
||||
mgr.getOrCreateManagedSequence("sqTwo");
|
||||
|
||||
REQUIRE(sqWeakPtrOne.lock() == sqWeakPtrOneRef.lock());
|
||||
REQUIRE(sqWeakPtrTwo.lock() != sqWeakPtrOneRef.lock());
|
||||
REQUIRE(sqWeakPtrTwo.lock() == sqWeakPtrTwoRef.lock());
|
||||
REQUIRE(sqWeakPtrOneRef.lock() != sqWeakPtrTwoRef.lock());
|
||||
EXPECT_EQ(sqWeakPtrOne.lock(), sqWeakPtrOneRef.lock());
|
||||
EXPECT_NE(sqWeakPtrTwo.lock(), sqWeakPtrOneRef.lock());
|
||||
EXPECT_EQ(sqWeakPtrTwo.lock(), sqWeakPtrTwoRef.lock());
|
||||
EXPECT_NE(sqWeakPtrOneRef.lock(), sqWeakPtrTwoRef.lock());
|
||||
}
|
||||
|
||||
TEST_CASE("End to end OpMult Flow with OpCreateTensor called with multiple tensors") {
|
||||
TEST(TestManager, TestMultipleTensorsAtOnce) {
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorLHS{ new kp::Tensor(
|
||||
{ 0, 1, 2 }) };
|
||||
|
|
@ -94,9 +94,9 @@ TEST_CASE("End to end OpMult Flow with OpCreateTensor called with multiple tenso
|
|||
|
||||
sq->record<kp::OpCreateTensor>({ tensorLHS, tensorRHS, tensorOutput });
|
||||
|
||||
REQUIRE(tensorLHS->isInit());
|
||||
REQUIRE(tensorRHS->isInit());
|
||||
REQUIRE(tensorOutput->isInit());
|
||||
EXPECT_TRUE(tensorLHS->isInit());
|
||||
EXPECT_TRUE(tensorRHS->isInit());
|
||||
EXPECT_TRUE(tensorOutput->isInit());
|
||||
|
||||
sq->record<kp::OpMult<>>({ tensorLHS, tensorRHS, tensorOutput });
|
||||
|
||||
|
|
@ -105,5 +105,5 @@ TEST_CASE("End to end OpMult Flow with OpCreateTensor called with multiple tenso
|
|||
}
|
||||
sqWeakPtr.reset();
|
||||
|
||||
REQUIRE(tensorOutput->data() == std::vector<float>{0, 4, 12});
|
||||
EXPECT_EQ(tensorOutput->data(), std::vector<float>({0, 4, 12}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
#include "catch2/catch.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
TEST_CASE("test_multiple_algo_exec_single_cmd_buf_record") {
|
||||
TEST(TestMultipleAlgoExecutions, SingleSequenceRecord) {
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
|
|
@ -43,10 +43,10 @@ TEST_CASE("test_multiple_algo_exec_single_cmd_buf_record") {
|
|||
}
|
||||
sqWeakPtr.reset();
|
||||
|
||||
REQUIRE(tensorA->data() == std::vector<float>{3, 3, 3});
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({3, 3, 3}));
|
||||
}
|
||||
|
||||
TEST_CASE("test_multiple_algo_exec_multiple_record") {
|
||||
TEST(TestMultipleAlgoExecutions, MultipleCmdBufRecords) {
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
|
|
@ -98,11 +98,11 @@ TEST_CASE("test_multiple_algo_exec_multiple_record") {
|
|||
}
|
||||
sqWeakPtr.reset();
|
||||
|
||||
REQUIRE(tensorA->data() == std::vector<float>{3, 3, 3});
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({3, 3, 3}));
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("test_multiple_algo_exec_multiple_sequence") {
|
||||
TEST(TestMultipleAlgoExecutions, MultipleSequences) {
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
|
|
@ -160,10 +160,10 @@ TEST_CASE("test_multiple_algo_exec_multiple_sequence") {
|
|||
sq->eval();
|
||||
}
|
||||
|
||||
REQUIRE(tensorA->data() == std::vector<float>{3, 3, 3});
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({3, 3, 3}));
|
||||
}
|
||||
|
||||
TEST_CASE("test_multiple_algo_exec_single_sequence_single_record") {
|
||||
TEST(TestMultipleAlgoExecutions, SingleRecordMultipleEval) {
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
|
|
@ -205,6 +205,6 @@ TEST_CASE("test_multiple_algo_exec_single_sequence_single_record") {
|
|||
sq->eval();
|
||||
}
|
||||
|
||||
REQUIRE(tensorA->data() == std::vector<float>{3, 3, 3});
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({3, 3, 3}));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
#include "catch2/catch.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
TEST_CASE("test_opcreatetensor_create_single_tensor") {
|
||||
TEST(TestOpCreateTensor, CreateSingleTensorSingleOp) {
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
|
|
@ -13,15 +13,15 @@ TEST_CASE("test_opcreatetensor_create_single_tensor") {
|
|||
|
||||
mgr.evalOpDefault<kp::OpCreateTensor>({tensorA});
|
||||
|
||||
REQUIRE(tensorA->isInit());
|
||||
EXPECT_TRUE(tensorA->isInit());
|
||||
|
||||
REQUIRE(tensorA->data() == testVecA);
|
||||
EXPECT_EQ(tensorA->data(), testVecA);
|
||||
|
||||
tensorA->freeMemoryDestroyGPUResources();
|
||||
REQUIRE(!tensorA->isInit());
|
||||
EXPECT_FALSE(tensorA->isInit());
|
||||
}
|
||||
|
||||
TEST_CASE("test_opcreatetensor_create_multiple_tensors_single_op") {
|
||||
TEST(TestOpCreateTensor, CreateMultipleTensorSingleOp) {
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
|
|
@ -33,14 +33,14 @@ TEST_CASE("test_opcreatetensor_create_multiple_tensors_single_op") {
|
|||
|
||||
mgr.evalOpDefault<kp::OpCreateTensor>({tensorA, tensorB});
|
||||
|
||||
REQUIRE(tensorA->isInit());
|
||||
REQUIRE(tensorB->isInit());
|
||||
EXPECT_TRUE(tensorA->isInit());
|
||||
EXPECT_TRUE(tensorB->isInit());
|
||||
|
||||
REQUIRE(tensorA->data() == testVecA);
|
||||
REQUIRE(tensorB->data() == testVecB);
|
||||
EXPECT_EQ(tensorA->data(), testVecA);
|
||||
EXPECT_EQ(tensorB->data(), testVecB);
|
||||
}
|
||||
|
||||
TEST_CASE("test_opcreatetensor_create_multiple_tensors_multiple_op") {
|
||||
TEST(TestOpCreateTensor, CreateMultipleTensorMultipleOp) {
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
|
|
@ -53,14 +53,14 @@ TEST_CASE("test_opcreatetensor_create_multiple_tensors_multiple_op") {
|
|||
mgr.evalOpDefault<kp::OpCreateTensor>({tensorA});
|
||||
mgr.evalOpDefault<kp::OpCreateTensor>({tensorB});
|
||||
|
||||
REQUIRE(tensorA->isInit());
|
||||
REQUIRE(tensorB->isInit());
|
||||
EXPECT_TRUE(tensorA->isInit());
|
||||
EXPECT_TRUE(tensorB->isInit());
|
||||
|
||||
REQUIRE(tensorA->data() == testVecA);
|
||||
REQUIRE(tensorB->data() == testVecB);
|
||||
EXPECT_EQ(tensorA->data(), testVecA);
|
||||
EXPECT_EQ(tensorB->data(), testVecB);
|
||||
}
|
||||
|
||||
TEST_CASE("test_opcreatetensor_manage_tensor_memory_when_destroyed") {
|
||||
TEST(TestOpCreateTensor, ManageTensorMemoryWhenOpCreateTensorDestroyed) {
|
||||
|
||||
std::vector<float> testVecA{ 9, 8, 7 };
|
||||
std::vector<float> testVecB{ 6, 5, 4 };
|
||||
|
|
@ -73,18 +73,18 @@ TEST_CASE("test_opcreatetensor_manage_tensor_memory_when_destroyed") {
|
|||
mgr.evalOpDefault<kp::OpCreateTensor>({tensorA});
|
||||
mgr.evalOpDefault<kp::OpCreateTensor>({tensorB});
|
||||
|
||||
REQUIRE(tensorA->isInit());
|
||||
REQUIRE(tensorB->isInit());
|
||||
EXPECT_TRUE(tensorA->isInit());
|
||||
EXPECT_TRUE(tensorB->isInit());
|
||||
|
||||
REQUIRE(tensorA->data() == testVecA);
|
||||
REQUIRE(tensorB->data() == testVecB);
|
||||
EXPECT_EQ(tensorA->data(), testVecA);
|
||||
EXPECT_EQ(tensorB->data(), testVecB);
|
||||
}
|
||||
|
||||
REQUIRE(!tensorA->isInit());
|
||||
REQUIRE(!tensorB->isInit());
|
||||
EXPECT_FALSE(tensorA->isInit());
|
||||
EXPECT_FALSE(tensorB->isInit());
|
||||
}
|
||||
|
||||
TEST_CASE("test_opcreatetensor_no_error_if_tensor_freed_before") {
|
||||
TEST(TestOpCreateTensor, NoErrorIfTensorFreedBefore) {
|
||||
|
||||
std::vector<float> testVecA{ 9, 8, 7 };
|
||||
std::vector<float> testVecB{ 6, 5, 4 };
|
||||
|
|
@ -97,15 +97,15 @@ TEST_CASE("test_opcreatetensor_no_error_if_tensor_freed_before") {
|
|||
mgr.evalOpDefault<kp::OpCreateTensor>({tensorA});
|
||||
mgr.evalOpDefault<kp::OpCreateTensor>({tensorB});
|
||||
|
||||
REQUIRE(tensorA->isInit());
|
||||
REQUIRE(tensorB->isInit());
|
||||
EXPECT_TRUE(tensorA->isInit());
|
||||
EXPECT_TRUE(tensorB->isInit());
|
||||
|
||||
REQUIRE(tensorA->data() == testVecA);
|
||||
REQUIRE(tensorB->data() == testVecB);
|
||||
EXPECT_EQ(tensorA->data(), testVecA);
|
||||
EXPECT_EQ(tensorB->data(), testVecB);
|
||||
|
||||
tensorA->freeMemoryDestroyGPUResources();
|
||||
tensorB->freeMemoryDestroyGPUResources();
|
||||
REQUIRE(!tensorA->isInit());
|
||||
REQUIRE(!tensorB->isInit());
|
||||
EXPECT_FALSE(tensorA->isInit());
|
||||
EXPECT_FALSE(tensorB->isInit());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,39 +1,39 @@
|
|||
|
||||
#include "catch2/catch.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
#include "kompute_test/shaders/shadertest_op_custom_shader.hpp"
|
||||
|
||||
TEST_CASE("test_op_shader_raw_data_from_constructor") {
|
||||
TEST(TestOpAlgoBase, ShaderRawDataFromConstructor) {
|
||||
kp::Manager mgr;
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 })};
|
||||
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 },
|
||||
true, // Whether to copy output from device
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
|
||||
REQUIRE(tensorA->data() == std::vector<float>{0, 1, 2});
|
||||
REQUIRE(tensorB->data() == std::vector<float>{3, 4, 5});
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({0, 1, 2}));
|
||||
EXPECT_EQ(tensorB->data(), std::vector<float>({3, 4, 5}));
|
||||
}
|
||||
|
||||
TEST_CASE("test_op_shader_compiled_data_from_constructor") {
|
||||
TEST(TestOpAlgoBase, ShaderCompiledDataFromConstructor) {
|
||||
kp::Manager mgr;
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 })};
|
||||
|
|
@ -48,11 +48,11 @@ TEST_CASE("test_op_shader_compiled_data_from_constructor") {
|
|||
kp::shader_data::test_shaders_glsl_test_op_custom_shader_comp_spv +
|
||||
kp::shader_data::test_shaders_glsl_test_op_custom_shader_comp_spv_len));
|
||||
|
||||
REQUIRE(tensorA->data() == std::vector<float>{0, 1, 2});
|
||||
REQUIRE(tensorB->data() == std::vector<float>{3, 4, 5});
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({0, 1, 2}));
|
||||
EXPECT_EQ(tensorB->data(), std::vector<float>({3, 4, 5}));
|
||||
}
|
||||
|
||||
TEST_CASE("test_op_shader_raw_from_file") {
|
||||
TEST(TestOpAlgoBase, ShaderRawDataFromFile) {
|
||||
kp::Manager mgr;
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 })};
|
||||
|
|
@ -64,11 +64,11 @@ TEST_CASE("test_op_shader_raw_from_file") {
|
|||
true, // Whether to copy output from device
|
||||
"test/shaders/glsl/test_op_custom_shader.comp");
|
||||
|
||||
REQUIRE(tensorA->data() == std::vector<float>{0, 1, 2});
|
||||
REQUIRE(tensorB->data() == std::vector<float>{3, 4, 5});
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({0, 1, 2}));
|
||||
EXPECT_EQ(tensorB->data(), std::vector<float>({3, 4, 5}));
|
||||
}
|
||||
|
||||
TEST_CASE("test_op_shader_compiled_from_file") {
|
||||
TEST(TestOpAlgoBase, ShaderCompiledDataFromFile) {
|
||||
kp::Manager mgr;
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 })};
|
||||
|
|
@ -80,6 +80,6 @@ TEST_CASE("test_op_shader_compiled_from_file") {
|
|||
true, // Whether to copy output from device
|
||||
"test/shaders/glsl/test_op_custom_shader.comp.spv");
|
||||
|
||||
REQUIRE(tensorA->data() == std::vector<float>{0, 1, 2});
|
||||
REQUIRE(tensorB->data() == std::vector<float>{3, 4, 5});
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({0, 1, 2}));
|
||||
EXPECT_EQ(tensorB->data(), std::vector<float>({3, 4, 5}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,26 @@
|
|||
|
||||
#include "catch2/catch.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
TEST_CASE("Sequence begin end recording should work as expected") {
|
||||
TEST(TestSequence, CmdBufSequenceBeginEnd) {
|
||||
kp::Manager mgr;
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr =
|
||||
mgr.getOrCreateManagedSequence("newSequence");
|
||||
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
|
||||
REQUIRE(sq->eval());
|
||||
REQUIRE(!sq->isRecording());
|
||||
REQUIRE(sq->begin());
|
||||
REQUIRE(sq->isRecording());
|
||||
REQUIRE(!sq->begin());
|
||||
REQUIRE(sq->isRecording());
|
||||
REQUIRE(sq->end());
|
||||
REQUIRE(!sq->isRecording());
|
||||
REQUIRE(!sq->end());
|
||||
REQUIRE(!sq->isRecording());
|
||||
REQUIRE(sq->eval());
|
||||
EXPECT_TRUE(sq->eval());
|
||||
EXPECT_TRUE(!sq->isRecording());
|
||||
EXPECT_TRUE(sq->begin());
|
||||
EXPECT_TRUE(sq->isRecording());
|
||||
EXPECT_TRUE(!sq->begin());
|
||||
EXPECT_TRUE(sq->isRecording());
|
||||
EXPECT_TRUE(sq->end());
|
||||
EXPECT_TRUE(!sq->isRecording());
|
||||
EXPECT_TRUE(!sq->end());
|
||||
EXPECT_TRUE(!sq->isRecording());
|
||||
EXPECT_TRUE(sq->eval());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
|
||||
#include <catch2/catch.hpp>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
TEST_CASE("test_tensor_constructor_data") {
|
||||
TEST(TestTensor, ConstructorData) {
|
||||
std::vector<float> vec{0,1,2};
|
||||
kp::Tensor tensor(vec);
|
||||
REQUIRE( tensor.size() == vec.size() );
|
||||
REQUIRE( tensor.data() == vec );
|
||||
EXPECT_EQ( tensor.size(), vec.size() );
|
||||
EXPECT_EQ( tensor.data(), vec );
|
||||
}
|
||||
|
||||
TEST_CASE("test_tensor_copy_from_other_tensor_host_data") {
|
||||
TEST(TestTensor, CopyFromHostData) {
|
||||
std::vector<float> vecA{0,1,2};
|
||||
std::vector<float> vecB{0,0,0};
|
||||
|
||||
|
|
@ -41,6 +41,6 @@ TEST_CASE("test_tensor_copy_from_other_tensor_host_data") {
|
|||
tensorB->mapDataFromHostMemory();
|
||||
}
|
||||
|
||||
REQUIRE(tensorA->data() == tensorB->data());
|
||||
EXPECT_EQ(tensorA->data(), tensorB->data());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
"name": "example",
|
||||
"version-string": "0.0.1",
|
||||
"dependencies": [
|
||||
"fmt",
|
||||
"spdlog",
|
||||
"vulkan",
|
||||
"catch2"
|
||||
"vulkan-hpp",
|
||||
"gtest"
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue