Updated example to not use native activity anymore

This commit is contained in:
Alejandro Saucedo 2020-10-03 18:27:39 +01:00
parent ba70a4c666
commit a73f82e191
23 changed files with 321 additions and 163 deletions

View file

@ -0,0 +1,35 @@
cmake_minimum_required(VERSION 3.4.1)
add_subdirectory(../../../../../../../ ${CMAKE_CURRENT_BINARY_DIR}/kompute_build)
set(ANDROID_APP_GLUE_DIR ${ANDROID_NDK}/sources/android/native_app_glue)
set(VK_ANDROID_COMMON_DIR ${ANDROID_NDK}/sources/third_party/vulkan/src/common)
set(VK_ANDROID_INCLUDE_DIR ${ANDROID_NDK}/sources/third_party/vulkan/src/include)
## build native_app_glue as a static lib
#include_directories(${ANDROID_APP_GLUE_DIR})
#add_library(app-glue STATIC
# ${ANDROID_APP_GLUE_DIR}/android_native_app_glue.c)
# build vulkan app
add_library(kompute_android SHARED
KomputeJniNative.cpp)
include_directories(
${VK_ANDROID_COMMON_DIR}
${VK_ANDROID_INCLUDE_DIR}
../../../../../../../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_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
target_link_libraries(kompute_android
kompute
# app-glue
log
kompute_vk_ndk_wrapper
android)

View file

@ -0,0 +1,111 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//#undef DEBUG
//#define RELEASE 1
#include <android/log.h>
//#include <android_native_app_glue.h>
//#include <cassert>
//#include <memory>
//#include <vector>
//#include <unistd.h>
#include <string.h>
#include <jni.h>
//#include "kompute/Kompute.hpp"
// Functions interacting with Android native activity
void android_main(struct android_app* state);
void terminate(void);
void handle_cmd(android_app* app, int32_t cmd);
// Android log function wrappers
static const char* kTAG = "Vulkan-Tutorial01";
#define LOGI(...) \
((void)__android_log_print(ANDROID_LOG_INFO, kTAG, __VA_ARGS__))
#define LOGW(...) \
((void)__android_log_print(ANDROID_LOG_WARN, kTAG, __VA_ARGS__))
#define LOGE(...) \
((void)__android_log_print(ANDROID_LOG_ERROR, kTAG, __VA_ARGS__))
JNIEXPORT jstring JNICALL
Java_com_ethicalml_kompute_examples_android_KomputeJni_stringFromJNI(JNIEnv *env, jobject thiz) {
#if defined(__arm__)
#if defined(__ARM_ARCH_7A__)
#if defined(__ARM_NEON__)
#if defined(__ARM_PCS_VFP)
#define ABI "armeabi-v7a/NEON (hard-float)"
#else
#define ABI "armeabi-v7a/NEON"
#endif
#else
#if defined(__ARM_PCS_VFP)
#define ABI "armeabi-v7a (hard-float)"
#else
#define ABI "armeabi-v7a"
#endif
#endif
#else
#define ABI "armeabi"
#endif
#elif defined(__i386__)
#define ABI "x86"
#elif defined(__x86_64__)
#define ABI "x86_64"
#elif defined(__mips64) /* mips64el-* toolchain defines __mips__ too */
#define ABI "mips64"
#elif defined(__mips__)
#define ABI "mips"
#elif defined(__aarch64__)
#define ABI "arm64-v8a"
#else
#define ABI "unknown"
#endif
LOGI("Initialising vulkan");
// if (!InitVulkan()) {
// LOGE("Vulkan is unavailable, install vulkan and re-start");
// return false;
// }
//
// LOGI("Creating manager");
//
// kp::Manager mgr;
//
// auto tensorA = mgr.buildTensor({0,1,2});
// auto tensorB = mgr.buildTensor({0,1,2});
// auto tensorC = mgr.buildTensor({1,2,3});
//
// LOGI("Result before:");
// for(const float & i : tensorC->data()) {
// LOGI("%f ", i);
// }
//
// mgr.evalOpDefault<kp::OpMult<>>({tensorA, tensorB, tensorC});
// mgr.evalOpDefault<kp::OpTensorSyncLocal>({tensorC});
//
// LOGI("Result after:");
// for(const float & i : tensorC->data()) {
// LOGI("%f ", i);
// }
return (*env).NewStringUTF("Hello from JNI ! Compiled with ABI ");
}