Updated repository to use cmakelists for compilation
This commit is contained in:
parent
ecc9a1e273
commit
af74e25e35
25 changed files with 250 additions and 228 deletions
1
.ccls
1
.ccls
|
|
@ -14,4 +14,5 @@
|
|||
-DKOMPUTE_INCLUDE_FOR_SYNTAX
|
||||
|
||||
-I./external/
|
||||
-I./src/include/
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
3
Makefile
3
Makefile
|
|
@ -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/* \
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include <fstream>
|
||||
|
||||
#include "Algorithm.hpp"
|
||||
#include "kompute/Algorithm.hpp"
|
||||
|
||||
namespace kp {
|
||||
|
||||
|
|
|
|||
39
src/CMakeLists.txt
Normal file
39
src/CMakeLists.txt
Normal 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)
|
||||
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "Manager.hpp"
|
||||
#include "kompute/Manager.hpp"
|
||||
|
||||
namespace kp {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include "Tensor.hpp"
|
||||
#include "kompute/Tensor.hpp"
|
||||
|
||||
#include "OpCreateTensor.hpp"
|
||||
#include "kompute/OpCreateTensor.hpp"
|
||||
|
||||
namespace kp {
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
#include "Sequence.hpp"
|
||||
#include "kompute/Sequence.hpp"
|
||||
|
||||
namespace kp {
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include <spdlog/fmt/bundled/ranges.h>
|
||||
#endif
|
||||
|
||||
#include "Tensor.hpp"
|
||||
#include "kompute/Tensor.hpp"
|
||||
|
||||
namespace kp {
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "Tensor.hpp"
|
||||
#include "kompute/Tensor.hpp"
|
||||
|
||||
namespace kp {
|
||||
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "Sequence.hpp"
|
||||
#include "kompute/Sequence.hpp"
|
||||
|
||||
namespace kp {
|
||||
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "Tensor.hpp"
|
||||
#include "kompute/Tensor.hpp"
|
||||
|
||||
namespace kp {
|
||||
|
||||
|
|
@ -10,9 +10,9 @@
|
|||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "Tensor.hpp"
|
||||
#include "kompute/Tensor.hpp"
|
||||
|
||||
#include "OpBase.hpp"
|
||||
#include "kompute/OpBase.hpp"
|
||||
|
||||
namespace kp {
|
||||
|
||||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "Tensor.hpp"
|
||||
#include "kompute/Tensor.hpp"
|
||||
|
||||
namespace kp {
|
||||
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "OpBase.hpp"
|
||||
#include "kompute/OpBase.hpp"
|
||||
|
||||
namespace kp {
|
||||
|
||||
117
src/main.cpp
117
src/main.cpp
|
|
@ -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
11
test/CMakeLists.txt
Normal 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
117
test/Main.cpp
Normal file → Executable 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
4
test/TestMain.cpp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#define CATCH_CONFIG_MAIN
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue