From db6aa3e1e33f9fd03a8c0afeba049c6c487d4296 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 21 Feb 2021 11:38:32 +0000 Subject: [PATCH 1/4] Added fmt library and updated to print log info by default --- .gitmodules | 4 +++ CMakeLists.txt | 8 ++++- Makefile | 2 +- external/fmt | 1 + single_include/kompute/Kompute.hpp | 47 +++++++++++++++--------------- src/CMakeLists.txt | 46 +++++++++++++++++++++++------ src/include/kompute/Core.hpp | 45 ++++++++++++++-------------- 7 files changed, 95 insertions(+), 58 deletions(-) create mode 160000 external/fmt diff --git a/.gitmodules b/.gitmodules index 108a5773..eeb2b007 100644 --- a/.gitmodules +++ b/.gitmodules @@ -18,3 +18,7 @@ path = external/glslang url = https://github.com/KhronosGroup/glslang/ branch = 11.1.0 +[submodule "external/fmt"] + path = external/fmt + url = https://github.com/fmtlib/fmt + branch = 7.1.3 diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f35414a..480ec445 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,10 +27,16 @@ if(KOMPUTE_OPT_ENABLE_SPDLOG) set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DKOMPUTE_ENABLE_SPDLOG=1") if(KOMPUTE_OPT_INSTALL) # Enable install parameters for spdlog (overrides parameters passed) - set(SPDLOG_INSTALL ON CACHE BOOL "Enables install of glslang" FORCE) + set(SPDLOG_INSTALL ON CACHE BOOL "Enables install of spdlot" FORCE) + set(SPDLOG_FMT_EXTERNAL ON CACHE BOOL "Enables external fmt as its current dep" FORCE) endif() endif() +if(KOMPUTE_OPT_INSTALL) + # Enable install parameters for fmt (overrides parameters passed) + set(FMT_INSTALL ON CACHE BOOL "Enables install of fmt" FORCE) +endif() + if(KOMPUTE_OPT_ANDOID_BUILD) set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DVK_USE_PLATFORM_ANDROID_KHR") endif() diff --git a/Makefile b/Makefile index 8f39a254..76a896fe 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,7 @@ mk_cmake: -DKOMPUTE_OPT_BUILD_DOCS=1 \ -DKOMPUTE_OPT_BUILD_SHADERS=1 \ -DKOMPUTE_OPT_BUILD_SINGLE_HEADER=1 \ - -DKOMPUTE_OPT_ENABLE_SPDLOG=1 \ + -DKOMPUTE_OPT_ENABLE_SPDLOG=0 \ -DKOMPUTE_OPT_CODE_COVERAGE=1 \ -G "Unix Makefiles" diff --git a/external/fmt b/external/fmt new file mode 160000 index 00000000..7bdf0628 --- /dev/null +++ b/external/fmt @@ -0,0 +1 @@ +Subproject commit 7bdf0628b1276379886c7f6dda2cef2b3b374f0b diff --git a/single_include/kompute/Kompute.hpp b/single_include/kompute/Kompute.hpp index 3aaeb040..b33101cd 100755 --- a/single_include/kompute/Kompute.hpp +++ b/single_include/kompute/Kompute.hpp @@ -1,6 +1,6 @@ #pragma once -#ifdef VK_USE_PLATFORM_ANDROID_KHR +#if VK_USE_PLATFORM_ANDROID_KHR #include #include // VK_NO_PROTOTYPES required before vulkan import but after wrapper.hpp @@ -8,6 +8,8 @@ static const char* KOMPUTE_LOG_TAG = "KomputeLog"; #endif +#include + #include // Typedefs to simplify interaction with core types @@ -51,57 +53,54 @@ extern py::object kp_debug, kp_info, kp_warning, kp_error; #else #include #if SPDLOG_ACTIVE_LEVEL > 1 -#define SPDLOG_DEBUG(message, ...) +#define SPDLOG_DEBUG(...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_DEBUG(message, ...) \ - ((void)__android_log_print(ANDROID_LOG_DEBUG, KOMPUTE_LOG_TAG, message)) +#define SPDLOG_DEBUG(...) \ + ((void)__android_log_print(ANDROID_LOG_DEBUG, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__))) #elif defined(KOMPUTE_BUILD_PYTHON) -#define SPDLOG_DEBUG(message, ...) kp_debug(message); +#define SPDLOG_DEBUG(...) kp_debug(fmt::format(__VA_ARGS__)) #else -#define SPDLOG_DEBUG(message, ...) \ - std::cout << "DEBUG: " << message << std::endl +#define SPDLOG_DEBUG(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) #endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 1 #if SPDLOG_ACTIVE_LEVEL > 2 -#define SPDLOG_INFO(message, ...) +#define SPDLOG_INFO(...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_INFO(message, ...) \ - ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message)) +#define SPDLOG_INFO(...) \ + ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__))) #elif defined(KOMPUTE_BUILD_PYTHON) -#define SPDLOG_INFO(message, ...) kp_info(message); +#define SPDLOG_INFO(...) kp_info(fmt::format(__VA_ARGS__)) #else -#define SPDLOG_INFO(message, ...) std::cout << "INFO: " << message << std::endl +#define SPDLOG_INFO(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) #endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 2 #if SPDLOG_ACTIVE_LEVEL > 3 -#define SPDLOG_WARN(message, ...) +#define SPDLOG_WARN(...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_WARN(message, ...) \ - ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message)) +#define SPDLOG_WARN(...) \ + ((void)__android_log_print(ANDROID_LOG_WARN, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__))) #elif defined(KOMPUTE_BUILD_PYTHON) -#define SPDLOG_WARN(message, ...) kp_warning(message); +#define SPDLOG_WARN(...) kp_warning(fmt::format(__VA_ARGS__)) #else -#define SPDLOG_WARN(message, ...) \ - std::cout << "WARNING: " << message << std::endl +#define SPDLOG_WARN(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) #endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 3 #if SPDLOG_ACTIVE_LEVEL > 4 -#define SPDLOG_ERROR(message, ...) +#define SPDLOG_ERROR(...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_ERROR(message, ...) \ - ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message)) +#define SPDLOG_ERROR(...) \ + ((void)__android_log_print(ANDROID_LOG_ERROR, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__))) #elif defined(KOMPUTE_BUILD_PYTHON) -#define SPDLOG_ERROR(message, ...) kp_error(message); +#define SPDLOG_ERROR(...) kp_error(fmt::format(__VA_ARGS__)) #else -#define SPDLOG_ERROR(message, ...) \ - std::cout << "ERROR: " << message << std::endl +#define SPDLOG_ERROR(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) #endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 4 #endif // KOMPUTE_SPDLOG_ENABLED diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b3cbad3a..dc36d722 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,13 +1,4 @@ -if(KOMPUTE_OPT_ENABLE_SPDLOG) - if(KOMPUTE_OPT_REPO_SUBMODULE_BUILD) - set(SPDLOG_INSTALL ON) - add_subdirectory(${PROJECT_SOURCE_DIR}/external/spdlog ${CMAKE_CURRENT_BINARY_DIR}/kompute_spdlog) - else() - find_package(spdlog REQUIRED) - endif() -endif() - if(KOMPUTE_OPT_ANDOID_BUILD) find_library(android android) endif() @@ -79,13 +70,42 @@ if(KOMPUTE_OPT_REPO_SUBMODULE_BUILD) $) endif() +##################################################### +#################### fmt ####################### +##################################################### + +if(KOMPUTE_OPT_REPO_SUBMODULE_BUILD) + add_subdirectory(${PROJECT_SOURCE_DIR}/external/fmt ${CMAKE_CURRENT_BINARY_DIR}/kompute_fmt) +else() + find_package(fmt REQUIRED) +endif() + +target_link_libraries( + kompute + fmt::fmt +) + +##################################################### +#################### SPDLOG ####################### +##################################################### + if(KOMPUTE_OPT_ENABLE_SPDLOG) + if(KOMPUTE_OPT_REPO_SUBMODULE_BUILD) + add_subdirectory(${PROJECT_SOURCE_DIR}/external/spdlog ${CMAKE_CURRENT_BINARY_DIR}/kompute_spdlog) + else() + find_package(spdlog REQUIRED) + endif() + target_link_libraries( kompute spdlog::spdlog ) endif() +##################################################### +#################### Android ####################### +##################################################### + if(KOMPUTE_OPT_ANDOID_BUILD) target_link_libraries( kompute @@ -95,11 +115,19 @@ if(KOMPUTE_OPT_ANDOID_BUILD) ) endif() +##################################################### +########## Built C++ Header SHADERS ################# +##################################################### + if(KOMPUTE_OPT_BUILD_SHADERS) add_dependencies(kompute build_shaders) endif() +##################################################### +#################### Single Header ####################### +##################################################### + if(KOMPUTE_OPT_BUILD_SINGLE_HEADER) add_dependencies(kompute build_single_header) diff --git a/src/include/kompute/Core.hpp b/src/include/kompute/Core.hpp index 9550d387..c3ec7b9c 100644 --- a/src/include/kompute/Core.hpp +++ b/src/include/kompute/Core.hpp @@ -8,6 +8,8 @@ static const char* KOMPUTE_LOG_TAG = "KomputeLog"; #endif +#include + #include // Typedefs to simplify interaction with core types @@ -51,57 +53,54 @@ extern py::object kp_debug, kp_info, kp_warning, kp_error; #else #include #if SPDLOG_ACTIVE_LEVEL > 1 -#define SPDLOG_DEBUG(message, ...) +#define SPDLOG_DEBUG(...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_DEBUG(message, ...) \ - ((void)__android_log_print(ANDROID_LOG_DEBUG, KOMPUTE_LOG_TAG, message)) +#define SPDLOG_DEBUG(...) \ + ((void)__android_log_print(ANDROID_LOG_DEBUG, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__))) #elif defined(KOMPUTE_BUILD_PYTHON) -#define SPDLOG_DEBUG(message, ...) kp_debug(message); +#define SPDLOG_DEBUG(...) kp_debug(fmt::format(__VA_ARGS__)) #else -#define SPDLOG_DEBUG(message, ...) \ - std::cout << "DEBUG: " << message << std::endl +#define SPDLOG_DEBUG(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) #endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 1 #if SPDLOG_ACTIVE_LEVEL > 2 -#define SPDLOG_INFO(message, ...) +#define SPDLOG_INFO(...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_INFO(message, ...) \ - ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message)) +#define SPDLOG_INFO(...) \ + ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__))) #elif defined(KOMPUTE_BUILD_PYTHON) -#define SPDLOG_INFO(message, ...) kp_info(message); +#define SPDLOG_INFO(...) kp_info(fmt::format(__VA_ARGS__)) #else -#define SPDLOG_INFO(message, ...) std::cout << "INFO: " << message << std::endl +#define SPDLOG_INFO(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) #endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 2 #if SPDLOG_ACTIVE_LEVEL > 3 -#define SPDLOG_WARN(message, ...) +#define SPDLOG_WARN(...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_WARN(message, ...) \ - ((void)__android_log_print(ANDROID_LOG_WARN, KOMPUTE_LOG_TAG, message)) +#define SPDLOG_WARN(...) \ + ((void)__android_log_print(ANDROID_LOG_WARN, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__))) #elif defined(KOMPUTE_BUILD_PYTHON) -#define SPDLOG_WARN(message, ...) kp_warning(message); +#define SPDLOG_WARN(...) kp_warning(fmt::format(__VA_ARGS__)) #else -#define SPDLOG_WARN(message, ...) \ - std::cout << "WARNING: " << message << std::endl +#define SPDLOG_WARN(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) #endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 3 #if SPDLOG_ACTIVE_LEVEL > 4 -#define SPDLOG_ERROR(message, ...) +#define SPDLOG_ERROR(...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_ERROR(message, ...) \ - ((void)__android_log_print(ANDROID_LOG_ERROR, KOMPUTE_LOG_TAG, message)) +#define SPDLOG_ERROR(...) \ + ((void)__android_log_print(ANDROID_LOG_ERROR, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__))) #elif defined(KOMPUTE_BUILD_PYTHON) -#define SPDLOG_ERROR(message, ...) kp_error(message); +#define SPDLOG_ERROR(...) kp_error(fmt::format(__VA_ARGS__)) #else -#define SPDLOG_ERROR(message, ...) \ - std::cout << "ERROR: " << message << std::endl +#define SPDLOG_ERROR(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) #endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 4 #endif // KOMPUTE_SPDLOG_ENABLED From 29c50e5728948d952f7bf8e79aad9db750e1bf31 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 21 Feb 2021 11:51:34 +0000 Subject: [PATCH 2/4] Amended SPDLOG_X log functions to be KP_LOG_X --- Makefile | 2 +- .../app/src/main/cpp/KomputeJniNative.cpp | 8 +- .../kompute_model_ml/KomputeModelMLNode.cpp | 10 +- .../gdnative_shared/src/KomputeModelML.cpp | 10 +- single_include/kompute/Kompute.hpp | 102 +++++++++--------- src/Algorithm.cpp | 60 +++++------ src/Manager.cpp | 60 +++++------ src/OpAlgoBase.cpp | 32 +++--- src/OpAlgoLhsRhsOut.cpp | 18 ++-- src/OpTensorCopy.cpp | 14 +-- src/OpTensorSyncDevice.cpp | 16 +-- src/OpTensorSyncLocal.cpp | 18 ++-- src/Sequence.cpp | 72 ++++++------- src/Shader.cpp | 10 +- src/Tensor.cpp | 62 +++++------ src/include/kompute/Core.hpp | 36 ++++--- src/include/kompute/Manager.hpp | 38 +++---- src/include/kompute/Sequence.hpp | 10 +- src/include/kompute/operations/OpBase.hpp | 12 +-- src/include/kompute/operations/OpMult.hpp | 6 +- test/TestLogisticRegression.cpp | 4 +- 21 files changed, 304 insertions(+), 296 deletions(-) diff --git a/Makefile b/Makefile index 76a896fe..8f39a254 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,7 @@ mk_cmake: -DKOMPUTE_OPT_BUILD_DOCS=1 \ -DKOMPUTE_OPT_BUILD_SHADERS=1 \ -DKOMPUTE_OPT_BUILD_SINGLE_HEADER=1 \ - -DKOMPUTE_OPT_ENABLE_SPDLOG=0 \ + -DKOMPUTE_OPT_ENABLE_SPDLOG=1 \ -DKOMPUTE_OPT_CODE_COVERAGE=1 \ -G "Unix Makefiles" diff --git a/examples/android/android-simple/app/src/main/cpp/KomputeJniNative.cpp b/examples/android/android-simple/app/src/main/cpp/KomputeJniNative.cpp index 995b785f..6aa27019 100644 --- a/examples/android/android-simple/app/src/main/cpp/KomputeJniNative.cpp +++ b/examples/android/android-simple/app/src/main/cpp/KomputeJniNative.cpp @@ -51,12 +51,12 @@ extern "C" { JNIEXPORT jboolean JNICALL Java_com_ethicalml_kompute_KomputeJni_initVulkan(JNIEnv *env, jobject thiz) { - SPDLOG_INFO("Initialising vulkan"); + KP_LOG_INFO("Initialising vulkan"); uint32_t totalRetries = 0; while (totalRetries < KOMPUTE_VK_INIT_RETRIES) { - SPDLOG_INFO("VULKAN LOAD TRY NUMBER: %u", totalRetries); + KP_LOG_INFO("VULKAN LOAD TRY NUMBER: %u", totalRetries); if(InitVulkan()) { break; } @@ -76,7 +76,7 @@ Java_com_ethicalml_kompute_KomputeJni_kompute( jfloatArray xjJFloatArr, jfloatArray yJFloatArr) { - SPDLOG_INFO("Creating manager"); + KP_LOG_INFO("Creating manager"); std::vector xiVector = jfloatArrayToVector(env, xiJFloatArr); std::vector xjVector = jfloatArrayToVector(env, xjJFloatArr); @@ -98,7 +98,7 @@ Java_com_ethicalml_kompute_KomputeJni_komputeParams( jfloatArray xjJFloatArr, jfloatArray yJFloatArr) { - SPDLOG_INFO("Creating manager"); + KP_LOG_INFO("Creating manager"); std::vector xiVector = jfloatArrayToVector(env, xiJFloatArr); std::vector xjVector = jfloatArrayToVector(env, xjJFloatArr); diff --git a/examples/godot_logistic_regression/custom_module/kompute_model_ml/KomputeModelMLNode.cpp b/examples/godot_logistic_regression/custom_module/kompute_model_ml/KomputeModelMLNode.cpp index 010a3164..c304deff 100644 --- a/examples/godot_logistic_regression/custom_module/kompute_model_ml/KomputeModelMLNode.cpp +++ b/examples/godot_logistic_regression/custom_module/kompute_model_ml/KomputeModelMLNode.cpp @@ -92,10 +92,10 @@ void KomputeModelMLNode::train(Array yArr, Array xIArr, Array xJArr) { } } - SPDLOG_INFO("RESULT: <<<<<<<<<<<<<<<<<<<"); - SPDLOG_INFO(wIn->data()[0]); - SPDLOG_INFO(wIn->data()[1]); - SPDLOG_INFO(bIn->data()[0]); + KP_LOG_INFO("RESULT: <<<<<<<<<<<<<<<<<<<"); + KP_LOG_INFO(wIn->data()[0]); + KP_LOG_INFO(wIn->data()[1]); + KP_LOG_INFO(bIn->data()[0]); this->mWeights = kp::Tensor(wIn->data()); this->mBias = kp::Tensor(bIn->data()); @@ -127,7 +127,7 @@ Array KomputeModelMLNode::predict(Array xI, Array xJ) { Array KomputeModelMLNode::get_params() { Array retArray; - SPDLOG_INFO(this->mWeights.size() + this->mBias.size()); + KP_LOG_INFO(this->mWeights.size() + this->mBias.size()); if(this->mWeights.size() + this->mBias.size() == 0) { return retArray; diff --git a/examples/godot_logistic_regression/gdnative_shared/src/KomputeModelML.cpp b/examples/godot_logistic_regression/gdnative_shared/src/KomputeModelML.cpp index e9a9c51b..f16c3c24 100644 --- a/examples/godot_logistic_regression/gdnative_shared/src/KomputeModelML.cpp +++ b/examples/godot_logistic_regression/gdnative_shared/src/KomputeModelML.cpp @@ -96,10 +96,10 @@ void KomputeModelML::train(Array yArr, Array xIArr, Array xJArr) { } } - SPDLOG_INFO("RESULT: <<<<<<<<<<<<<<<<<<<"); - SPDLOG_INFO(wIn->data()[0]); - SPDLOG_INFO(wIn->data()[1]); - SPDLOG_INFO(bIn->data()[0]); + KP_LOG_INFO("RESULT: <<<<<<<<<<<<<<<<<<<"); + KP_LOG_INFO(wIn->data()[0]); + KP_LOG_INFO(wIn->data()[1]); + KP_LOG_INFO(bIn->data()[0]); this->mWeights = kp::Tensor(wIn->data()); this->mBias = kp::Tensor(bIn->data()); @@ -131,7 +131,7 @@ Array KomputeModelML::predict(Array xI, Array xJ) { Array KomputeModelML::get_params() { Array retArray; - SPDLOG_INFO(this->mWeights.size() + this->mBias.size()); + KP_LOG_INFO(this->mWeights.size() + this->mBias.size()); if(this->mWeights.size() + this->mBias.size() == 0) { return retArray; diff --git a/single_include/kompute/Kompute.hpp b/single_include/kompute/Kompute.hpp index b33101cd..5d50a74c 100755 --- a/single_include/kompute/Kompute.hpp +++ b/single_include/kompute/Kompute.hpp @@ -50,57 +50,61 @@ extern py::object kp_debug, kp_info, kp_warning, kp_error; #ifndef KOMPUTE_LOG_OVERRIDE #if KOMPUTE_ENABLE_SPDLOG #include +#define KP_LOG_DEBUG(...) SPDLOG_DEBUG(__VA_ARGS__) +#define KP_LOG_INFO(...) SPDLOG_INFO(__VA_ARGS__) +#define KP_LOG_WARN(...) SPDLOG_WARN(__VA_ARGS__) +#define KP_LOG_ERROR(...) SPDLOG_ERROR(__VA_ARGS__) #else #include #if SPDLOG_ACTIVE_LEVEL > 1 -#define SPDLOG_DEBUG(...) +#define KP_LOG_DEBUG(...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_DEBUG(...) \ +#define KP_LOG_DEBUG(...) \ ((void)__android_log_print(ANDROID_LOG_DEBUG, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__))) #elif defined(KOMPUTE_BUILD_PYTHON) -#define SPDLOG_DEBUG(...) kp_debug(fmt::format(__VA_ARGS__)) +#define KP_LOG_DEBUG(...) kp_debug(fmt::format(__VA_ARGS__)) #else -#define SPDLOG_DEBUG(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) +#define KP_LOG_DEBUG(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) #endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 1 #if SPDLOG_ACTIVE_LEVEL > 2 -#define SPDLOG_INFO(...) +#define KP_LOG_INFO(...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_INFO(...) \ +#define KP_LOG_INFO(...) \ ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__))) #elif defined(KOMPUTE_BUILD_PYTHON) -#define SPDLOG_INFO(...) kp_info(fmt::format(__VA_ARGS__)) +#define KP_LOG_INFO(...) kp_info(fmt::format(__VA_ARGS__)) #else -#define SPDLOG_INFO(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) +#define KP_LOG_INFO(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) #endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 2 #if SPDLOG_ACTIVE_LEVEL > 3 -#define SPDLOG_WARN(...) +#define KP_LOG_WARN(...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_WARN(...) \ +#define KP_LOG_WARN(...) \ ((void)__android_log_print(ANDROID_LOG_WARN, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__))) #elif defined(KOMPUTE_BUILD_PYTHON) -#define SPDLOG_WARN(...) kp_warning(fmt::format(__VA_ARGS__)) +#define KP_LOG_WARN(...) kp_warning(fmt::format(__VA_ARGS__)) #else -#define SPDLOG_WARN(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) +#define KP_LOG_WARN(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) #endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 3 #if SPDLOG_ACTIVE_LEVEL > 4 -#define SPDLOG_ERROR(...) +#define KP_LOG_ERROR(...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_ERROR(...) \ +#define KP_LOG_ERROR(...) \ ((void)__android_log_print(ANDROID_LOG_ERROR, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__))) #elif defined(KOMPUTE_BUILD_PYTHON) -#define SPDLOG_ERROR(...) kp_error(fmt::format(__VA_ARGS__)) +#define KP_LOG_ERROR(...) kp_error(fmt::format(__VA_ARGS__)) #else -#define SPDLOG_ERROR(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) +#define KP_LOG_ERROR(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) #endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 4 #endif // KOMPUTE_SPDLOG_ENABLED @@ -1006,7 +1010,7 @@ class OpBase /** * Base constructor, should not be used unless explicitly intended. */ - OpBase() { SPDLOG_DEBUG("Compute OpBase base constructor"); } + OpBase() { KP_LOG_DEBUG("Compute OpBase base constructor"); } /** * Default constructor with parameters that provides the bare minimum @@ -1023,7 +1027,7 @@ class OpBase std::shared_ptr commandBuffer, std::vector>& tensors) { - SPDLOG_DEBUG("Compute OpBase constructor with params"); + KP_LOG_DEBUG("Compute OpBase constructor with params"); this->mPhysicalDevice = physicalDevice; this->mDevice = device; @@ -1038,20 +1042,20 @@ class OpBase */ virtual ~OpBase() { - SPDLOG_DEBUG("Kompute OpBase destructor started"); + KP_LOG_DEBUG("Kompute OpBase destructor started"); if (!this->mDevice) { - SPDLOG_WARN("Kompute OpBase destructor called with empty device"); + KP_LOG_WARN("Kompute OpBase destructor called with empty device"); return; } if (this->mFreeTensors) { - SPDLOG_DEBUG("Kompute OpBase freeing tensors"); + KP_LOG_DEBUG("Kompute OpBase freeing tensors"); for (std::shared_ptr tensor : this->mTensors) { if (tensor && tensor->isInit()) { tensor->freeMemoryDestroyGPUResources(); } else { - SPDLOG_WARN("Kompute OpBase expected to free " + KP_LOG_WARN("Kompute OpBase expected to free " "tensor but has already been freed."); } } @@ -1234,15 +1238,15 @@ class Sequence "Kompute Sequence record(...) template only valid with " "OpBase derived classes"); - SPDLOG_DEBUG("Kompute Sequence record function started"); + KP_LOG_DEBUG("Kompute Sequence record function started"); if (!this->isRecording()) { - SPDLOG_ERROR( + KP_LOG_ERROR( "Kompute sequence record attempted when not record BEGIN"); return false; } - SPDLOG_DEBUG("Kompute Sequence creating OpBase derived class instance"); + KP_LOG_DEBUG("Kompute Sequence creating OpBase derived class instance"); T* op = new T(this->mPhysicalDevice, this->mDevice, this->mCommandBuffer, @@ -1253,11 +1257,11 @@ class Sequence std::unique_ptr baseOpPtr{ baseOp }; - SPDLOG_DEBUG( + KP_LOG_DEBUG( "Kompute Sequence running init on OpBase derived class instance"); baseOpPtr->init(); - SPDLOG_DEBUG( + KP_LOG_DEBUG( "Kompute Sequence running record on OpBase derived class instance"); baseOpPtr->record(); @@ -1423,23 +1427,23 @@ class Manager std::string sequenceName, TArgs&&... params) { - SPDLOG_DEBUG("Kompute Manager evalOp triggered"); + KP_LOG_DEBUG("Kompute Manager evalOp triggered"); std::shared_ptr sq = this->sequence(sequenceName); - SPDLOG_DEBUG("Kompute Manager evalOp running sequence BEGIN"); + KP_LOG_DEBUG("Kompute Manager evalOp running sequence BEGIN"); sq->begin(); - SPDLOG_DEBUG("Kompute Manager evalOp running sequence RECORD"); + KP_LOG_DEBUG("Kompute Manager evalOp running sequence RECORD"); sq->record(tensors, std::forward(params)...); - SPDLOG_DEBUG("Kompute Manager evalOp running sequence END"); + KP_LOG_DEBUG("Kompute Manager evalOp running sequence END"); sq->end(); - SPDLOG_DEBUG("Kompute Manager evalOp running sequence EVAL"); + KP_LOG_DEBUG("Kompute Manager evalOp running sequence EVAL"); sq->eval(); - SPDLOG_DEBUG("Kompute Manager evalOp running sequence SUCCESS"); + KP_LOG_DEBUG("Kompute Manager evalOp running sequence SUCCESS"); } /** @@ -1453,7 +1457,7 @@ class Manager void evalOpDefault(std::vector> tensors, TArgs&&... params) { - SPDLOG_DEBUG("Kompute Manager evalOp Default triggered"); + KP_LOG_DEBUG("Kompute Manager evalOp Default triggered"); this->mCurrentSequenceIndex++; this->evalOp( tensors, KP_DEFAULT_SESSION, std::forward(params)...); @@ -1472,24 +1476,24 @@ class Manager std::string sequenceName, TArgs&&... params) { - SPDLOG_DEBUG("Kompute Manager evalOpAsync triggered"); + KP_LOG_DEBUG("Kompute Manager evalOpAsync triggered"); std::shared_ptr sq = this->sequence(sequenceName); - SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence BEGIN"); + KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence BEGIN"); sq->begin(); - SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence RECORD"); + KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence RECORD"); sq->record(tensors, std::forward(params)...); - SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence END"); + KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence END"); sq->end(); - SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence EVAL"); + KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence EVAL"); sq->evalAsync(); - SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence SUCCESS"); + KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence SUCCESS"); } /** @@ -1504,7 +1508,7 @@ class Manager void evalOpAsyncDefault(std::vector> tensors, TArgs&&... params) { - SPDLOG_DEBUG("Kompute Manager evalOpAsyncDefault triggered"); + KP_LOG_DEBUG("Kompute Manager evalOpAsyncDefault triggered"); this->mCurrentSequenceIndex++; this->evalOpAsync( tensors, KP_DEFAULT_SESSION, std::forward(params)...); @@ -1518,23 +1522,23 @@ class Manager */ void evalOpAwait(std::string sequenceName, uint64_t waitFor = UINT64_MAX) { - SPDLOG_DEBUG("Kompute Manager evalOpAwait triggered with sequence {}", + KP_LOG_DEBUG("Kompute Manager evalOpAwait triggered with sequence {}", sequenceName); std::unordered_map>::iterator found = this->mManagedSequences.find(sequenceName); if (found != this->mManagedSequences.end()) { if (std::shared_ptr sq = found->second) { - SPDLOG_DEBUG("Kompute Manager evalOpAwait running sequence " + KP_LOG_DEBUG("Kompute Manager evalOpAwait running sequence " "Sequence EVAL AWAIT"); if (sq->isRunning()) { sq->evalAwait(waitFor); } } - SPDLOG_DEBUG( + KP_LOG_DEBUG( "Kompute Manager evalOpAwait running sequence SUCCESS"); } else { - SPDLOG_ERROR("Kompute Manager evalOpAwait Sequence not found"); + KP_LOG_ERROR("Kompute Manager evalOpAwait Sequence not found"); } } @@ -1547,7 +1551,7 @@ class Manager */ void evalOpAwaitDefault(uint64_t waitFor = UINT64_MAX) { - SPDLOG_DEBUG("Kompute Manager evalOpAwaitDefault triggered"); + KP_LOG_DEBUG("Kompute Manager evalOpAwaitDefault triggered"); this->evalOpAwait(KP_DEFAULT_SESSION, waitFor); } @@ -2011,7 +2015,7 @@ class OpMult : public OpAlgoBase const Workgroup& komputeWorkgroup = {}) : OpAlgoBase(physicalDevice, device, commandBuffer, tensors, "", komputeWorkgroup) { - SPDLOG_DEBUG("Kompute OpMult constructor with params"); + KP_LOG_DEBUG("Kompute OpMult constructor with params"); #ifndef RELEASE this->mShaderFilePath = "shaders/glsl/opmult.comp.spv"; @@ -2025,7 +2029,7 @@ class OpMult : public OpAlgoBase */ std::vector fetchSpirvBinaryData() override { - SPDLOG_WARN( + KP_LOG_WARN( "Kompute OpMult Running shaders directly from header"); return std::vector( @@ -2041,7 +2045,7 @@ class OpMult : public OpAlgoBase * components but does not destroy the underlying tensors */ ~OpMult() override { - SPDLOG_DEBUG("Kompute OpMult destructor started"); + KP_LOG_DEBUG("Kompute OpMult destructor started"); } }; diff --git a/src/Algorithm.cpp b/src/Algorithm.cpp index 528e8605..3217ee99 100644 --- a/src/Algorithm.cpp +++ b/src/Algorithm.cpp @@ -6,14 +6,14 @@ namespace kp { Algorithm::Algorithm() { - SPDLOG_DEBUG("Kompute Algorithm base constructor"); + KP_LOG_DEBUG("Kompute Algorithm base constructor"); } Algorithm::Algorithm(std::shared_ptr device, std::shared_ptr commandBuffer, const Constants& specializationConstants) { - SPDLOG_DEBUG("Kompute Algorithm Constructor with device"); + KP_LOG_DEBUG("Kompute Algorithm Constructor with device"); this->mDevice = device; this->mCommandBuffer = commandBuffer; @@ -22,18 +22,18 @@ Algorithm::Algorithm(std::shared_ptr device, Algorithm::~Algorithm() { - SPDLOG_DEBUG("Kompute Algorithm Destructor started"); + KP_LOG_DEBUG("Kompute Algorithm Destructor started"); if (!this->mDevice) { - SPDLOG_ERROR( + KP_LOG_ERROR( "Kompute Algorithm destructor reached with null Device pointer"); return; } if (this->mFreePipeline) { - SPDLOG_DEBUG("Kompute Algorithm Destroying pipeline"); + KP_LOG_DEBUG("Kompute Algorithm Destroying pipeline"); if (!this->mPipeline) { - SPDLOG_ERROR("Kompute Algorithm Error requested to destroy " + KP_LOG_ERROR("Kompute Algorithm Error requested to destroy " "pipeline but it is null"); } this->mDevice->destroy( @@ -42,9 +42,9 @@ Algorithm::~Algorithm() } if (this->mFreePipelineCache) { - SPDLOG_DEBUG("Kompute Algorithm Destroying pipeline cache"); + KP_LOG_DEBUG("Kompute Algorithm Destroying pipeline cache"); if (!this->mPipelineCache) { - SPDLOG_ERROR("Kompute Algorithm Error requested to destroy " + KP_LOG_ERROR("Kompute Algorithm Error requested to destroy " "pipeline cache but it is null"); } this->mDevice->destroy( @@ -53,9 +53,9 @@ Algorithm::~Algorithm() } if (this->mFreePipelineLayout) { - SPDLOG_DEBUG("Kompute Algorithm Destroying pipeline layout"); + KP_LOG_DEBUG("Kompute Algorithm Destroying pipeline layout"); if (!this->mPipelineLayout) { - SPDLOG_ERROR("Kompute Algorithm Error requested to destroy " + KP_LOG_ERROR("Kompute Algorithm Error requested to destroy " "pipeline layout but it is null"); } this->mDevice->destroy( @@ -64,9 +64,9 @@ Algorithm::~Algorithm() } if (this->mFreeShaderModule) { - SPDLOG_DEBUG("Kompute Algorithm Destroying shader module"); + KP_LOG_DEBUG("Kompute Algorithm Destroying shader module"); if (!this->mShaderModule) { - SPDLOG_ERROR("Kompute Algorithm Error requested to destroy shader " + KP_LOG_ERROR("Kompute Algorithm Error requested to destroy shader " "module but it is null"); } this->mDevice->destroy( @@ -75,9 +75,9 @@ Algorithm::~Algorithm() } if (this->mFreeDescriptorSet) { - SPDLOG_DEBUG("Kompute Algorithm Freeing Descriptor Set"); + KP_LOG_DEBUG("Kompute Algorithm Freeing Descriptor Set"); if (!this->mDescriptorSet) { - SPDLOG_ERROR( + KP_LOG_ERROR( "Kompute Algorithm Error requested to free descriptor set"); } this->mDevice->freeDescriptorSets( @@ -85,9 +85,9 @@ Algorithm::~Algorithm() } if (this->mFreeDescriptorSetLayout) { - SPDLOG_DEBUG("Kompute Algorithm Destroying Descriptor Set Layout"); + KP_LOG_DEBUG("Kompute Algorithm Destroying Descriptor Set Layout"); if (!this->mDescriptorSetLayout) { - SPDLOG_ERROR("Kompute Algorithm Error requested to destroy " + KP_LOG_ERROR("Kompute Algorithm Error requested to destroy " "descriptor set layout but it is null"); } this->mDevice->destroy( @@ -96,9 +96,9 @@ Algorithm::~Algorithm() } if (this->mFreeDescriptorPool) { - SPDLOG_DEBUG("Kompute Algorithm Destroying Descriptor Pool"); + KP_LOG_DEBUG("Kompute Algorithm Destroying Descriptor Pool"); if (!this->mDescriptorPool) { - SPDLOG_ERROR("Kompute Algorithm Error requested to destroy " + KP_LOG_ERROR("Kompute Algorithm Error requested to destroy " "descriptor pool but it is null"); } this->mDevice->destroy( @@ -111,7 +111,7 @@ void Algorithm::init(const std::vector& shaderFileData, std::vector> tensorParams) { - SPDLOG_DEBUG("Kompute Algorithm init started"); + KP_LOG_DEBUG("Kompute Algorithm init started"); this->createParameters(tensorParams); this->createShaderModule(shaderFileData); @@ -130,7 +130,7 @@ Algorithm::createDescriptorPool() void Algorithm::createParameters(std::vector>& tensorParams) { - SPDLOG_DEBUG("Kompute Algorithm createParameters started"); + KP_LOG_DEBUG("Kompute Algorithm createParameters started"); std::vector descriptorPoolSizes = { vk::DescriptorPoolSize( @@ -145,7 +145,7 @@ Algorithm::createParameters(std::vector>& tensorParams) static_cast(descriptorPoolSizes.size()), descriptorPoolSizes.data()); - SPDLOG_DEBUG("Kompute Algorithm creating descriptor pool"); + KP_LOG_DEBUG("Kompute Algorithm creating descriptor pool"); this->mDescriptorPool = std::make_shared(); this->mDevice->createDescriptorPool( &descriptorPoolInfo, nullptr, this->mDescriptorPool.get()); @@ -166,7 +166,7 @@ Algorithm::createParameters(std::vector>& tensorParams) static_cast(descriptorSetBindings.size()), descriptorSetBindings.data()); - SPDLOG_DEBUG("Kompute Algorithm creating descriptor set layout"); + KP_LOG_DEBUG("Kompute Algorithm creating descriptor set layout"); this->mDescriptorSetLayout = std::make_shared(); this->mDevice->createDescriptorSetLayout( &descriptorSetLayoutInfo, nullptr, this->mDescriptorSetLayout.get()); @@ -177,13 +177,13 @@ Algorithm::createParameters(std::vector>& tensorParams) 1, // Descriptor set layout count this->mDescriptorSetLayout.get()); - SPDLOG_DEBUG("Kompute Algorithm allocating descriptor sets"); + KP_LOG_DEBUG("Kompute Algorithm allocating descriptor sets"); this->mDescriptorSet = std::make_shared(); this->mDevice->allocateDescriptorSets(&descriptorSetAllocateInfo, this->mDescriptorSet.get()); this->mFreeDescriptorSet = true; - SPDLOG_DEBUG("Kompute Algorithm updating descriptor sets"); + KP_LOG_DEBUG("Kompute Algorithm updating descriptor sets"); for (size_t i = 0; i < tensorParams.size(); i++) { std::vector computeWriteDescriptorSets; @@ -203,20 +203,20 @@ Algorithm::createParameters(std::vector>& tensorParams) nullptr); } - SPDLOG_DEBUG("Kompue Algorithm successfully run init"); + KP_LOG_DEBUG("Kompue Algorithm successfully run init"); } void Algorithm::createShaderModule(const std::vector& shaderFileData) { - SPDLOG_DEBUG("Kompute Algorithm createShaderModule started"); + KP_LOG_DEBUG("Kompute Algorithm createShaderModule started"); vk::ShaderModuleCreateInfo shaderModuleInfo( vk::ShaderModuleCreateFlags(), sizeof(uint32_t) * shaderFileData.size(), shaderFileData.data()); - SPDLOG_DEBUG("Kompute Algorithm Creating shader module. ShaderFileSize: {}", + KP_LOG_DEBUG("Kompute Algorithm Creating shader module. ShaderFileSize: {}", shaderFileData.size()); this->mFreeShaderModule = true; this->mShaderModule = std::make_shared(); @@ -224,13 +224,13 @@ Algorithm::createShaderModule(const std::vector& shaderFileData) &shaderModuleInfo, nullptr, this->mShaderModule.get()); this->mFreeShaderModule = true; - SPDLOG_DEBUG("Kompute Algorithm create shader module success"); + KP_LOG_DEBUG("Kompute Algorithm create shader module success"); } void Algorithm::createPipeline() { - SPDLOG_DEBUG("Kompute Algorithm calling create Pipeline"); + KP_LOG_DEBUG("Kompute Algorithm calling create Pipeline"); vk::PipelineLayoutCreateInfo pipelineLayoutInfo( vk::PipelineLayoutCreateFlags(), @@ -302,7 +302,7 @@ Algorithm::createPipeline() void Algorithm::recordDispatch(uint32_t x, uint32_t y, uint32_t z) { - SPDLOG_DEBUG("Kompute Algorithm calling record dispatch"); + KP_LOG_DEBUG("Kompute Algorithm calling record dispatch"); this->mCommandBuffer->bindPipeline(vk::PipelineBindPoint::eCompute, *this->mPipeline); diff --git a/src/Manager.cpp b/src/Manager.cpp index c66a4030..18b2bf28 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -18,7 +18,7 @@ debugMessageCallback(VkDebugReportFlagsEXT flags, const char* pMessage, void* pUserData) { - SPDLOG_DEBUG("[VALIDATION]: {} - {}", pLayerPrefix, pMessage); + KP_LOG_DEBUG("[VALIDATION]: {} - {}", pLayerPrefix, pMessage); return VK_FALSE; } #endif @@ -50,16 +50,16 @@ Manager::Manager(std::shared_ptr instance, Manager::~Manager() { - SPDLOG_DEBUG("Kompute Manager Destructor started"); + KP_LOG_DEBUG("Kompute Manager Destructor started"); if (this->mDevice == nullptr) { - SPDLOG_ERROR( + KP_LOG_ERROR( "Kompute Manager destructor reached with null Device pointer"); return; } if (this->mManagedSequences.size()) { - SPDLOG_DEBUG("Kompute Manager explicitly running destructor for " + KP_LOG_DEBUG("Kompute Manager explicitly running destructor for " "managed sequences"); for (const std::pair>& sqPair : this->mManagedSequences) { @@ -69,10 +69,10 @@ Manager::~Manager() } if (this->mManagedTensors.size()) { - SPDLOG_DEBUG("Kompute Manager explicitly freeing tensors"); + KP_LOG_DEBUG("Kompute Manager explicitly freeing tensors"); for (const std::shared_ptr& tensor : this->mManagedTensors) { if (!tensor->isInit()) { - SPDLOG_ERROR("Kompute Manager attempted to free managed tensor " + KP_LOG_ERROR("Kompute Manager attempted to free managed tensor " "but not tensor is not initialised"); } tensor->freeMemoryDestroyGPUResources(); @@ -81,14 +81,14 @@ Manager::~Manager() } if (this->mFreeDevice) { - SPDLOG_INFO("Destroying device"); + KP_LOG_INFO("Destroying device"); this->mDevice->destroy( (vk::Optional)nullptr); - SPDLOG_DEBUG("Kompute Manager Destroyed Device"); + KP_LOG_DEBUG("Kompute Manager Destroyed Device"); } if (this->mInstance == nullptr) { - SPDLOG_ERROR( + KP_LOG_ERROR( "Kompute Manager destructor reached with null Instance pointer"); return; } @@ -98,7 +98,7 @@ Manager::~Manager() if (this->mDebugReportCallback) { this->mInstance->destroyDebugReportCallbackEXT( this->mDebugReportCallback, nullptr, this->mDebugDispatcher); - SPDLOG_DEBUG("Kompute Manager Destroyed Debug Report Callback"); + KP_LOG_DEBUG("Kompute Manager Destroyed Debug Report Callback"); } #endif #endif @@ -106,14 +106,14 @@ Manager::~Manager() if (this->mFreeInstance) { this->mInstance->destroy( (vk::Optional)nullptr); - SPDLOG_DEBUG("Kompute Manager Destroyed Instance"); + KP_LOG_DEBUG("Kompute Manager Destroyed Instance"); } } std::shared_ptr Manager::sequence(std::string sequenceName, uint32_t queueIndex) { - SPDLOG_DEBUG("Kompute Manager sequence() with sequenceName: {} " + KP_LOG_DEBUG("Kompute Manager sequence() with sequenceName: {} " "and queueIndex: {}", sequenceName, queueIndex); @@ -143,7 +143,7 @@ void Manager::createInstance() { - SPDLOG_DEBUG("Kompute Manager creating instance"); + KP_LOG_DEBUG("Kompute Manager creating instance"); this->mFreeInstance = true; @@ -168,7 +168,7 @@ Manager::createInstance() #if DEBUG #ifndef KOMPUTE_DISABLE_VK_DEBUG_LAYERS - SPDLOG_DEBUG("Kompute Manager adding debug validation layers"); + KP_LOG_DEBUG("Kompute Manager adding debug validation layers"); // We'll identify the layers that are supported std::vector validLayerNames; std::vector desiredLayerNames = { @@ -201,11 +201,11 @@ Manager::createInstance() this->mInstance = std::make_shared(); vk::createInstance( &computeInstanceCreateInfo, nullptr, this->mInstance.get()); - SPDLOG_DEBUG("Kompute Manager Instance Created"); + KP_LOG_DEBUG("Kompute Manager Instance Created"); #if DEBUG #ifndef KOMPUTE_DISABLE_VK_DEBUG_LAYERS - SPDLOG_DEBUG("Kompute Manager adding debug callbacks"); + KP_LOG_DEBUG("Kompute Manager adding debug callbacks"); if (validLayerNames.size() > 0) { vk::DebugReportFlagsEXT debugFlags = vk::DebugReportFlagBitsEXT::eError | @@ -228,7 +228,7 @@ void Manager::createDevice(const std::vector& familyQueueIndices) { - SPDLOG_DEBUG("Kompute Manager creating Device"); + KP_LOG_DEBUG("Kompute Manager creating Device"); if (this->mInstance == nullptr) { throw std::runtime_error("Kompute Manager instance is null"); @@ -252,7 +252,7 @@ Manager::createDevice(const std::vector& familyQueueIndices) vk::PhysicalDeviceProperties physicalDeviceProperties = physicalDevice.getProperties(); - SPDLOG_INFO("Using physical device index {} found {}", + KP_LOG_INFO("Using physical device index {} found {}", this->mPhysicalDeviceIndex, physicalDeviceProperties.deviceName); @@ -311,7 +311,7 @@ Manager::createDevice(const std::vector& familyQueueIndices) this->mDevice = std::make_shared(); physicalDevice.createDevice( &deviceCreateInfo, nullptr, this->mDevice.get()); - SPDLOG_DEBUG("Kompute Manager device created"); + KP_LOG_DEBUG("Kompute Manager device created"); for (const uint32_t& familyQueueIndex : this->mComputeQueueFamilyIndices) { std::shared_ptr currQueue = std::make_shared(); @@ -325,7 +325,7 @@ Manager::createDevice(const std::vector& familyQueueIndices) this->mComputeQueues.push_back(currQueue); } - SPDLOG_DEBUG("Kompute Manager compute queue obtained"); + KP_LOG_DEBUG("Kompute Manager compute queue obtained"); } std::shared_ptr @@ -334,9 +334,9 @@ Manager::tensor( Tensor::TensorTypes tensorType, bool syncDataToGPU) { - SPDLOG_DEBUG("Kompute Manager tensor triggered"); + KP_LOG_DEBUG("Kompute Manager tensor triggered"); - SPDLOG_DEBUG("Kompute Manager creating new tensor shared ptr"); + KP_LOG_DEBUG("Kompute Manager creating new tensor shared ptr"); std::shared_ptr tensor = std::make_shared(kp::Tensor(data, tensorType)); @@ -354,7 +354,7 @@ void Manager::rebuild(std::vector> tensors, bool syncDataToGPU) { - SPDLOG_DEBUG("Kompute Manager rebuild triggered"); + KP_LOG_DEBUG("Kompute Manager rebuild triggered"); for (std::shared_ptr tensor : tensors) { // False syncData to run all tensors at once instead one by one @@ -370,7 +370,7 @@ void Manager::rebuild(std::shared_ptr tensor, bool syncDataToGPU) { - SPDLOG_DEBUG("Kompute Manager rebuild Tensor triggered"); + KP_LOG_DEBUG("Kompute Manager rebuild Tensor triggered"); if (tensor->isInit()) { tensor->freeMemoryDestroyGPUResources(); @@ -392,7 +392,7 @@ Manager::rebuild(std::shared_ptr tensor, void Manager::destroy(std::shared_ptr tensor) { - SPDLOG_DEBUG("Kompute Manager rebuild Tensor triggered"); + KP_LOG_DEBUG("Kompute Manager rebuild Tensor triggered"); if (tensor->isInit()) { tensor->freeMemoryDestroyGPUResources(); @@ -410,7 +410,7 @@ Manager::destroy(std::shared_ptr tensor) void Manager::destroy(std::vector> tensors) { - SPDLOG_DEBUG("Kompute Manager rebuild Tensor triggered"); + KP_LOG_DEBUG("Kompute Manager rebuild Tensor triggered"); for (std::shared_ptr tensor : tensors) { this->destroy(tensor); @@ -420,7 +420,7 @@ Manager::destroy(std::vector> tensors) void Manager::destroy(std::vector> sequences) { - SPDLOG_DEBUG("Kompute Manager rebuild Sequence triggered"); + KP_LOG_DEBUG("Kompute Manager rebuild Sequence triggered"); for (std::shared_ptr sequence : sequences) { this->destroy(sequence); @@ -430,7 +430,7 @@ Manager::destroy(std::vector> sequences) void Manager::destroy(std::shared_ptr sequence) { - SPDLOG_DEBUG("Kompute Manager rebuild Sequence triggered"); + KP_LOG_DEBUG("Kompute Manager rebuild Sequence triggered"); // Inefficient but required to delete by value // Depending on the amount of named sequences created may be worth creating @@ -450,7 +450,7 @@ Manager::destroy(std::shared_ptr sequence) void Manager::destroy(const std::string& sequenceName) { - SPDLOG_DEBUG("Kompute Manager rebuild Sequence triggered"); + KP_LOG_DEBUG("Kompute Manager rebuild Sequence triggered"); std::unordered_map>::iterator found = this->mManagedSequences.find(sequenceName); @@ -467,7 +467,7 @@ Manager::destroy(const std::string& sequenceName) void Manager::destroy(const std::vector& sequenceNames) { - SPDLOG_DEBUG("Kompute Manager rebuild Sequence triggered"); + KP_LOG_DEBUG("Kompute Manager rebuild Sequence triggered"); for (const std::string& sequenceName : sequenceNames) { this->destroy(sequenceName); diff --git a/src/OpAlgoBase.cpp b/src/OpAlgoBase.cpp index ee22c6fe..71b61beb 100644 --- a/src/OpAlgoBase.cpp +++ b/src/OpAlgoBase.cpp @@ -6,7 +6,7 @@ namespace kp { OpAlgoBase::OpAlgoBase() { - SPDLOG_DEBUG("Kompute OpAlgoBase constructor base"); + KP_LOG_DEBUG("Kompute OpAlgoBase constructor base"); } OpAlgoBase::OpAlgoBase(std::shared_ptr physicalDevice, @@ -17,7 +17,7 @@ OpAlgoBase::OpAlgoBase(std::shared_ptr physicalDevice, const Constants& specializationConstants) : OpBase(physicalDevice, device, commandBuffer, tensors) { - SPDLOG_DEBUG("Kompute OpAlgoBase constructor with params numTensors: {}", + KP_LOG_DEBUG("Kompute OpAlgoBase constructor with params numTensors: {}", tensors.size()); // The dispatch size is set up based on either explicitly provided template @@ -33,7 +33,7 @@ OpAlgoBase::OpAlgoBase(std::shared_ptr physicalDevice, } else { this->mKomputeWorkgroup = { tensors[0]->size(), 1, 1 }; } - SPDLOG_INFO("Kompute OpAlgoBase dispatch size X: {}, Y: {}, Z: {}", + KP_LOG_INFO("Kompute OpAlgoBase dispatch size X: {}, Y: {}, Z: {}", this->mKomputeWorkgroup[0], this->mKomputeWorkgroup[1], this->mKomputeWorkgroup[2]); @@ -50,7 +50,7 @@ OpAlgoBase::OpAlgoBase(std::shared_ptr physicalDevice, const Constants& specializationConstants) : OpAlgoBase(physicalDevice, device, commandBuffer, tensors, komputeWorkgroup, specializationConstants) { - SPDLOG_DEBUG( + KP_LOG_DEBUG( "Kompute OpAlgoBase shaderFilePath constructo with shaderfile path: {}", shaderFilePath); @@ -66,7 +66,7 @@ OpAlgoBase::OpAlgoBase(std::shared_ptr physicalDevice, const Constants& specializationConstants) : OpAlgoBase(physicalDevice, device, commandBuffer, tensors, komputeWorkgroup, specializationConstants) { - SPDLOG_DEBUG("Kompute OpAlgoBase shaderFilePath constructo with shader raw " + KP_LOG_DEBUG("Kompute OpAlgoBase shaderFilePath constructo with shader raw " "data length: {}", shaderDataRaw.size()); @@ -75,13 +75,13 @@ OpAlgoBase::OpAlgoBase(std::shared_ptr physicalDevice, OpAlgoBase::~OpAlgoBase() { - SPDLOG_DEBUG("Kompute OpAlgoBase destructor started"); + KP_LOG_DEBUG("Kompute OpAlgoBase destructor started"); } void OpAlgoBase::init() { - SPDLOG_DEBUG("Kompute OpAlgoBase init called"); + KP_LOG_DEBUG("Kompute OpAlgoBase init called"); if (this->mTensors.size() < 1) { throw std::runtime_error( @@ -96,11 +96,11 @@ OpAlgoBase::init() } } - SPDLOG_DEBUG("Kompute OpAlgoBase fetching spirv data"); + KP_LOG_DEBUG("Kompute OpAlgoBase fetching spirv data"); std::vector shaderFileData = this->fetchSpirvBinaryData(); - SPDLOG_DEBUG("Kompute OpAlgoBase Initialising algorithm component"); + KP_LOG_DEBUG("Kompute OpAlgoBase Initialising algorithm component"); this->mAlgorithm->init(shaderFileData, this->mTensors); } @@ -108,7 +108,7 @@ OpAlgoBase::init() void OpAlgoBase::record() { - SPDLOG_DEBUG("Kompute OpAlgoBase record called"); + KP_LOG_DEBUG("Kompute OpAlgoBase record called"); // Barrier to ensure the data is finished writing to buffer memory for (std::shared_ptr tensor : this->mTensors) { @@ -128,22 +128,22 @@ OpAlgoBase::record() void OpAlgoBase::preEval() { - SPDLOG_DEBUG("Kompute OpAlgoBase preEval called"); + KP_LOG_DEBUG("Kompute OpAlgoBase preEval called"); } void OpAlgoBase::postEval() { - SPDLOG_DEBUG("Kompute OpAlgoBase postSubmit called"); + KP_LOG_DEBUG("Kompute OpAlgoBase postSubmit called"); } std::vector OpAlgoBase::fetchSpirvBinaryData() { - SPDLOG_DEBUG("Kompute OpAlgoBase Running fetchSpirvBinaryData"); + KP_LOG_DEBUG("Kompute OpAlgoBase Running fetchSpirvBinaryData"); if (this->mShaderFilePath.size()) { - SPDLOG_DEBUG("Kompute OpAlgoBase Reading data from file path"); + KP_LOG_DEBUG("Kompute OpAlgoBase Reading data from file path"); std::ifstream fileStream(this->mShaderFilePath, std::ios::binary | std::ios::in | @@ -160,11 +160,11 @@ OpAlgoBase::fetchSpirvBinaryData() fileStream.read(shaderDataRaw, shaderFileSize); fileStream.close(); - SPDLOG_WARN("Kompute OpAlgoBase fetched {} bytes", shaderFileSize); + KP_LOG_WARN("Kompute OpAlgoBase fetched {} bytes", shaderFileSize); return std::vector((uint32_t*)shaderDataRaw, (uint32_t*)(shaderDataRaw + shaderFileSize)); } else if (this->mShaderDataRaw.size()) { - SPDLOG_DEBUG("Kompute OpAlgoBase Reading data from data provided"); + KP_LOG_DEBUG("Kompute OpAlgoBase Reading data from data provided"); return this->mShaderDataRaw; } else { throw std::runtime_error( diff --git a/src/OpAlgoLhsRhsOut.cpp b/src/OpAlgoLhsRhsOut.cpp index a12583f2..c93e5c55 100644 --- a/src/OpAlgoLhsRhsOut.cpp +++ b/src/OpAlgoLhsRhsOut.cpp @@ -6,7 +6,7 @@ namespace kp { OpAlgoLhsRhsOut::OpAlgoLhsRhsOut() { - SPDLOG_DEBUG("Kompute OpAlgoLhsRhsOut constructor base"); + KP_LOG_DEBUG("Kompute OpAlgoLhsRhsOut constructor base"); } OpAlgoLhsRhsOut::OpAlgoLhsRhsOut( @@ -20,24 +20,24 @@ OpAlgoLhsRhsOut::OpAlgoLhsRhsOut( // a granular way. : OpAlgoBase(physicalDevice, device, commandBuffer, tensors, komputeWorkgroup) { - SPDLOG_DEBUG("Kompute OpAlgoLhsRhsOut constructor with params"); + KP_LOG_DEBUG("Kompute OpAlgoLhsRhsOut constructor with params"); } OpAlgoLhsRhsOut::~OpAlgoLhsRhsOut() { - SPDLOG_DEBUG("Kompute OpAlgoLhsRhsOut destructor started"); + KP_LOG_DEBUG("Kompute OpAlgoLhsRhsOut destructor started"); } void OpAlgoLhsRhsOut::init() { - SPDLOG_DEBUG("Kompute OpAlgoLhsRhsOut init called"); + KP_LOG_DEBUG("Kompute OpAlgoLhsRhsOut init called"); if (this->mTensors.size() < 3) { throw std::runtime_error( "Kompute OpAlgoLhsRhsOut called with less than 1 tensor"); } else if (this->mTensors.size() > 3) { - SPDLOG_WARN( + KP_LOG_WARN( "Kompute OpAlgoLhsRhsOut called with more than 3 this->mTensors"); } @@ -65,11 +65,11 @@ OpAlgoLhsRhsOut::init() " Output: " + std::to_string(this->mTensorOutput->size())); } - SPDLOG_DEBUG("Kompute OpAlgoLhsRhsOut fetching spirv data"); + KP_LOG_DEBUG("Kompute OpAlgoLhsRhsOut fetching spirv data"); std::vector shaderFileData = this->fetchSpirvBinaryData(); - SPDLOG_DEBUG("Kompute OpAlgoLhsRhsOut Initialising algorithm component"); + KP_LOG_DEBUG("Kompute OpAlgoLhsRhsOut Initialising algorithm component"); this->mAlgorithm->init(shaderFileData, this->mTensors); } @@ -77,7 +77,7 @@ OpAlgoLhsRhsOut::init() void OpAlgoLhsRhsOut::record() { - SPDLOG_DEBUG("Kompute OpAlgoLhsRhsOut record called"); + KP_LOG_DEBUG("Kompute OpAlgoLhsRhsOut record called"); // Barrier to ensure the data is finished writing to buffer memory this->mTensorLHS->recordBufferMemoryBarrier( @@ -114,7 +114,7 @@ OpAlgoLhsRhsOut::record() void OpAlgoLhsRhsOut::postEval() { - SPDLOG_DEBUG("Kompute OpAlgoLhsRhsOut postSubmit called"); + KP_LOG_DEBUG("Kompute OpAlgoLhsRhsOut postSubmit called"); this->mTensorOutput->mapDataFromHostMemory(); } diff --git a/src/OpTensorCopy.cpp b/src/OpTensorCopy.cpp index 3726c71e..98450dc8 100644 --- a/src/OpTensorCopy.cpp +++ b/src/OpTensorCopy.cpp @@ -5,7 +5,7 @@ namespace kp { OpTensorCopy::OpTensorCopy() { - SPDLOG_DEBUG("Kompute OpTensorCopy constructor base"); + KP_LOG_DEBUG("Kompute OpTensorCopy constructor base"); } OpTensorCopy::OpTensorCopy(std::shared_ptr physicalDevice, @@ -14,18 +14,18 @@ OpTensorCopy::OpTensorCopy(std::shared_ptr physicalDevice, std::vector> tensors) : OpBase(physicalDevice, device, commandBuffer, tensors) { - SPDLOG_DEBUG("Kompute OpTensorCopy constructor with params"); + KP_LOG_DEBUG("Kompute OpTensorCopy constructor with params"); } OpTensorCopy::~OpTensorCopy() { - SPDLOG_DEBUG("Kompute OpTensorCopy destructor started"); + KP_LOG_DEBUG("Kompute OpTensorCopy destructor started"); } void OpTensorCopy::init() { - SPDLOG_DEBUG("Kompute OpTensorCopy init called"); + KP_LOG_DEBUG("Kompute OpTensorCopy init called"); if (this->mTensors.size() < 2) { throw std::runtime_error( @@ -48,7 +48,7 @@ OpTensorCopy::init() void OpTensorCopy::record() { - SPDLOG_DEBUG("Kompute OpTensorCopy record called"); + KP_LOG_DEBUG("Kompute OpTensorCopy record called"); // We iterate from the second tensor onwards and record a copy to all for (size_t i = 1; i < this->mTensors.size(); i++) { @@ -60,13 +60,13 @@ OpTensorCopy::record() void OpTensorCopy::preEval() { - SPDLOG_DEBUG("Kompute OpTensorCopy preEval called"); + KP_LOG_DEBUG("Kompute OpTensorCopy preEval called"); } void OpTensorCopy::postEval() { - SPDLOG_DEBUG("Kompute OpTensorCopy postEval called"); + KP_LOG_DEBUG("Kompute OpTensorCopy postEval called"); // Copy the data from the first tensor into all the tensors for (size_t i = 1; i < this->mTensors.size(); i++) { diff --git a/src/OpTensorSyncDevice.cpp b/src/OpTensorSyncDevice.cpp index 92bd7512..fdd15389 100644 --- a/src/OpTensorSyncDevice.cpp +++ b/src/OpTensorSyncDevice.cpp @@ -7,7 +7,7 @@ namespace kp { OpTensorSyncDevice::OpTensorSyncDevice() { - SPDLOG_DEBUG("Kompute OpTensorSyncDevice constructor base"); + KP_LOG_DEBUG("Kompute OpTensorSyncDevice constructor base"); } OpTensorSyncDevice::OpTensorSyncDevice( @@ -17,18 +17,18 @@ OpTensorSyncDevice::OpTensorSyncDevice( std::vector> tensors) : OpBase(physicalDevice, device, commandBuffer, tensors) { - SPDLOG_DEBUG("Kompute OpTensorSyncDevice constructor with params"); + KP_LOG_DEBUG("Kompute OpTensorSyncDevice constructor with params"); } OpTensorSyncDevice::~OpTensorSyncDevice() { - SPDLOG_DEBUG("Kompute OpTensorSyncDevice destructor started"); + KP_LOG_DEBUG("Kompute OpTensorSyncDevice destructor started"); } void OpTensorSyncDevice::init() { - SPDLOG_DEBUG("Kompute OpTensorSyncDevice init called"); + KP_LOG_DEBUG("Kompute OpTensorSyncDevice init called"); if (this->mTensors.size() < 1) { throw std::runtime_error( @@ -41,7 +41,7 @@ OpTensorSyncDevice::init() "has not been initialized"); } if (tensor->tensorType() == Tensor::TensorTypes::eStorage) { - SPDLOG_WARN( + KP_LOG_WARN( "Kompute OpTensorSyncLocal tensor parameter is of type " "TensorTypes::eStorage and hence cannot be used to receive or " "pass data."); @@ -52,7 +52,7 @@ OpTensorSyncDevice::init() void OpTensorSyncDevice::record() { - SPDLOG_DEBUG("Kompute OpTensorSyncDevice record called"); + KP_LOG_DEBUG("Kompute OpTensorSyncDevice record called"); for (size_t i = 0; i < this->mTensors.size(); i++) { if (this->mTensors[i]->tensorType() == Tensor::TensorTypes::eDevice) { @@ -65,7 +65,7 @@ OpTensorSyncDevice::record() void OpTensorSyncDevice::preEval() { - SPDLOG_DEBUG("Kompute OpTensorSyncDevice preEval called"); + KP_LOG_DEBUG("Kompute OpTensorSyncDevice preEval called"); // Performing sync of data as eval can be called multiple times with same op for (size_t i = 0; i < this->mTensors.size(); i++) { @@ -78,7 +78,7 @@ OpTensorSyncDevice::preEval() void OpTensorSyncDevice::postEval() { - SPDLOG_DEBUG("Kompute OpTensorSyncDevice postEval called"); + KP_LOG_DEBUG("Kompute OpTensorSyncDevice postEval called"); } } diff --git a/src/OpTensorSyncLocal.cpp b/src/OpTensorSyncLocal.cpp index c7a4fb63..ccf8e70c 100644 --- a/src/OpTensorSyncLocal.cpp +++ b/src/OpTensorSyncLocal.cpp @@ -7,7 +7,7 @@ namespace kp { OpTensorSyncLocal::OpTensorSyncLocal() { - SPDLOG_DEBUG("Kompute OpTensorSyncLocal constructor base"); + KP_LOG_DEBUG("Kompute OpTensorSyncLocal constructor base"); } OpTensorSyncLocal::OpTensorSyncLocal( @@ -17,18 +17,18 @@ OpTensorSyncLocal::OpTensorSyncLocal( std::vector> tensors) : OpBase(physicalDevice, device, commandBuffer, tensors) { - SPDLOG_DEBUG("Kompute OpTensorSyncLocal constructor with params"); + KP_LOG_DEBUG("Kompute OpTensorSyncLocal constructor with params"); } OpTensorSyncLocal::~OpTensorSyncLocal() { - SPDLOG_DEBUG("Kompute OpTensorSyncLocal destructor started"); + KP_LOG_DEBUG("Kompute OpTensorSyncLocal destructor started"); } void OpTensorSyncLocal::init() { - SPDLOG_DEBUG("Kompute OpTensorSyncLocal init called"); + KP_LOG_DEBUG("Kompute OpTensorSyncLocal init called"); if (this->mTensors.size() < 1) { throw std::runtime_error( @@ -41,7 +41,7 @@ OpTensorSyncLocal::init() "Kompute OpTensorSyncLocal: Tensor has not been initialized"); } if (tensor->tensorType() == Tensor::TensorTypes::eStorage) { - SPDLOG_WARN( + KP_LOG_WARN( "Kompute OpTensorSyncLocal tensor parameter is of type " "TensorTypes::eStorage and hence cannot be used to receive or " "pass data."); @@ -52,7 +52,7 @@ OpTensorSyncLocal::init() void OpTensorSyncLocal::record() { - SPDLOG_DEBUG("Kompute OpTensorSyncLocal record called"); + KP_LOG_DEBUG("Kompute OpTensorSyncLocal record called"); for (size_t i = 0; i < this->mTensors.size(); i++) { if (this->mTensors[i]->tensorType() == Tensor::TensorTypes::eDevice) { @@ -65,15 +65,15 @@ OpTensorSyncLocal::record() void OpTensorSyncLocal::preEval() { - SPDLOG_DEBUG("Kompute OpTensorSyncLocal preEval called"); + KP_LOG_DEBUG("Kompute OpTensorSyncLocal preEval called"); } void OpTensorSyncLocal::postEval() { - SPDLOG_DEBUG("Kompute OpTensorSyncLocal postEval called"); + KP_LOG_DEBUG("Kompute OpTensorSyncLocal postEval called"); - SPDLOG_DEBUG("Kompute OpTensorSyncLocal mapping data into tensor local"); + KP_LOG_DEBUG("Kompute OpTensorSyncLocal mapping data into tensor local"); for (size_t i = 0; i < this->mTensors.size(); i++) { if (this->mTensors[i]->tensorType() != Tensor::TensorTypes::eStorage) { this->mTensors[i]->mapDataFromHostMemory(); diff --git a/src/Sequence.cpp b/src/Sequence.cpp index 3c3b7b10..19fdf11e 100644 --- a/src/Sequence.cpp +++ b/src/Sequence.cpp @@ -5,7 +5,7 @@ namespace kp { Sequence::Sequence() { - SPDLOG_DEBUG("Kompute Sequence base constructor"); + KP_LOG_DEBUG("Kompute Sequence base constructor"); this->mIsInit = false; } @@ -14,7 +14,7 @@ Sequence::Sequence(std::shared_ptr physicalDevice, std::shared_ptr computeQueue, uint32_t queueIndex) { - SPDLOG_DEBUG("Kompute Sequence Constructor with existing device & queue"); + KP_LOG_DEBUG("Kompute Sequence Constructor with existing device & queue"); this->mPhysicalDevice = physicalDevice; this->mDevice = device; @@ -25,10 +25,10 @@ Sequence::Sequence(std::shared_ptr physicalDevice, Sequence::~Sequence() { - SPDLOG_DEBUG("Kompute Sequence Destructor started"); + KP_LOG_DEBUG("Kompute Sequence Destructor started"); if (!this->mIsInit) { - SPDLOG_INFO("Kompute Sequence destructor called but sequence is not " + KP_LOG_INFO("Kompute Sequence destructor called but sequence is not " "initialized so no need to removing GPU resources."); return; } else { @@ -47,15 +47,15 @@ Sequence::init() bool Sequence::begin() { - SPDLOG_DEBUG("Kompute sequence called BEGIN"); + KP_LOG_DEBUG("Kompute sequence called BEGIN"); if (this->isRecording()) { - SPDLOG_WARN("Kompute Sequence begin called when already recording"); + KP_LOG_WARN("Kompute Sequence begin called when already recording"); return false; } if (this->isRunning()) { - SPDLOG_WARN( + KP_LOG_WARN( "Kompute Sequence begin called when sequence still running"); return false; } @@ -65,16 +65,16 @@ Sequence::begin() } if (this->mOperations.size()) { - SPDLOG_INFO("Kompute Sequence clearing previous operations"); + KP_LOG_INFO("Kompute Sequence clearing previous operations"); this->mOperations.clear(); } if (!this->mRecording) { - SPDLOG_INFO("Kompute Sequence command recording BEGIN"); + KP_LOG_INFO("Kompute Sequence command recording BEGIN"); this->mCommandBuffer->begin(vk::CommandBufferBeginInfo()); this->mRecording = true; } else { - SPDLOG_WARN("Kompute Sequence attempted to start command recording " + KP_LOG_WARN("Kompute Sequence attempted to start command recording " "but recording already started"); } return true; @@ -83,10 +83,10 @@ Sequence::begin() bool Sequence::end() { - SPDLOG_DEBUG("Kompute Sequence calling END"); + KP_LOG_DEBUG("Kompute Sequence calling END"); if (!this->isRecording()) { - SPDLOG_WARN("Kompute Sequence end called when not recording"); + KP_LOG_WARN("Kompute Sequence end called when not recording"); return false; } @@ -95,11 +95,11 @@ Sequence::end() } if (this->mRecording) { - SPDLOG_INFO("Kompute Sequence command recording END"); + KP_LOG_INFO("Kompute Sequence command recording END"); this->mCommandBuffer->end(); this->mRecording = false; } else { - SPDLOG_WARN("Kompute Sequence attempted to end command recording but " + KP_LOG_WARN("Kompute Sequence attempted to end command recording but " "recording not started"); } return true; @@ -108,17 +108,17 @@ Sequence::end() bool Sequence::eval() { - SPDLOG_DEBUG("Kompute sequence EVAL BEGIN"); + KP_LOG_DEBUG("Kompute sequence EVAL BEGIN"); bool evalResult = this->evalAsync(); if (!evalResult) { - SPDLOG_DEBUG("Kompute sequence EVAL FAILURE"); + KP_LOG_DEBUG("Kompute sequence EVAL FAILURE"); return false; } evalResult = this->evalAwait(); - SPDLOG_DEBUG("Kompute sequence EVAL SUCCESS"); + KP_LOG_DEBUG("Kompute sequence EVAL SUCCESS"); return evalResult; } @@ -127,11 +127,11 @@ bool Sequence::evalAsync() { if (this->isRecording()) { - SPDLOG_WARN("Kompute Sequence evalAsync called when still recording"); + KP_LOG_WARN("Kompute Sequence evalAsync called when still recording"); return false; } if (this->mIsRunning) { - SPDLOG_WARN("Kompute Sequence evalAsync called when an eval async was " + KP_LOG_WARN("Kompute Sequence evalAsync called when an eval async was " "called without successful wait"); return false; } @@ -147,7 +147,7 @@ Sequence::evalAsync() this->mFence = this->mDevice->createFence(vk::FenceCreateInfo()); - SPDLOG_DEBUG( + KP_LOG_DEBUG( "Kompute sequence submitting command buffer into compute queue"); this->mComputeQueue->submit(1, &submitInfo, this->mFence); @@ -159,7 +159,7 @@ bool Sequence::evalAwait(uint64_t waitFor) { if (!this->mIsRunning) { - SPDLOG_WARN("Kompute Sequence evalAwait called without existing eval"); + KP_LOG_WARN("Kompute Sequence evalAwait called without existing eval"); return false; } @@ -171,7 +171,7 @@ Sequence::evalAwait(uint64_t waitFor) this->mIsRunning = false; if (result == vk::Result::eTimeout) { - SPDLOG_WARN("Kompute Sequence evalAwait timed out"); + KP_LOG_WARN("Kompute Sequence evalAwait timed out"); return false; } @@ -203,26 +203,26 @@ Sequence::isInit() void Sequence::freeMemoryDestroyGPUResources() { - SPDLOG_DEBUG("Kompute Sequence freeMemoryDestroyGPUResources called"); + KP_LOG_DEBUG("Kompute Sequence freeMemoryDestroyGPUResources called"); if (!this->mIsInit) { - SPDLOG_ERROR("Kompute Sequence freeMemoryDestroyGPUResources called " + KP_LOG_ERROR("Kompute Sequence freeMemoryDestroyGPUResources called " "but Sequence is not initialized so there's no relevant " "GPU resources."); return; } if (!this->mDevice) { - SPDLOG_ERROR("Kompute Sequence freeMemoryDestroyGPUResources called " + KP_LOG_ERROR("Kompute Sequence freeMemoryDestroyGPUResources called " "with null Device pointer"); this->mIsInit = false; return; } if (this->mFreeCommandBuffer) { - SPDLOG_INFO("Freeing CommandBuffer"); + KP_LOG_INFO("Freeing CommandBuffer"); if (!this->mCommandBuffer) { - SPDLOG_ERROR( + KP_LOG_ERROR( "Kompute Sequence freeMemoryDestroyGPUResources called with null " "CommandPool pointer"); this->mIsInit = false; @@ -230,13 +230,13 @@ Sequence::freeMemoryDestroyGPUResources() } this->mDevice->freeCommandBuffers( *this->mCommandPool, 1, this->mCommandBuffer.get()); - SPDLOG_DEBUG("Kompute Sequence Freed CommandBuffer"); + KP_LOG_DEBUG("Kompute Sequence Freed CommandBuffer"); } if (this->mFreeCommandPool) { - SPDLOG_INFO("Destroying CommandPool"); + KP_LOG_INFO("Destroying CommandPool"); if (this->mCommandPool == nullptr) { - SPDLOG_ERROR( + KP_LOG_ERROR( "Kompute Sequence freeMemoryDestroyGPUResources called with null " "CommandPool pointer"); this->mIsInit = false; @@ -245,11 +245,11 @@ Sequence::freeMemoryDestroyGPUResources() this->mDevice->destroy( *this->mCommandPool, (vk::Optional)nullptr); - SPDLOG_DEBUG("Kompute Sequence Destroyed CommandPool"); + KP_LOG_DEBUG("Kompute Sequence Destroyed CommandPool"); } if (this->mOperations.size()) { - SPDLOG_INFO("Kompute Sequence clearing operations buffer"); + KP_LOG_INFO("Kompute Sequence clearing operations buffer"); this->mOperations.clear(); } @@ -259,7 +259,7 @@ Sequence::freeMemoryDestroyGPUResources() void Sequence::createCommandPool() { - SPDLOG_DEBUG("Kompute Sequence creating command pool"); + KP_LOG_DEBUG("Kompute Sequence creating command pool"); if (!this->mDevice) { throw std::runtime_error("Kompute Sequence device is null"); @@ -275,13 +275,13 @@ Sequence::createCommandPool() this->mCommandPool = std::make_shared(); this->mDevice->createCommandPool( &commandPoolInfo, nullptr, this->mCommandPool.get()); - SPDLOG_DEBUG("Kompute Sequence Command Pool Created"); + KP_LOG_DEBUG("Kompute Sequence Command Pool Created"); } void Sequence::createCommandBuffer() { - SPDLOG_DEBUG("Kompute Sequence creating command buffer"); + KP_LOG_DEBUG("Kompute Sequence creating command buffer"); if (!this->mDevice) { throw std::runtime_error("Kompute Sequence device is null"); } @@ -297,7 +297,7 @@ Sequence::createCommandBuffer() this->mCommandBuffer = std::make_shared(); this->mDevice->allocateCommandBuffers(&commandBufferAllocateInfo, this->mCommandBuffer.get()); - SPDLOG_DEBUG("Kompute Sequence Command Buffer Created"); + KP_LOG_DEBUG("Kompute Sequence Command Buffer Created"); } } diff --git a/src/Shader.cpp b/src/Shader.cpp index 3f42ee26..17429919 100644 --- a/src/Shader.cpp +++ b/src/Shader.cpp @@ -38,7 +38,7 @@ Shader::compile_sources(const std::vector& sources, if (!shader.parse(&glslang::DefaultTBuiltInResource, 100, false, messages)) { info_log = std::string(shader.getInfoLog()) + "\n" + std::string(shader.getInfoDebugLog()); - SPDLOG_ERROR("Kompute Shader Error: {}", info_log); + KP_LOG_ERROR("Kompute Shader Error: {}", info_log); throw std::runtime_error(info_log); } @@ -49,7 +49,7 @@ Shader::compile_sources(const std::vector& sources, if (!program.link(messages)) { info_log = std::string(program.getInfoLog()) + "\n" + std::string(program.getInfoDebugLog()); - SPDLOG_ERROR("Kompute Shader Error: {}", info_log); + KP_LOG_ERROR("Kompute Shader Error: {}", info_log); throw std::runtime_error(info_log); } @@ -57,7 +57,7 @@ Shader::compile_sources(const std::vector& sources, if (shader.getInfoLog()) { info_log += std::string(shader.getInfoLog()) + "\n" + std::string(shader.getInfoDebugLog()) + "\n"; - SPDLOG_INFO("Kompute Shader Information: {}", info_log); + KP_LOG_INFO("Kompute Shader Information: {}", info_log); } glslang::TIntermediate *intermediate = program.getIntermediate(language); @@ -65,7 +65,7 @@ Shader::compile_sources(const std::vector& sources, if (!intermediate) { info_log += "Failed to get shared intermediate code.\n"; - SPDLOG_ERROR("Kompute Shader Error: {}", info_log); + KP_LOG_ERROR("Kompute Shader Error: {}", info_log); throw std::runtime_error(info_log); } @@ -76,7 +76,7 @@ Shader::compile_sources(const std::vector& sources, if (shader.getInfoLog()) { info_log += logger.getAllMessages() + "\n"; - SPDLOG_DEBUG("Kompute Shader all result messages: {}", info_log); + KP_LOG_DEBUG("Kompute Shader all result messages: {}", info_log); } // Shutdown glslang library. diff --git a/src/Tensor.cpp b/src/Tensor.cpp index a1ba1544..16b7f9e8 100644 --- a/src/Tensor.cpp +++ b/src/Tensor.cpp @@ -5,14 +5,14 @@ namespace kp { Tensor::Tensor() { - SPDLOG_DEBUG("Kompute Tensor base constructor"); + KP_LOG_DEBUG("Kompute Tensor base constructor"); this->mTensorType = TensorTypes::eDevice; } Tensor::Tensor(const std::vector& data, TensorTypes tensorType) { #if DEBUG - SPDLOG_DEBUG("Kompute Tensor constructor data length: {}, and type: {}", + KP_LOG_DEBUG("Kompute Tensor constructor data length: {}, and type: {}", data.size(), tensorType); #endif @@ -24,21 +24,21 @@ Tensor::Tensor(const std::vector& data, TensorTypes tensorType) Tensor::~Tensor() { - SPDLOG_DEBUG("Kompute Tensor destructor started. Type: {}", + KP_LOG_DEBUG("Kompute Tensor destructor started. Type: {}", this->tensorType()); if (this->isInit()) { this->freeMemoryDestroyGPUResources(); } - SPDLOG_DEBUG("Kompute Tensor destructor success"); + KP_LOG_DEBUG("Kompute Tensor destructor success"); } void Tensor::init(std::shared_ptr physicalDevice, std::shared_ptr device) { - SPDLOG_DEBUG("Kompute Tensor running init with Vulkan params and num data " + KP_LOG_DEBUG("Kompute Tensor running init with Vulkan params and num data " "elementS: {}", this->mData.size()); @@ -111,7 +111,7 @@ Tensor::recordCopyFrom(std::shared_ptr commandBuffer, vk::DeviceSize bufferSize(this->memorySize()); vk::BufferCopy copyRegion(0, 0, bufferSize); - SPDLOG_DEBUG("Kompute Tensor recordCopyFrom data size {}.", bufferSize); + KP_LOG_DEBUG("Kompute Tensor recordCopyFrom data size {}.", bufferSize); this->copyBuffer(commandBuffer, copyFromTensor->mPrimaryBuffer, @@ -129,7 +129,7 @@ Tensor::recordCopyFromStagingToDevice( vk::DeviceSize bufferSize(this->memorySize()); vk::BufferCopy copyRegion(0, 0, bufferSize); - SPDLOG_DEBUG("Kompute Tensor copying data size {}.", bufferSize); + KP_LOG_DEBUG("Kompute Tensor copying data size {}.", bufferSize); this->copyBuffer(commandBuffer, this->mStagingBuffer, @@ -147,7 +147,7 @@ Tensor::recordCopyFromDeviceToStaging( vk::DeviceSize bufferSize(this->memorySize()); vk::BufferCopy copyRegion(0, 0, bufferSize); - SPDLOG_DEBUG("Kompute Tensor copying data size {}.", bufferSize); + KP_LOG_DEBUG("Kompute Tensor copying data size {}.", bufferSize); this->copyBuffer(commandBuffer, this->mPrimaryBuffer, @@ -191,7 +191,7 @@ Tensor::recordBufferMemoryBarrier( vk::PipelineStageFlagBits srcStageMask, vk::PipelineStageFlagBits dstStageMask) { - SPDLOG_DEBUG("Kompute Tensor recording buffer memory barrier"); + KP_LOG_DEBUG("Kompute Tensor recording buffer memory barrier"); vk::DeviceSize bufferSize = this->memorySize(); @@ -223,7 +223,7 @@ Tensor::constructDescriptorBufferInfo() void Tensor::mapDataFromHostMemory() { - SPDLOG_DEBUG("Kompute Tensor mapping data from host buffer"); + KP_LOG_DEBUG("Kompute Tensor mapping data from host buffer"); std::shared_ptr hostVisibleMemory = nullptr; @@ -232,7 +232,7 @@ Tensor::mapDataFromHostMemory() } else if (this->mTensorType == TensorTypes::eDevice) { hostVisibleMemory = this->mStagingMemory; } else { - SPDLOG_WARN( + KP_LOG_WARN( "Kompute Tensor mapping data not supported on storage tensor"); return; } @@ -250,7 +250,7 @@ void Tensor::mapDataIntoHostMemory() { - SPDLOG_DEBUG("Kompute Tensor local mapping tensor data to host buffer"); + KP_LOG_DEBUG("Kompute Tensor local mapping tensor data to host buffer"); std::shared_ptr hostVisibleMemory = nullptr; @@ -259,7 +259,7 @@ Tensor::mapDataIntoHostMemory() } else if (this->mTensorType == TensorTypes::eDevice) { hostVisibleMemory = this->mStagingMemory; } else { - SPDLOG_WARN( + KP_LOG_WARN( "Kompute Tensor mapping data not supported on storage tensor"); return; } @@ -342,7 +342,7 @@ Tensor::getStagingMemoryPropertyFlags() void Tensor::allocateMemoryCreateGPUResources() { - SPDLOG_DEBUG("Kompute Tensor creating buffer"); + KP_LOG_DEBUG("Kompute Tensor creating buffer"); if (!this->mIsInit) { throw std::runtime_error( @@ -356,7 +356,7 @@ Tensor::allocateMemoryCreateGPUResources() throw std::runtime_error("Kompute Tensor device is null"); } - SPDLOG_DEBUG("Kompute Tensor creating primary buffer and memory"); + KP_LOG_DEBUG("Kompute Tensor creating primary buffer and memory"); this->mPrimaryBuffer = std::make_shared(); this->createBuffer(this->mPrimaryBuffer, @@ -369,7 +369,7 @@ Tensor::allocateMemoryCreateGPUResources() this->mFreePrimaryMemory = true; if (this->mTensorType == TensorTypes::eDevice) { - SPDLOG_DEBUG("Kompute Tensor creating staging buffer and memory"); + KP_LOG_DEBUG("Kompute Tensor creating staging buffer and memory"); this->mStagingBuffer = std::make_shared(); this->createBuffer(this->mStagingBuffer, @@ -382,7 +382,7 @@ Tensor::allocateMemoryCreateGPUResources() this->mFreeStagingMemory = true; } - SPDLOG_DEBUG("Kompute Tensor buffer & memory creation successful"); + KP_LOG_DEBUG("Kompute Tensor buffer & memory creation successful"); } void @@ -397,7 +397,7 @@ Tensor::createBuffer(std::shared_ptr buffer, "Kompute Tensor attempted to create a zero-sized buffer"); } - SPDLOG_DEBUG("Kompute Tensor creating buffer with memory size: {}, and " + KP_LOG_DEBUG("Kompute Tensor creating buffer with memory size: {}, and " "usage flags: {}", bufferSize, vk::to_string(bufferUsageFlags)); @@ -417,7 +417,7 @@ Tensor::allocateBindMemory(std::shared_ptr buffer, vk::MemoryPropertyFlags memoryPropertyFlags) { - SPDLOG_DEBUG("Kompute Tensor allocating and binding memory"); + KP_LOG_DEBUG("Kompute Tensor allocating and binding memory"); vk::PhysicalDeviceMemoryProperties memoryProperties = this->mPhysicalDevice->getMemoryProperties(); @@ -440,7 +440,7 @@ Tensor::allocateBindMemory(std::shared_ptr buffer, "Memory type index for buffer creation not found"); } - SPDLOG_DEBUG( + KP_LOG_DEBUG( "Kompute Tensor allocating memory index: {}, size {}, flags: {}", memoryTypeIndex, memoryRequirements.size, @@ -457,22 +457,22 @@ Tensor::allocateBindMemory(std::shared_ptr buffer, void Tensor::freeMemoryDestroyGPUResources() { - SPDLOG_DEBUG("Kompute Tensor started freeMemoryDestroyGPUResources"); + KP_LOG_DEBUG("Kompute Tensor started freeMemoryDestroyGPUResources"); this->mIsInit = false; if (!this->mDevice) { - SPDLOG_ERROR( + KP_LOG_ERROR( "Kompute Tensor destructor reached with null Device pointer"); return; } if (this->mFreePrimaryBuffer) { if (!this->mPrimaryBuffer) { - SPDLOG_ERROR("Kompose Tensor expected to destroy primary buffer " + KP_LOG_ERROR("Kompose Tensor expected to destroy primary buffer " "but got null buffer"); } else { - SPDLOG_DEBUG("Kompose Tensor destroying primary buffer"); + KP_LOG_DEBUG("Kompose Tensor destroying primary buffer"); this->mDevice->destroy( *this->mPrimaryBuffer, (vk::Optional)nullptr); @@ -482,10 +482,10 @@ Tensor::freeMemoryDestroyGPUResources() if (this->mFreeStagingBuffer) { if (!this->mStagingBuffer) { - SPDLOG_ERROR("Kompose Tensor expected to destroy staging buffer " + KP_LOG_ERROR("Kompose Tensor expected to destroy staging buffer " "but got null buffer"); } else { - SPDLOG_DEBUG("Kompose Tensor destroying staging buffer"); + KP_LOG_DEBUG("Kompose Tensor destroying staging buffer"); this->mDevice->destroy( *this->mStagingBuffer, (vk::Optional)nullptr); @@ -495,10 +495,10 @@ Tensor::freeMemoryDestroyGPUResources() if (this->mFreePrimaryMemory) { if (!this->mPrimaryMemory) { - SPDLOG_ERROR("Kompose Tensor expected to free primary memory but " + KP_LOG_ERROR("Kompose Tensor expected to free primary memory but " "got null memory"); } else { - SPDLOG_DEBUG("Kompose Tensor freeing primary memory"); + KP_LOG_DEBUG("Kompose Tensor freeing primary memory"); this->mDevice->freeMemory( *this->mPrimaryMemory, (vk::Optional)nullptr); @@ -508,10 +508,10 @@ Tensor::freeMemoryDestroyGPUResources() if (this->mFreeStagingMemory) { if (!this->mStagingMemory) { - SPDLOG_ERROR("Kompose Tensor expected to free staging memory but " + KP_LOG_ERROR("Kompose Tensor expected to free staging memory but " "got null memory"); } else { - SPDLOG_DEBUG("Kompose Tensor freeing staging memory"); + KP_LOG_DEBUG("Kompose Tensor freeing staging memory"); this->mDevice->freeMemory( *this->mStagingMemory, (vk::Optional)nullptr); @@ -519,7 +519,7 @@ Tensor::freeMemoryDestroyGPUResources() } } - SPDLOG_DEBUG("Kompute Tensor successful freeMemoryDestroyGPUResources"); + KP_LOG_DEBUG("Kompute Tensor successful freeMemoryDestroyGPUResources"); } } diff --git a/src/include/kompute/Core.hpp b/src/include/kompute/Core.hpp index c3ec7b9c..6da52953 100644 --- a/src/include/kompute/Core.hpp +++ b/src/include/kompute/Core.hpp @@ -50,57 +50,61 @@ extern py::object kp_debug, kp_info, kp_warning, kp_error; #ifndef KOMPUTE_LOG_OVERRIDE #if KOMPUTE_ENABLE_SPDLOG #include +#define KP_LOG_DEBUG(...) SPDLOG_DEBUG(__VA_ARGS__) +#define KP_LOG_INFO(...) SPDLOG_INFO(__VA_ARGS__) +#define KP_LOG_WARN(...) SPDLOG_WARN(__VA_ARGS__) +#define KP_LOG_ERROR(...) SPDLOG_ERROR(__VA_ARGS__) #else #include #if SPDLOG_ACTIVE_LEVEL > 1 -#define SPDLOG_DEBUG(...) +#define KP_LOG_DEBUG(...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_DEBUG(...) \ +#define KP_LOG_DEBUG(...) \ ((void)__android_log_print(ANDROID_LOG_DEBUG, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__))) #elif defined(KOMPUTE_BUILD_PYTHON) -#define SPDLOG_DEBUG(...) kp_debug(fmt::format(__VA_ARGS__)) +#define KP_LOG_DEBUG(...) kp_debug(fmt::format(__VA_ARGS__)) #else -#define SPDLOG_DEBUG(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) +#define KP_LOG_DEBUG(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) #endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 1 #if SPDLOG_ACTIVE_LEVEL > 2 -#define SPDLOG_INFO(...) +#define KP_LOG_INFO(...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_INFO(...) \ +#define KP_LOG_INFO(...) \ ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__))) #elif defined(KOMPUTE_BUILD_PYTHON) -#define SPDLOG_INFO(...) kp_info(fmt::format(__VA_ARGS__)) +#define KP_LOG_INFO(...) kp_info(fmt::format(__VA_ARGS__)) #else -#define SPDLOG_INFO(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) +#define KP_LOG_INFO(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) #endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 2 #if SPDLOG_ACTIVE_LEVEL > 3 -#define SPDLOG_WARN(...) +#define KP_LOG_WARN(...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_WARN(...) \ +#define KP_LOG_WARN(...) \ ((void)__android_log_print(ANDROID_LOG_WARN, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__))) #elif defined(KOMPUTE_BUILD_PYTHON) -#define SPDLOG_WARN(...) kp_warning(fmt::format(__VA_ARGS__)) +#define KP_LOG_WARN(...) kp_warning(fmt::format(__VA_ARGS__)) #else -#define SPDLOG_WARN(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) +#define KP_LOG_WARN(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) #endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 3 #if SPDLOG_ACTIVE_LEVEL > 4 -#define SPDLOG_ERROR(...) +#define KP_LOG_ERROR(...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_ERROR(...) \ +#define KP_LOG_ERROR(...) \ ((void)__android_log_print(ANDROID_LOG_ERROR, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__))) #elif defined(KOMPUTE_BUILD_PYTHON) -#define SPDLOG_ERROR(...) kp_error(fmt::format(__VA_ARGS__)) +#define KP_LOG_ERROR(...) kp_error(fmt::format(__VA_ARGS__)) #else -#define SPDLOG_ERROR(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) +#define KP_LOG_ERROR(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__)) #endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 4 #endif // KOMPUTE_SPDLOG_ENABLED diff --git a/src/include/kompute/Manager.hpp b/src/include/kompute/Manager.hpp index f13a4552..1ca302b3 100644 --- a/src/include/kompute/Manager.hpp +++ b/src/include/kompute/Manager.hpp @@ -84,23 +84,23 @@ class Manager std::string sequenceName, TArgs&&... params) { - SPDLOG_DEBUG("Kompute Manager evalOp triggered"); + KP_LOG_DEBUG("Kompute Manager evalOp triggered"); std::shared_ptr sq = this->sequence(sequenceName); - SPDLOG_DEBUG("Kompute Manager evalOp running sequence BEGIN"); + KP_LOG_DEBUG("Kompute Manager evalOp running sequence BEGIN"); sq->begin(); - SPDLOG_DEBUG("Kompute Manager evalOp running sequence RECORD"); + KP_LOG_DEBUG("Kompute Manager evalOp running sequence RECORD"); sq->record(tensors, std::forward(params)...); - SPDLOG_DEBUG("Kompute Manager evalOp running sequence END"); + KP_LOG_DEBUG("Kompute Manager evalOp running sequence END"); sq->end(); - SPDLOG_DEBUG("Kompute Manager evalOp running sequence EVAL"); + KP_LOG_DEBUG("Kompute Manager evalOp running sequence EVAL"); sq->eval(); - SPDLOG_DEBUG("Kompute Manager evalOp running sequence SUCCESS"); + KP_LOG_DEBUG("Kompute Manager evalOp running sequence SUCCESS"); } /** @@ -114,7 +114,7 @@ class Manager void evalOpDefault(std::vector> tensors, TArgs&&... params) { - SPDLOG_DEBUG("Kompute Manager evalOp Default triggered"); + KP_LOG_DEBUG("Kompute Manager evalOp Default triggered"); this->mCurrentSequenceIndex++; this->evalOp( tensors, KP_DEFAULT_SESSION, std::forward(params)...); @@ -133,24 +133,24 @@ class Manager std::string sequenceName, TArgs&&... params) { - SPDLOG_DEBUG("Kompute Manager evalOpAsync triggered"); + KP_LOG_DEBUG("Kompute Manager evalOpAsync triggered"); std::shared_ptr sq = this->sequence(sequenceName); - SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence BEGIN"); + KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence BEGIN"); sq->begin(); - SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence RECORD"); + KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence RECORD"); sq->record(tensors, std::forward(params)...); - SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence END"); + KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence END"); sq->end(); - SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence EVAL"); + KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence EVAL"); sq->evalAsync(); - SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence SUCCESS"); + KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence SUCCESS"); } /** @@ -165,7 +165,7 @@ class Manager void evalOpAsyncDefault(std::vector> tensors, TArgs&&... params) { - SPDLOG_DEBUG("Kompute Manager evalOpAsyncDefault triggered"); + KP_LOG_DEBUG("Kompute Manager evalOpAsyncDefault triggered"); this->mCurrentSequenceIndex++; this->evalOpAsync( tensors, KP_DEFAULT_SESSION, std::forward(params)...); @@ -179,23 +179,23 @@ class Manager */ void evalOpAwait(std::string sequenceName, uint64_t waitFor = UINT64_MAX) { - SPDLOG_DEBUG("Kompute Manager evalOpAwait triggered with sequence {}", + KP_LOG_DEBUG("Kompute Manager evalOpAwait triggered with sequence {}", sequenceName); std::unordered_map>::iterator found = this->mManagedSequences.find(sequenceName); if (found != this->mManagedSequences.end()) { if (std::shared_ptr sq = found->second) { - SPDLOG_DEBUG("Kompute Manager evalOpAwait running sequence " + KP_LOG_DEBUG("Kompute Manager evalOpAwait running sequence " "Sequence EVAL AWAIT"); if (sq->isRunning()) { sq->evalAwait(waitFor); } } - SPDLOG_DEBUG( + KP_LOG_DEBUG( "Kompute Manager evalOpAwait running sequence SUCCESS"); } else { - SPDLOG_ERROR("Kompute Manager evalOpAwait Sequence not found"); + KP_LOG_ERROR("Kompute Manager evalOpAwait Sequence not found"); } } @@ -208,7 +208,7 @@ class Manager */ void evalOpAwaitDefault(uint64_t waitFor = UINT64_MAX) { - SPDLOG_DEBUG("Kompute Manager evalOpAwaitDefault triggered"); + KP_LOG_DEBUG("Kompute Manager evalOpAwaitDefault triggered"); this->evalOpAwait(KP_DEFAULT_SESSION, waitFor); } diff --git a/src/include/kompute/Sequence.hpp b/src/include/kompute/Sequence.hpp index 5d483c27..d9691089 100644 --- a/src/include/kompute/Sequence.hpp +++ b/src/include/kompute/Sequence.hpp @@ -129,15 +129,15 @@ class Sequence "Kompute Sequence record(...) template only valid with " "OpBase derived classes"); - SPDLOG_DEBUG("Kompute Sequence record function started"); + KP_LOG_DEBUG("Kompute Sequence record function started"); if (!this->isRecording()) { - SPDLOG_ERROR( + KP_LOG_ERROR( "Kompute sequence record attempted when not record BEGIN"); return false; } - SPDLOG_DEBUG("Kompute Sequence creating OpBase derived class instance"); + KP_LOG_DEBUG("Kompute Sequence creating OpBase derived class instance"); T* op = new T(this->mPhysicalDevice, this->mDevice, this->mCommandBuffer, @@ -148,11 +148,11 @@ class Sequence std::unique_ptr baseOpPtr{ baseOp }; - SPDLOG_DEBUG( + KP_LOG_DEBUG( "Kompute Sequence running init on OpBase derived class instance"); baseOpPtr->init(); - SPDLOG_DEBUG( + KP_LOG_DEBUG( "Kompute Sequence running record on OpBase derived class instance"); baseOpPtr->record(); diff --git a/src/include/kompute/operations/OpBase.hpp b/src/include/kompute/operations/OpBase.hpp index a423abc2..bc9ee59a 100644 --- a/src/include/kompute/operations/OpBase.hpp +++ b/src/include/kompute/operations/OpBase.hpp @@ -20,7 +20,7 @@ class OpBase /** * Base constructor, should not be used unless explicitly intended. */ - OpBase() { SPDLOG_DEBUG("Compute OpBase base constructor"); } + OpBase() { KP_LOG_DEBUG("Compute OpBase base constructor"); } /** * Default constructor with parameters that provides the bare minimum @@ -37,7 +37,7 @@ class OpBase std::shared_ptr commandBuffer, std::vector>& tensors) { - SPDLOG_DEBUG("Compute OpBase constructor with params"); + KP_LOG_DEBUG("Compute OpBase constructor with params"); this->mPhysicalDevice = physicalDevice; this->mDevice = device; @@ -52,20 +52,20 @@ class OpBase */ virtual ~OpBase() { - SPDLOG_DEBUG("Kompute OpBase destructor started"); + KP_LOG_DEBUG("Kompute OpBase destructor started"); if (!this->mDevice) { - SPDLOG_WARN("Kompute OpBase destructor called with empty device"); + KP_LOG_WARN("Kompute OpBase destructor called with empty device"); return; } if (this->mFreeTensors) { - SPDLOG_DEBUG("Kompute OpBase freeing tensors"); + KP_LOG_DEBUG("Kompute OpBase freeing tensors"); for (std::shared_ptr tensor : this->mTensors) { if (tensor && tensor->isInit()) { tensor->freeMemoryDestroyGPUResources(); } else { - SPDLOG_WARN("Kompute OpBase expected to free " + KP_LOG_WARN("Kompute OpBase expected to free " "tensor but has already been freed."); } } diff --git a/src/include/kompute/operations/OpMult.hpp b/src/include/kompute/operations/OpMult.hpp index a887f4af..a921fb2d 100644 --- a/src/include/kompute/operations/OpMult.hpp +++ b/src/include/kompute/operations/OpMult.hpp @@ -47,7 +47,7 @@ class OpMult : public OpAlgoBase const Workgroup& komputeWorkgroup = {}) : OpAlgoBase(physicalDevice, device, commandBuffer, tensors, "", komputeWorkgroup) { - SPDLOG_DEBUG("Kompute OpMult constructor with params"); + KP_LOG_DEBUG("Kompute OpMult constructor with params"); #ifndef RELEASE this->mShaderFilePath = "shaders/glsl/opmult.comp.spv"; @@ -61,7 +61,7 @@ class OpMult : public OpAlgoBase */ std::vector fetchSpirvBinaryData() override { - SPDLOG_WARN( + KP_LOG_WARN( "Kompute OpMult Running shaders directly from header"); return std::vector( @@ -77,7 +77,7 @@ class OpMult : public OpAlgoBase * components but does not destroy the underlying tensors */ ~OpMult() override { - SPDLOG_DEBUG("Kompute OpMult destructor started"); + KP_LOG_DEBUG("Kompute OpMult destructor started"); } }; diff --git a/test/TestLogisticRegression.cpp b/test/TestLogisticRegression.cpp index 39e4ff8a..e0f0b0e6 100644 --- a/test/TestLogisticRegression.cpp +++ b/test/TestLogisticRegression.cpp @@ -75,7 +75,7 @@ TEST(TestLogisticRegression, TestMainLogisticRegression) EXPECT_GT(wIn->data()[1], 1.0); EXPECT_LT(bIn->data()[0], 0.0); - SPDLOG_WARN("Result wIn i: {}, wIn j: {}, bIn: {}", + KP_LOG_WARN("Result wIn i: {}, wIn j: {}, bIn: {}", wIn->data()[0], wIn->data()[1], bIn->data()[0]); @@ -156,7 +156,7 @@ TEST(TestLogisticRegression, TestMainLogisticRegressionManualCopy) EXPECT_GT(wIn->data()[1], 1.0); EXPECT_LT(bIn->data()[0], 0.0); - SPDLOG_WARN("Result wIn i: {}, wIn j: {}, bIn: {}", + KP_LOG_WARN("Result wIn i: {}, wIn j: {}, bIn: {}", wIn->data()[0], wIn->data()[1], bIn->data()[0]); From f474d21088331ab2af2091d88451a7dc1e73c9b0 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 21 Feb 2021 12:12:16 +0000 Subject: [PATCH 3/4] Updated documentation examples --- README.md | 2 +- docs/overview/advanced-examples.rst | 279 ++-------------------------- docs/overview/async-parallel.rst | 12 +- 3 files changed, 22 insertions(+), 271 deletions(-) diff --git a/README.md b/README.md index e4a302a0..8d8e1394 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ int main() { // 3. Run operation with string shader synchronously mgr.evalOpDefault( { tensorInA, tensorInB, tensorOut }, - std::vector(shaderString.begin(), shaderString.end())); + kp::Shader::compile_source(shaderString)); // 4. Map results back from GPU memory to print the results mgr.evalOpDefault({ tensorInA, tensorInB, tensorOut }); diff --git a/docs/overview/advanced-examples.rst b/docs/overview/advanced-examples.rst index 665c4f0c..bd9d5506 100644 --- a/docs/overview/advanced-examples.rst +++ b/docs/overview/advanced-examples.rst @@ -45,7 +45,7 @@ Pass compute shader data in glsl/hlsl text or compiled SPIR-V format (or as path auto tensorB = std::make_shared(kp::Tensor({ 0., 0., 0. })); // Create tensors data explicitly in GPU with an operation - mgr.evalOpDefault({ tensorA, tensorB }); + mgr.rebuild({ tensorA, tensorB }); // Define your shader as a string (using string literals for simplicity) // (You can also pass the raw compiled bytes, or even path to file) @@ -67,7 +67,7 @@ Pass compute shader data in glsl/hlsl text or compiled SPIR-V format (or as path // Run Kompute operation on the parameters provided with dispatch layout mgr.evalOpDefault( { tensorA, tensorB }, - std::vector(shader.begin(), shader.end())); + kp::Shader::compile_source(shader)); // Sync the GPU memory back to the local tensor mgr.evalOpDefault({ tensorA, tensorB }); @@ -105,7 +105,7 @@ Record commands in a single submit by using a Sequence to send in batch to GPU. sq->begin(); // Record batch commands to send to GPU - sq->record>({ tensorLHS, tensorRHS, tensorOutput }); + sq->record({ tensorLHS, tensorRHS, tensorOutput }); sq->record({tensorOutput, tensorLHS, tensorRHS}); // Stop recording @@ -146,7 +146,7 @@ You can submit operations asynchronously with the async/await commands in the kp auto tensor = std::make_shared(kp::Tensor(std::vector(10, 0.0))); // Create tensors data explicitly in GPU with an operation - mgr.evalOpAsyncDefault({ tensor }); + mgr.rebuild(tensor) // Define your shader as a string (using string literals for simplicity) // (You can also pass the raw compiled bytes, or even path to file) @@ -174,6 +174,8 @@ You can submit operations asynchronously with the async/await commands in the kp } )"); + std::vector spirv = kp::Shader::compile_source(shader); + // We can now await for the previous submitted command // The first parameter can be the amount of time to wait // The time provided is in nanoseconds @@ -182,7 +184,7 @@ You can submit operations asynchronously with the async/await commands in the kp // Run Async Kompute operation on the parameters provided mgr.evalOpAsyncDefault( { tensor }, - std::vector(shader.begin(), shader.end())); + spirv); // Here we can do other work @@ -234,7 +236,7 @@ Back to `examples list <#simple-examples>`_. auto tensorB = std::make_shared(kp::Tensor(std::vector(10, 0.0))); // We run the first step synchronously on the default sequence - mgr.evalOpDefault({ tensorA, tensorB }); + mgr.rebuild({ tensorA, tensorB }); // Define your shader as a string (using string literals for simplicity) // (You can also pass the raw compiled bytes, or even path to file) @@ -262,17 +264,19 @@ Back to `examples list <#simple-examples>`_. } )"); + std::vector spirv = kp::Shader::compile_source(shader); + // Run the first parallel operation in the `queueOne` sequence mgr.evalOpAsync( { tensorA }, "queueOne", - std::vector(shader.begin(), shader.end())); + spirv); // Run the second parallel operation in the `queueTwo` sequence mgr.evalOpAsync( { tensorB }, "queueTwo", - std::vector(shader.begin(), shader.end())); + spirv); // Here we can do other work @@ -308,7 +312,7 @@ We also provide tools that allow you to `convert shaders into C++ headers mShaderFilePath = "shaders/glsl/opmult.comp"; + this->mShaderFilePath = "shaders/glsl/opmult.comp.spv"; } } @@ -323,7 +327,7 @@ We also provide tools that allow you to `convert shaders into C++ headers (kp::Tensor({ 0., 0., 0. })); // Create tensors data explicitly in GPU with an operation - mgr.evalOpDefault({ tensorLhs, tensorRhs, tensorOut }); + mgr.rebuild({ tensorLhs, tensorRhs, tensorOut }); // Run Kompute operation on the parameters provided with dispatch layout mgr.evalOpDefault>( @@ -334,258 +338,3 @@ We also provide tools that allow you to `convert shaders into C++ headers `_. - -.. image:: ../images/logistic-regression.jpg - :width: 300px - - -In summary, we have: - - -* Vector ``X`` with input data (with a pair of inputs ``Xi`` and ``Xj``\ ) -* Output ``Y`` with expected predictions - -With this we will: - -* Optimize the function simplified as ``Y = WX + b`` -* We'll want our program to learn the parameters ``W`` and ``b`` - -We will have to convert this into Kompute terminology. - -First specifically around the inputs, we will be using the following: - -* Two vertors for the variable `X`, vector `Xi` and `Xj` -* One vector `Y` for the true predictions -* A vector `W` containing the two input weight values to use for inference -* A vector `B` containing a single input parameter for `b` - -.. code-block:: cpp - :linenos: - - std::vector wInVec = { 0.001, 0.001 }; - std::vector bInVec = { 0 }; - - std::shared_ptr xI{ new kp::Tensor({ 0, 1, 1, 1, 1 })}; - std::shared_ptr xJ{ new kp::Tensor({ 0, 0, 0, 1, 1 })}; - - std::shared_ptr y{ new kp::Tensor({ 0, 0, 0, 1, 1 })}; - - std::shared_ptr wIn{ - new kp::Tensor(wInVec, kp::Tensor::TensorTypes::eStaging)}; - - std::shared_ptr bIn{ - new kp::Tensor(bInVec, kp::Tensor::TensorTypes::eStaging)}; - - -We will have the following output vectors: - -* Two output vectors `Wi` and `Wj` to store all the deltas to perform gradient descent on W -* One output vector `Bout` to store all the deltas to perform gradient descent on B - -.. code-block:: cpp - :linenos: - - std::shared_ptr wOutI{ new kp::Tensor({ 0, 0, 0, 0, 0 })}; - std::shared_ptr wOutJ{ new kp::Tensor({ 0, 0, 0, 0, 0 })}; - - std::shared_ptr bOut{ new kp::Tensor({ 0, 0, 0, 0, 0 })}; - - -For simplicity we will store all the tensors inside a params variable: - -.. code-block:: cpp - :linenos: - - std::vector> params = - {xI, xJ, y, wIn, wOutI, wOutJ, bIn, bOut}; - - -Now that we have the inputs and outputs we will be able to use them in the processing. The workflow we will be using is the following: - -1. Create a Sequence to record and submit GPU commands -2. Submit OpCreateTensor to create all the tensors -3. Record the OpAlgo with the Logistic Regression shader -4. Loop across number of iterations: - 4-a. Submit algo operation on LR shader - 4-b. Re-calculate weights from loss -5. Print output weights and bias - -1. Create a sequence to record and submit GPU commands - -.. code-block:: cpp - :linenos: - - kp::Manager mgr; - - if (std::shared_ptr sq = - mgr.sequence("createTensors").lock()) - { - // ... - - - -Submit OpCreateTensor to create all the tensors - -.. code-block:: cpp - :linenos: - - { - // ... continuing from codeblock above - - sq->begin(); - - sq->record(params); - - sq->end(); - sq->eval(); - - -Record the OpAlgo with the Logistic Regression shader - -Once we re-record, all the instructions that were recorded previously are cleared. - -Because of this we can record now the new commands which will consist of the following: - - -.. code-block:: cpp - :linenos: - - { - // ... continuing from codeblock above - - sq->begin(); - - sq->record({wIn, bIn}); - - sq->record( - params, - false, // Whether to copy output from device - "test/shaders/glsl/test_logistic_regression.comp"); - - sq->record({wOutI, wOutJ, bOut}); - - sq->end(); - - - -Loop across number of iterations + 4-a. Submit algo operation on LR shader - -.. code-block:: cpp - :linenos: - - { - // ... continuing from codeblock above - - uint32_t ITERATIONS = 100; - - for (size_t i = 0; i < ITERATIONS; i++) - { - // Run evaluation which passes data through shader once - sq->eval(); - - - -4-b. Re-calculate weights from loss - - -Once the shader code is executed, we are able to use the outputs from the shader calculation. - -In this case we want to basically add all the calculated weights and bias from the back-prop step. - -.. code-block:: cpp - :linenos: - - { - // ... - for (size_t i = 0; i < ITERATIONS; i++) - { - // ... continuing from codeblock above - - // Run evaluation which passes data through shader once - sq->eval(); - - // Subtract the resulting weights and biases - for(size_t j = 0; j < bOut->size(); j++) { - wInVec[0] -= wOutI->data()[j]; - wInVec[1] -= wOutJ->data()[j]; - bInVec[0] -= bOut->data()[j]; - } - // Set the data for the GPU to use in the next iteration - wIn->mapDataIntoHostMemory(); - bIn->mapDataIntoHostMemory(); - } - -5. Print output weights and bias - -.. code-block:: cpp - :linenos: - - std::cout << "Weight i: " << wIn->data()[0] << std::endl; - std::cout << "Weight j: " << wIn->data()[1] << std::endl; - std::cout << "Bias: " << bIn->data()[0] << std::endl; - - - -Logistic Regression Compute Shader ----------------------------------- - -Finally you can see the shader used for the logistic regression usecase below: - -.. code-block:: cpp - :linenos: - - #version 450 - - layout (constant_id = 0) const uint M = 0; - - layout (local_size_x = 1) in; - - layout(set = 0, binding = 0) buffer bxi { float xi[]; }; - layout(set = 0, binding = 1) buffer bxj { float xj[]; }; - layout(set = 0, binding = 2) buffer by { float y[]; }; - layout(set = 0, binding = 3) buffer bwin { float win[]; }; - layout(set = 0, binding = 4) buffer bwouti { float wouti[]; }; - layout(set = 0, binding = 5) buffer bwoutj { float woutj[]; }; - layout(set = 0, binding = 6) buffer bbin { float bin[]; }; - layout(set = 0, binding = 7) buffer bbout { float bout[]; }; - - float learningRate = 0.1; - float m = float(M); - - float sigmoid(float z) { - return 1.0 / (1.0 + exp(-z)); - } - - float inference(vec2 x, vec2 w, float b) { - float z = dot(w, x) + b; - float yHat = sigmoid(z); - return yHat; - } - - float calculateLoss(float yHat, float y) { - return -(y * log(yHat) + (1.0 - y) * log(1.0 - yHat)); - } - - void main() { - uint idx = gl_GlobalInvocationID.x; - - vec2 wCurr = vec2(win[0], win[1]); - float bCurr = bin[0]; - - vec2 xCurr = vec2(xi[idx], xj[idx]); - float yCurr = y[idx]; - - float yHat = inference(xCurr, wCurr, bCurr); - float loss = calculateLoss(yHat, yCurr); - - float dZ = yHat - yCurr; - vec2 dW = (1. / m) * xCurr * dZ; - float dB = (1. / m) * dZ; - wouti[idx] = learningRate * dW.x; - woutj[idx] = learningRate * dW.y; - bout[idx] = learningRate * dB; - } diff --git a/docs/overview/async-parallel.rst b/docs/overview/async-parallel.rst index 1e0178b4..0a31ef17 100644 --- a/docs/overview/async-parallel.rst +++ b/docs/overview/async-parallel.rst @@ -64,7 +64,7 @@ Sequences can be executed in synchronously or asynchronously without having to c :linenos: // Create tensors data explicitly in GPU with an operation - mgr.evalOpAsyncDefault({ tensor }); + mgr.rebuild({ tensor }); While this is running we can actually do other things like in this case create the shader we'll be using. @@ -125,7 +125,7 @@ Similar to above we can run other commands such as the `OpAlgoBase` asynchronous // Run Async Kompute operation on the parameters provided mgr.evalOpAsyncDefault>( { tensor }, - std::vector(shader.begin(), shader.end())); + kp::Shader::compile_source(shader)); // Here we can do other work @@ -226,7 +226,7 @@ Similar to the asyncrhonous usecase above, we can still run synchronous commands :linenos: // We run the first step synchronously on the default sequence - mgr.evalOpDefault({ tensorA, tensorB }); + mgr.rebuild({ tensorA, tensorB }); // Define your shader as a string (using string literals for simplicity) // (You can also pass the raw compiled bytes, or even path to file) @@ -259,17 +259,19 @@ Now we can actually trigger the parallel processing, running two OpAlgoBase Oper .. code-block:: cpp :linenos: + std::vector spirv = kp::Shader::compile_source(shader); + // Run the first parallel operation in the `queueOne` sequence mgr.evalOpAsync>( { tensorA }, "queueOne", - std::vector(shader.begin(), shader.end())); + spirv); // Run the second parallel operation in the `queueTwo` sequence mgr.evalOpAsync>( { tensorB }, "queueTwo", - std::vector(shader.begin(), shader.end())); + spirv); Similar to the asynchronous example above, we are able to do other work whilst the tasks are executing. From 7a252a0036df4eb8f21fe27a9eee96fb852333a2 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 21 Feb 2021 12:22:51 +0000 Subject: [PATCH 4/4] Updated spdlog to always use fmt from external in cmake --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 480ec445..bebb2a54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,10 +25,10 @@ set(KOMPUTE_EXTRA_CXX_FLAGS "" CACHE STRING "Extra compile flags for Kompute, se if(KOMPUTE_OPT_ENABLE_SPDLOG) set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DKOMPUTE_ENABLE_SPDLOG=1") + set(SPDLOG_FMT_EXTERNAL ON CACHE BOOL "Enables external fmt as its current dep" FORCE) if(KOMPUTE_OPT_INSTALL) # Enable install parameters for spdlog (overrides parameters passed) set(SPDLOG_INSTALL ON CACHE BOOL "Enables install of spdlot" FORCE) - set(SPDLOG_FMT_EXTERNAL ON CACHE BOOL "Enables external fmt as its current dep" FORCE) endif() endif()