Skip to content

Commit

Permalink
Updated SPDLOG as an optional dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
axsaucedo committed Sep 3, 2020
1 parent 0410ae0 commit 36a6092
Show file tree
Hide file tree
Showing 19 changed files with 150 additions and 76 deletions.
18 changes: 12 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ project(kompute VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 17)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_VERBOSE_MAKEFILE on)

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG=1")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DRELEASE=1")
# Enable or disable targets
option(KOMPUTE_OPT_BUILD_TESTS "Enable if you want to build tests" 1)
option(KOMPUTE_OPT_BUILD_DOCS "Enable if you want to build documentation" 1)
option(KOMPUTE_OPT_DEBUG_SYMBOLS "Enable if you want to build debug with symbols" 0)
option(KOMPUTE_OPT_ENABLE_SPDLOG "Extra compile flags for Kompute, see docs for full list" 1)

set(KOMPUTE_EXTRA_CXX_FLAGS "" CACHE STRING "Extra compile flags for Kompute, see docs for full list")

set(CMAKE_VERBOSE_MAKEFILE on)
if(KOMPUTE_OPT_ENABLE_SPDLOG)
set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DKOMPUTE_ENABLE_SPDLOG=1")
endif()

option(KOMPUTE_OPT_BUILD_TESTS "Enable if you want to build tests" ON)
option(KOMPUTE_OPT_BUILD_DOCS "Enable if you want to build documentation" ON)
option(KOMPUTE_OPT_DEBUG_SYMBOLS "Enable if you want to build debug with symbols" 0)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG=1 ${KOMPUTE_EXTRA_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DRELEASE=1 ${KOMPUTE_EXTRA_CXX_FLAGS}")

# Allow scripts to call main kompute Makefile
function(kompute_make KOMPUTE_MAKE_TARGET)
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ mk_run_tests: mk_build_tests
####### Visual studio build shortcut commands #######

VS_BUILD_TYPE ?= "Debug"
VS_CMAKE_EXTRA_FLAGS ?= ""

vs_cmake:
$(CMAKE_BIN) \
-Bbuild \
-DCMAKE_TOOLCHAIN_FILE=$(VCPKG_WIN_PATH) \
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
$(VS_CMAKE_EXTRA_FLAGS) \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-G "Visual Studio 16 2019"

Expand Down
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
* Explicit relationships for GPU and host memory ownership and memory management
* Providing [simple usecases]() as well as [advanced machine learning & data processing](https://axsaucedo.github.io/vulkan-kompute/overview/advanced-examples.html) examples


![](https://raw.githubusercontent.com/axsaucedo/vulkan-kompute/master/docs/images/komputer-2.gif)


## Getting Started

### Setup
Expand Down Expand Up @@ -177,6 +181,32 @@ We cover more advanced examples and applications of Vulkan Kompute, such as mach

You can find these in the advanced examples documentation section, such as the [logistic regression example](https://axsaucedo.github.io/vulkan-kompute/overview/advanced-examples.html).

## Build Overview

### Dependencies

Given Kompute is expected to be used across a broad range of architectures and hardware, it will be important to make sure we are able to minimise dependencies.

#### Required dependencies

The only required dependency in the build is Vulkan (vulkan.h and vulkan.hpp which are both part of the Vulkan SDK).

#### Optional dependencies

SPDLOG is the preferred logging library, however by default Vulkan Kompute runs without SPDLOG by overriding the macros. It also provides an easy way to override the macros if you prefer to bring your own logging framework. The macro override is the following:

```c++
#ifndef KOMPUTE_LOG_OVERRIDE // Use this if you want to define custom macro overrides
#if KOMPUTE_SPDLOG_ENABLED // Use this if you want to enable SPDLOG
#include <spdlog/spdlog.h>
#endif //KOMPUTE_SPDLOG_ENABLED
// ... Otherwise it adds macros that use std::cout (and only print first element)
#endif // KOMPUTE_LOG_OVERRIDE
```

You can choose to build with or without SPDLOG by using the cmake flag `KOMPUTE_OPT_ENABLE_SPDLOG`.


## Motivations

Vulkan Kompute was created after identifying the challenge most GPU processing projects with Vulkan undergo - namely having to build extensive boilerplate for Vulkan and create abstractions and interfaces that expose the core compute capabilities. It is only after a few thousand lines of code that it's possible to start building the application-specific logic.
Expand Down Expand Up @@ -275,8 +305,3 @@ make mk_cmake MK_BUILD_TYPE="Release"
make mk_run_tests
```


# The Komputer is waiting for instructions...

![](https://raw.githubusercontent.com/axsaucedo/vulkan-kompute/master/docs/images/komputer-2.gif)

36 changes: 32 additions & 4 deletions single_include/kompute/Kompute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,38 @@

// SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import
#if DEBUG
#ifndef SPDLOG_ACTIVE_LEVEL
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
#endif
#endif

#ifndef KOMPUTE_LOG_OVERRIDE
#if KOMPUTE_ENABLE_SPDLOG
#include <spdlog/spdlog.h>
#else
#include <iostream>
#if SPDLOG_ACTIVE_LEVEL > 1
#define SPDLOG_DEBUG(message, ...)
#else
#define SPDLOG_DEBUG(message, ...) std::cout << "DEBUG: " << message << std::endl
#endif // SPDLOG_ACTIVE_LEVEL > 1
#if SPDLOG_ACTIVE_LEVEL > 2
#define SPDLOG_INFO(message, ...)
#else
#define SPDLOG_INFO(message, ...) std::cout << "INFO: " << message << std::endl
#endif // SPDLOG_ACTIVE_LEVEL > 2
#if SPDLOG_ACTIVE_LEVEL > 3
#define SPDLOG_WARN(message, ...)
#else
#define SPDLOG_WARN(message, ...) std::cout << "WARNING: " << message << std::endl
#endif // SPDLOG_ACTIVE_LEVEL > 3
#if SPDLOG_ACTIVE_LEVEL > 4
#define SPDLOG_ERROR(message, ...)
#else
#define SPDLOG_ERROR(message, ...) std::cout << "ERROR: " << message << std::endl
#endif // SPDLOG_ACTIVE_LEVEL > 4
#endif //KOMPUTE_SPDLOG_ENABLED
#endif // KOMPUTE_LOG_OVERRIDE

/*
THIS FILE HAS BEEN AUTOMATICALLY GENERATED - DO NOT EDIT
Expand Down Expand Up @@ -407,7 +435,7 @@ class OpBase
SPDLOG_DEBUG("Kompute OpBase destructor started");

if (!this->mDevice) {
spdlog::warn("Kompute OpBase destructor called with empty device");
SPDLOG_WARN("Kompute OpBase destructor called with empty device");
return;
}

Expand All @@ -417,7 +445,7 @@ class OpBase
if (tensor && tensor->isInit()) {
tensor->freeMemoryDestroyGPUResources();
} else {
spdlog::error("Kompute OpBase expected to free "
SPDLOG_ERROR("Kompute OpBase expected to free "
"tensor but has already been freed.");
}
}
Expand Down Expand Up @@ -550,7 +578,7 @@ class Sequence
SPDLOG_DEBUG("Kompute Sequence record function started");

if (!this->isRecording()) {
spdlog::error(
SPDLOG_ERROR(
"Kompute sequence record attempted when not record BEGIN");
return false;
}
Expand Down Expand Up @@ -999,7 +1027,7 @@ OpAlgoBase<tX, tY, tZ>::OpAlgoBase(std::shared_ptr<vk::PhysicalDevice> physicalD
this->mY = 1;
this->mZ = 1;
}
spdlog::info("Kompute OpAlgoBase dispatch size X: {}, Y: {}, Z: {}",
SPDLOG_INFO("Kompute OpAlgoBase dispatch size X: {}, Y: {}, Z: {}",
this->mX,
this->mY,
this->mZ);
Expand Down
2 changes: 1 addition & 1 deletion src/Algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Algorithm::~Algorithm()
SPDLOG_DEBUG("Kompute Algorithm Destructor started");

if (!this->mDevice) {
spdlog::error(
SPDLOG_ERROR(
"Kompute Algorithm destructor reached with null Device pointer");
return;
}
Expand Down
10 changes: 7 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

find_package(fmt REQUIRED)
find_package(spdlog REQUIRED)
find_package(Vulkan REQUIRED)

Expand All @@ -25,11 +24,16 @@ target_include_directories(

target_link_libraries(
kompute
fmt::fmt
spdlog::spdlog
Vulkan::Vulkan
)

if(KOMPUTE_OPT_ENABLE_SPDLOG)
target_link_libraries(
kompute
spdlog::spdlog
)
endif()

add_dependencies(kompute
build_shaders
build_single_header)
Expand Down
10 changes: 5 additions & 5 deletions src/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Manager::~Manager()
SPDLOG_DEBUG("Kompute Manager Destructor started");

if (this->mDevice == nullptr) {
spdlog::error(
SPDLOG_ERROR(
"Kompute Manager destructor reached with null Device pointer");
return;
}
Expand All @@ -61,13 +61,13 @@ Manager::~Manager()
}

if (this->mFreeDevice) {
spdlog::info("Destroying device");
SPDLOG_INFO("Destroying device");
this->mDevice->destroy();
SPDLOG_DEBUG("Kompute Manager Destroyed Device");
}

if (this->mInstance == nullptr) {
spdlog::error(
SPDLOG_ERROR(
"Kompute Manager destructor reached with null Instance pointer");
return;
}
Expand Down Expand Up @@ -214,7 +214,7 @@ Manager::createDevice()
vk::PhysicalDeviceProperties physicalDeviceProperties =
physicalDevice.getProperties();

spdlog::info("Using physical device index {} found {}",
SPDLOG_INFO("Using physical device index {} found {}",
this->mPhysicalDeviceIndex,
physicalDeviceProperties.deviceName);

Expand All @@ -234,7 +234,7 @@ Manager::createDevice()
}

if (this->mComputeQueueFamilyIndex < 0) {
spdlog::critical("Compute queue is not supported");
throw std::runtime_error("Compute queue is not supported");
}

const float defaultQueuePriority(0.0f);
Expand Down
24 changes: 12 additions & 12 deletions src/Sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ Sequence::~Sequence()
SPDLOG_DEBUG("Kompute Sequence Destructor started");

if (!this->mDevice) {
spdlog::error(
SPDLOG_ERROR(
"Kompute Sequence destructor reached with null Device pointer");
return;
}

if (this->mFreeCommandBuffer) {
spdlog::info("Freeing CommandBuffer");
SPDLOG_INFO("Freeing CommandBuffer");
if (!this->mCommandBuffer) {
spdlog::error("Kompute Sequence destructor reached with null "
SPDLOG_ERROR("Kompute Sequence destructor reached with null "
"CommandPool pointer");
return;
}
Expand All @@ -46,9 +46,9 @@ Sequence::~Sequence()
}

if (this->mFreeCommandPool) {
spdlog::info("Destroying CommandPool");
SPDLOG_INFO("Destroying CommandPool");
if (this->mCommandPool == nullptr) {
spdlog::error("Kompute Sequence destructor reached with null "
SPDLOG_ERROR("Kompute Sequence destructor reached with null "
"CommandPool pointer");
return;
}
Expand All @@ -71,7 +71,7 @@ Sequence::begin()
SPDLOG_DEBUG("Kompute sequence called BEGIN");

if (this->isRecording()) {
spdlog::warn("Kompute Sequence begin called when already recording");
SPDLOG_WARN("Kompute Sequence begin called when already recording");
return false;
}

Expand All @@ -80,11 +80,11 @@ Sequence::begin()
}

if (!this->mRecording) {
spdlog::info("Kompute Sequence command recording BEGIN");
SPDLOG_INFO("Kompute Sequence command recording BEGIN");
this->mCommandBuffer->begin(vk::CommandBufferBeginInfo());
this->mRecording = true;
} else {
spdlog::warn("Kompute Sequence attempted to start command recording "
SPDLOG_WARN("Kompute Sequence attempted to start command recording "
"but recording already started");
}
return true;
Expand All @@ -96,7 +96,7 @@ Sequence::end()
SPDLOG_DEBUG("Kompute Sequence calling END");

if (!this->isRecording()) {
spdlog::warn("Kompute Sequence end called when not recording");
SPDLOG_WARN("Kompute Sequence end called when not recording");
return false;
}

Expand All @@ -105,11 +105,11 @@ Sequence::end()
}

if (this->mRecording) {
spdlog::info("Kompute Sequence command recording END");
SPDLOG_INFO("Kompute Sequence command recording END");
this->mCommandBuffer->end();
this->mRecording = false;
} else {
spdlog::warn("Kompute Sequence attempted to end command recording but "
SPDLOG_WARN("Kompute Sequence attempted to end command recording but "
"recording not started");
}
return true;
Expand All @@ -121,7 +121,7 @@ Sequence::eval()
SPDLOG_DEBUG("Kompute sequence compute recording EVAL");

if (this->isRecording()) {
spdlog::warn("Kompute Sequence eval called when still recording");
SPDLOG_WARN("Kompute Sequence eval called when still recording");
return false;
}

Expand Down
15 changes: 9 additions & 6 deletions src/Tensor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

#if DEBUG
#include <fmt/ranges.h>
#if KOMPUTE_SPDLOG_ENABLED
// Only enabled if spdlog is enabled
#include <spdlog/fmt/ranges.h>
#endif
#endif

#include "kompute/Tensor.hpp"
Expand Down Expand Up @@ -169,7 +172,7 @@ Tensor::mapDataFromHostMemory()
SPDLOG_DEBUG("Kompute Tensor mapping data from host buffer");

if (this->mTensorType != TensorTypes::eStaging) {
spdlog::error(
SPDLOG_ERROR(
"Mapping tensor data manually from DEVICE buffer instead of "
"using record GPU command with staging buffer");
return;
Expand All @@ -191,7 +194,7 @@ Tensor::mapDataIntoHostMemory()
SPDLOG_DEBUG("Kompute Tensor local mapping tensor data to host buffer");

if (this->mTensorType != TensorTypes::eStaging) {
spdlog::error(
SPDLOG_ERROR(
"Mapping tensor data manually to DEVICE memory instead of "
"using record GPU command with staging buffer");
return;
Expand Down Expand Up @@ -335,14 +338,14 @@ Tensor::freeMemoryDestroyGPUResources()
this->mIsInit = false;

if (!this->mDevice) {
spdlog::error(
SPDLOG_ERROR(
"Kompute Tensor destructor reached with null Device pointer");
return;
}

if (this->mFreeBuffer) {
if (!this->mBuffer) {
spdlog::error(
SPDLOG_ERROR(
"Kompose Tensor expected to free buffer but got null buffer");
} else {
SPDLOG_DEBUG("Kompose Tensor destroying buffer");
Expand All @@ -353,7 +356,7 @@ Tensor::freeMemoryDestroyGPUResources()

if (this->mFreeMemory) {
if (!this->mMemory) {
spdlog::error(
SPDLOG_ERROR(
"Kompose Tensor expected to free buffer but got null memory");
} else {
SPDLOG_DEBUG("Kompose Tensor freeing memory");
Expand Down
Loading

0 comments on commit 36a6092

Please sign in to comment.