Skip to content

Commit

Permalink
Enable ml-service and ml-offloading
Browse files Browse the repository at this point in the history
 - Add ml-service and ml-offloading feature
 - Update doc for ml-service build
 - Add deviceMLOps.MLAgent repo as submodule

Signed-off-by: Gichan Jang <[email protected]>
  • Loading branch information
gichan-jang committed Jan 22, 2025
1 parent 6b9f4d5 commit 943b903
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 21 deletions.
7 changes: 5 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
url = https://github.com/nnstreamer/nnstreamer-edge
branch = main
[submodule "externals/llama2.c"]
path = externals/llama2.c
url = https://github.com/nnsuite/llama2.c
path = externals/llama2.c
url = https://github.com/nnsuite/llama2.c
[submodule "externals/deviceMLOps.MLAgent"]
path = externals/deviceMLOps.MLAgent
url = https://github.com/nnstreamer/deviceMLOps.MLAgent.git
6 changes: 4 additions & 2 deletions documentation/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,16 +434,18 @@ $ ./sdkmanager --sdk_root=${HOME}/Android/Sdk --install "platforms;android-34" "
#### Cloning the GitHub Repository
The Android app's GitHub repository can be found here. To build it, you need to clone the repository
first.
first. If you clone with recursive option, you can receive the submodule together.

```bash
$ git clone https://github.com/nnstreamer/nnstreamer-android
$ git clone --recursive https://github.com/nnstreamer/nnstreamer-android
$ ls nnstreamer-android/
build.gradle.kts externals gradle gradle.properties gradlew gradlew.bat LICENSE ml_inference_offloading nnstreamer-api README.md settings.gradle.kts
$ cd nnstreamer-android
```

To build the application with ml-service feature, you need to set the feature ```feature.mlService=true``` in the [gradle.properties](/gradle.properties).

#### Building the Android App using Gradle

In the `nnstreamer-android` directory, `Gradle Wrapper` files have already been generated. You can
Expand Down
69 changes: 57 additions & 12 deletions externals/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ tasks {
}

fun downloadFile(url: URL, outputFileName: String) {
url.openStream().use {
Channels.newChannel(it).use { rbc ->
FileOutputStream(outputFileName).use { fos ->
fos.channel.transferFrom(rbc, 0, Long.MAX_VALUE)
val outFile = File(outputFileName)
if (!outFile.exists()) {
url.openStream().use {
Channels.newChannel(it).use { rbc ->
FileOutputStream(outputFileName).use { fos ->
fos.channel.transferFrom(rbc, 0, Long.MAX_VALUE)
}
}
}
} else {
println("$outputFileName already exists. Skip download.")
}
}

Expand Down Expand Up @@ -106,6 +111,32 @@ tasks {
}
}

val curlVersion = libs.versions.curl.get()
val enabledCurl = when {
!project.hasProperty("feature.mlService") -> {
false
}
project.properties["feature.mlService"].toString() == "false" -> {
false
}
else -> {
true
}
}

val sqliteVersion = libs.versions.sqlite.get()
val enabledSqlite = when {
!project.hasProperty("feature.mlService") -> {
false
}
project.properties["feature.mlService"].toString() == "false" -> {
false
}
else -> {
true
}
}

val tfliteDownloadable =
Downloadable(
"tensorflow-lite-$tfliteVersion.tar",
Expand All @@ -116,6 +147,26 @@ tasks {
)
downloadables.add(tfliteDownloadable)

val curlDownloadable =
Downloadable(
"curl-$curlVersion.tar",
"ml-api/java/android/nnstreamer/src/main/jni",
"https://raw.githubusercontent.com/nnstreamer/nnstreamer-android-resource/master/external",
enabledCurl,
".xz"
)
downloadables.add(curlDownloadable)

val sqliteDownloadable =
Downloadable(
"sqlite-$sqliteVersion.tar",
"ml-api/java/android/nnstreamer/src/main/jni",
"https://raw.githubusercontent.com/nnstreamer/nnstreamer-android-resource/master/external",
enabledSqlite,
".xz"
)
downloadables.add(sqliteDownloadable)


register("prepareDownloadable") {
if (!downloadablePath.isDirectory()) {
Expand All @@ -125,13 +176,11 @@ tasks {

for (downloadable in downloadables) {
val (tarFileName, targetDir, url, isEnabled, downloadableFormat, digestFileName) = downloadable
val targetPath = projectDir.toPath().resolve(targetDir)

if (!isEnabled || targetPath.isDirectory()) {
if (!isEnabled) {
continue
}

println("Could not find $targetPath")
println("...downloading from $url")
println("This step may take some time to complete...")

Expand Down Expand Up @@ -192,10 +241,6 @@ tasks {
val tree = tarTree(tarPath)
var intoPath = projectDir.toPath().resolve(targetDir)

if (intoPath.exists()) {
continue
}

tree.visit {
if (this.relativePath.startsWith(targetDir)) {
intoPath = projectDir.toPath()
Expand All @@ -211,6 +256,7 @@ tasks {
tarPath.deleteIfExists()
}
}
dependsOn("updateGitSubmodules")
dependsOn("prepareDownloadable")
}

Expand Down Expand Up @@ -244,5 +290,4 @@ tasks {

tasks.named("build") {
dependsOn("copyFromTar")
dependsOn("updateGitSubmodules")
}
1 change: 1 addition & 0 deletions externals/deviceMLOps.MLAgent
Submodule deviceMLOps.MLAgent added at 70252a
2 changes: 1 addition & 1 deletion externals/ml-api
Submodule ml-api updated 112 files
2 changes: 1 addition & 1 deletion externals/nnstreamer
Submodule nnstreamer updated 276 files
2 changes: 1 addition & 1 deletion externals/nnstreamer-edge
Submodule nnstreamer-edge updated 60 files
+20 −0 .github/actions/check-rebuild/action.yml
+71 −0 .github/actions/check-rebuild/check_if_rebuild_requires.sh
+38 −0 .github/actions/gitpush/action.yml
+5 −0 .github/workflows/_typos.toml
+84 −0 .github/workflows/daily-build-gbs.yml
+57 −0 .github/workflows/gbs_build.yml
+79 −0 .github/workflows/gen_coverage_badge.py
+110 −0 .github/workflows/pdebuild.yml
+17 −0 .github/workflows/spell-checker.yml
+2,303 −0 .github/workflows/static.check.scripts/Doxyfile.prj
+133 −0 .github/workflows/static.check.scripts/cppcheck.sh
+102 −0 .github/workflows/static.check.scripts/doxygen-build.sh
+170 −0 .github/workflows/static.check.scripts/doxygen-tag.sh
+51 −0 .github/workflows/static.check.scripts/executable.sh
+122 −0 .github/workflows/static.check.scripts/flawfinder.sh
+62 −0 .github/workflows/static.check.scripts/hardcoded-path.sh
+79 −0 .github/workflows/static.check.scripts/indent.sh
+93 −0 .github/workflows/static.check.scripts/misspelling.sh
+68 −0 .github/workflows/static.check.scripts/newline.sh
+49 −0 .github/workflows/static.check.scripts/nobody.sh
+100 −0 .github/workflows/static.check.scripts/prohibited-words.sh
+3 −0 .github/workflows/static.check.scripts/prohibited-words.txt
+81 −0 .github/workflows/static.check.scripts/pylint.sh
+78 −0 .github/workflows/static.check.scripts/rpm-spec.sh
+99 −0 .github/workflows/static.check.scripts/shellcheck.sh
+55 −0 .github/workflows/static.check.scripts/signed-off-by.sh
+90 −0 .github/workflows/static.check.scripts/sloccount.sh
+55 −0 .github/workflows/static.check.scripts/timestamp.sh
+158 −0 .github/workflows/static.check.yml
+0 −1 .github/workflows/tizen_integration_test.yml
+7 −8 CMakeLists.txt
+1 −2 README.md
+6 −0 debian/changelog
+3 −0 debian/nnstreamer-edge-dev.install
+52 −0 include/nnstreamer-edge-custom.h
+242 −0 include/nnstreamer-edge-data.h
+145 −0 include/nnstreamer-edge-event.h
+59 −202 include/nnstreamer-edge.h
+2 −2 jni/nnstreamer-edge.mk
+45 −13 packaging/nnstreamer-edge.spec
+10 −9 src/CMakeLists.txt
+0 −466 src/libnnstreamer-edge/nnstreamer-edge-aitt.c
+0 −104 src/libnnstreamer-edge/nnstreamer-edge-aitt.h
+370 −0 src/libnnstreamer-edge/nnstreamer-edge-custom-impl.c
+96 −0 src/libnnstreamer-edge/nnstreamer-edge-custom-impl.h
+4 −3 src/libnnstreamer-edge/nnstreamer-edge-data.c
+0 −68 src/libnnstreamer-edge/nnstreamer-edge-data.h
+62 −9 src/libnnstreamer-edge/nnstreamer-edge-event.c
+0 −49 src/libnnstreamer-edge/nnstreamer-edge-event.h
+290 −125 src/libnnstreamer-edge/nnstreamer-edge-internal.c
+1 −1 src/libnnstreamer-edge/nnstreamer-edge-metadata.h
+1 −1 src/libnnstreamer-edge/nnstreamer-edge-mqtt.h
+29 −23 src/libnnstreamer-edge/nnstreamer-edge-queue.c
+13 −11 src/libnnstreamer-edge/nnstreamer-edge-queue.h
+13 −6 tests/CMakeLists.txt
+226 −0 tests/nnstreamer-edge-custom-test.c
+0 −666 tests/unittest_nnstreamer-edge-aitt.cc
+421 −0 tests/unittest_nnstreamer-edge-custom.cc
+218 −30 tests/unittest_nnstreamer-edge.cc
+1 −1 tools/build_TizenRT/Makefile
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
org.gradle.jvmargs=-Xmx4096M -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx4096M -Xms4096M -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
dir.externals=externals
dir.downloadable=downloadable
dir.gstAndroid=gst-1.0-android-universal
dir.tfliteAndroid=tensorflow-lite
dir.nnstreamer=nnstreamer
dir.nnstreamerEdge=nnstreamer-edge
dir.mlopsAgent=deviceMLOps.MLAgent
dir.mlApi=ml-api
# To use llama2.c uncomment the line below
# dir.llama2c=llama2.c
Expand All @@ -13,4 +14,6 @@ dir.mlApi=ml-api
kotlin.code.style=official
android.useAndroidX=true
android.enableJetifier=true
feature.mlOffloading=true
feature.mlService=true
#NOTE: Do not change the lines above
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ uiTestJunit4Android = "1.7.5"
xyz-simple-git-plugin = "2.0.3"
cameraCore = "1.4.0"
firebaseCrashlyticsBuildtools = "3.0.2"
curl = "7.60.0"
sqlite = "3.48.0"

[libraries]
commons-compress = { group = "org.apache.commons", name = "commons-compress", version.ref = "commons-compress-lib" }
Expand Down
11 changes: 10 additions & 1 deletion nnstreamer-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ android {
val nnsEdgeDir = properties["dir.nnstreamerEdge"].toString()
val nnsEdgeRootPath = externalDirPath.resolve(nnsEdgeDir)

val mlopsAgentDir = properties["dir.mlopsAgent"].toString()
val mlopsAgentRootPath = externalDirPath.resolve(mlopsAgentDir)

val mlOffloadingFeature = properties["feature.mlOffloading"].toString()
val mlServiceFeature = properties["feature.mlService"].toString()

val mlApiDir = properties["dir.mlApi"].toString()
val mlApiRootPath = externalDirPath.resolve(mlApiDir)
val mlApiNNSJniPath = mlApiRootPath.resolve("java/android/nnstreamer/src/main/jni")
Expand All @@ -41,7 +47,10 @@ android {
"GSTREAMER_ROOT_ANDROID=$gstRootPath",
"NNSTREAMER_ROOT=$nnsRootPath",
"NNSTREAMER_EDGE_ROOT=$nnsEdgeRootPath",
"ML_API_ROOT=$mlApiRootPath"
"MLOPS_AGENT_ROOT=$mlopsAgentRootPath",
"ML_API_ROOT=$mlApiRootPath",
"ENABLE_ML_OFFLOADING=$mlOffloadingFeature",
"ENABLE_ML_SERVICE=$mlServiceFeature"
)
targets("nnstreamer-native")

Expand Down

0 comments on commit 943b903

Please sign in to comment.