Fully functional JNI UI based app
This commit is contained in:
parent
a73f82e191
commit
652e010895
6 changed files with 89 additions and 87 deletions
|
|
@ -12,8 +12,8 @@ set(VK_ANDROID_INCLUDE_DIR ${ANDROID_NDK}/sources/third_party/vulkan/src/include
|
|||
# ${ANDROID_APP_GLUE_DIR}/android_native_app_glue.c)
|
||||
|
||||
# build vulkan app
|
||||
add_library(kompute_android SHARED
|
||||
KomputeJniNative.cpp)
|
||||
add_library(kompute-jni SHARED
|
||||
kompute-jni.cpp)
|
||||
|
||||
include_directories(
|
||||
${VK_ANDROID_COMMON_DIR}
|
||||
|
|
@ -24,10 +24,10 @@ include_directories(
|
|||
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")
|
||||
#set(CMAKE_SHARED_LINKER_FLAGS
|
||||
# "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
|
||||
|
||||
target_link_libraries(kompute_android
|
||||
target_link_libraries(kompute-jni
|
||||
kompute
|
||||
# app-glue
|
||||
log
|
||||
|
|
|
|||
|
|
@ -12,30 +12,30 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//#undef DEBUG
|
||||
//#define RELEASE 1
|
||||
#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 <unistd.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <jni.h>
|
||||
|
||||
//#include "kompute/Kompute.hpp"
|
||||
#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);
|
||||
//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";
|
||||
static const char* kTAG = "KomputeJni";
|
||||
#define LOGI(...) \
|
||||
((void)__android_log_print(ANDROID_LOG_INFO, kTAG, __VA_ARGS__))
|
||||
#define LOGW(...) \
|
||||
|
|
@ -43,27 +43,27 @@ static const char* kTAG = "Vulkan-Tutorial01";
|
|||
#define LOGE(...) \
|
||||
((void)__android_log_print(ANDROID_LOG_ERROR, kTAG, __VA_ARGS__))
|
||||
|
||||
|
||||
extern "C" {
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_ethicalml_kompute_examples_android_KomputeJni_stringFromJNI(JNIEnv *env, jobject thiz) {
|
||||
Java_com_ethicalml_komputejni_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
|
||||
#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__)
|
||||
|
|
@ -80,32 +80,36 @@ Java_com_ethicalml_kompute_examples_android_KomputeJni_stringFromJNI(JNIEnv *env
|
|||
|
||||
|
||||
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);
|
||||
// }
|
||||
// TODO: This optionally to be initialized from Kompute
|
||||
if(!InitVulkan()) {
|
||||
sleep(1);
|
||||
if (!InitVulkan()) {
|
||||
LOGE("Vulkan is unavailable, install vulkan and re-start");
|
||||
return (*env).NewStringUTF("ERROR");
|
||||
}
|
||||
}
|
||||
|
||||
return (*env).NewStringUTF("Hello from JNI ! Compiled with ABI ");
|
||||
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("SUCCESS");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue