Initial addition of input blocks
This commit is contained in:
parent
652e010895
commit
a1e25fc792
13 changed files with 181 additions and 170 deletions
|
|
@ -2,11 +2,6 @@ apply plugin: 'com.android.application'
|
|||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
//Properties properties = new Properties()
|
||||
//properties.load(project.rootProject.file('local.properties').newDataInputStream())
|
||||
//def ndkDir = properties.getProperty('ndk.dir')
|
||||
//def valLayerBinDir = "${ndkDir}/sources/third_party/vulkan/src/build-android/jniLibs"
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
ndkVersion '21.2.6472646'
|
||||
|
|
@ -46,15 +41,6 @@ android {
|
|||
}
|
||||
}
|
||||
|
||||
// sourceSets {
|
||||
// main {
|
||||
// jniLibs {
|
||||
// // Must have ndk-r12 or better which including layer binaries
|
||||
// srcDirs = ["${valLayerBinDir}"]
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
flavorDimensions 'cpuArch'
|
||||
productFlavors {
|
||||
arm8 {
|
||||
|
|
@ -81,5 +67,4 @@ dependencies {
|
|||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
// implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- BEGIN_INCLUDE(manifest) -->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.ethicalml.komputejni">
|
||||
package="com.ethicalml.kompute">
|
||||
|
||||
<!-- <application android:label="@string/app_name"-->
|
||||
<!-- android:theme="@android:style/Theme.NoTitleBar.Fullscreen">-->
|
||||
<!-- <!– Our activity is the built-in NativeActivity framework class.-->
|
||||
<!-- This will take care of integrating with our NDK code. –>-->
|
||||
<!-- <activity android:name="android.app.NativeActivity"-->
|
||||
<!-- android:label="@string/app_name"-->
|
||||
<!-- android:configChanges="orientation|keyboardHidden">-->
|
||||
<!-- <!– Tell NativeActivity the name of or .so –>-->
|
||||
<!-- <meta-data android:name="android.app.lib_name"-->
|
||||
<!-- android:value="kompute_android" />-->
|
||||
<!-- <intent-filter>-->
|
||||
<!-- <action android:name="android.intent.action.MAIN" />-->
|
||||
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
|
||||
<!-- </intent-filter>-->
|
||||
<!-- </activity>-->
|
||||
<!-- </application>-->
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
|
|
|
|||
BIN
examples/android/android-simple/app/src/main/assets/kompute.jpg
Executable file
BIN
examples/android/android-simple/app/src/main/assets/kompute.jpg
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.2 MiB |
|
|
@ -2,18 +2,10 @@ 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-jni SHARED
|
||||
kompute-jni.cpp)
|
||||
KomputeJniNative.cpp)
|
||||
|
||||
include_directories(
|
||||
${VK_ANDROID_COMMON_DIR}
|
||||
|
|
@ -24,12 +16,8 @@ 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")
|
||||
|
||||
target_link_libraries(kompute-jni
|
||||
kompute
|
||||
# app-glue
|
||||
log
|
||||
kompute_vk_ndk_wrapper
|
||||
android)
|
||||
|
|
@ -27,12 +27,9 @@
|
|||
|
||||
#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);
|
||||
|
||||
#ifndef KOMPUTE_VK_INIT_RETRIES
|
||||
#define KOMPUTE_VK_INIT_RETRIES 5
|
||||
#endif
|
||||
|
||||
// Android log function wrappers
|
||||
static const char* kTAG = "KomputeJni";
|
||||
|
|
@ -44,51 +41,28 @@ static const char* kTAG = "KomputeJni";
|
|||
((void)__android_log_print(ANDROID_LOG_ERROR, kTAG, __VA_ARGS__))
|
||||
|
||||
extern "C" {
|
||||
JNIEXPORT jstring JNICALL
|
||||
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
|
||||
#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
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_ethicalml_kompute_KomputeJni_initVulkan(JNIEnv *env, jobject thiz) {
|
||||
|
||||
LOGI("Initialising vulkan");
|
||||
// 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");
|
||||
|
||||
uint32_t totalRetries = 0;
|
||||
|
||||
while (totalRetries < KOMPUTE_VK_INIT_RETRIES) {
|
||||
if(InitVulkan()) {
|
||||
break;
|
||||
}
|
||||
totalRetries++;
|
||||
}
|
||||
|
||||
return totalRetries < KOMPUTE_VK_INIT_RETRIES;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_ethicalml_kompute_KomputeJni_stringFromJNI(JNIEnv *env, jobject thiz) {
|
||||
|
||||
LOGI("Creating manager");
|
||||
|
||||
kp::Manager mgr;
|
||||
|
|
@ -110,6 +84,6 @@ Java_com_ethicalml_komputejni_KomputeJni_stringFromJNI(JNIEnv *env, jobject thiz
|
|||
LOGI("%f ", i);
|
||||
}
|
||||
|
||||
return (*env).NewStringUTF("SUCCESS");
|
||||
return env->NewStringUTF("Result is: ");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package com.ethicalml.kompute
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.ethicalml.kompute.databinding.ActivityKomputeJniBinding
|
||||
|
||||
class KomputeJni : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val binding = ActivityKomputeJniBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
binding.komputeGifView.loadUrl("file:///android_asset/komputer-2.gif")
|
||||
|
||||
binding.komputeGifView.getSettings().setUseWideViewPort(true)
|
||||
binding.komputeGifView.getSettings().setLoadWithOverviewMode(true)
|
||||
|
||||
val successVulkanInit = initVulkan()
|
||||
Log.i("KomputeJni", "Vulkan Result: " + successVulkanInit)
|
||||
|
||||
binding.komputeJniTextview.text = stringFromJNI()
|
||||
}
|
||||
|
||||
external fun initVulkan(): Boolean
|
||||
|
||||
external fun stringFromJNI(): String
|
||||
|
||||
companion object {
|
||||
init {
|
||||
System.loadLibrary("kompute-jni")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package com.ethicalml.komputejni
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.ethicalml.komputejni.databinding.ActivityKomputeJniBinding
|
||||
|
||||
class KomputeJni : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
/*
|
||||
* Retrieve our TextView and set its content.
|
||||
* the text is retrieved by calling a native
|
||||
* function.
|
||||
*/
|
||||
val binding = ActivityKomputeJniBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
binding.komputeJniTextview.text = stringFromJNI()
|
||||
}
|
||||
|
||||
/*
|
||||
* A native method that is implemented by the
|
||||
* 'hello-jni' native library, which is packaged
|
||||
* with this application.
|
||||
*/
|
||||
external fun stringFromJNI(): String?
|
||||
|
||||
/*
|
||||
* This is another native method declaration that is *not*
|
||||
* implemented by 'hello-jni'. This is simply to show that
|
||||
* you can declare as many native methods in your Java code
|
||||
* as you want, their implementation is searched in the
|
||||
* currently loaded native libraries only the first time
|
||||
* you call them.
|
||||
*
|
||||
* Trying to call this function will result in a
|
||||
* java.lang.UnsatisfiedLinkError exception !
|
||||
*/
|
||||
external fun unimplementedStringFromJNI(): String?
|
||||
|
||||
companion object {
|
||||
/*
|
||||
* this is used to load the 'hello-jni' library on application
|
||||
* startup. The library has already been unpacked into
|
||||
* /data/data/com.example.hellojni/lib/libhello-jni.so
|
||||
* at the installation time by the package manager.
|
||||
*/
|
||||
init {
|
||||
System.loadLibrary("kompute-jni")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,20 +1,107 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/activity_kompute_jni"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.example.hellojni.HelloJni">
|
||||
tools:context="com.ethicalml.kompute.KomputeJni">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/kompute_jni_textview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/activity_kompute_jni"
|
||||
app:layout_constraintLeft_toLeftOf="@+id/activity_kompute_jni"
|
||||
app:layout_constraintRight_toRightOf="@+id/activity_kompute_jni"
|
||||
app:layout_constraintTop_toTopOf="@+id/activity_kompute_jni" />
|
||||
<LinearLayout
|
||||
android:layout_width="409dp"
|
||||
android:layout_height="354dp"
|
||||
android:orientation="vertical"
|
||||
tools:layout_editor_absoluteX="1dp"
|
||||
tools:layout_editor_absoluteY="376dp">
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="409dp"
|
||||
android:layout_height="50dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="10dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:adjustViewBounds="true"
|
||||
android:cropToPadding="true"
|
||||
android:src="@mipmap/kompute_icon_foreground" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Kompute Android"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Input Xi"
|
||||
android:textSize="24sp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTextTextPersonName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:inputType="textPersonName"
|
||||
android:text="Name" />
|
||||
</LinearLayout>
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Result:"
|
||||
android:textSize="24sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/kompute_jni_textview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Input Xi"
|
||||
android:textSize="24sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp" />
|
||||
|
||||
<WebView
|
||||
android:id="@+id/kompute_gif_view"
|
||||
android:layout_width="409dp"
|
||||
android:layout_height="230dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/kompute_icon_background"/>
|
||||
<foreground android:drawable="@mipmap/kompute_icon_foreground"/>
|
||||
</adaptive-icon>
|
||||
BIN
examples/android/android-simple/app/src/main/res/mipmap-xhdpi/kompute_icon.png
Executable file
BIN
examples/android/android-simple/app/src/main/res/mipmap-xhdpi/kompute_icon.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="kompute_icon_background">#FFFFFF</color>
|
||||
</resources>
|
||||
Loading…
Add table
Add a link
Reference in a new issue