diff --git a/examples/android/android-simple/app/build.gradle b/examples/android/android-simple/app/build.gradle index 877e1046e..3990324a3 100644 --- a/examples/android/android-simple/app/build.gradle +++ b/examples/android/android-simple/app/build.gradle @@ -8,7 +8,7 @@ android { defaultConfig { applicationId "com.ethicalml.kompute" - minSdkVersion 26 + minSdkVersion 23 targetSdkVersion 29 versionCode = 1 versionName = "0.0.1" @@ -20,7 +20,8 @@ android { '-DKOMPUTE_OPT_ANDOID_BUILD=1', '-DKOMPUTE_OPT_INSTALL=0', '-DKOMPUTE_OPT_BUILD_SINGLE_HEADER=1', - '-DKOMPUTE_OPT_DISABLE_VK_DEBUG_LAYERS=1' + '-DKOMPUTE_OPT_DISABLE_VK_DEBUG_LAYERS=1', + '-DKOMPUTE_EXTRA_CXX_FLAGS=-DKOMPUTE_VK_API_MINOR_VERSION=0' } } } diff --git a/examples/android/android-simple/app/src/main/cpp/CMakeLists.txt b/examples/android/android-simple/app/src/main/cpp/CMakeLists.txt index e3470cacc..a4e9b3ab1 100644 --- a/examples/android/android-simple/app/src/main/cpp/CMakeLists.txt +++ b/examples/android/android-simple/app/src/main/cpp/CMakeLists.txt @@ -13,8 +13,9 @@ include_directories( ../../../../../../../single_include/ ../../../../../../../vk_ndk_wrapper_include/) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 \ - -DVK_USE_PLATFORM_ANDROID_KHR=1 -DKOMPUTE_DISABLE_VK_DEBUG_LAYERS=1") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 \ + -DVK_USE_PLATFORM_ANDROID_KHR=1 \ + -DKOMPUTE_DISABLE_VK_DEBUG_LAYERS=1") target_link_libraries(kompute-jni kompute 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 9ca5c702f..d3e6d85cf 100644 --- a/examples/android/android-simple/app/src/main/cpp/KomputeJniNative.cpp +++ b/examples/android/android-simple/app/src/main/cpp/KomputeJniNative.cpp @@ -66,9 +66,11 @@ Java_com_ethicalml_kompute_KomputeJni_initVulkan(JNIEnv *env, jobject thiz) { uint32_t totalRetries = 0; while (totalRetries < KOMPUTE_VK_INIT_RETRIES) { + LOGI("VULKAN LOAD TRY NUMBER: %u", totalRetries); if(InitVulkan()) { break; } + sleep(1); totalRetries++; } diff --git a/examples/android/android-simple/app/src/main/java/com/ethicalml/kompute/KomputeJni.kt b/examples/android/android-simple/app/src/main/java/com/ethicalml/kompute/KomputeJni.kt index d6e44e482..6a3d3e6c6 100755 --- a/examples/android/android-simple/app/src/main/java/com/ethicalml/kompute/KomputeJni.kt +++ b/examples/android/android-simple/app/src/main/java/com/ethicalml/kompute/KomputeJni.kt @@ -51,9 +51,6 @@ class KomputeJni : AppCompatActivity() { fun KomputeButtonOnClick(v: View) { -// val binding = ActivityKomputeJniBinding.inflate(layoutInflater) -// setContentView(binding.root) - val xiEditText = findViewById(R.id.XIEditText) val xjEditText = findViewById(R.id.XJEditText) val yEditText = findViewById(R.id.YEditText) diff --git a/single_include/kompute/Kompute.hpp b/single_include/kompute/Kompute.hpp index 3d8f327ba..91c982296 100755 --- a/single_include/kompute/Kompute.hpp +++ b/single_include/kompute/Kompute.hpp @@ -1,25 +1,28 @@ -//#define VK_NO_PROTOTYPES 1 -//#undef VK_NO_PROTOTYPES -//#undef DEBUG -//#ifndef RELEASE -//#define RELEASE 1 -//#endif -//#define USE_DEBUG_EXTENTIONS - #ifdef VK_USE_PLATFORM_ANDROID_KHR -//#include -//#include +#include #include - // VK_NO_PROTOTYPES required before vulkan import but after wrapper.hpp #undef VK_NO_PROTOTYPES #define DVULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1 +static const char* KOMPUTE_LOG_TAG = "KomputeLog"; #endif #include +// Must be after vulkan is included +#ifndef KOMPUTE_VK_API_VERSION +#ifndef KOMPUTE_VK_API_MAJOR_VERSION +#define KOMPUTE_VK_API_MAJOR_VERSION 1 +#endif // KOMPUTE_VK_API_MAJOR_VERSION +#ifndef KOMPUTE_VK_API_MINOR_VERSION +#define KOMPUTE_VK_API_MINOR_VERSION 1 +#endif // KOMPUTE_VK_API_MINOR_VERSION + +#define KOMPUTE_VK_API_VERSION VK_MAKE_VERSION(KOMPUTE_VK_API_MAJOR_VERSION, KOMPUTE_VK_API_MINOR_VERSION, 0) +#endif // KOMPUTE_VK_API_VERSION + // SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import #if !defined(SPDLOG_ACTIVE_LEVEL) #if DEBUG @@ -37,25 +40,41 @@ #if SPDLOG_ACTIVE_LEVEL > 1 #define SPDLOG_DEBUG(message, ...) #else +#if defined(VK_USE_PLATFORM_ANDROID_KHR) +#define SPDLOG_DEBUG(message, ...) ((void)__android_log_print(ANDROID_LOG_DEBUG, KOMPUTE_LOG_TAG, message)) +#else #define SPDLOG_DEBUG(message, ...) \ std::cout << "DEBUG: " << message << std::endl +#endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 1 #if SPDLOG_ACTIVE_LEVEL > 2 #define SPDLOG_INFO(message, ...) #else +#if defined(VK_USE_PLATFORM_ANDROID_KHR) +#define SPDLOG_INFO(message, ...) ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message)) +#else #define SPDLOG_INFO(message, ...) std::cout << "INFO: " << message << std::endl +#endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 2 #if SPDLOG_ACTIVE_LEVEL > 3 #define SPDLOG_WARN(message, ...) #else +#if defined(VK_USE_PLATFORM_ANDROID_KHR) +#define SPDLOG_WARN(message, ...) ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message)) +#else #define SPDLOG_WARN(message, ...) \ std::cout << "WARNING: " << message << std::endl +#endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 3 #if SPDLOG_ACTIVE_LEVEL > 4 #define SPDLOG_ERROR(message, ...) #else +#if defined(VK_USE_PLATFORM_ANDROID_KHR) +#define SPDLOG_ERROR(message, ...) ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message)) +#else #define SPDLOG_ERROR(message, ...) \ std::cout << "ERROR: " << message << std::endl +#endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 4 #endif // KOMPUTE_SPDLOG_ENABLED #endif // KOMPUTE_LOG_OVERRIDE diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 02c792cf8..4c2c1cf4c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,7 +64,6 @@ if(NOT KOMPUTE_OPT_ANDOID_BUILD) else() target_link_libraries( kompute - "libvulkan.so" ) endif() diff --git a/src/Manager.cpp b/src/Manager.cpp index 6a7fd3345..1debb4c9a 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -122,7 +122,9 @@ Manager::createInstance() vk::ApplicationInfo applicationInfo; applicationInfo.pApplicationName = "Vulkan Kompute"; applicationInfo.pEngineName = "VulkanKompute"; - applicationInfo.apiVersion = VK_API_VERSION_1_1; + applicationInfo.apiVersion = KOMPUTE_VK_API_VERSION; + applicationInfo.engineVersion = KOMPUTE_VK_API_VERSION; + applicationInfo.applicationVersion = KOMPUTE_VK_API_VERSION; std::vector applicationExtensions; applicationExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); diff --git a/src/include/kompute/Core.hpp b/src/include/kompute/Core.hpp index 3bdab7411..06a283f4b 100644 --- a/src/include/kompute/Core.hpp +++ b/src/include/kompute/Core.hpp @@ -1,25 +1,28 @@ #pragma once -//#define VK_NO_PROTOTYPES 1 -//#undef VK_NO_PROTOTYPES -//#undef DEBUG -//#ifndef RELEASE -//#define RELEASE 1 -//#endif -//#define USE_DEBUG_EXTENTIONS - #ifdef VK_USE_PLATFORM_ANDROID_KHR -//#include -//#include +#include #include - // VK_NO_PROTOTYPES required before vulkan import but after wrapper.hpp #undef VK_NO_PROTOTYPES #define DVULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1 +static const char* KOMPUTE_LOG_TAG = "KomputeLog"; #endif #include +// Must be after vulkan is included +#ifndef KOMPUTE_VK_API_VERSION +#ifndef KOMPUTE_VK_API_MAJOR_VERSION +#define KOMPUTE_VK_API_MAJOR_VERSION 1 +#endif // KOMPUTE_VK_API_MAJOR_VERSION +#ifndef KOMPUTE_VK_API_MINOR_VERSION +#define KOMPUTE_VK_API_MINOR_VERSION 1 +#endif // KOMPUTE_VK_API_MINOR_VERSION + +#define KOMPUTE_VK_API_VERSION VK_MAKE_VERSION(KOMPUTE_VK_API_MAJOR_VERSION, KOMPUTE_VK_API_MINOR_VERSION, 0) +#endif // KOMPUTE_VK_API_VERSION + // SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import #if !defined(SPDLOG_ACTIVE_LEVEL) #if DEBUG @@ -37,25 +40,41 @@ #if SPDLOG_ACTIVE_LEVEL > 1 #define SPDLOG_DEBUG(message, ...) #else +#if defined(VK_USE_PLATFORM_ANDROID_KHR) +#define SPDLOG_DEBUG(message, ...) ((void)__android_log_print(ANDROID_LOG_DEBUG, KOMPUTE_LOG_TAG, message)) +#else #define SPDLOG_DEBUG(message, ...) \ std::cout << "DEBUG: " << message << std::endl +#endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 1 #if SPDLOG_ACTIVE_LEVEL > 2 #define SPDLOG_INFO(message, ...) #else +#if defined(VK_USE_PLATFORM_ANDROID_KHR) +#define SPDLOG_INFO(message, ...) ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message)) +#else #define SPDLOG_INFO(message, ...) std::cout << "INFO: " << message << std::endl +#endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 2 #if SPDLOG_ACTIVE_LEVEL > 3 #define SPDLOG_WARN(message, ...) #else +#if defined(VK_USE_PLATFORM_ANDROID_KHR) +#define SPDLOG_WARN(message, ...) ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message)) +#else #define SPDLOG_WARN(message, ...) \ std::cout << "WARNING: " << message << std::endl +#endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 3 #if SPDLOG_ACTIVE_LEVEL > 4 #define SPDLOG_ERROR(message, ...) #else +#if defined(VK_USE_PLATFORM_ANDROID_KHR) +#define SPDLOG_ERROR(message, ...) ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message)) +#else #define SPDLOG_ERROR(message, ...) \ std::cout << "ERROR: " << message << std::endl +#endif // VK_USE_PLATFORM_ANDROID_KHR #endif // SPDLOG_ACTIVE_LEVEL > 4 #endif // KOMPUTE_SPDLOG_ENABLED #endif // KOMPUTE_LOG_OVERRIDE