Added base tests for end to end manager functionality
This commit is contained in:
parent
1748694b3a
commit
39b051160a
7 changed files with 199 additions and 181 deletions
|
|
@ -1,7 +1,11 @@
|
|||
|
||||
find_package(Catch2 REQUIRED)
|
||||
|
||||
add_executable(test_kompute Main.cpp)
|
||||
file(GLOB test_kompute_CPP
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
)
|
||||
|
||||
add_executable(test_kompute ${test_kompute_CPP})
|
||||
|
||||
target_include_directories(
|
||||
test_kompute PUBLIC
|
||||
|
|
|
|||
114
test/Main.cpp
114
test/Main.cpp
|
|
@ -1,114 +0,0 @@
|
|||
#if defined(_WIN32)
|
||||
#pragma comment(linker, "/subsystem:console")
|
||||
#endif
|
||||
|
||||
// SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import
|
||||
#if DEBUG
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
// ranges.h must come after spdlog.h
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
#if DEBUG
|
||||
spdlog::set_level(spdlog::level::debug);
|
||||
#else
|
||||
spdlog::set_level(spdlog::level::info);
|
||||
#endif
|
||||
|
||||
try {
|
||||
|
||||
// Run Kompute
|
||||
|
||||
{
|
||||
spdlog::info("Creating manager");
|
||||
kp::Manager mgr;
|
||||
|
||||
spdlog::info("Creating first tensor");
|
||||
std::shared_ptr<kp::Tensor> tensorLHS{ new kp::Tensor( { 0, 1, 2 }) };
|
||||
mgr.evalOp<kp::OpCreateTensor>({ tensorLHS });
|
||||
|
||||
spdlog::info("Creating second tensor");
|
||||
std::shared_ptr<kp::Tensor> tensorRHS{ new kp::Tensor(
|
||||
{ 2, 4, 6 }) };
|
||||
mgr.evalOp<kp::OpCreateTensor>({ tensorRHS });
|
||||
|
||||
// TODO: Add capabilities for just output tensor types
|
||||
spdlog::info("Creating output tensor");
|
||||
std::shared_ptr<kp::Tensor> tensorOutput{ new kp::Tensor(
|
||||
{ 0, 0, 0 }) };
|
||||
mgr.evalOp<kp::OpCreateTensor>({ tensorOutput });
|
||||
|
||||
spdlog::info("OpCreateTensor success for tensors");
|
||||
spdlog::info("Tensor one: {}", tensorLHS->data());
|
||||
spdlog::info("Tensor two: {}", tensorRHS->data());
|
||||
spdlog::info("Tensor output: {}", tensorOutput->data());
|
||||
|
||||
spdlog::info("Calling op mult");
|
||||
mgr.evalOp<kp::OpMult<>>({ tensorLHS, tensorRHS, tensorOutput });
|
||||
|
||||
spdlog::info("OpMult call success");
|
||||
spdlog::info("Tensor output: {}", tensorOutput->data());
|
||||
|
||||
spdlog::info("Called manager eval success END PROGRAM");
|
||||
}
|
||||
{
|
||||
spdlog::info("Creating manager");
|
||||
kp::Manager mgr;
|
||||
kp::Sequence sq = mgr.constructSequence();
|
||||
sq.begin();
|
||||
|
||||
spdlog::info("Creating first tensor");
|
||||
std::shared_ptr<kp::Tensor> tensorLHS{ new kp::Tensor(
|
||||
{ 0, 1, 2 }) };
|
||||
|
||||
spdlog::info("Creating second tensor");
|
||||
std::shared_ptr<kp::Tensor> tensorRHS{ new kp::Tensor(
|
||||
{ 2, 4, 6 }) };
|
||||
|
||||
// TODO: Add capabilities for just output tensor types
|
||||
spdlog::info("Creating output tensor");
|
||||
std::shared_ptr<kp::Tensor> tensorOutput{ new kp::Tensor(
|
||||
{ 0, 0, 0 }) };
|
||||
|
||||
sq.record<kp::OpCreateTensor>({ tensorLHS });
|
||||
sq.record<kp::OpCreateTensor>({ tensorRHS });
|
||||
sq.record<kp::OpCreateTensor>({ tensorOutput });
|
||||
|
||||
spdlog::info("OpCreateTensor success for tensors");
|
||||
spdlog::info("Tensor one: {}", tensorLHS->data());
|
||||
spdlog::info("Tensor two: {}", tensorRHS->data());
|
||||
spdlog::info("Tensor output: {}", tensorOutput->data());
|
||||
|
||||
spdlog::info("Calling op mult");
|
||||
sq.record<kp::OpMult<>>({ tensorLHS, tensorRHS, tensorOutput });
|
||||
|
||||
sq.end();
|
||||
sq.eval();
|
||||
|
||||
spdlog::info("OpMult call success");
|
||||
spdlog::info("Tensor output: {}", tensorOutput->data());
|
||||
|
||||
spdlog::info("Called manager eval success END PROGRAM");
|
||||
}
|
||||
|
||||
return 0;
|
||||
} catch (const std::exception& exc) {
|
||||
spdlog::error("Exception caught: {}", exc.what());
|
||||
return 1;
|
||||
} catch (...) {
|
||||
spdlog::error("Uncaught exception");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,28 @@
|
|||
#define CATCH_CONFIG_MAIN
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
|
||||
// clang-format: SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import
|
||||
#if DEBUG
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
|
||||
#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[] ) {
|
||||
|
||||
#if DEBUG
|
||||
spdlog::set_level(spdlog::level::debug);
|
||||
#else
|
||||
spdlog::set_level(spdlog::level::info);
|
||||
#endif
|
||||
|
||||
int result = Catch::Session().run( argc, argv );
|
||||
|
||||
// global clean-up...
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
104
test/TestManager.cpp
Executable file
104
test/TestManager.cpp
Executable file
|
|
@ -0,0 +1,104 @@
|
|||
#if defined(_WIN32)
|
||||
#pragma comment(linker, "/subsystem:console")
|
||||
#endif
|
||||
|
||||
// clang-format: SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import
|
||||
#if DEBUG
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
// clang-format: ranges.h must come after spdlog.h
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
TEST_CASE("End to end OpMult Flow should execute correctly from manager") {
|
||||
spdlog::info("TEST CASE STARTING");
|
||||
|
||||
spdlog::info("Creating manager");
|
||||
kp::Manager mgr;
|
||||
|
||||
spdlog::info("Creating first tensor");
|
||||
std::shared_ptr<kp::Tensor> tensorLHS{ new kp::Tensor( { 0, 1, 2 }) };
|
||||
mgr.evalOp<kp::OpCreateTensor>({ tensorLHS });
|
||||
|
||||
spdlog::info("Creating second tensor");
|
||||
std::shared_ptr<kp::Tensor> tensorRHS{ new kp::Tensor(
|
||||
{ 2, 4, 6 }) };
|
||||
mgr.evalOp<kp::OpCreateTensor>({ tensorRHS });
|
||||
|
||||
// TODO: Add capabilities for just output tensor types
|
||||
spdlog::info("Creating output tensor");
|
||||
std::shared_ptr<kp::Tensor> tensorOutput{ new kp::Tensor(
|
||||
{ 0, 0, 0 }) };
|
||||
mgr.evalOp<kp::OpCreateTensor>({ tensorOutput });
|
||||
|
||||
spdlog::info("OpCreateTensor success for tensors");
|
||||
spdlog::info("Tensor one: {}", tensorLHS->data());
|
||||
spdlog::info("Tensor two: {}", tensorRHS->data());
|
||||
spdlog::info("Tensor output: {}", tensorOutput->data());
|
||||
|
||||
spdlog::info("Calling op mult");
|
||||
mgr.evalOp<kp::OpMult<>>({ tensorLHS, tensorRHS, tensorOutput });
|
||||
|
||||
spdlog::info("OpMult call success");
|
||||
spdlog::info("Tensor output: {}", tensorOutput->data());
|
||||
|
||||
REQUIRE(tensorOutput->data() == std::vector<uint32_t>{0, 4, 12});
|
||||
|
||||
spdlog::info("Called manager eval success END PROGRAM");
|
||||
}
|
||||
|
||||
TEST_CASE("End to end OpMult Flow should execute correctly from sequence") {
|
||||
spdlog::info("TEST CASE STARTING");
|
||||
|
||||
spdlog::info("Creating manager");
|
||||
|
||||
spdlog::info("Creating first tensor");
|
||||
std::shared_ptr<kp::Tensor> tensorLHS{ new kp::Tensor(
|
||||
{ 0, 1, 2 }) };
|
||||
|
||||
spdlog::info("Creating second tensor");
|
||||
std::shared_ptr<kp::Tensor> tensorRHS{ new kp::Tensor(
|
||||
{ 2, 4, 6 }) };
|
||||
|
||||
// TODO: Add capabilities for just output tensor types
|
||||
spdlog::info("Creating output tensor");
|
||||
std::shared_ptr<kp::Tensor> tensorOutput{ new kp::Tensor(
|
||||
{ 0, 0, 0 }) };
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
std::weak_ptr<kp::Sequence> sq_ref = mgr.managedSequence();
|
||||
if (std::shared_ptr<kp::Sequence> sq = sq_ref.lock()) {
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpCreateTensor>({ tensorLHS });
|
||||
sq->record<kp::OpCreateTensor>({ tensorRHS });
|
||||
sq->record<kp::OpCreateTensor>({ tensorOutput });
|
||||
|
||||
spdlog::info("OpCreateTensor success for tensors");
|
||||
spdlog::info("Tensor one: {}", tensorLHS->data());
|
||||
spdlog::info("Tensor two: {}", tensorRHS->data());
|
||||
spdlog::info("Tensor output: {}", tensorOutput->data());
|
||||
|
||||
spdlog::info("Calling op mult");
|
||||
sq->record<kp::OpMult<>>({ tensorLHS, tensorRHS, tensorOutput });
|
||||
|
||||
sq->end();
|
||||
sq->eval();
|
||||
}
|
||||
sq_ref.reset();
|
||||
|
||||
spdlog::info("OpMult call success");
|
||||
spdlog::info("Tensor output: {}", tensorOutput->data());
|
||||
|
||||
REQUIRE(tensorOutput->data() == std::vector<uint32_t>{0, 4, 12});
|
||||
|
||||
spdlog::info("Called manager eval success END PROGRAM");
|
||||
}
|
||||
|
|
@ -1,25 +1,10 @@
|
|||
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
#include "Tensor.hpp"
|
||||
#include "kompute/Tensor.hpp"
|
||||
|
||||
|
||||
int Factorial( int number ) {
|
||||
return number <= 1 ? number : Factorial( number - 1 ) * number; // fail
|
||||
// return number <= 1 ? 1 : Factorial( number - 1 ) * number; // pass
|
||||
}
|
||||
|
||||
TEST_CASE( "Factorial of 0 is 1 (fail)", "[single-file]" ) {
|
||||
REQUIRE( Factorial(0) == 1 );
|
||||
}
|
||||
|
||||
TEST_CASE( "Factorials of 1 and higher are computed (pass)", "[single-file]" ) {
|
||||
REQUIRE( Factorial(1) == 1 );
|
||||
REQUIRE( Factorial(2) == 2 );
|
||||
REQUIRE( Factorial(3) == 6 );
|
||||
REQUIRE( Factorial(10) == 3628800 );
|
||||
}
|
||||
|
||||
TEST_CASE("Exploring if manager test compiles") {
|
||||
kp::Tensor tensor({0,1,2});
|
||||
REQUIRE( tensor.size() == 3 );
|
||||
TEST_CASE("Tensor should have same vector as initialised") {
|
||||
std::vector<uint32_t> vec{0,1,2};
|
||||
kp::Tensor tensor(vec);
|
||||
REQUIRE( tensor.data() == vec );
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue