Updated repository to use cmakelists for compilation

This commit is contained in:
Alejandro Saucedo 2020-08-24 20:56:25 +01:00
parent ecc9a1e273
commit af74e25e35
25 changed files with 250 additions and 228 deletions

1
.ccls
View file

@ -14,4 +14,5 @@
-DKOMPUTE_INCLUDE_FOR_SYNTAX
-I./external/
-I./src/include/

View file

@ -5,31 +5,14 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(fmt REQUIRED)
find_package(spdlog REQUIRED)
find_package(Vulkan REQUIRED)
# Custom commands
option(KOMPUTE_BUILD_TESTS "Enable if you want to build tests" ON)
file(GLOB kompute_SRC
"${CMAKE_CURRENT_LIST_DIR}/src/*.hpp"
"${CMAKE_CURRENT_LIST_DIR}/src/*.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/shaders/*.hpp"
"${CMAKE_CURRENT_LIST_DIR}/src/shaders/*.cpp"
)
add_subdirectory(src)
add_executable(kompute
${kompute_SRC})
target_include_directories(
kompute PUBLIC
fmt
spdlog
Vulkan
)
target_link_libraries(
kompute
fmt::fmt
spdlog::spdlog
Vulkan::Vulkan
)
if(KOMPUTE_BUILD_TESTS)
include(CTest)
enable_testing()
add_subdirectory(test)
endif()

View file

@ -22,6 +22,9 @@ run_cmake:
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
-G "Visual Studio 16 2019"
clean_cmake:
rm -rf build/
build: clean build_shaders
$(CC) \
src/* \

View file

@ -1,6 +1,6 @@
#include <fstream>
#include "Algorithm.hpp"
#include "kompute/Algorithm.hpp"
namespace kp {

39
src/CMakeLists.txt Normal file
View file

@ -0,0 +1,39 @@
find_package(fmt REQUIRED)
find_package(spdlog REQUIRED)
find_package(Vulkan REQUIRED)
file(GLOB kompute_CPP
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
)
add_library(kompute
${kompute_CPP})
target_include_directories(
kompute PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
target_link_libraries(
kompute
fmt::fmt
spdlog::spdlog
Vulkan::Vulkan
)
add_library(kompute::kompute ALIAS kompute)
install(TARGETS kompute EXPORT KomputeTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
INCLUDES DESTINATION include)
install(DIRECTORY include/ DESTINATION include)
install(EXPORT KomputeTargets
FILE KomputeTargets.cmake
NAMESPACE kp::
DESTINATION lib/cmake/kompute)

View file

@ -2,7 +2,7 @@
#include <set>
#include <string>
#include "Manager.hpp"
#include "kompute/Manager.hpp"
namespace kp {

View file

@ -1,7 +1,7 @@
#include "Tensor.hpp"
#include "kompute/Tensor.hpp"
#include "OpCreateTensor.hpp"
#include "kompute/OpCreateTensor.hpp"
namespace kp {

View file

@ -1,62 +0,0 @@
// Defining OPMULT_H to ensure cpp class doesn't reimport
#define OPMULT_HPP
#pragma once
#include <vulkan/vulkan.h>
#include <vulkan/vulkan.hpp>
// SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import
#if DEBUG
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
#endif
#include <spdlog/spdlog.h>
#include "Algorithm.hpp"
#include "Tensor.hpp"
#include "OpBase.hpp"
namespace kp {
template<uint32_t tX = 0, uint32_t tY = 0, uint32_t tZ = 0>
class OpMult : public OpBase
{
public:
OpMult();
OpMult(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
std::shared_ptr<vk::Device> device,
std::shared_ptr<vk::CommandBuffer> commandBuffer);
~OpMult();
void init(std::vector<std::shared_ptr<Tensor>> tensors) override;
void record() override;
void postSubmit() override;
private:
// Always owned resources
std::shared_ptr<Tensor> mTensorOutputStaging;
// Optionally owned resources
std::shared_ptr<Algorithm> mAlgorithm;
bool mFreeAlgorithm = false;
// Never owned resources
std::shared_ptr<Tensor> mTensorLHS;
std::shared_ptr<Tensor> mTensorRHS;
std::shared_ptr<Tensor> mTensorOutput;
uint32_t mX;
uint32_t mY;
uint32_t mZ;
};
} // End namespace kp
// Including implemenation for template class
#include "OpMult.cpp"

View file

@ -1,5 +1,5 @@
#include "Sequence.hpp"
#include "kompute/Sequence.hpp"
namespace kp {

View file

@ -3,7 +3,7 @@
#include <spdlog/fmt/bundled/ranges.h>
#endif
#include "Tensor.hpp"
#include "kompute/Tensor.hpp"
namespace kp {

View file

@ -10,7 +10,7 @@
#include <spdlog/spdlog.h>
#include "Tensor.hpp"
#include "kompute/Tensor.hpp"
namespace kp {

View file

@ -10,7 +10,7 @@
#include <spdlog/spdlog.h>
#include "Sequence.hpp"
#include "kompute/Sequence.hpp"
namespace kp {

View file

@ -12,7 +12,7 @@
#include <spdlog/spdlog.h>
#include "Tensor.hpp"
#include "kompute/Tensor.hpp"
namespace kp {

View file

@ -10,9 +10,9 @@
#include <spdlog/spdlog.h>
#include "Tensor.hpp"
#include "kompute/Tensor.hpp"
#include "OpBase.hpp"
#include "kompute/OpBase.hpp"
namespace kp {

View file

@ -1,19 +1,65 @@
#ifndef OPMULT_CPP
#define OPMULT_CPP
#pragma once
#include <fstream>
#include "Tensor.hpp"
#include <vulkan/vulkan.h>
#include <vulkan/vulkan.hpp>
#if RELEASE
#include <shaders/opmult.hpp>
// SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import
#if DEBUG
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
#endif
// Only defining hpp file for syntax validation in editors
#ifndef OPMULT_HPP
#include "OpMult.hpp"
#endif
#include <spdlog/spdlog.h>
#include "kompute/Algorithm.hpp"
#include "kompute/Tensor.hpp"
#include "kompute/OpBase.hpp"
namespace kp {
template<uint32_t tX = 0, uint32_t tY = 0, uint32_t tZ = 0>
class OpMult : public OpBase
{
public:
OpMult();
OpMult(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
std::shared_ptr<vk::Device> device,
std::shared_ptr<vk::CommandBuffer> commandBuffer);
~OpMult();
void init(std::vector<std::shared_ptr<Tensor>> tensors) override;
void record() override;
void postSubmit() override;
private:
// Always owned resources
std::shared_ptr<Tensor> mTensorOutputStaging;
// Optionally owned resources
std::shared_ptr<Algorithm> mAlgorithm;
bool mFreeAlgorithm = false;
// Never owned resources
std::shared_ptr<Tensor> mTensorLHS;
std::shared_ptr<Tensor> mTensorRHS;
std::shared_ptr<Tensor> mTensorOutput;
uint32_t mX;
uint32_t mY;
uint32_t mZ;
};
} // End namespace kp
// Including implemenation for template class
#ifndef OPMULT_CPP
#define OPMULT_CPP
namespace kp {
@ -187,3 +233,4 @@ OpMult<tX, tY, tZ>::postSubmit()
#endif // #ifndef OPMULT_CPP

View file

@ -10,7 +10,7 @@
#include <spdlog/spdlog.h>
#include "Tensor.hpp"
#include "kompute/Tensor.hpp"
namespace kp {

View file

@ -10,7 +10,7 @@
#include <spdlog/spdlog.h>
#include "OpBase.hpp"
#include "kompute/OpBase.hpp"
namespace kp {

View file

@ -1,117 +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 "Manager.hpp"
#include "OpCreateTensor.hpp"
#include "OpMult.hpp"
#include "Tensor.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;
}
}

11
test/CMakeLists.txt Normal file
View file

@ -0,0 +1,11 @@
find_package(Catch2 REQUIRED)
add_executable(test_kompute Main.cpp)
target_link_libraries(test_kompute PRIVATE Catch2::Catch2)
target_link_libraries(test_kompute PRIVATE kompute)
add_test(NAME test_kompute COMMAND test_kompute)

117
test/Main.cpp Normal file → Executable file
View file

@ -1,4 +1,117 @@
#define CATCH_CONFIG_MAIN
#if defined(_WIN32)
#pragma comment(linker, "/subsystem:console")
#endif
#include "catch2/catch.hpp"
// 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/Manager.hpp"
#include "kompute/OpCreateTensor.hpp"
#include "kompute/OpMult.hpp"
#include "kompute/Tensor.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;
}
}

4
test/TestMain.cpp Normal file
View file

@ -0,0 +1,4 @@
#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"