Initial addition of input blocks

This commit is contained in:
Alejandro Saucedo 2020-10-04 08:07:17 +01:00
parent 652e010895
commit a1e25fc792
13 changed files with 181 additions and 170 deletions

View file

@ -0,0 +1,89 @@
// 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"
#ifndef KOMPUTE_VK_INIT_RETRIES
#define KOMPUTE_VK_INIT_RETRIES 5
#endif
// Android log function wrappers
static const char* kTAG = "KomputeJni";
#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__))
extern "C" {
JNIEXPORT jboolean JNICALL
Java_com_ethicalml_kompute_KomputeJni_initVulkan(JNIEnv *env, jobject thiz) {
LOGI("Initialising vulkan");
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;
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("Result is: ");
}
}