├── .gitignore ├── Server ├── src │ └── main │ │ ├── resources │ │ ├── .gitignore │ │ ├── output │ │ │ └── .gitignore │ │ └── datasets │ │ │ └── README.txt │ │ ├── c++ │ │ ├── utils_JNITest.h │ │ └── utils_JNITest.cpp │ │ ├── java │ │ ├── utils │ │ │ ├── Helpers.java │ │ │ ├── JNITest.java │ │ │ ├── Parser.java │ │ │ ├── MatrixOps.java │ │ │ ├── MyDataset.java │ │ │ ├── dl4j │ │ │ │ ├── MySolver.java │ │ │ │ ├── MyDl4jDataset.java │ │ │ │ ├── Nd4jSerializer.java │ │ │ │ ├── MyDefaultGradient.java │ │ │ │ ├── MyMultiLayerNetwork.java │ │ │ │ ├── MultiLayerNetworkSerializer.java │ │ │ │ └── MyStochasticGradientDescent.java │ │ │ ├── RegModel.java │ │ │ └── ByteVec.java │ │ ├── apps │ │ │ ├── dl4j │ │ │ │ └── Dl4jExtraParams.java │ │ │ ├── lr │ │ │ │ ├── LRGradients.java │ │ │ │ ├── LRModelParams.java │ │ │ │ └── LROfflineSampler.java │ │ │ ├── mlp │ │ │ │ ├── MLPGradients.java │ │ │ │ ├── MLPModelParams.java │ │ │ │ └── MLPUpdater.java │ │ │ ├── simpleCNN │ │ │ │ └── SimpleCNNOfflineSampler.java │ │ │ ├── cppNN │ │ │ │ └── CppNNOfflineSampler.java │ │ │ ├── SPSampler.java │ │ │ └── SPUpdater.java │ │ └── coreComponents │ │ │ ├── Sampler.java │ │ │ ├── Profiler.java │ │ │ ├── DummyProfiler.java │ │ │ ├── SGDUpdater.java │ │ │ ├── OldProfiler.java │ │ │ ├── SyncProfiler.java │ │ │ ├── DummyProfilerLogger.java │ │ │ └── RoundRobinDispatcher.java │ │ ├── webapp │ │ ├── index.jsp │ │ └── WEB-INF │ │ │ └── web.xml │ │ └── python │ │ └── profilerBackend.py ├── .gitignore ├── .settings │ ├── org.eclipse.wst.jsdt.ui.superType.name │ ├── org.eclipse.wst.validation.prefs │ ├── org.eclipse.wst.jsdt.ui.superType.container │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.ws.service.policy.prefs │ ├── org.eclipse.ltk.core.refactoring.prefs │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.jdt.core.prefs │ ├── .jsdtscope │ └── org.eclipse.wst.common.component ├── WebContent │ ├── META-INF │ │ └── MANIFEST.MF │ └── WEB-INF │ │ └── web.xml ├── .project ├── Makefile └── .classpath ├── CONTRIBUTORS ├── Client ├── settings.gradle ├── app │ ├── src │ │ └── main │ │ │ ├── java │ │ │ ├── utils │ │ │ │ ├── Helpers.java │ │ │ │ ├── MyDataset.java │ │ │ │ ├── dl4j │ │ │ │ │ ├── MySolver.java │ │ │ │ │ ├── MyDl4jDataset.java │ │ │ │ │ ├── Nd4jSerializer.java │ │ │ │ │ ├── MyMultiLayerNetwork.java │ │ │ │ │ ├── MultiLayerNetworkSerializer.java │ │ │ │ │ └── MyStochasticGradientDescent.java │ │ │ │ └── NetworkParser.java │ │ │ ├── apps │ │ │ │ ├── dl4j │ │ │ │ │ └── Dl4jExtraParams.java │ │ │ │ ├── lr │ │ │ │ │ ├── LRGradients.java │ │ │ │ │ └── LRModelParams.java │ │ │ │ ├── mlp │ │ │ │ │ ├── MLPGradients.java │ │ │ │ │ └── MLPModelParams.java │ │ │ │ └── SPGradientGenerator.java │ │ │ └── coreComponents │ │ │ │ └── GradientGenerator.java │ │ │ ├── res │ │ │ ├── drawable │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── drawable-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── drawable-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── drawable-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── drawable-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ ├── values-v11 │ │ │ │ └── styles.xml │ │ │ ├── menu │ │ │ │ └── main.xml │ │ │ ├── values-v14 │ │ │ │ └── styles.xml │ │ │ └── layout │ │ │ │ └── activity_main.xml │ │ │ ├── AndroidManifest.xml │ │ │ └── cpp │ │ │ ├── native-lib.cpp │ │ │ ├── CMakeLists.txt │ │ │ └── caloree.h │ ├── libs │ │ └── connectionclass-1.0.1.jar │ └── proguard-rules.pro ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── .gitignore ├── build.gradle ├── gradle.properties ├── volley │ ├── TimeoutError.java │ ├── NoConnectionError.java │ ├── Network.java │ ├── ServerError.java │ ├── ParseError.java │ ├── toolbox │ │ ├── Authenticator.java │ │ ├── NoCache.java │ │ ├── HttpStack.java │ │ ├── JsonArrayRequest.java │ │ ├── ClearCacheRequest.java │ │ ├── Volley.java │ │ ├── StringRequest.java │ │ ├── JsonObjectRequest.java │ │ ├── AndroidAuthenticator.java │ │ ├── PoolingByteArrayOutputStream.java │ │ └── JsonRequest.java │ ├── NetworkError.java │ ├── ResponseDelivery.java │ ├── RetryPolicy.java │ ├── VolleyError.java │ ├── AuthFailureError.java │ ├── NetworkResponse.java │ ├── Response.java │ ├── Cache.java │ └── DefaultRetryPolicy.java └── gradlew.bat ├── Driver ├── .gitignore ├── src │ └── main │ │ ├── c++ │ │ ├── utils_JNITest.h │ │ └── utils_JNITest.cpp │ │ └── java │ │ ├── utils │ │ ├── Helpers.java │ │ ├── JNITest.java │ │ ├── Parser.java │ │ ├── MatrixOps.java │ │ ├── MyDataset.java │ │ ├── dl4j │ │ │ ├── MySolver.java │ │ │ ├── MyDl4jDataset.java │ │ │ ├── Nd4jSerializer.java │ │ │ ├── CustomCrossEntropy.java │ │ │ ├── MyDefaultGradient.java │ │ │ ├── MyMultiLayerNetwork.java │ │ │ ├── MultiLayerNetworkSerializer.java │ │ │ └── MyStochasticGradientDescent.java │ │ ├── Result.java │ │ ├── QuickSelect.java │ │ └── CsvWriter.java │ │ ├── apps │ │ ├── dl4j │ │ │ └── Dl4jExtraParams.java │ │ ├── mlp │ │ │ └── MLPModelParams.java │ │ └── lr │ │ │ └── LRModelParams.java │ │ └── coreComponents │ │ └── Model.java ├── .settings │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.project.facet.core.xml │ └── org.eclipse.jdt.core.prefs ├── .classpath ├── .project └── Makefile ├── badges ├── artifacts_available.jpg └── artifacts_evaluated_functional.jpg ├── client_cmd_deployment ├── start_emu_single_machine.sh ├── stop_emu_single_machine.sh ├── stop_emu_g5k.sh ├── start_emu_g5k.sh ├── oldSetup.txt ├── run_on_single_machine.sh ├── runner.py └── run_on_g5k.sh ├── commonLib ├── simpleCNN │ └── CNN │ │ ├── point_t.h │ │ ├── types.h │ │ ├── gradient_t.h │ │ ├── optimization_method.h │ │ ├── layer_t.h │ │ ├── dropout_layer_t.h │ │ └── relu_layer_t.h ├── cpp_utils │ ├── utils_JNITest.h │ ├── utils_JNITest.cpp │ └── Base64.h ├── dl4j_utils │ ├── MyDl4jDataset.java │ ├── MultiLayerNetworkSerializer.java │ └── Nd4jSerializer.java ├── utils │ ├── MyDataset.java │ ├── JNITest.java │ └── Parser.java └── cppNN │ └── mojo.h ├── LICENCE ├── local_deploy.sh └── emnistParser.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | /bin/ 3 | /target/ 4 | -------------------------------------------------------------------------------- /Server/src/main/resources/.gitignore: -------------------------------------------------------------------------------- 1 | *.csv 2 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Vlad Nitu (vlad.nitu@insa-lyon.fr) 2 | -------------------------------------------------------------------------------- /Client/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app'//, ':volley' -------------------------------------------------------------------------------- /Server/src/main/resources/output/.gitignore: -------------------------------------------------------------------------------- 1 | *.csv 2 | -------------------------------------------------------------------------------- /Driver/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | /target/ 3 | .idea 4 | *.iml -------------------------------------------------------------------------------- /Server/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | /target/ 3 | .idea 4 | *.iml 5 | -------------------------------------------------------------------------------- /Server/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /Driver/src/main/c++/utils_JNITest.h: -------------------------------------------------------------------------------- 1 | ../../../../commonLib/cpp_utils/utils_JNITest.h -------------------------------------------------------------------------------- /Driver/src/main/java/utils/Helpers.java: -------------------------------------------------------------------------------- 1 | ../../../../../commonLib/utils/Helpers.java -------------------------------------------------------------------------------- /Driver/src/main/java/utils/JNITest.java: -------------------------------------------------------------------------------- 1 | ../../../../../commonLib/utils/JNITest.java -------------------------------------------------------------------------------- /Driver/src/main/java/utils/Parser.java: -------------------------------------------------------------------------------- 1 | ../../../../../commonLib/utils/Parser.java -------------------------------------------------------------------------------- /Server/src/main/c++/utils_JNITest.h: -------------------------------------------------------------------------------- 1 | ../../../../commonLib/cpp_utils/utils_JNITest.h -------------------------------------------------------------------------------- /Server/src/main/java/utils/Helpers.java: -------------------------------------------------------------------------------- 1 | ../../../../../commonLib/utils/Helpers.java -------------------------------------------------------------------------------- /Server/src/main/java/utils/JNITest.java: -------------------------------------------------------------------------------- 1 | ../../../../../commonLib/utils/JNITest.java -------------------------------------------------------------------------------- /Server/src/main/java/utils/Parser.java: -------------------------------------------------------------------------------- 1 | ../../../../../commonLib/utils/Parser.java -------------------------------------------------------------------------------- /Driver/src/main/c++/utils_JNITest.cpp: -------------------------------------------------------------------------------- 1 | ../../../../commonLib/cpp_utils/utils_JNITest.cpp -------------------------------------------------------------------------------- /Driver/src/main/java/utils/MatrixOps.java: -------------------------------------------------------------------------------- 1 | ../../../../../commonLib/utils/MatrixOps.java -------------------------------------------------------------------------------- /Driver/src/main/java/utils/MyDataset.java: -------------------------------------------------------------------------------- 1 | ../../../../../commonLib/utils/MyDataset.java -------------------------------------------------------------------------------- /Server/src/main/c++/utils_JNITest.cpp: -------------------------------------------------------------------------------- 1 | ../../../../commonLib/cpp_utils/utils_JNITest.cpp -------------------------------------------------------------------------------- /Server/src/main/java/utils/MatrixOps.java: -------------------------------------------------------------------------------- 1 | ../../../../../commonLib/utils/MatrixOps.java -------------------------------------------------------------------------------- /Server/src/main/java/utils/MyDataset.java: -------------------------------------------------------------------------------- 1 | ../../../../../commonLib/utils/MyDataset.java -------------------------------------------------------------------------------- /Client/app/src/main/java/utils/Helpers.java: -------------------------------------------------------------------------------- 1 | ../../../../../../commonLib/utils/Helpers.java -------------------------------------------------------------------------------- /Client/app/src/main/java/utils/MyDataset.java: -------------------------------------------------------------------------------- 1 | ../../../../../../commonLib/utils/MyDataset.java -------------------------------------------------------------------------------- /Server/WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /Driver/src/main/java/utils/dl4j/MySolver.java: -------------------------------------------------------------------------------- 1 | ../../../../../../commonLib/dl4j_utils/MySolver.java -------------------------------------------------------------------------------- /Server/src/main/java/utils/dl4j/MySolver.java: -------------------------------------------------------------------------------- 1 | ../../../../../../commonLib/dl4j_utils/MySolver.java -------------------------------------------------------------------------------- /Client/app/src/main/java/utils/dl4j/MySolver.java: -------------------------------------------------------------------------------- 1 | ../../../../../../../commonLib/dl4j_utils/MySolver.java -------------------------------------------------------------------------------- /Driver/src/main/java/utils/dl4j/MyDl4jDataset.java: -------------------------------------------------------------------------------- 1 | ../../../../../../commonLib/dl4j_utils/MyDl4jDataset.java -------------------------------------------------------------------------------- /Server/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /Server/src/main/java/utils/dl4j/MyDl4jDataset.java: -------------------------------------------------------------------------------- 1 | ../../../../../../commonLib/dl4j_utils/MyDl4jDataset.java -------------------------------------------------------------------------------- /Server/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /Driver/src/main/java/utils/dl4j/Nd4jSerializer.java: -------------------------------------------------------------------------------- 1 | ../../../../../../commonLib/dl4j_utils/Nd4jSerializer.java -------------------------------------------------------------------------------- /Server/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /Server/src/main/java/utils/dl4j/Nd4jSerializer.java: -------------------------------------------------------------------------------- 1 | ../../../../../../commonLib/dl4j_utils/Nd4jSerializer.java -------------------------------------------------------------------------------- /badges/artifacts_available.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamaskinos/fleet/HEAD/badges/artifacts_available.jpg -------------------------------------------------------------------------------- /Client/app/src/main/java/utils/dl4j/MyDl4jDataset.java: -------------------------------------------------------------------------------- 1 | ../../../../../../../commonLib/dl4j_utils/MyDl4jDataset.java -------------------------------------------------------------------------------- /Client/app/src/main/java/utils/dl4j/Nd4jSerializer.java: -------------------------------------------------------------------------------- 1 | ../../../../../../../commonLib/dl4j_utils/Nd4jSerializer.java -------------------------------------------------------------------------------- /Driver/src/main/java/utils/dl4j/CustomCrossEntropy.java: -------------------------------------------------------------------------------- 1 | ../../../../../../commonLib/dl4j_utils/CustomCrossEntropy.java -------------------------------------------------------------------------------- /Driver/src/main/java/utils/dl4j/MyDefaultGradient.java: -------------------------------------------------------------------------------- 1 | ../../../../../../commonLib/dl4j_utils/MyDefaultGradient.java -------------------------------------------------------------------------------- /Server/src/main/java/utils/dl4j/MyDefaultGradient.java: -------------------------------------------------------------------------------- 1 | ../../../../../../commonLib/dl4j_utils/MyDefaultGradient.java -------------------------------------------------------------------------------- /Driver/src/main/java/utils/dl4j/MyMultiLayerNetwork.java: -------------------------------------------------------------------------------- 1 | ../../../../../../commonLib/dl4j_utils/MyMultiLayerNetwork.java -------------------------------------------------------------------------------- /Server/src/main/java/utils/dl4j/MyMultiLayerNetwork.java: -------------------------------------------------------------------------------- 1 | ../../../../../../commonLib/dl4j_utils/MyMultiLayerNetwork.java -------------------------------------------------------------------------------- /Client/app/src/main/java/utils/dl4j/MyMultiLayerNetwork.java: -------------------------------------------------------------------------------- 1 | ../../../../../../../commonLib/dl4j_utils/MyMultiLayerNetwork.java -------------------------------------------------------------------------------- /Client/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamaskinos/fleet/HEAD/Client/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Client/app/libs/connectionclass-1.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamaskinos/fleet/HEAD/Client/app/libs/connectionclass-1.0.1.jar -------------------------------------------------------------------------------- /Driver/src/main/java/utils/dl4j/MultiLayerNetworkSerializer.java: -------------------------------------------------------------------------------- 1 | ../../../../../../commonLib/dl4j_utils/MultiLayerNetworkSerializer.java -------------------------------------------------------------------------------- /Driver/src/main/java/utils/dl4j/MyStochasticGradientDescent.java: -------------------------------------------------------------------------------- 1 | ../../../../../../commonLib/dl4j_utils/MyStochasticGradientDescent.java -------------------------------------------------------------------------------- /Server/src/main/java/utils/dl4j/MultiLayerNetworkSerializer.java: -------------------------------------------------------------------------------- 1 | ../../../../../../commonLib/dl4j_utils/MultiLayerNetworkSerializer.java -------------------------------------------------------------------------------- /Server/src/main/java/utils/dl4j/MyStochasticGradientDescent.java: -------------------------------------------------------------------------------- 1 | ../../../../../../commonLib/dl4j_utils/MyStochasticGradientDescent.java -------------------------------------------------------------------------------- /badges/artifacts_evaluated_functional.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamaskinos/fleet/HEAD/badges/artifacts_evaluated_functional.jpg -------------------------------------------------------------------------------- /Client/app/src/main/java/utils/dl4j/MultiLayerNetworkSerializer.java: -------------------------------------------------------------------------------- 1 | ../../../../../../../commonLib/dl4j_utils/MultiLayerNetworkSerializer.java -------------------------------------------------------------------------------- /Client/app/src/main/java/utils/dl4j/MyStochasticGradientDescent.java: -------------------------------------------------------------------------------- 1 | ../../../../../../../commonLib/dl4j_utils/MyStochasticGradientDescent.java -------------------------------------------------------------------------------- /Driver/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /Server/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /Client/app/src/main/res/drawable/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamaskinos/fleet/HEAD/Client/app/src/main/res/drawable/ic_launcher.png -------------------------------------------------------------------------------- /Server/.settings/org.eclipse.wst.ws.service.policy.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.wst.ws.service.policy.projectEnabled=false 3 | -------------------------------------------------------------------------------- /Client/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamaskinos/fleet/HEAD/Client/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Client/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamaskinos/fleet/HEAD/Client/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Client/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamaskinos/fleet/HEAD/Client/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Client/app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamaskinos/fleet/HEAD/Client/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Client/app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamaskinos/fleet/HEAD/Client/app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Client/app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamaskinos/fleet/HEAD/Client/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Client/app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamaskinos/fleet/HEAD/Client/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Client/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamaskinos/fleet/HEAD/Client/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Client/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdamaskinos/fleet/HEAD/Client/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Server/.settings/org.eclipse.ltk.core.refactoring.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false 3 | -------------------------------------------------------------------------------- /Driver/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Client/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | *.apk 3 | .gradle 4 | /local.properties 5 | #/.idea/workspace.xml 6 | #/.idea/libraries 7 | .idea 8 | .DS_Store 9 | build/ 10 | /captures 11 | .externalNativeBuild 12 | -------------------------------------------------------------------------------- /Client/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /Server/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | Archetype Created Web Application 7 | 8 | -------------------------------------------------------------------------------- /Client/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /Client/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Client 5 | Hello world! 6 | Settings 7 | 8 | 9 | -------------------------------------------------------------------------------- /Client/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Feb 05 17:22:34 CET 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip 7 | -------------------------------------------------------------------------------- /Server/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Server/src/main/resources/datasets/README.txt: -------------------------------------------------------------------------------- 1 | In profiler_samples 2 | from the leftmost column to rightmost column: 3 | [memory size, #running processes, #core, network speed, batch size, latency] 4 | 5 | In profiler_energy_samples_mojo 6 | deviceAvailableRa deviceTotalRam deviceCpuUsage temperature batteryLevel volt meanSizeEnergy 7 | -------------------------------------------------------------------------------- /client_cmd_deployment/start_emu_single_machine.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$1" = "" ] || [ "$2" = "" ]; then 4 | echo -e "$0 <#emulators> " 5 | exit 1 6 | fi 7 | 8 | 9 | # start emulator in each node 10 | i=1 11 | for i in $(seq 1 $1); do 12 | echo "Starting emu$i" 13 | emulator -memory $2 -avd emu$i -no-window & 14 | done 15 | -------------------------------------------------------------------------------- /client_cmd_deployment/stop_emu_single_machine.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$1" = "" ]; then 4 | echo -e "$0 <#emulators>" 5 | exit 1 6 | fi 7 | 8 | 9 | 10 | for i in $(seq 1 $1); do 11 | p=$((5554+($i-1)*2)) 12 | echo "Stopping emulator-$p" 13 | adb -s emulator-$p emu kill 14 | done 15 | 16 | sleep 2 17 | pkill -9 -f adb 18 | pkill -9 -f monkeyrunner 19 | -------------------------------------------------------------------------------- /Client/app/src/main/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /commonLib/simpleCNN/CNN/point_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | #pragma once 11 | struct point_t { 12 | int x, y, z; 13 | }; 14 | using tdsize = point_t; 15 | -------------------------------------------------------------------------------- /Client/app/src/main/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /commonLib/simpleCNN/CNN/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | #pragma once 11 | 12 | enum class layer_type { 13 | conv, 14 | fc, 15 | relu, 16 | pool, 17 | dropout_layer 18 | }; 19 | -------------------------------------------------------------------------------- /Client/app/src/main/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Server/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /commonLib/cpp_utils/utils_JNITest.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class utils_JNITest */ 4 | 5 | #ifndef _Included_utils_JNITest 6 | #define _Included_utils_JNITest 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: utils_JNITest 12 | * Method: hello 13 | * Signature: ()V 14 | */ 15 | JNIEXPORT void JNICALL Java_utils_JNITest_hello 16 | (JNIEnv *, jobject); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /commonLib/simpleCNN/CNN/gradient_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | #pragma once 11 | 12 | 13 | struct gradient_t { 14 | float grad; 15 | float oldgrad; 16 | 17 | gradient_t() { 18 | grad = 0; 19 | oldgrad = 0; 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /client_cmd_deployment/stop_emu_g5k.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | uniq $OAR_NODEFILE > ~/tf_nodes$OAR_JOBID 5 | 6 | while read p; do 7 | echo "Stopping emulator on: "$p 8 | ssh $p "export ANDROID_SDK_HOME=$ANDROID_SDK_HOME; \ 9 | ~/opt/android-sdk-linux/platform-tools/adb -s emulator-5554 emu kill" < /dev/tty 10 | sleep 2 11 | ssh $p "pkill -9 -f adb" < /dev/tty 12 | ssh $p "pkill -9 -f monkeyrunner" < /dev/tty 13 | # fuser -k -n tcp 5554" < /dev/tty 14 | done < ~/tf_nodes$OAR_JOBID 15 | 16 | rm ~/tf_nodes$OAR_JOBID 17 | 18 | -------------------------------------------------------------------------------- /Driver/src/main/java/utils/Result.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package utils; 11 | 12 | public class Result { 13 | 14 | public double error; 15 | public double accuracy; 16 | 17 | public Result(double error, double accuracy){ 18 | this.error = error; 19 | this.accuracy = accuracy; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Server/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Driver/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Server/WebContent/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Server 4 | 5 | index.html 6 | index.htm 7 | index.jsp 8 | default.html 9 | default.htm 10 | default.jsp 11 | 12 | -------------------------------------------------------------------------------- /commonLib/cpp_utils/utils_JNITest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | #include 11 | #include 12 | #include "utils_JNITest.h" 13 | 14 | JNIEXPORT void JNICALL Java_utils_JNITest_hello(JNIEnv *, jobject) { 15 | printf("Checking JNI...\n"); 16 | #ifdef __cplusplus 17 | printf("__cplusplus is defined\n"); 18 | #else 19 | printf("__cplusplus is NOT defined\n"); 20 | #endif 21 | fflush(stdout); 22 | return; 23 | } 24 | -------------------------------------------------------------------------------- /Driver/src/main/java/apps/dl4j/Dl4jExtraParams.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package apps.dl4j; 11 | 12 | public class Dl4jExtraParams { 13 | 14 | public Dl4jExtraParams() { 15 | 16 | } 17 | public Dl4jExtraParams(long trainTime, int currEpoch, int hashCode) { 18 | this.trainTime = trainTime; 19 | this.currEpoch = currEpoch; 20 | this.hashCode = hashCode; 21 | } 22 | public long trainTime; 23 | public int currEpoch; 24 | public int hashCode; 25 | } 26 | -------------------------------------------------------------------------------- /Client/app/src/main/java/apps/dl4j/Dl4jExtraParams.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package apps.dl4j; 11 | 12 | public class Dl4jExtraParams { 13 | 14 | public Dl4jExtraParams() { 15 | 16 | } 17 | public Dl4jExtraParams(long trainTime, int currEpoch, int hashCode) { 18 | this.trainTime = trainTime; 19 | this.currEpoch = currEpoch; 20 | this.hashCode = hashCode; 21 | } 22 | public long trainTime; 23 | public int currEpoch; 24 | public int hashCode; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Driver/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.8 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 12 | org.eclipse.jdt.core.compiler.source=1.8 13 | -------------------------------------------------------------------------------- /Server/src/main/java/apps/dl4j/Dl4jExtraParams.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package apps.dl4j; 11 | 12 | public class Dl4jExtraParams { 13 | 14 | public Dl4jExtraParams() { 15 | 16 | } 17 | public Dl4jExtraParams(long trainTime, int currEpoch, int hashCode) { 18 | this.trainTime = trainTime; 19 | this.currEpoch = currEpoch; 20 | this.hashCode = hashCode; 21 | } 22 | public long trainTime; 23 | public int currEpoch; 24 | public int hashCode; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Server/src/main/java/coreComponents/Sampler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package coreComponents; 11 | 12 | 13 | import com.esotericsoftware.kryo.io.Output; 14 | 15 | public interface Sampler { 16 | 17 | /** 18 | * Get miniBatch with the specified size and serialize it to Kryo output 19 | * @param size 20 | * @param output 21 | */ 22 | void getSample(int size, Output output); 23 | 24 | /** 25 | * Reset sampler (triggered by the Driver) (e.g., reset example pool) 26 | */ 27 | void reset(); 28 | } 29 | -------------------------------------------------------------------------------- /Client/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | 4 | buildscript { 5 | repositories { 6 | jcenter() 7 | google() 8 | } 9 | dependencies { 10 | // classpath 'com.android.tools.build:gradle:3.3.2' 11 | classpath 'com.android.tools.build:gradle:3.2.1' 12 | //classpath 'com.android.tools.build:gradle:2.2.0' 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | jcenter() 21 | google() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } -------------------------------------------------------------------------------- /Client/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Client/gradle.properties: -------------------------------------------------------------------------------- 1 | ## Project-wide Gradle settings. 2 | # 3 | # For more details on how to configure your build environment visit 4 | # http://www.gradle.org/docs/current/userguide/build_environment.html 5 | # 6 | # Specifies the JVM arguments used for the daemon process. 7 | # The setting is particularly useful for tweaking memory settings. 8 | # Default value: -Xmx1024m -XX:MaxPermSize=256m 9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 10 | org.gradle.jvmargs=-Xmx1536M 11 | # When configured, Gradle will run in incubating parallel mode. 12 | # This option should only be used with decoupled projects. More details, visit 13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 14 | # org.gradle.parallel=true 15 | #Wed Feb 15 12:11:54 CET 2017 16 | 17 | -------------------------------------------------------------------------------- /Server/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /commonLib/simpleCNN/CNN/optimization_method.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | #pragma once 11 | 12 | #include "gradient_t.h" 13 | 14 | double LEARNING_RATE = 0.005; 15 | double MOMENTUM = 0.8; 16 | double WEIGHT_DECAY = 0.001; 17 | 18 | static float update_weight(float w, gradient_t &grad, float multp = 1) { 19 | float m = (grad.grad + grad.oldgrad * MOMENTUM); 20 | w -= LEARNING_RATE * m * multp + 21 | LEARNING_RATE * WEIGHT_DECAY * w; 22 | return w; 23 | } 24 | 25 | static void update_gradient(gradient_t &grad) { 26 | grad.oldgrad = (grad.grad + grad.oldgrad * MOMENTUM); 27 | } 28 | -------------------------------------------------------------------------------- /Driver/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Driver 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.common.project.facet.core.builder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.m2e.core.maven2Nature 26 | org.eclipse.jdt.core.javanature 27 | org.eclipse.wst.common.project.facet.core.nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /client_cmd_deployment/start_emu_g5k.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$1" = "" ] || [ "$2" = "" ]; then 4 | echo -e "usage with kadeploy reservation: \n \ 5 | $ oarsub -C [job_id] \n \ 6 | frontend:$ $0 <#nodes> " 7 | exit 1 8 | fi 9 | 10 | uniq $OAR_NODEFILE | head -$1 > ~/tf_nodes$OAR_JOBID 11 | 12 | # start emulator in each node 13 | i=1 14 | while read p; do 15 | echo "Starting emulator on: "$p 16 | ssh $p "export ANDROID_SDK_HOME=$ANDROID_SDK_HOME; \ 17 | ~/opt/android-sdk-linux/emulator/emulator -memory $2 -avd emu$i -no-window" < /dev/tty & 18 | # ~/opt/android-sdk-linux/tools/emulator -memory $2 -avd emu$i -no-window" < /dev/tty & 19 | # ~/opt/android-sdk-linux/tools/emulator64-x86 -memory 2048 -avd emu$i -noskin -no-window -partition-size 512 -no-snapshot-load" < /dev/tty & 20 | i=$((i+1)) 21 | done < ~/tf_nodes$OAR_JOBID 22 | 23 | rm ~/tf_nodes$OAR_JOBID 24 | 25 | -------------------------------------------------------------------------------- /Client/volley/TimeoutError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley; 18 | 19 | /** 20 | * Indicates that the connection or the socket timed out. 21 | */ 22 | @SuppressWarnings("serial") 23 | public class TimeoutError extends VolleyError { } 24 | -------------------------------------------------------------------------------- /Client/app/src/main/java/apps/lr/LRGradients.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package apps.lr; 11 | 12 | import org.jblas.DoubleMatrix; 13 | 14 | /** 15 | * Gradients computed on a mini-batch 16 | */ 17 | public class LRGradients { 18 | 19 | /** 20 | * layer weights 21 | */ 22 | public DoubleMatrix delta_weights, delta_biases; 23 | /** 24 | * mini-batch size 25 | */ 26 | public int batchSize; 27 | 28 | public LRGradients() { 29 | 30 | } 31 | public LRGradients(DoubleMatrix delta_weights, DoubleMatrix delta_biases, int batchSize) { 32 | this.delta_weights = delta_weights; 33 | this.delta_biases = delta_biases; 34 | this.batchSize = batchSize; 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /commonLib/simpleCNN/CNN/layer_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | #pragma once 11 | 12 | #include "types.h" 13 | #include "tensor_t.h" 14 | 15 | #pragma pack(push, 1) 16 | struct layer_t { 17 | layer_type type; 18 | tensor_t grads_in; 19 | tensor_t grads_acc; 20 | tensor_t in; 21 | tensor_t out; 22 | 23 | void accumulate_grads() { 24 | this->grads_acc.add(grads_in); 25 | } 26 | 27 | void grads_acc_to_in(float quotient) { 28 | for (int i = 0; i < this->grads_in.size.x * this->grads_in.size.y * this->grads_in.size.z; ++i) { 29 | this->grads_in.data[i] = grads_acc.data[i] / quotient; 30 | grads_acc.data[i] = 0; 31 | } 32 | } 33 | }; 34 | #pragma pack(pop) 35 | -------------------------------------------------------------------------------- /Server/src/main/java/apps/lr/LRGradients.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package apps.lr; 11 | import org.jblas.DoubleMatrix; 12 | 13 | /** 14 | * Gradients computed on a mini-batch 15 | */ 16 | public class LRGradients { 17 | 18 | /** 19 | * layer weights, biases 20 | */ 21 | public DoubleMatrix delta_weights; 22 | public DoubleMatrix delta_biases; 23 | /** 24 | * mini-batch size 25 | */ 26 | public int batchSize; 27 | 28 | public LRGradients() { 29 | 30 | } 31 | public LRGradients(DoubleMatrix delta_weights, DoubleMatrix delta_biases, int batchSize) { 32 | this.delta_weights = delta_weights; 33 | this.delta_biases = delta_biases; 34 | this.batchSize = batchSize; 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Server/src/main/java/coreComponents/Profiler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package coreComponents; 11 | 12 | import utils.DeviceInfo; 13 | 14 | public interface Profiler { 15 | 16 | /** 17 | * Sends stats for updating the model 18 | */ 19 | public void pushStats(String clientId, DeviceInfo stats); 20 | 21 | /** 22 | * Sends stats (i.e., features) and receives the output mini-batch size 23 | */ 24 | public int getMiniBatchSize(String clientId, DeviceInfo stats); 25 | 26 | /** 27 | * Useful for implementing a dispatcher profiler 28 | * Returns whether the client should send another request for the current profilers' epoch 29 | * i.e., this will return true as many times as the profilers size is 30 | * @param clientId 31 | * @return 32 | */ 33 | public boolean continueRequests(String clientId); 34 | } 35 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Georgios Damaskinos 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Client/volley/NoConnectionError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley; 18 | 19 | /** 20 | * Error indicating that no connection could be established when performing a Volley request. 21 | */ 22 | @SuppressWarnings("serial") 23 | public class NoConnectionError extends NetworkError { 24 | public NoConnectionError() { 25 | super(); 26 | } 27 | 28 | public NoConnectionError(Throwable reason) { 29 | super(reason); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Server/src/main/java/coreComponents/DummyProfiler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package coreComponents; 11 | 12 | import utils.DeviceInfo; 13 | 14 | /** 15 | * Dummy profiler 16 | * @author damaskin 17 | * 18 | */ 19 | public class DummyProfiler implements Profiler { 20 | 21 | private int fixedOutput; 22 | 23 | public DummyProfiler(int fixedOutput) { 24 | this.fixedOutput = fixedOutput; 25 | } 26 | 27 | public void pushStats(String clientId, DeviceInfo stats) { 28 | System.out.println("Push stats for clientId " + clientId + ": " + stats.toString(-1, 1, true)); 29 | } 30 | 31 | public int getMiniBatchSize(String clientId, DeviceInfo stats) { 32 | System.out.println("Get mini-batch size for clientId " + clientId + ": " + stats.toString(-1, 0, true)); 33 | return fixedOutput; 34 | } 35 | 36 | public boolean continueRequests(String clientId) { 37 | return false; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Server/src/main/java/apps/mlp/MLPGradients.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package apps.mlp; 11 | import org.jblas.DoubleMatrix; 12 | 13 | /** 14 | * Gradients computed on a mini-batch 15 | */ 16 | public class MLPGradients { 17 | 18 | /** 19 | * layer weights 20 | */ 21 | public DoubleMatrix delta_w1, delta_w2; 22 | /** 23 | * bias parameters 24 | */ 25 | public DoubleMatrix delta_b1, delta_b2; 26 | 27 | /** 28 | * mini-batch size 29 | */ 30 | public int batchSize; 31 | 32 | public MLPGradients() { 33 | 34 | } 35 | public MLPGradients(DoubleMatrix delta_w1, DoubleMatrix delta_w2, DoubleMatrix delta_b1, DoubleMatrix delta_b2, int batchSize) { 36 | this.delta_w1 = delta_w1; 37 | this.delta_w2 = delta_w2; 38 | this.delta_b1 = delta_b1; 39 | this.delta_b2 = delta_b2; 40 | this.batchSize = batchSize; 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Client/app/src/main/java/apps/mlp/MLPGradients.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package apps.mlp; 11 | 12 | import org.jblas.DoubleMatrix; 13 | 14 | /** 15 | * Gradients computed on a mini-batch 16 | */ 17 | public class MLPGradients { 18 | 19 | /** 20 | * layer weights 21 | */ 22 | public DoubleMatrix delta_w1, delta_w2; 23 | /** 24 | * bias parameters 25 | */ 26 | public DoubleMatrix delta_b1, delta_b2; 27 | 28 | /** 29 | * mini-batch size 30 | */ 31 | public int batchSize; 32 | 33 | public MLPGradients() { 34 | 35 | } 36 | public MLPGradients(DoubleMatrix delta_w1, DoubleMatrix delta_w2, DoubleMatrix delta_b1, DoubleMatrix delta_b2, int batchSize) { 37 | this.delta_w1 = delta_w1; 38 | this.delta_w2 = delta_w2; 39 | this.delta_b1 = delta_b1; 40 | this.delta_b2 = delta_b2; 41 | this.batchSize = batchSize; 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Client/volley/Network.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley; 18 | 19 | /** 20 | * An interface for performing requests. 21 | */ 22 | public interface Network { 23 | /** 24 | * Performs the specified request. 25 | * @param request Request to process 26 | * @return A {@link NetworkResponse} with data and caching metadata; will never be null 27 | * @throws VolleyError on errors 28 | */ 29 | public NetworkResponse performRequest(Request request) throws VolleyError; 30 | } 31 | -------------------------------------------------------------------------------- /client_cmd_deployment/oldSetup.txt: -------------------------------------------------------------------------------- 1 | cd ~ 2 | apt-get install qemu-kvm libvirt-bin virtinst virt-viewer ebtables dnsmasq 3 | 4 | modprobe kvm_intel 5 | 6 | systemctl enable libvirtd 7 | systemctl start libvirtd 8 | 9 | apt-get install openjdk-7-jre openjdk-7-jdk icedtea-7-plugin 10 | 11 | wget http://dl.google.com/android/android-sdk_r23.0.2-linux.tgz 12 | tar -xvzf android-sdk_r23.0.2-linux.tgz 13 | 14 | rm android-sdk_r23.0.2-linux.tgz 15 | 16 | /var/lib/dpkg/info/ca-certificates-java.postinst configure 17 | 18 | cd ~/android-sdk-linux/tools 19 | ./android update sdk --no-ui 20 | 21 | cd ../tools 22 | ./android update sdk -a --no-ui --filter tools 23 | cd ../tools 24 | # 32-bit version 25 | ./android update sdk -a --no-ui --filter sys-img-x86-android-23 26 | # 64-bit version 27 | ./android update sdk -a --no-ui --filter sys-img-x86_64-android-23 28 | 29 | 30 | ------ 31 | Tested on g5k 32 | ----- 33 | 34 | wget http://dl.google.com/android/android-sdk_r23.0.2-linux.tgz 35 | tar -xvzf android-sdk_r23.0.2-linux.tgz 36 | cd ~/android-sdk-linux/tools 37 | ./android update sdk --no-ui 38 | cd ../tools 39 | ./android update sdk -a --no-ui --filter sys-img-x86-android-23 40 | 41 | -------------------------------------------------------------------------------- /Client/volley/ServerError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley; 18 | 19 | import com.android.volley.NetworkResponse; 20 | import com.android.volley.VolleyError; 21 | 22 | /** 23 | * Indicates that the error responded with an error response. 24 | */ 25 | @SuppressWarnings("serial") 26 | public class ServerError extends VolleyError { 27 | public ServerError(NetworkResponse networkResponse) { 28 | super(networkResponse); 29 | } 30 | 31 | public ServerError() { 32 | super(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /commonLib/dl4j_utils/MyDl4jDataset.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package utils.dl4j; 11 | 12 | import org.nd4j.linalg.dataset.DataSet; 13 | import utils.MyDataset; 14 | import org.nd4j.linalg.cpu.nativecpu.NDArray; 15 | 16 | public class MyDl4jDataset extends MyDataset { 17 | 18 | public DataSet dataset; 19 | 20 | /** 21 | * Constructs dataset 22 | * @param xset inputs 23 | * @param tset labels 24 | */ 25 | public MyDl4jDataset(double[][] xset, double[][] tset) { 26 | NDArray Xset = new NDArray(xset); 27 | NDArray Tset = new NDArray(tset); 28 | dataset = new DataSet(Xset, Tset); 29 | numExamples = Xset.rows(); 30 | featureSize = Xset.columns(); 31 | numLabels = Tset.columns(); 32 | } 33 | 34 | public MyDl4jDataset(DataSet dataset) { 35 | this.dataset = dataset; 36 | numExamples = dataset.getFeatureMatrix().rows(); 37 | featureSize = dataset.getFeatureMatrix().columns(); 38 | numLabels = dataset.getLabels().columns(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Client/volley/ParseError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley; 18 | 19 | import com.android.volley.NetworkResponse; 20 | import com.android.volley.VolleyError; 21 | 22 | /** 23 | * Indicates that the server's response could not be parsed. 24 | */ 25 | @SuppressWarnings("serial") 26 | public class ParseError extends VolleyError { 27 | public ParseError() { } 28 | 29 | public ParseError(NetworkResponse networkResponse) { 30 | super(networkResponse); 31 | } 32 | 33 | public ParseError(Throwable cause) { 34 | super(cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Driver/Makefile: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | CFLAGS=-c -std=c++11 -fPIC -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -I$(JAVA_HOME)/include/darwin 3 | LDFLAGS=-fPIC -shared 4 | 5 | SOURCES_DIR=src/main/c++ 6 | OBJECTS_DIR=target/c++ 7 | 8 | LIB_SOURCES_DIR=../commonLib/cpp_utils 9 | LIB_OBJECTS_DIR=target/c++/lib 10 | 11 | UNAME_S := $(shell uname -s) 12 | ifeq ($(UNAME_S),Linux) 13 | EXECUTABLE=target/classes/libnative.so 14 | endif 15 | ifeq ($(UNAME_S),Darwin) # Mac specific 16 | # EXECUTABLE=target/classes/libnative.jnilib 17 | EXECUTABLE=target/classes/libnative.so 18 | endif 19 | 20 | SOURCES=$(shell find '$(SOURCES_DIR)' -type f -name '*.cpp') 21 | OBJECTS=$(SOURCES:$(SOURCES_DIR)/%.cpp=$(OBJECTS_DIR)/%.o) 22 | 23 | LIB_SOURCES=$(shell find $(LIB_SOURCES_DIR) -type f -name '*.cpp') 24 | LIB_OBJECTS=$(LIB_SOURCES:$(LIB_SOURCES_DIR)/%.cpp=$(LIB_OBJECTS_DIR)/%.o) 25 | 26 | all: $(EXECUTABLE) 27 | 28 | $(EXECUTABLE): $(LIB_OBJECTS) $(OBJECTS) 29 | $(CC) $(LDFLAGS) $(OBJECTS) $(LIB_OBJECTS) -o $@ 30 | 31 | #$(OBJECTS): $(SOURCES) 32 | $(OBJECTS_DIR)/%.o: $(SOURCES_DIR)/%.cpp 33 | mkdir -p $(OBJECTS_DIR) 34 | $(CC) $(CFLAGS) $< -o $@ 35 | 36 | $(LIB_OBJECTS_DIR)/%.o: $(LIB_SOURCES_DIR)/%.cpp 37 | mkdir -p $(LIB_OBJECTS_DIR) 38 | $(CC) $(CFLAGS) $< -o $@ 39 | 40 | clean: 41 | rm -rf $(OBJECTS_DIR) $(EXECUTABLE) 42 | -------------------------------------------------------------------------------- /commonLib/cpp_utils/Base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | #ifndef _BASE64_H_ 11 | #define _BASE64_H_ 12 | 13 | #include 14 | #include 15 | 16 | typedef unsigned char BYTE; 17 | 18 | /* Class implementing encoding and decoding operations for int and float vectors 19 | * Precision is bounded by maxInt and max(input_vector)*/ 20 | class Base64 21 | { 22 | public: 23 | static std::string encode(std::vector v); 24 | static std::string encode(std::vector v); 25 | static std::vector decodeInt(std::string encoded_string); 26 | static std::vector decodeFloat(std::string encoded_string); 27 | private: 28 | static int numDigits(int number); 29 | static std::vector decode(std::string encoded_string); 30 | static std::string encode(const std::vector& buf); 31 | static std::string encode(const BYTE* buf, unsigned int bufLen); 32 | static std::vector float2int(std::vector v); 33 | static std::vector int2float(std::vector v); 34 | }; 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /Client/volley/toolbox/Authenticator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley.toolbox; 18 | 19 | import com.android.volley.AuthFailureError; 20 | 21 | /** 22 | * An interface for interacting with auth tokens. 23 | */ 24 | public interface Authenticator { 25 | /** 26 | * Synchronously retrieves an auth token. 27 | * 28 | * @throws AuthFailureError If authentication did not succeed 29 | */ 30 | public String getAuthToken() throws AuthFailureError; 31 | 32 | /** 33 | * Invalidates the provided auth token. 34 | */ 35 | public void invalidateAuthToken(String authToken); 36 | } 37 | -------------------------------------------------------------------------------- /Client/volley/NetworkError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley; 18 | 19 | import com.android.volley.NetworkResponse; 20 | import com.android.volley.VolleyError; 21 | 22 | /** 23 | * Indicates that there was a network error when performing a Volley request. 24 | */ 25 | @SuppressWarnings("serial") 26 | public class NetworkError extends VolleyError { 27 | public NetworkError() { 28 | super(); 29 | } 30 | 31 | public NetworkError(Throwable cause) { 32 | super(cause); 33 | } 34 | 35 | public NetworkError(NetworkResponse networkResponse) { 36 | super(networkResponse); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /commonLib/dl4j_utils/MultiLayerNetworkSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package utils.dl4j; 11 | import java.io.IOException; 12 | 13 | import org.deeplearning4j.nn.api.Model; 14 | import org.deeplearning4j.util.ModelSerializer; 15 | 16 | import com.esotericsoftware.kryo.Kryo; 17 | import com.esotericsoftware.kryo.Serializer; 18 | import com.esotericsoftware.kryo.io.Input; 19 | import com.esotericsoftware.kryo.io.Output; 20 | 21 | public class MultiLayerNetworkSerializer extends Serializer{ 22 | 23 | @Override 24 | public void write(Kryo kryo, Output output, Model model) { 25 | try { 26 | ModelSerializer.writeModel(model, output, false); 27 | } catch (IOException e) { 28 | // TODO Auto-generated catch block 29 | e.printStackTrace(); 30 | } 31 | } 32 | 33 | @Override 34 | public Model read(Kryo kryo, Input input, Class type) { 35 | try { 36 | return ModelSerializer.restoreMultiLayerNetwork(input, false); 37 | } catch (IOException e) { 38 | e.printStackTrace(); 39 | return null; 40 | } 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /Server/src/main/java/apps/simpleCNN/SimpleCNNOfflineSampler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package apps.simpleCNN; 11 | 12 | import com.esotericsoftware.kryo.Kryo; 13 | import com.esotericsoftware.kryo.io.Output; 14 | import com.esotericsoftware.kryo.serializers.DefaultArraySerializers.ByteArraySerializer; 15 | 16 | import coreComponents.Sampler; 17 | 18 | public class SimpleCNNOfflineSampler implements Sampler { 19 | 20 | private Kryo kryo; 21 | 22 | private native void initSampler(String s); 23 | private native byte[] getMiniBatch(int batchSize); 24 | 25 | /** 26 | * Offline Sampler constructor 27 | * @param prefix (e.g. /path/to/datasets/spambase_) 28 | */ 29 | public SimpleCNNOfflineSampler(String prefix){ 30 | 31 | // TODO prefix pass 32 | kryo = new Kryo(); 33 | kryo.register(byte[].class, new ByteArraySerializer()); 34 | initSampler(prefix); 35 | } 36 | 37 | 38 | public void getSample(int size, Output output) { 39 | kryo.writeObject(output, getMiniBatch(size)); 40 | } 41 | 42 | 43 | @Override 44 | public void reset() { 45 | // TODO 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /Server/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Server 4 | 5 | 6 | 7 | 8 | 9 | org.python.pydev.PyDevBuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.m2e.core.maven2Builder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.jem.workbench.JavaEMFNature 36 | org.eclipse.wst.common.modulecore.ModuleCoreNature 37 | org.eclipse.jdt.core.javanature 38 | org.eclipse.m2e.core.maven2Nature 39 | org.eclipse.wst.common.project.facet.core.nature 40 | org.eclipse.wst.jsdt.core.jsNature 41 | org.python.pydev.pythonNature 42 | 43 | 44 | -------------------------------------------------------------------------------- /Client/app/src/main/java/apps/lr/LRModelParams.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package apps.lr; 11 | 12 | import org.jblas.DoubleMatrix; 13 | 14 | public class LRModelParams { 15 | 16 | public LRModelParams() { 17 | 18 | } 19 | 20 | public LRModelParams(double rate, int featuresize, int numlabels, DoubleMatrix weights, DoubleMatrix biases, int currEpoch, long trainTime) { 21 | this.rate = rate; 22 | this.featuresize = featuresize; 23 | this.numlabels = numlabels; 24 | this.weights = weights; 25 | this.biases = biases; 26 | this.currEpoch = currEpoch; 27 | this.trainTime = trainTime; 28 | } 29 | 30 | public double rate; 31 | 32 | public int featuresize; 33 | public int numlabels; 34 | /** 35 | * layer weights 36 | */ 37 | public DoubleMatrix weights, biases; 38 | /** 39 | * number of outer iterations of the model (how many times the model was 40 | * trained on the whole trainingSet). 41 | */ 42 | public int currEpoch; 43 | /** 44 | * total training time 45 | */ 46 | public long trainTime; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Client/volley/ResponseDelivery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley; 18 | 19 | public interface ResponseDelivery { 20 | /** 21 | * Parses a response from the network or cache and delivers it. 22 | */ 23 | public void postResponse(Request request, Response response); 24 | 25 | /** 26 | * Parses a response from the network or cache and delivers it. The provided 27 | * Runnable will be executed after delivery. 28 | */ 29 | public void postResponse(Request request, Response response, Runnable runnable); 30 | 31 | /** 32 | * Posts an error for the given request. 33 | */ 34 | public void postError(Request request, VolleyError error); 35 | } 36 | -------------------------------------------------------------------------------- /Client/volley/toolbox/NoCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley.toolbox; 18 | 19 | import com.android.volley.Cache; 20 | 21 | /** 22 | * A cache that doesn't. 23 | */ 24 | public class NoCache implements Cache { 25 | @Override 26 | public void clear() { 27 | } 28 | 29 | @Override 30 | public Entry get(String key) { 31 | return null; 32 | } 33 | 34 | @Override 35 | public void put(String key, Entry entry) { 36 | } 37 | 38 | @Override 39 | public void invalidate(String key, boolean fullExpire) { 40 | } 41 | 42 | @Override 43 | public void remove(String key) { 44 | } 45 | 46 | @Override 47 | public void initialize() { 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Server/src/main/java/apps/cppNN/CppNNOfflineSampler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package apps.cppNN; 11 | 12 | import com.esotericsoftware.kryo.Kryo; 13 | import com.esotericsoftware.kryo.io.Output; 14 | import com.esotericsoftware.kryo.serializers.DefaultArraySerializers.ByteArraySerializer; 15 | 16 | import coreComponents.Sampler; 17 | import utils.ByteVec; 18 | import utils.Kardam; 19 | 20 | public class CppNNOfflineSampler implements Sampler { 21 | 22 | private Kryo kryo; 23 | 24 | private native void initSampler(String s); 25 | private native byte[] getMiniBatch(int batchSize); 26 | 27 | 28 | /** 29 | * Offline Sampler constructor 30 | * @param prefix (e.g. /path/to/datasets/spambase_) 31 | */ 32 | public CppNNOfflineSampler(String prefix){ 33 | 34 | // TODO prefix pass 35 | kryo = new Kryo(); 36 | kryo.register(byte[].class, new ByteArraySerializer()); 37 | initSampler(prefix); 38 | } 39 | 40 | 41 | public void getSample(int size, Output output) { 42 | synchronized(kryo) { 43 | kryo.writeObject(output, getMiniBatch(size)); 44 | } 45 | } 46 | 47 | @Override 48 | public void reset() { 49 | // TODO 50 | 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /Client/app/src/main/java/coreComponents/GradientGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package coreComponents; 11 | 12 | import com.esotericsoftware.kryo.io.Input; 13 | import com.esotericsoftware.kryo.io.Output; 14 | 15 | import java.io.InputStream; 16 | 17 | /** 18 | * Created by Mercury on 2016/11/10. 19 | */ 20 | 21 | public interface GradientGenerator { 22 | 23 | /** 24 | * Application specific method for computing gradients 25 | * @param output output stream for writting the serialized gradients 26 | */ 27 | void computeGradient(Output output); 28 | 29 | /** 30 | * Application specific method for fetching parameters from the server 31 | * @param input stream which contains serialized model parameters and mini-batch (input, labels) 32 | **/ 33 | void fetch(Input input); 34 | 35 | /** 36 | * Get the size of the mini-batch that the most recent gradients were computed on 37 | * @return 38 | */ 39 | int getSize(); 40 | 41 | 42 | double getFetchMiniBatchTime(); 43 | 44 | double getFetchModelTime(); 45 | 46 | double getComputeGradientsTime(); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Driver/src/main/java/utils/QuickSelect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package utils; 11 | 12 | public class QuickSelect { 13 | 14 | public static double select(double[] nums, int k) { 15 | int start = 0, end = nums.length - 1, index = nums.length - k; 16 | while (start < end) { 17 | int pivot = partion(nums, start, end); 18 | if (pivot < index) start = pivot + 1; 19 | else if (pivot > index) end = pivot - 1; 20 | else return nums[pivot]; 21 | } 22 | return nums[start]; 23 | } 24 | 25 | private static int partion(double[] nums, int start, int end) { 26 | int pivot = start; 27 | double temp; 28 | while (start <= end) { 29 | while (start <= end && nums[start] <= nums[pivot]) start++; 30 | while (start <= end && nums[end] > nums[pivot]) end--; 31 | if (start > end) break; 32 | temp = nums[start]; 33 | nums[start] = nums[end]; 34 | nums[end] = temp; 35 | } 36 | temp = nums[end]; 37 | nums[end] = nums[pivot]; 38 | nums[pivot] = temp; 39 | return end; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Server/Makefile: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | CFLAGS=-c -std=c++11 -fPIC -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -I$(JAVA_HOME)/include/darwin 3 | LDFLAGS=-fPIC -shared -g 4 | 5 | SOURCES_DIR=src/main/c++ 6 | OBJECTS_DIR=target/c++ 7 | 8 | LIB_SOURCES_DIR=../commonLib/cpp_utils 9 | LIB_OBJECTS_DIR=target/c++/lib 10 | 11 | UNAME_S := $(shell uname -s) 12 | ifeq ($(UNAME_S),Linux) 13 | EXECUTABLE=target/classes/libnative.so 14 | #EXECUTABLE=$(TOMCAT_HOME)/lib/libnative.so # when non-maven tomcat is used 15 | endif 16 | ifeq ($(UNAME_S),Darwin) 17 | EXECUTABLE=target/classes/libnative.so 18 | #EXECUTABLE=target/classes/libnative.jnilib 19 | #EXECUTABLE=$(TOMCAT_HOME)/lib/libnative.jnilib # when non-maven tomcat is used 20 | endif 21 | 22 | SOURCES=$(shell find '$(SOURCES_DIR)' -type f -name '*.cpp') 23 | OBJECTS=$(SOURCES:$(SOURCES_DIR)/%.cpp=$(OBJECTS_DIR)/%.o) 24 | 25 | LIB_SOURCES=$(shell find $(LIB_SOURCES_DIR) -type f -name '*.cpp') 26 | LIB_OBJECTS=$(LIB_SOURCES:$(LIB_SOURCES_DIR)/%.cpp=$(LIB_OBJECTS_DIR)/%.o) 27 | 28 | all: $(EXECUTABLE) 29 | 30 | $(EXECUTABLE): $(LIB_OBJECTS) $(OBJECTS) 31 | $(CC) $(LDFLAGS) $(OBJECTS) $(LIB_OBJECTS) -o $@ 32 | 33 | #$(OBJECTS): $(SOURCES) 34 | $(OBJECTS_DIR)/%.o: $(SOURCES_DIR)/%.cpp 35 | mkdir -p $(OBJECTS_DIR) 36 | $(CC) $(CFLAGS) $< -o $@ 37 | 38 | $(LIB_OBJECTS_DIR)/%.o: $(LIB_SOURCES_DIR)/%.cpp 39 | mkdir -p $(LIB_OBJECTS_DIR) 40 | $(CC) $(CFLAGS) $< -o $@ 41 | 42 | clean: 43 | rm -rf $(OBJECTS_DIR) $(EXECUTABLE) 44 | -------------------------------------------------------------------------------- /Server/src/main/java/coreComponents/SGDUpdater.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package coreComponents; 11 | 12 | import java.io.InputStream; 13 | import com.esotericsoftware.kryo.io.Output; 14 | 15 | import apps.SPSampler; 16 | 17 | public interface SGDUpdater { 18 | 19 | /** 20 | * Initializes-Resets Updater (e.g., set initial model params, get learning rate) 21 | * by using the information that the Driver sends with the initialization request 22 | * @param input contains the serialized byte[] returned from XXXModel#getParams() of the Driver 23 | * @param sampler reference to the sampler => updater - sampler communication 24 | */ 25 | void initialize(InputStream input, Sampler sampler); 26 | 27 | /** 28 | * Fetches the current parameters of the model 29 | * @param isComputationRequest true => computation request , false => evaluation request 30 | * @return 31 | */ 32 | void getParameters(Output output, boolean isComputationRequest); 33 | 34 | /** 35 | * Updates the current model with the serialized gradients 36 | * @param input contains the serialized byte[] returned from GradientGenerator of the Client 37 | */ 38 | void update(InputStream input); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Server/src/main/java/apps/SPSampler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package apps; 11 | 12 | import com.esotericsoftware.kryo.io.Output; 13 | 14 | import apps.cppNN.CppNNOfflineSampler; 15 | import apps.dl4j.Dl4jOfflineSampler; 16 | import apps.dl4j.Dl4jStreamOfflineSampler; 17 | import apps.lr.LROfflineSampler; 18 | import apps.mlp.MLPOfflineSampler; 19 | import apps.simpleCNN.SimpleCNNOfflineSampler; 20 | 21 | import coreComponents.Sampler; 22 | 23 | 24 | public class SPSampler implements Sampler { 25 | 26 | // TODO: modify with the Application's Sampler 27 | //MLPOfflineSampler sampler; 28 | //Dl4jOfflineSampler sampler; 29 | //public LROfflineSampler sampler; 30 | //SimpleCNNOfflineSampler sampler; 31 | public CppNNOfflineSampler sampler; 32 | 33 | public SPSampler(String prefix) { 34 | //sampler = new LROfflineSampler(prefix); 35 | //sampler = new MLPOfflineSampler(prefix); 36 | //sampler = new Dl4jOfflineSampler(prefix); 37 | //sampler = new SimpleCNNOfflineSampler(prefix); 38 | sampler = new CppNNOfflineSampler(prefix); 39 | } 40 | 41 | @Override 42 | public void getSample(int size, Output output) { 43 | sampler.getSample(size, output); 44 | } 45 | 46 | @Override 47 | public void reset() { 48 | sampler.reset(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Server/src/main/java/apps/SPUpdater.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package apps; 11 | 12 | import java.io.InputStream; 13 | 14 | import com.esotericsoftware.kryo.io.Output; 15 | 16 | import apps.cppNN.CppNNUpdater; 17 | import apps.dl4j.Dl4jUpdater; 18 | import apps.lr.LRUpdater; 19 | import apps.mlp.MLPUpdater; 20 | import apps.simpleCNN.SimpleCNNUpdater; 21 | 22 | import coreComponents.SGDUpdater; 23 | import coreComponents.Sampler; 24 | 25 | /** 26 | * Updater implemented by the Service Provider 27 | * 28 | */ 29 | public class SPUpdater implements SGDUpdater { 30 | 31 | // TODO: modify with the Application's Updater 32 | //public MLPUpdater upd = new MLPUpdater(); 33 | //Dl4jUpdater upd = new Dl4jUpdater(); 34 | //public LRUpdater upd = new LRUpdater(); 35 | //SimpleCNNUpdater upd = new NativeCNNUpdater(); 36 | public CppNNUpdater upd = new CppNNUpdater(); 37 | 38 | public void initialize(InputStream input, Sampler sampler) { 39 | upd.initialize(input, sampler); 40 | } 41 | 42 | @Override 43 | public void getParameters(Output output, boolean isComputationRequest) { 44 | upd.getParameters(output, isComputationRequest); 45 | } 46 | 47 | @Override 48 | public void update(InputStream input) { 49 | upd.update(input); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /Client/volley/RetryPolicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley; 18 | 19 | /** 20 | * Retry policy for a request. 21 | */ 22 | public interface RetryPolicy { 23 | 24 | /** 25 | * Returns the current timeout (used for logging). 26 | */ 27 | public int getCurrentTimeout(); 28 | 29 | /** 30 | * Returns the current retry count (used for logging). 31 | */ 32 | public int getCurrentRetryCount(); 33 | 34 | /** 35 | * Prepares for the next retry by applying a backoff to the timeout. 36 | * @param error The error code of the last attempt. 37 | * @throws VolleyError In the event that the retry could not be performed (for example if we 38 | * ran out of attempts), the passed in error is thrown. 39 | */ 40 | public void retry(VolleyError error) throws VolleyError; 41 | } 42 | -------------------------------------------------------------------------------- /commonLib/utils/MyDataset.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package utils; 11 | 12 | import org.jblas.DoubleMatrix; 13 | 14 | /** 15 | * Dataset consists of an X input set and a target value set. 16 | * 17 | */ 18 | public class MyDataset { 19 | 20 | public MyDataset() { 21 | 22 | } 23 | 24 | /** 25 | * Constructs dataset 26 | * @param xset inputs 27 | * @param tset labels 28 | */ 29 | public MyDataset(DoubleMatrix xset, DoubleMatrix tset) { 30 | this.Xset = xset; 31 | this.Tset = tset; 32 | numExamples = xset.rows; 33 | featureSize = xset.columns; 34 | numLabels = tset.columns; 35 | } 36 | 37 | /** 38 | * Constructs dataset 39 | * @param xset inputs 40 | * @param tset labels 41 | */ 42 | public MyDataset(double[][] xset, double[][] tset) { 43 | this.Xset = new DoubleMatrix(xset); 44 | this.Tset = new DoubleMatrix(tset); 45 | numExamples = Xset.rows; 46 | featureSize = Xset.columns; 47 | numLabels = Tset.columns; 48 | } 49 | 50 | public int numExamples() { 51 | return numExamples; 52 | } 53 | 54 | public int featureSize() { 55 | return featureSize; 56 | } 57 | 58 | public int numLabels() { 59 | return numLabels; 60 | } 61 | 62 | protected int numExamples, featureSize, numLabels; 63 | public DoubleMatrix Xset, Tset; 64 | } 65 | -------------------------------------------------------------------------------- /Client/volley/VolleyError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley; 18 | 19 | /** 20 | * Exception style class encapsulating Volley errors 21 | */ 22 | @SuppressWarnings("serial") 23 | public class VolleyError extends Exception { 24 | public final NetworkResponse networkResponse; 25 | 26 | public VolleyError() { 27 | networkResponse = null; 28 | } 29 | 30 | public VolleyError(NetworkResponse response) { 31 | networkResponse = response; 32 | } 33 | 34 | public VolleyError(String exceptionMessage) { 35 | super(exceptionMessage); 36 | networkResponse = null; 37 | } 38 | 39 | public VolleyError(String exceptionMessage, Throwable reason) { 40 | super(exceptionMessage, reason); 41 | networkResponse = null; 42 | } 43 | 44 | public VolleyError(Throwable cause) { 45 | super(cause); 46 | networkResponse = null; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Client/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/aubian/Android/Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | #-ignorewarnings 19 | #-keep class android.support.v7.widget.SearchView { *; } 20 | #-dontwarn com.github.jaiimageio.impl.plugins.tiff.TIFFJPEGCompressor 21 | #-dontwarn com.google.common.util.concurrent.MoreExecutors 22 | #-dontwarn com.twelvemonkeys.imageio.plugins.tiff.* 23 | #-dontwarn javassist.bytecode.ClassFile 24 | #-dontwarn lombok.delombok.ant.Tasks$Delombok 25 | #-dontwarn lombok.launch.PatchFixesHider$Util 26 | #-dontwarn org.bytedeco.javacpp.indexer.UnsafeRaw 27 | #-keep org.deeplearning4j.* 28 | #-dontwarn org.joda.time.DateTimeZone 29 | #-keep org.nd4j.shade.jackson.dataformat.xml.XmlFactory 30 | #-dontwarn org.objenesis.instantiator.* 31 | #-dontwarn org.reflections.util.Utils 32 | #-dontwarn com.google.common.cache.Striped64 33 | #-keep class android.support.v4.app.** { *; } 34 | #-keep interface android.support.v4.app.** { *; } 35 | #-keep class android.support.v7.app.** { *; } 36 | #-keep interface android.support.v7.app.** { *; } -------------------------------------------------------------------------------- /Driver/src/main/java/apps/mlp/MLPModelParams.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package apps.mlp; 11 | 12 | import org.jblas.DoubleMatrix; 13 | 14 | public class MLPModelParams { 15 | 16 | public MLPModelParams() { 17 | 18 | } 19 | 20 | public MLPModelParams(double momentum, double numerator, double pow, double sigma, int featureSize, int hiddenNum, 21 | DoubleMatrix w1, DoubleMatrix w2, DoubleMatrix b1, DoubleMatrix b2, int currEpoch, long trainTime) { 22 | this.momentum = momentum; 23 | this.numerator = numerator; 24 | this.pow = pow; 25 | this.sigma = sigma; 26 | this.featureSize = featureSize; 27 | this.hiddenNum = hiddenNum; 28 | this.w1 = w1; 29 | this.w2 = w2; 30 | this.b1 = b1; 31 | this.b2 = b2; 32 | this.currEpoch = currEpoch; 33 | this.trainTime = trainTime; 34 | } 35 | 36 | public double momentum; 37 | public double numerator; 38 | public double pow; 39 | public double sigma; 40 | 41 | public int featureSize; 42 | public int hiddenNum; 43 | 44 | /** 45 | * layer weights 46 | */ 47 | public DoubleMatrix w1, w2; 48 | /** 49 | * bias parameters 50 | */ 51 | public DoubleMatrix b1, b2; 52 | /** 53 | * number of outer iterations of the model (how many times the model was 54 | * trained on the whole trainingSet). 55 | */ 56 | public int currEpoch; 57 | /** 58 | * total training time 59 | */ 60 | public long trainTime; 61 | 62 | } 63 | -------------------------------------------------------------------------------- /Server/src/main/java/apps/mlp/MLPModelParams.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package apps.mlp; 11 | 12 | import org.jblas.DoubleMatrix; 13 | 14 | public class MLPModelParams { 15 | 16 | public MLPModelParams() { 17 | 18 | } 19 | 20 | public MLPModelParams(double momentum, double numerator, double pow, double sigma, int featureSize, int hiddenNum, 21 | DoubleMatrix w1, DoubleMatrix w2, DoubleMatrix b1, DoubleMatrix b2, int currEpoch, long trainTime) { 22 | this.momentum = momentum; 23 | this.numerator = numerator; 24 | this.pow = pow; 25 | this.sigma = sigma; 26 | this.featureSize = featureSize; 27 | this.hiddenNum = hiddenNum; 28 | this.w1 = w1; 29 | this.w2 = w2; 30 | this.b1 = b1; 31 | this.b2 = b2; 32 | this.currEpoch = currEpoch; 33 | this.trainTime = trainTime; 34 | } 35 | 36 | public double momentum; 37 | public double numerator; 38 | public double pow; 39 | public double sigma; 40 | 41 | public int featureSize; 42 | public int hiddenNum; 43 | 44 | /** 45 | * layer weights 46 | */ 47 | public DoubleMatrix w1, w2; 48 | /** 49 | * bias parameters 50 | */ 51 | public DoubleMatrix b1, b2; 52 | /** 53 | * number of outer iterations of the model (how many times the model was 54 | * trained on the whole trainingSet). 55 | */ 56 | public int currEpoch; 57 | /** 58 | * total training time 59 | */ 60 | public long trainTime; 61 | 62 | } 63 | -------------------------------------------------------------------------------- /Client/volley/toolbox/HttpStack.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley.toolbox; 18 | 19 | import com.android.volley.AuthFailureError; 20 | import com.android.volley.Request; 21 | 22 | import org.apache.http.HttpResponse; 23 | 24 | import java.io.IOException; 25 | import java.util.Map; 26 | 27 | /** 28 | * An HTTP stack abstraction. 29 | */ 30 | public interface HttpStack { 31 | /** 32 | * Performs an HTTP request with the given parameters. 33 | * 34 | *

A GET request is sent if request.getPostBody() == null. A POST request is sent otherwise, 35 | * and the Content-Type header is set to request.getPostBodyContentType().

36 | * 37 | * @param request the request to perform 38 | * @param additionalHeaders additional headers to be sent together with 39 | * {@link Request#getHeaders()} 40 | * @return the HTTP response 41 | */ 42 | public HttpResponse performRequest(Request request, Map additionalHeaders) 43 | throws IOException, AuthFailureError; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Server/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Client/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 28 | 29 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /client_cmd_deployment/run_on_single_machine.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | handler() 4 | { 5 | echo "Killed" 6 | # kill all background processes 7 | echo "INFO: Terminating on $emuSerial..." 8 | echo $package 9 | adb -s emulator-$emuSerial uninstall com.androidsrc.client 10 | #~/opt/android-sdk-linux/platform-tools/adb shell am force-stop com.androidsrc.client" < /dev/tty 11 | exit 12 | } 13 | 14 | function pause(){ 15 | read -p "$*" 16 | } 17 | 18 | trap handler SIGINT 19 | 20 | if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ] || [ "$4" = "" ] || [ "$5" = "" ]; then 21 | echo -e "usage: \nfrontend:$ $0 " 22 | exit 1 23 | fi 24 | 25 | emuSerial=$1 26 | runner=$(readlink -f $2) 27 | apk=$(readlink -f $3) 28 | serverIP=$4 29 | serverPort=$5 30 | timeout=$6 31 | 32 | while true; do 33 | 34 | # install apk and add permissions 35 | echo "INFO: Reinstalling $apk on: $emuSerial" 36 | echo "INFO: If Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE] -> ctrl-c and rerun the script" 37 | adb -s emulator-$emuSerial install -r $apk 38 | adb -s emulator-$emuSerial shell pm grant com.androidsrc.client android.permission.DUMP 39 | 40 | wait 41 | 42 | echo "INFO: Running $runner on: $emuSerial" 43 | echo "INFO: Make sure all .setText() commands are commented out on the Client!" 44 | echo "INFO: To monitor output run: node$: adb logcat" 45 | monkeyrunner $runner $emuSerial $serverIP $serverPort 46 | 47 | wait 48 | 49 | echo "App is running; Kill this script with -INT to stop the app. Sleeping for $timeout seconds before reinstalling it ..." 50 | sleep $timeout 51 | 52 | done 53 | #pause 'Apps are running. Press any key to exit the script or ctrl-c to kill them and exit...' 54 | -------------------------------------------------------------------------------- /Client/app/src/main/java/apps/SPGradientGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package apps; 11 | 12 | 13 | import com.esotericsoftware.kryo.io.Input; 14 | import com.esotericsoftware.kryo.io.Output; 15 | 16 | import apps.cppNN.CppNNGradientGenerator; 17 | import apps.lr.LRGradientGenerator; 18 | import coreComponents.GradientGenerator; 19 | 20 | 21 | public class SPGradientGenerator implements GradientGenerator { 22 | 23 | // TODO: modify with the Application's SPGradientGenerator 24 | //SimpleSimpleCNNGradientGenerator gen = new SimpleSimpleCNNGradientGenerator(); 25 | CppNNGradientGenerator gen = new CppNNGradientGenerator(); 26 | //Dl4jGradientGenerator gen = new Dl4jGradientGenerator(); 27 | //MLPGradientGenerator gen = new MLPGradientGenerator(); 28 | //LRGradientGenerator gen = new LRGradientGenerator(); 29 | 30 | public void fetch(Input input) { 31 | gen.fetch(input); 32 | } 33 | 34 | public void computeGradient(Output output){ 35 | gen.computeGradient(output); 36 | } 37 | 38 | @Override 39 | public int getSize() { 40 | return gen.getSize(); 41 | } 42 | 43 | @Override 44 | public double getFetchMiniBatchTime() { 45 | return gen.getFetchMiniBatchTime(); 46 | } 47 | 48 | @Override 49 | public double getFetchModelTime() { 50 | return gen.getFetchModelTime(); 51 | } 52 | 53 | @Override 54 | public double getComputeGradientsTime() { 55 | return gen.getComputeGradientsTime(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /client_cmd_deployment/runner.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2020 Georgios Damaskinos 3 | All rights reserved. 4 | @author Georgios Damaskinos 5 | This source code is licensed under the MIT license found in the 6 | LICENSE file in the root directory of this source tree. 7 | """ 8 | 9 | 10 | from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice 11 | import socket 12 | import os 13 | import time 14 | import sys 15 | 16 | # definitions 17 | package = "com.androidsrc.client" 18 | activity = "coreComponents.MainActivity" 19 | 20 | runComponent = package + "/" + activity 21 | 22 | emuSerial = int(sys.argv[1]) 23 | serverIP = sys.argv[2] 24 | serverPort = int(sys.argv[3]) 25 | 26 | start_time = time.time() 27 | device = "emulator-" + str(emuSerial) 28 | 29 | device1 = MonkeyRunner.waitForConnection(deviceId=device) 30 | device1.startActivity(component=runComponent) 31 | 32 | device1.touch(0, 0, MonkeyDevice.DOWN_AND_UP) 33 | MonkeyRunner.sleep(5) # DON'T MODIFY 34 | 35 | # Text Box 1 (IP) 36 | # avoid MonkeyRunner issues when having sleep time after each button press 37 | # otherwise only a few first characters are input 38 | for c in serverIP: 39 | device1.type(c) 40 | device1.press("KEYCODE_TAB", MonkeyDevice.DOWN_AND_UP) 41 | 42 | # Text Box 2 (port) 43 | device1.type(str(serverPort)) 44 | device1.press("KEYCODE_TAB", MonkeyDevice.DOWN_AND_UP) 45 | 46 | # Text Box 3 (clientId) 47 | device1.type(socket.gethostname() + ":" + device) 48 | device1.press("KEYCODE_TAB", MonkeyDevice.DOWN_AND_UP) 49 | 50 | # Text Box 4 (sleep time) 51 | device1.type("0") 52 | device1.press("KEYCODE_TAB", MonkeyDevice.DOWN_AND_UP) 53 | 54 | # Button 1 (start) 55 | device1.press("KEYCODE_ENTER", MonkeyDevice.DOWN_AND_UP) 56 | 57 | print("Total runner.py time: %g" % (time.time() - start_time)) 58 | 59 | -------------------------------------------------------------------------------- /Client/app/src/main/java/apps/mlp/MLPModelParams.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package apps.mlp; 11 | 12 | import org.jblas.DoubleMatrix; 13 | 14 | public class MLPModelParams { 15 | 16 | 17 | public MLPModelParams() { 18 | 19 | } 20 | 21 | public MLPModelParams(double momentum, double numerator, double pow, double sigma, int featureSize, int hiddenNum, 22 | DoubleMatrix w1, DoubleMatrix w2, DoubleMatrix b1, DoubleMatrix b2, int currEpoch, long trainTime) { 23 | this.momentum = momentum; 24 | this.numerator = numerator; 25 | this.pow = pow; 26 | this.sigma = sigma; 27 | this.featureSize = featureSize; 28 | this.hiddenNum = hiddenNum; 29 | this.w1 = w1; 30 | this.w2 = w2; 31 | this.b1 = b1; 32 | this.b2 = b2; 33 | this.currEpoch = currEpoch; 34 | this.trainTime = trainTime; 35 | } 36 | 37 | public double momentum; 38 | public double numerator; 39 | public double pow; 40 | public double sigma; 41 | 42 | public int featureSize; 43 | public int hiddenNum; 44 | 45 | /** 46 | * layer weights 47 | */ 48 | public DoubleMatrix w1, w2; 49 | /** 50 | * bias parameters 51 | */ 52 | public DoubleMatrix b1, b2; 53 | /** 54 | * number of outer iterations of the model (how many times the model was 55 | * trained on the whole trainingSet). 56 | */ 57 | public int currEpoch; 58 | /** 59 | * total training time 60 | */ 61 | public long trainTime; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /commonLib/utils/JNITest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package utils; 11 | 12 | import java.io.File; 13 | import java.io.FileOutputStream; 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | import java.io.OutputStream; 17 | 18 | public class JNITest { 19 | 20 | public native void hello(); 21 | 22 | static { 23 | String name = new File("./target/classes/libnative.so").getAbsolutePath(); 24 | try { 25 | System.load(name); 26 | } catch (UnsatisfiedLinkError e2) { 27 | try { 28 | name = "native"; // EXECUTABLE=target/classes/libnative.so 29 | System.load(name); 30 | } catch (UnsatisfiedLinkError e) { 31 | try { 32 | String filename = System.mapLibraryName(name); 33 | InputStream in = JNITest.class.getClassLoader().getResourceAsStream(filename); 34 | int pos = filename.lastIndexOf('.'); 35 | File file = File.createTempFile(filename.substring(0, pos), filename.substring(pos)); 36 | file.deleteOnExit(); 37 | try { 38 | byte[] buf = new byte[4096]; 39 | OutputStream out = new FileOutputStream(file); 40 | try { 41 | while (in.available() > 0) { 42 | int len = in.read(buf); 43 | if (len >= 0) { 44 | out.write(buf, 0, len); 45 | } 46 | } 47 | } finally { 48 | out.close(); 49 | } 50 | } finally { 51 | in.close(); 52 | } 53 | System.load(file.getAbsolutePath()); 54 | } catch (IOException e1) { 55 | // TODO Auto-generated catch block 56 | e1.printStackTrace(); 57 | } 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Driver/src/main/java/coreComponents/Model.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package coreComponents; 11 | import java.io.InputStream; 12 | 13 | import utils.MyDataset; 14 | import utils.Result; 15 | /** 16 | * Interface for single neural network model 17 | * 18 | */ 19 | public interface Model { 20 | /** 21 | * Initializes the required parameters for the model. 22 | */ 23 | public void initialize(); 24 | 25 | /** 26 | * Evaluates the model on the given dataset 27 | */ 28 | public Result evaluate(MyDataset set); 29 | 30 | public void printParams(); 31 | 32 | public int getcurrEpoch(); 33 | 34 | /** 35 | * Gets total time (in milliseconds) that the model has been trained till the last update. 36 | * @return 37 | */ 38 | public long getTrainTime(); 39 | 40 | /** 41 | * Fetch the model from the serialized representation sent by the Server 42 | * @param result 43 | */ 44 | public void fetchParams(InputStream input); 45 | 46 | /** 47 | * Predict t-values for the test set. 48 | * 49 | * @return 2D (single column) matrix with predicted classes (0 or 1) for 50 | * each test x_input 51 | */ 52 | public int[][] predict(); 53 | 54 | /** 55 | * Saves the current state of the model for early stopping. 56 | */ 57 | public void saveState(); 58 | 59 | /** 60 | * Restore the saved state for future evaluation. 61 | */ 62 | public void restoreState(); 63 | 64 | /** 65 | * Stop any activities 66 | */ 67 | public void cleanUp(); 68 | 69 | /** 70 | * Get the parameters for the initialization of the Server 71 | * @return 72 | */ 73 | public byte[] getParams(); 74 | } 75 | -------------------------------------------------------------------------------- /commonLib/simpleCNN/CNN/dropout_layer_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | #pragma once 11 | 12 | #include "layer_t.h" 13 | 14 | #pragma pack(push, 1) 15 | 16 | struct dropout_layer_t { 17 | layer_type type = layer_type::dropout_layer; 18 | tensor_t grads_in; 19 | tensor_t grads_acc; 20 | tensor_t in; 21 | tensor_t out; 22 | tensor_t hitmap; 23 | float p_activation; 24 | 25 | dropout_layer_t(tdsize in_size, float p_activation) 26 | : 27 | in(in_size.x, in_size.y, in_size.z), 28 | out(in_size.x, in_size.y, in_size.z), 29 | hitmap(in_size.x, in_size.y, in_size.z), 30 | grads_in(in_size.x, in_size.y, in_size.z), 31 | grads_acc(in_size.x, in_size.y, in_size.z), 32 | p_activation(p_activation) { 33 | 34 | } 35 | 36 | void activate(tensor_t &in) { 37 | this->in = in; 38 | activate(); 39 | } 40 | 41 | void init_acc_grads() { 42 | 43 | } 44 | 45 | 46 | void activate() { 47 | for (int i = 0; i < in.size.x * in.size.y * in.size.z; i++) { 48 | bool active = (rand() % RAND_MAX) / float(RAND_MAX) <= p_activation; 49 | hitmap.data[i] = active; 50 | out.data[i] = active ? in.data[i] : 0.0f; 51 | } 52 | } 53 | 54 | 55 | void fix_weights() { 56 | 57 | } 58 | 59 | void calc_grads(tensor_t &grad_next_layer) { 60 | for (int i = 0; i < in.size.x * in.size.y * in.size.z; i++) 61 | grads_in.data[i] = hitmap.data[i] ? grad_next_layer.data[i] : 0.0f; 62 | } 63 | }; 64 | 65 | #pragma pack(pop) 66 | -------------------------------------------------------------------------------- /Server/src/main/java/coreComponents/OldProfiler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package coreComponents; 11 | 12 | import java.io.IOException; 13 | import java.net.ServerSocket; 14 | import java.net.Socket; 15 | import java.util.Map; 16 | 17 | 18 | /** 19 | * Deprecated thread-task profiler 20 | * Abstract class for implementing a profiler 21 | * A profiler is a thread-task that spawns other thread-tasks for handling client requests 22 | * @author damaskin 23 | * 24 | */ 25 | public abstract class OldProfiler implements Runnable { 26 | 27 | final ServerSocket profilerSocket; 28 | 29 | abstract void handleClientRequest(Socket socket); 30 | 31 | public OldProfiler(ServerSocket profilerSocket) { 32 | this.profilerSocket = profilerSocket; 33 | } 34 | 35 | @Override 36 | /** 37 | * Main thread-task running 38 | */ 39 | public void run() { 40 | try { 41 | while (true) { 42 | Socket socket = profilerSocket.accept(); 43 | 44 | // when a request arrives, run a handler thread to handle it 45 | HandleClient handleTask = new HandleClient(socket); 46 | 47 | //HandleClient handleTask = new HandleClient(socket, model); 48 | new Thread(handleTask).start(); 49 | } 50 | } catch (IOException e) { 51 | e.printStackTrace(); 52 | } finally { 53 | try { 54 | profilerSocket.close(); 55 | } catch (IOException e) { 56 | e.printStackTrace(); 57 | } 58 | } 59 | } 60 | 61 | class HandleClient implements Runnable { 62 | 63 | private Socket socket; 64 | 65 | public HandleClient(Socket socket){ 66 | this.socket = socket; 67 | } 68 | 69 | public void run() { 70 | handleClientRequest(socket); 71 | } 72 | } 73 | 74 | 75 | } 76 | -------------------------------------------------------------------------------- /Driver/src/main/java/apps/lr/LRModelParams.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package apps.lr; 11 | 12 | import org.jblas.DoubleMatrix; 13 | 14 | public class LRModelParams { 15 | 16 | public LRModelParams() { 17 | 18 | } 19 | 20 | public LRModelParams(double rate, int featuresize, int numlabels, DoubleMatrix weights, DoubleMatrix biases, int currEpoch, long trainTime) { 21 | this.rate = rate; 22 | this.featuresize = featuresize; 23 | this.numlabels = numlabels; 24 | this.weights = weights; 25 | this.biases = biases; 26 | this.currEpoch = currEpoch; 27 | this.trainTime = trainTime; 28 | } 29 | 30 | public LRModelParams(double rate, int featuresize, int numlabels, DoubleMatrix weights, DoubleMatrix biases) { 31 | this.rate = rate; 32 | this.featuresize = featuresize; 33 | this.numlabels = numlabels; 34 | this.weights = weights; 35 | this.biases = biases; 36 | } 37 | 38 | 39 | public LRModelParams clone() { 40 | LRModelParams cloneModel = new LRModelParams(this.rate,this.featuresize, this.numlabels, this.weights,this.biases,this.currEpoch,this.trainTime); 41 | return cloneModel; 42 | } 43 | 44 | public void update(DoubleMatrix weights, DoubleMatrix biases){ 45 | this.weights = weights; 46 | this.biases = biases; 47 | } 48 | 49 | public double rate; 50 | 51 | public int featuresize; 52 | public int numlabels; 53 | /** 54 | * layer weights, biases 55 | */ 56 | public DoubleMatrix weights; 57 | public DoubleMatrix biases; 58 | /** 59 | * number of outer iterations of the model (how many times the model was 60 | * trained on the whole trainingSet). 61 | */ 62 | public int currEpoch; 63 | /** 64 | * total training time 65 | */ 66 | public long trainTime; 67 | 68 | } 69 | -------------------------------------------------------------------------------- /Server/src/main/java/apps/lr/LRModelParams.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package apps.lr; 11 | 12 | import org.jblas.DoubleMatrix; 13 | 14 | public class LRModelParams { 15 | 16 | public LRModelParams() { 17 | 18 | } 19 | 20 | public LRModelParams(double rate, int featuresize, int numlabels, DoubleMatrix weights, DoubleMatrix biases, int currEpoch, long trainTime) { 21 | this.rate = rate; 22 | this.featuresize = featuresize; 23 | this.numlabels = numlabels; 24 | this.weights = weights; 25 | this.biases = biases; 26 | this.currEpoch = currEpoch; 27 | this.trainTime = trainTime; 28 | } 29 | 30 | public LRModelParams(double rate, int featuresize, int numlabels, DoubleMatrix weights, DoubleMatrix biases) { 31 | this.rate = rate; 32 | this.featuresize = featuresize; 33 | this.numlabels = numlabels; 34 | this.weights = weights; 35 | this.biases = biases; 36 | } 37 | 38 | 39 | public LRModelParams clone() { 40 | LRModelParams cloneModel = new LRModelParams(this.rate,this.featuresize, this.numlabels, this.weights,this.biases,this.currEpoch,this.trainTime); 41 | return cloneModel; 42 | } 43 | 44 | public void update(DoubleMatrix weights, DoubleMatrix biases){ 45 | this.weights = weights; 46 | this.biases = biases; 47 | } 48 | 49 | public double rate; 50 | 51 | public int featuresize; 52 | public int numlabels; 53 | /** 54 | * layer weights, biases 55 | */ 56 | public DoubleMatrix weights; 57 | public DoubleMatrix biases; 58 | /** 59 | * number of outer iterations of the model (how many times the model was 60 | * trained on the whole trainingSet). 61 | */ 62 | public int currEpoch; 63 | /** 64 | * total training time 65 | */ 66 | public long trainTime; 67 | 68 | } 69 | -------------------------------------------------------------------------------- /commonLib/simpleCNN/CNN/relu_layer_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | #pragma once 11 | 12 | #include "layer_t.h" 13 | 14 | #pragma pack(push, 1) 15 | 16 | struct relu_layer_t { 17 | layer_type type = layer_type::relu; 18 | tensor_t grads_in; 19 | tensor_t grads_acc; 20 | tensor_t in; 21 | tensor_t out; 22 | 23 | relu_layer_t(tdsize in_size) 24 | : 25 | in(in_size.x, in_size.y, in_size.z), 26 | out(in_size.x, in_size.y, in_size.z), 27 | grads_acc(in_size.x, in_size.y, in_size.z), 28 | grads_in(in_size.x, in_size.y, in_size.z) { 29 | } 30 | 31 | 32 | void activate(tensor_t &in) { 33 | this->in = in; 34 | activate(); 35 | } 36 | 37 | void init_acc_grads() { 38 | 39 | } 40 | 41 | void activate() { 42 | for (int i = 0; i < in.size.x; i++) 43 | for (int j = 0; j < in.size.y; j++) 44 | for (int z = 0; z < in.size.z; z++) { 45 | float v = in(i, j, z); 46 | if (v < 0) 47 | v = 0; 48 | out(i, j, z) = v; 49 | } 50 | 51 | } 52 | 53 | void fix_weights() { 54 | 55 | } 56 | 57 | void calc_grads(tensor_t &grad_next_layer) { 58 | for (int i = 0; i < in.size.x; i++) 59 | for (int j = 0; j < in.size.y; j++) 60 | for (int z = 0; z < in.size.z; z++) { 61 | grads_in(i, j, z) = (in(i, j, z) < 0) ? 62 | (0) : 63 | (1 * grad_next_layer(i, j, z)); 64 | } 65 | } 66 | }; 67 | 68 | #pragma pack(pop) 69 | -------------------------------------------------------------------------------- /Server/src/main/java/coreComponents/SyncProfiler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package coreComponents; 11 | 12 | import utils.DeviceInfo; 13 | 14 | /** 15 | * Dummy profiler 16 | * @author damaskin 17 | * 18 | */ 19 | public class SyncProfiler implements Profiler { 20 | 21 | final double latencySLO, energySLO; 22 | 23 | /** 24 | * Number of currently connected clients 25 | */ 26 | int numConnected; 27 | 28 | int numClients; 29 | 30 | /** 31 | * Starts accepting requests only after all the clients have been connected 32 | * @param latencySLO 33 | * @param energySLO 34 | * @param numClients number of clients to wait for before serving the first request 35 | */ 36 | public SyncProfiler(double latencySLO, double energySLO, int numClients) { 37 | this.latencySLO = latencySLO; 38 | this.energySLO = energySLO; 39 | this.numClients = numClients; 40 | } 41 | 42 | 43 | public void pushStats(String clientId, DeviceInfo stats) { 44 | System.out.println("Push stats for clientId " + clientId + ": " + stats.toString(-1, 1, true)); 45 | } 46 | 47 | public int getMiniBatchSize(String clientId, DeviceInfo stats) { 48 | System.out.println("Get mini-batch size for clientId " + clientId + ": " + stats.toString(-1, 0, true)); 49 | numConnected++; 50 | 51 | if (numConnected < numClients) 52 | System.out.println(clientId + " waiting as numConnected= " + numConnected); 53 | 54 | while (numConnected < numClients) { 55 | try { 56 | Thread.sleep(3000); 57 | } catch (InterruptedException e) { 58 | // TODO Auto-generated catch block 59 | e.printStackTrace(); 60 | } 61 | } 62 | return 104; 63 | } 64 | 65 | public boolean continueRequests(String clientId) { 66 | return false; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /Client/volley/AuthFailureError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley; 18 | 19 | import android.content.Intent; 20 | 21 | import com.android.volley.NetworkResponse; 22 | import com.android.volley.VolleyError; 23 | 24 | /** 25 | * Error indicating that there was an authentication failure when performing a Request. 26 | */ 27 | @SuppressWarnings("serial") 28 | public class AuthFailureError extends VolleyError { 29 | /** An intent that can be used to resolve this exception. (Brings up the password dialog.) */ 30 | private Intent mResolutionIntent; 31 | 32 | public AuthFailureError() { } 33 | 34 | public AuthFailureError(Intent intent) { 35 | mResolutionIntent = intent; 36 | } 37 | 38 | public AuthFailureError(NetworkResponse response) { 39 | super(response); 40 | } 41 | 42 | public AuthFailureError(String message) { 43 | super(message); 44 | } 45 | 46 | public AuthFailureError(String message, Exception reason) { 47 | super(message, reason); 48 | } 49 | 50 | public Intent getResolutionIntent() { 51 | return mResolutionIntent; 52 | } 53 | 54 | @Override 55 | public String getMessage() { 56 | if (mResolutionIntent != null) { 57 | return "User needs to (re)enter credentials."; 58 | } 59 | return super.getMessage(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Server/src/main/java/coreComponents/DummyProfilerLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package coreComponents; 11 | 12 | import java.io.File; 13 | import java.io.FileWriter; 14 | import java.io.IOException; 15 | import java.util.HashMap; 16 | 17 | import utils.DeviceInfo; 18 | 19 | /** 20 | * Pseudo-profiler that log profiler info (device stats) in a csv file and outputs a fixed mini-batch size 21 | * Can be used for collected the PHT for CALOREE 22 | * @author damaskin 23 | * 24 | */ 25 | public class DummyProfilerLogger implements Profiler { 26 | 27 | private FileWriter writer; 28 | 29 | private int fixedOutput; 30 | 31 | public DummyProfilerLogger(int fixedOutput) { 32 | 33 | this.fixedOutput = fixedOutput; 34 | 35 | System.out.println("[WriteCsv \"Profiler\"]"); 36 | System.out.println(DeviceInfo.header()); 37 | 38 | //output file 39 | // FIXME eclipse issues (no such file) -> works on the server 40 | String outputCsvPath = "src/main/resources/output/threads_test_output.csv"; 41 | File file = new File(outputCsvPath); 42 | 43 | try { 44 | writer = new FileWriter(file, false); 45 | writer.write(DeviceInfo.header() + "\n"); 46 | writer.flush(); 47 | } catch (IOException e) { 48 | e.printStackTrace(); 49 | } 50 | } 51 | 52 | 53 | public void pushStats(String clientId, DeviceInfo stats) { 54 | try { 55 | writer.write(stats.toString(-1, 1, false) + "\n"); 56 | writer.flush(); 57 | } catch (IOException e) { 58 | e.printStackTrace(); 59 | } 60 | } 61 | 62 | 63 | public int getMiniBatchSize(String clientId, DeviceInfo stats) { 64 | try { 65 | writer.write(stats.toString(-1, 0, false) + "\n"); 66 | writer.flush(); 67 | } catch (IOException e) { 68 | e.printStackTrace(); 69 | } 70 | 71 | return fixedOutput; 72 | } 73 | 74 | 75 | public boolean continueRequests(String clientId) { 76 | return false; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /Client/app/src/main/cpp/native-lib.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | extern "C" 27 | JNIEXPORT jbyteArray JNICALL 28 | Java_coreComponents_MainActivity_transferBytes(JNIEnv * env, jobject instance, jbyteArray input) { 29 | //copy bytes from java 30 | jbyte* buffer = env->GetByteArrayElements(input, NULL); 31 | 32 | jsize size = env->GetArrayLength(input); 33 | 34 | buffer[size] = '\0'; 35 | 36 | __android_log_print(ANDROID_LOG_DEBUG, "INFO", "Received: %s", buffer); 37 | env->ReleaseByteArrayElements(input, buffer, 0); 38 | 39 | 40 | // TEST HEAP SIZE ALLOCATION 41 | // https://github.com/hqt/heapsize-testing 42 | long testBytes = 1024*1024*100; 43 | char *blob = (char*) malloc(sizeof(char) * testBytes); 44 | for (long i=0; iNewByteArray(strlen(response)); 62 | env->SetByteArrayRegion(array, 0, strlen(response), (jbyte*)response); 63 | 64 | return array; 65 | } 66 | -------------------------------------------------------------------------------- /client_cmd_deployment/run_on_g5k.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | handler() 4 | { 5 | echo "Killed" 6 | # kill all background processes 7 | while read p; do 8 | echo "INFO: Terminating on $p..." 9 | echo $package 10 | ssh $p "export ANDROID_SDK_HOME=$ANDROID_SDK_HOME; \ 11 | ~/opt/android-sdk-linux/platform-tools/adb uninstall com.androidsrc.client" < /dev/tty 12 | #~/opt/android-sdk-linux/platform-tools/adb shell am force-stop com.androidsrc.client" < /dev/tty 13 | done < ~/tf_nodes$OAR_JOBID 14 | 15 | rm ~/tf_nodes$OAR_JOBID 16 | 17 | exit 18 | } 19 | 20 | function pause(){ 21 | read -p "$*" 22 | } 23 | 24 | trap handler SIGINT 25 | 26 | if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ] || [ "$4" = "" ] ; then 27 | echo -e "usage: \nfrontend:$ $0 <#nodes> " 28 | exit 1 29 | fi 30 | 31 | server_ip=$4 32 | exec=$(readlink -f $2) 33 | #package=$(awk '/definitions/{getline; print $3}' $exec) 34 | 35 | uniq $OAR_NODEFILE | head -$1 > ~/tf_nodes$OAR_JOBID 36 | 37 | # install apk and add permissions 38 | apk=$(readlink -f $3) 39 | while read p; do 40 | echo "INFO: Reinstalling apk $exec on: "$p 41 | echo "INFO: If Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE] -> ctrl-c and rerun the script" 42 | ssh $p "export ANDROID_SDK_HOME=$ANDROID_SDK_HOME; \ 43 | ~/opt/android-sdk-linux/platform-tools/adb -s emulator-5554 install -r $apk; \ 44 | ~/opt/android-sdk-linux/platform-tools/adb shell pm grant com.androidsrc.client android.permission.DUMP" < /dev/tty & 45 | done < ~/tf_nodes$OAR_JOBID 46 | 47 | 48 | wait 49 | 50 | id=1 51 | while read p; do 52 | echo "INFO: Running $exec on: "$p 53 | echo "INFO: Make sure all .setText() commands are commented out on the Client!" 54 | echo "INFO: To monitor output run: node$: adb logcat" 55 | ssh $p "export ANDROID_SDK_HOME=$ANDROID_SDK_HOME; export WORKER_ID=$id; \ 56 | export JAVA_HOME=$JAVA_HOME; export PATH=$JAVA_HOME/bin:$PATH; \ 57 | ~/opt/android-sdk-linux/tools/bin/monkeyrunner $exec 1 $server_ip" < /dev/tty & 58 | id=$((id+1)) 59 | done < ~/tf_nodes$OAR_JOBID 60 | 61 | wait 62 | 63 | pause 'Apps are running. Press any key to exit the script or ctrl-c to kill them and exit...' 64 | -------------------------------------------------------------------------------- /Client/volley/NetworkResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley; 18 | 19 | import org.apache.http.HttpStatus; 20 | 21 | import java.util.Collections; 22 | import java.util.Map; 23 | 24 | /** 25 | * Data and headers returned from {@link Network#performRequest(Request)}. 26 | */ 27 | public class NetworkResponse { 28 | /** 29 | * Creates a new network response. 30 | * @param statusCode the HTTP status code 31 | * @param data Response body 32 | * @param headers Headers returned with this response, or null for none 33 | * @param notModified True if the server returned a 304 and the data was already in cache 34 | */ 35 | public NetworkResponse(int statusCode, byte[] data, Map headers, 36 | boolean notModified) { 37 | this.statusCode = statusCode; 38 | this.data = data; 39 | this.headers = headers; 40 | this.notModified = notModified; 41 | } 42 | 43 | public NetworkResponse(byte[] data) { 44 | this(HttpStatus.SC_OK, data, Collections.emptyMap(), false); 45 | } 46 | 47 | public NetworkResponse(byte[] data, Map headers) { 48 | this(HttpStatus.SC_OK, data, headers, false); 49 | } 50 | 51 | /** The HTTP status code. */ 52 | public final int statusCode; 53 | 54 | /** Raw data from this response. */ 55 | public final byte[] data; 56 | 57 | /** Response headers. */ 58 | public final Map headers; 59 | 60 | /** True if the server returned a 304 (Not Modified). */ 61 | public final boolean notModified; 62 | } 63 | -------------------------------------------------------------------------------- /Client/app/src/main/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | set(compiler_c_flags "-Wno-error=format-security") 3 | ADD_DEFINITIONS( 4 | -std=c++11 5 | -mfpu=neon 6 | -O1 7 | -mtune=cortex-a57.cortex-a53 8 | # Other flags 9 | ) 10 | add_library( # Specifies the name of the library. 11 | native-lib 12 | 13 | # Sets the library as a shared library. 14 | SHARED 15 | 16 | # Provides a relative path to your source file(s). 17 | native-lib.cpp) 18 | 19 | add_library( # Specifies the name of the library. 20 | simpleCNN-lib 21 | 22 | # Sets the library as a shared library. 23 | SHARED 24 | 25 | # Provides a relative path to your source file(s). 26 | simpleCNN-lib.cpp) 27 | 28 | add_library( # Specifies the name of the library. 29 | cppNN-lib 30 | 31 | # Sets the library as a shared library. 32 | SHARED 33 | 34 | # Provides a relative path to your source file(s). 35 | cppNN-lib.cpp) 36 | 37 | add_library( # Specifies the name of the library. 38 | caloree 39 | 40 | # Sets the library as a shared library. 41 | SHARED 42 | 43 | # Provides a relative path to your source file(s). 44 | caloree.cpp) 45 | 46 | add_library( # Specifies the name of the library. 47 | Base64 48 | 49 | # Sets the library as a shared library. 50 | SHARED 51 | 52 | # Provides a relative path to your source file(s). 53 | ../../../../../commonLib/cpp_utils/Base64.cpp) 54 | 55 | 56 | # Include libraries needed for native-lib 57 | target_link_libraries(native-lib 58 | android 59 | log) 60 | 61 | # Include libraries needed for caloree 62 | target_link_libraries(caloree 63 | log) 64 | 65 | # Include libraries needed for cppNN-lib 66 | target_link_libraries(cppNN-lib 67 | caloree 68 | Base64 69 | android 70 | log) 71 | 72 | # Include libraries needed for simpleCNN-lib 73 | target_link_libraries(simpleCNN-lib 74 | Base64 75 | android 76 | log) 77 | -------------------------------------------------------------------------------- /Client/volley/toolbox/JsonArrayRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley.toolbox; 18 | 19 | import com.android.volley.NetworkResponse; 20 | import com.android.volley.ParseError; 21 | import com.android.volley.Response; 22 | import com.android.volley.Response.ErrorListener; 23 | import com.android.volley.Response.Listener; 24 | 25 | import org.json.JSONArray; 26 | import org.json.JSONException; 27 | 28 | import java.io.UnsupportedEncodingException; 29 | 30 | /** 31 | * A request for retrieving a {@link JSONArray} response body at a given URL. 32 | */ 33 | public class JsonArrayRequest extends JsonRequest { 34 | 35 | /** 36 | * Creates a new request. 37 | * @param url URL to fetch the JSON from 38 | * @param listener Listener to receive the JSON response 39 | * @param errorListener Error listener, or null to ignore errors. 40 | */ 41 | public JsonArrayRequest(String url, Listener listener, ErrorListener errorListener) { 42 | super(Method.GET, url, null, listener, errorListener); 43 | } 44 | 45 | @Override 46 | protected Response parseNetworkResponse(NetworkResponse response) { 47 | try { 48 | String jsonString = 49 | new String(response.data, HttpHeaderParser.parseCharset(response.headers)); 50 | return Response.success(new JSONArray(jsonString), 51 | HttpHeaderParser.parseCacheHeaders(response)); 52 | } catch (UnsupportedEncodingException e) { 53 | return Response.error(new ParseError(e)); 54 | } catch (JSONException je) { 55 | return Response.error(new ParseError(je)); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Client/app/src/main/cpp/caloree.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | /* 11 | * ===================================================================================== 12 | * 13 | * Filename: caloree.h 14 | * 15 | * Description: 16 | * 17 | * Version: 1.0 18 | * Created: 13/12/2019 16:56:21 19 | * Revision: none 20 | * Compiler: gcc 21 | * 22 | * Author: YOUR NAME (), 23 | * Organization: 24 | * 25 | * ===================================================================================== 26 | */ 27 | 28 | #include 29 | #include 30 | 31 | typedef std::tuple int_tuple_t; 32 | typedef std::map cmap_t; 33 | 34 | class config { 35 | public: 36 | int_tuple_t threadConf; 37 | int n_examples; 38 | 39 | config(int_tuple_t tConf, int n_ex){ 40 | threadConf = tConf; 41 | n_examples = n_ex; 42 | } 43 | int_tuple_t get_thread_conf() { 44 | return threadConf; 45 | } 46 | int get_nexamples() { 47 | return n_examples; 48 | } 49 | }; 50 | typedef std::tuple conf_tuple_t; 51 | 52 | long long getTimeNsec() { 53 | struct timespec now; 54 | clock_gettime(CLOCK_MONOTONIC, &now); 55 | return (int64_t) now.tv_sec*1000000000LL + now.tv_nsec; 56 | } 57 | 58 | void init(int n_examples, double perex_base_latency, 59 | double perex_target_latency, 60 | int r, double p); 61 | 62 | conf_tuple_t get_config(double next_speedup, int n_round_examples); 63 | 64 | double compute_next_xup(double last_latency); 65 | 66 | long long install_conf(std::atomic* bitset, int* current_example_wait, int littleThreads1, 67 | int bigThreads1, int nexamples1, int littleThreads2, int bigThreads2, int nexamples2, 68 | pthread_mutex_t* block_lock, pthread_cond_t* block_nonzero, bool* block, 69 | pthread_mutex_t* master_lock, pthread_cond_t* master_nonzero, bool* master_block); 70 | 71 | void unlock_all(pthread_mutex_t* block_lock, pthread_cond_t* block_nonzero, bool* block); 72 | 73 | double get_average_speedup(); 74 | 75 | int get_nrounds(); 76 | -------------------------------------------------------------------------------- /Client/volley/toolbox/ClearCacheRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley.toolbox; 18 | 19 | import com.android.volley.Cache; 20 | import com.android.volley.NetworkResponse; 21 | import com.android.volley.Request; 22 | import com.android.volley.Response; 23 | 24 | import android.os.Handler; 25 | import android.os.Looper; 26 | 27 | /** 28 | * A synthetic request used for clearing the cache. 29 | */ 30 | public class ClearCacheRequest extends Request { 31 | private final Cache mCache; 32 | private final Runnable mCallback; 33 | 34 | /** 35 | * Creates a synthetic request for clearing the cache. 36 | * @param cache Cache to clear 37 | * @param callback Callback to make on the main thread once the cache is clear, 38 | * or null for none 39 | */ 40 | public ClearCacheRequest(Cache cache, Runnable callback) { 41 | super(Method.GET, null, null); 42 | mCache = cache; 43 | mCallback = callback; 44 | } 45 | 46 | @Override 47 | public boolean isCanceled() { 48 | // This is a little bit of a hack, but hey, why not. 49 | mCache.clear(); 50 | if (mCallback != null) { 51 | Handler handler = new Handler(Looper.getMainLooper()); 52 | handler.postAtFrontOfQueue(mCallback); 53 | } 54 | return true; 55 | } 56 | 57 | @Override 58 | public Priority getPriority() { 59 | return Priority.IMMEDIATE; 60 | } 61 | 62 | @Override 63 | protected Response parseNetworkResponse(NetworkResponse response) { 64 | return null; 65 | } 66 | 67 | @Override 68 | protected void deliverResponse(Object response) { 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /local_deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Deploys FLeet locally 4 | 5 | handler() 6 | { 7 | echo "Killing FLeet modules ..." 8 | kill $serverPID 9 | kill $driverPID 10 | gradle --stop 11 | pkill -f "run_on_single_machine.sh $emuSerial" 12 | pkill -f "local_deploy.sh $emuSerial" 13 | exit 14 | } 15 | 16 | trap handler SIGINT 17 | 18 | 19 | if [ "$#" -ne 16 ]; then 20 | echo "usage: \nfrontend:$ $0 " 21 | exit 1 22 | fi 23 | 24 | cmd="$0 $@" 25 | emuSerial=$1 26 | serverPort=$2 27 | log_file=$(readlink -f $3) 28 | dataset_dir=$(readlink -f $4) 29 | batch_size_threshold=$5 30 | similarity_threshold=$6 31 | clientRequestsNum=$7 32 | evalRounds=$8 33 | lrate=$9 34 | M=${10} 35 | E=${11} 36 | sigma=${12} 37 | C=${13} 38 | staleness_size=${14} 39 | policy=${15} 40 | alpha=${16} 41 | 42 | SCRIPT=`realpath -s $0` 43 | SCRIPTPATH=`dirname $SCRIPT` 44 | 45 | # check if emulator is running 46 | { 47 | adb -s emulator-$emuSerial shell getprop init.svc.bootanim > /dev/null 48 | } || { 49 | echo "Must first start Android emulator. e.g., cd $SCRIPTPATH/client_cmd_deployment && ./start_emu_single_machine.sh $number_of_emus 1 1000" 50 | exit 51 | } 52 | 53 | echo "Reproduce with: $cmd" > $log_file 54 | cd $SCRIPTPATH 55 | echo "Git commit: $(git rev-parse HEAD)" >> $log_file 56 | echo "Git status: $(git status)" >> $log_file 57 | echo "Emulator serial: $emuSerial" >> $log_file 58 | 59 | # Compile Client 60 | echo "Compiling Client..." 61 | cd $SCRIPTPATH/Client 62 | gradle assembleDebug >> $log_file 2>&1 63 | 64 | # Compile and launch Server 65 | echo "Compiling and launching Server..." 66 | cd $SCRIPTPATH/Server 67 | mvn clean 68 | mvn -Dport=$serverPort tomcat7:run >> $log_file 2>&1 & 69 | serverPID=$! 70 | 71 | # Compile and launch Driver 72 | echo "Compiling and launching Driver..." 73 | cd $SCRIPTPATH/Driver 74 | mvn clean install >> $log_file 2>&1 75 | mvn exec:java -Dexec.mainClass="coreComponents.Driver" -Dexec.args="http://localhost:${serverPort}/Server/Server $dataset_dir $dataset_dir $batch_size_threshold $similarity_threshold $clientRequestsNum $evalRounds $lrate $M $E $sigma $C $staleness_size $policy $alpha" >> $log_file 2>&1 & 76 | driverPID=$! 77 | 78 | echo "Server PID: "$serverPID 79 | echo "Driver PID: "$driverPID 80 | 81 | # Launch Client 82 | echo "Launching Client..." 83 | cd $SCRIPTPATH/client_cmd_deployment 84 | ./run_on_single_machine.sh $emuSerial runner.py $SCRIPTPATH/Client/app/build/outputs/apk/debug/app-x86-debug.apk $(hostname -I | awk '{print $1}') $serverPort 120 85 | 86 | -------------------------------------------------------------------------------- /Client/volley/toolbox/Volley.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley.toolbox; 18 | 19 | import android.content.Context; 20 | import android.content.pm.PackageInfo; 21 | import android.content.pm.PackageManager.NameNotFoundException; 22 | import android.net.http.AndroidHttpClient; 23 | import android.os.Build; 24 | 25 | import com.android.volley.Network; 26 | import com.android.volley.RequestQueue; 27 | 28 | import java.io.File; 29 | 30 | public class Volley { 31 | 32 | /** Default on-disk cache directory. */ 33 | private static final String DEFAULT_CACHE_DIR = "volley"; 34 | 35 | /** 36 | * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it. 37 | * 38 | * @param context A {@link Context} to use for creating the cache dir. 39 | * @return A started {@link RequestQueue} instance. 40 | */ 41 | public static RequestQueue newRequestQueue(Context context) { 42 | File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); 43 | 44 | String userAgent = "volley/0"; 45 | try { 46 | String packageName = context.getPackageName(); 47 | 48 | PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); 49 | userAgent = packageName + "/" + info.versionCode; 50 | } catch (NameNotFoundException e) { 51 | } 52 | 53 | HttpStack stack; 54 | if (Build.VERSION.SDK_INT >= 9) { 55 | stack = new HurlStack(); 56 | } else { 57 | // Prior to Gingerbread, HttpUrlConnection was unreliable. 58 | // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html 59 | stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); 60 | } 61 | 62 | Network network = new BasicNetwork(stack); 63 | 64 | RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network); 65 | queue.start(); 66 | 67 | return queue; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Client/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /Driver/src/main/java/utils/CsvWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package utils; 11 | 12 | import java.io.FileWriter; 13 | import java.io.IOException; 14 | 15 | import org.supercsv.io.CsvListWriter; 16 | import org.supercsv.io.ICsvListWriter; 17 | import org.supercsv.prefs.CsvPreference; 18 | 19 | public class CsvWriter { 20 | 21 | ICsvListWriter csvWriter; 22 | 23 | public CsvWriter(String uri) throws IOException { 24 | csvWriter = new CsvListWriter(new FileWriter(uri), 25 | CsvPreference.STANDARD_PREFERENCE); 26 | } 27 | 28 | 29 | public void writeCsv(String[][] csvMatrix) { 30 | 31 | try { 32 | for (int i = 0; i < csvMatrix.length; i++) { 33 | csvWriter.write(csvMatrix[i]); 34 | } 35 | } catch (IOException e) { 36 | e.printStackTrace(); // TODO handle exception properly 37 | } finally { 38 | try { 39 | csvWriter.flush(); 40 | } catch (IOException e) { 41 | e.printStackTrace(); 42 | } 43 | } 44 | } 45 | 46 | public void writeCsv(double[][] csvMatrix) { 47 | // parse double 2D matrix to String 2D matrix 48 | String[][] output = new String[csvMatrix.length][csvMatrix[0].length]; 49 | for (int row=0; row 5 | This source code is licensed under the MIT license found in the 6 | LICENSE file in the root directory of this source tree. 7 | """ 8 | 9 | import numpy as np 10 | import scipy.io 11 | import argparse 12 | from sklearn import preprocessing 13 | from sklearn.model_selection import train_test_split 14 | 15 | def oneHot(vector): 16 | zeros = np.zeros(len(np.unique(vector)), dtype=int) 17 | out = [] 18 | for x in vector: 19 | temp = list(zeros) 20 | temp[int(x)] = 1 21 | out += [temp] 22 | 23 | return np.array(out) 24 | 25 | if __name__ == "__main__": 26 | parser = argparse.ArgumentParser(description='EMNIST dataset parser to csv files') 27 | 28 | parser.add_argument("input",help="/path/to/emnist-byclass.mat that can be downloaded from http://www.itl.nist.gov/iaui/vip/cs_links/EMNIST/matlab.zip") 29 | parser.add_argument("output_prefix",help="path prefix for the output .csv files") 30 | parser.add_argument("--validation_ratio", 31 | type=float, 32 | default=0.2, 33 | help="len(validation_set) = validation_ratio * len(training_set)") 34 | 35 | args = parser.parse_args() 36 | 37 | ## load and convert to numpy 38 | mat = scipy.io.loadmat(args.input) 39 | 40 | trainX = mat['dataset']['train'][0][0]['images'][0][0] 41 | trainY = mat['dataset']['train'][0][0]['labels'][0][0] 42 | 43 | testX = mat['dataset']['test'][0][0]['images'][0][0] 44 | testY = mat['dataset']['test'][0][0]['labels'][0][0] 45 | 46 | # convert labels into one-hot vectors 47 | trainY = oneHot(trainY) 48 | testY = oneHot(testY) 49 | 50 | ## preprocessing 51 | trainX = preprocessing.MinMaxScaler(feature_range=(0,1)).fit_transform(trainX) 52 | testX = preprocessing.MinMaxScaler(feature_range=(0,1)).fit_transform(testX) 53 | 54 | # validation split 55 | trainX, valX, trainY, valY = train_test_split(trainX, 56 | trainY, 57 | train_size=1-args.validation_ratio, 58 | random_state=42, 59 | shuffle=True) 60 | 61 | ## save to csv files 62 | np.savetxt(args.output_prefix + 'training_features.csv', trainX, fmt='%.10f', delimiter=",") 63 | np.savetxt(args.output_prefix + 'validation_features.csv', valX, fmt='%.10f', delimiter=",") 64 | np.savetxt(args.output_prefix + 'test_features.csv', testX, fmt='%.10f', delimiter=",") 65 | 66 | np.savetxt(args.output_prefix + 'training_labels.csv', trainY, fmt='%d', delimiter=",") 67 | np.savetxt(args.output_prefix + 'validation_labels.csv', valY, fmt='%d', delimiter=",") 68 | np.savetxt(args.output_prefix + 'test_labels.csv', testY, fmt='%d', delimiter=",") 69 | 70 | -------------------------------------------------------------------------------- /Client/volley/toolbox/StringRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley.toolbox; 18 | 19 | import com.android.volley.NetworkResponse; 20 | import com.android.volley.Request; 21 | import com.android.volley.Response; 22 | import com.android.volley.Response.ErrorListener; 23 | import com.android.volley.Response.Listener; 24 | 25 | import java.io.UnsupportedEncodingException; 26 | 27 | /** 28 | * A canned request for retrieving the response body at a given URL as a String. 29 | */ 30 | public class StringRequest extends Request { 31 | private final Listener mListener; 32 | 33 | /** 34 | * Creates a new request with the given method. 35 | * 36 | * @param method the request {@link Method} to use 37 | * @param url URL to fetch the string at 38 | * @param listener Listener to receive the String response 39 | * @param errorListener Error listener, or null to ignore errors 40 | */ 41 | public StringRequest(int method, String url, Listener listener, 42 | ErrorListener errorListener) { 43 | super(method, url, errorListener); 44 | mListener = listener; 45 | } 46 | 47 | /** 48 | * Creates a new GET request. 49 | * 50 | * @param url URL to fetch the string at 51 | * @param listener Listener to receive the String response 52 | * @param errorListener Error listener, or null to ignore errors 53 | */ 54 | public StringRequest(String url, Listener listener, ErrorListener errorListener) { 55 | this(Method.GET, url, listener, errorListener); 56 | } 57 | 58 | @Override 59 | protected void deliverResponse(String response) { 60 | mListener.onResponse(response); 61 | } 62 | 63 | @Override 64 | protected Response parseNetworkResponse(NetworkResponse response) { 65 | String parsed; 66 | try { 67 | parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); 68 | } catch (UnsupportedEncodingException e) { 69 | parsed = new String(response.data); 70 | } 71 | return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response)); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /commonLib/dl4j_utils/Nd4jSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package utils.dl4j; 11 | 12 | 13 | import com.esotericsoftware.kryo.Kryo; 14 | import com.esotericsoftware.kryo.Serializer; 15 | import com.esotericsoftware.kryo.io.Input; 16 | import com.esotericsoftware.kryo.io.Output; 17 | import org.nd4j.linalg.api.ndarray.INDArray; 18 | import org.nd4j.linalg.factory.Nd4j; 19 | 20 | import java.io.DataInputStream; 21 | import java.io.DataOutputStream; 22 | import java.io.IOException; 23 | 24 | /** 25 | * Created by agibsonccc on 5/22/16. 26 | */ 27 | public class Nd4jSerializer extends Serializer { 28 | /** 29 | * Writes the bytes for the object to the output. 30 | *

31 | * This method should not be called directly, instead this serializer can be passed to {@link Kryo} write methods that accept a 32 | * serialier. 33 | * 34 | * @param kryo 35 | * @param output 36 | * @param object May be null if {@link #getAcceptsNull()} is true. 37 | */ 38 | @Override 39 | public void write(Kryo kryo, Output output, INDArray object) { 40 | DataOutputStream dos = new DataOutputStream(output); 41 | try { 42 | Nd4j.write(object,dos); 43 | } catch (IOException e) { 44 | throw new RuntimeException(e); 45 | } 46 | //Note: output should NOT be closed manually here - may be needed elsewhere (and closing here will cause serialization to fail) 47 | } 48 | 49 | /** 50 | * Reads bytes and returns a new object of the specified concrete type. 51 | *

52 | * Before Kryo can be used to read child objects, {@link Kryo#reference(Object)} must be called with the parent object to 53 | * ensure it can be referenced by the child objects. Any serializer that uses {@link Kryo} to read a child object may need to 54 | * be reentrant. 55 | *

56 | * This method should not be called directly, instead this serializer can be passed to {@link Kryo} read methods that accept a 57 | * serialier. 58 | * 59 | * @param kryo 60 | * @param input 61 | * @param type 62 | * @return May be null if {@link #getAcceptsNull()} is true. 63 | */ 64 | @Override 65 | public INDArray read(Kryo kryo, Input input, Class type) { 66 | DataInputStream dis = new DataInputStream(input); 67 | try { 68 | return Nd4j.read(dis); 69 | } catch (IOException e) { 70 | throw new RuntimeException(e); 71 | } 72 | //Note: input should NOT be closed manually here - may be needed elsewhere (and closing here will cause serialization to fail) 73 | } 74 | 75 | 76 | 77 | } 78 | -------------------------------------------------------------------------------- /Client/volley/Response.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley; 18 | 19 | /** 20 | * Encapsulates a parsed response for delivery. 21 | * 22 | * @param Parsed type of this response 23 | */ 24 | public class Response { 25 | 26 | /** Callback interface for delivering parsed responses. */ 27 | public interface Listener { 28 | /** Called when a response is received. */ 29 | public void onResponse(T response); 30 | } 31 | 32 | /** Callback interface for delivering error responses. */ 33 | public interface ErrorListener { 34 | /** 35 | * Callback method that an error has been occurred with the 36 | * provided error code and optional user-readable message. 37 | */ 38 | public void onErrorResponse(VolleyError error); 39 | } 40 | 41 | /** Returns a successful response containing the parsed result. */ 42 | public static Response success(T result, Cache.Entry cacheEntry) { 43 | return new Response(result, cacheEntry); 44 | } 45 | 46 | /** 47 | * Returns a failed response containing the given error code and an optional 48 | * localized message displayed to the user. 49 | */ 50 | public static Response error(VolleyError error) { 51 | return new Response(error); 52 | } 53 | 54 | /** Parsed response, or null in the case of error. */ 55 | public final T result; 56 | 57 | /** Cache metadata for this response, or null in the case of error. */ 58 | public final Cache.Entry cacheEntry; 59 | 60 | /** Detailed error information if errorCode != OK. */ 61 | public final VolleyError error; 62 | 63 | /** True if this response was a soft-expired one and a second one MAY be coming. */ 64 | public boolean intermediate = false; 65 | 66 | /** 67 | * Returns whether this response is considered successful. 68 | */ 69 | public boolean isSuccess() { 70 | return error == null; 71 | } 72 | 73 | 74 | private Response(T result, Cache.Entry cacheEntry) { 75 | this.result = result; 76 | this.cacheEntry = cacheEntry; 77 | this.error = null; 78 | } 79 | 80 | private Response(VolleyError error) { 81 | this.result = null; 82 | this.cacheEntry = null; 83 | this.error = error; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Client/app/src/main/java/utils/NetworkParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package utils; 11 | 12 | import android.net.ConnectivityManager; 13 | import android.net.wifi.WifiInfo; 14 | import android.telephony.TelephonyManager; 15 | 16 | /** 17 | * Created by Mercury on 2016/11/18. 18 | */ 19 | 20 | public class NetworkParser { 21 | 22 | 23 | public static double netSpeed(int type, int subType, WifiInfo wifiInfo){ 24 | 25 | if(type==ConnectivityManager.TYPE_WIFI){ 26 | return wifiInfo.getLinkSpeed(); 27 | 28 | }else if(type==ConnectivityManager.TYPE_MOBILE){ 29 | switch(subType){ 30 | case TelephonyManager.NETWORK_TYPE_1xRTT: 31 | return 0.1; // ~ 50-100 kbps 32 | case TelephonyManager.NETWORK_TYPE_CDMA: 33 | return 0.06; // ~ 14-64 kbps 34 | case TelephonyManager.NETWORK_TYPE_EDGE: 35 | return 0.1; // ~ 50-100 kbps 36 | case TelephonyManager.NETWORK_TYPE_EVDO_0: 37 | return 1; // ~ 400-1000 kbps 38 | case TelephonyManager.NETWORK_TYPE_EVDO_A: 39 | return 1.4; // ~ 600-1400 kbps 40 | case TelephonyManager.NETWORK_TYPE_GPRS: 41 | return 0.1; // ~ 100 kbps 42 | case TelephonyManager.NETWORK_TYPE_HSDPA: 43 | return 14; // ~ 2-14 Mbps 44 | case TelephonyManager.NETWORK_TYPE_HSPA: 45 | return 1.7; // ~ 700-1700 kbps 46 | case TelephonyManager.NETWORK_TYPE_HSUPA: 47 | return 21; // ~ 1-23 Mbps 48 | case TelephonyManager.NETWORK_TYPE_UMTS: 49 | return 6; // ~ 400-7000 kbps 50 | 51 | /* 52 | * Above API level 7, make sure to set android:targetSdkVersion 53 | * to appropriate level to use these 54 | */ 55 | case TelephonyManager.NETWORK_TYPE_EHRPD: // API level 11 56 | return 2; // ~ 1-2 Mbps 57 | case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9 58 | return 5; // ~ 5 Mbps 59 | case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13 60 | return 18; // ~ 10-20 Mbps 61 | case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8 62 | return 0.025; // ~25 kbps 63 | case TelephonyManager.NETWORK_TYPE_LTE: // API level 11 64 | return 20; // ~ 10+ Mbps 65 | 66 | case TelephonyManager.NETWORK_TYPE_UNKNOWN: 67 | default: 68 | return 10; 69 | } 70 | }else{ 71 | return 10; 72 | } 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /Client/volley/Cache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley; 18 | 19 | import java.util.Collections; 20 | import java.util.Map; 21 | 22 | /** 23 | * An interface for a cache keyed by a String with a byte array as data. 24 | */ 25 | public interface Cache { 26 | /** 27 | * Retrieves an entry from the cache. 28 | * @param key Cache key 29 | * @return An {@link Entry} or null in the event of a cache miss 30 | */ 31 | public Entry get(String key); 32 | 33 | /** 34 | * Adds or replaces an entry to the cache. 35 | * @param key Cache key 36 | * @param entry Data to store and metadata for cache coherency, TTL, etc. 37 | */ 38 | public void put(String key, Entry entry); 39 | 40 | /** 41 | * Performs any potentially long-running actions needed to initialize the cache; 42 | * will be called from a worker thread. 43 | */ 44 | public void initialize(); 45 | 46 | /** 47 | * Invalidates an entry in the cache. 48 | * @param key Cache key 49 | * @param fullExpire True to fully expire the entry, false to soft expire 50 | */ 51 | public void invalidate(String key, boolean fullExpire); 52 | 53 | /** 54 | * Removes an entry from the cache. 55 | * @param key Cache key 56 | */ 57 | public void remove(String key); 58 | 59 | /** 60 | * Empties the cache. 61 | */ 62 | public void clear(); 63 | 64 | /** 65 | * Data and metadata for an entry returned by the cache. 66 | */ 67 | public static class Entry { 68 | /** The data returned from cache. */ 69 | public byte[] data; 70 | 71 | /** ETag for cache coherency. */ 72 | public String etag; 73 | 74 | /** Date of this response as reported by the server. */ 75 | public long serverDate; 76 | 77 | /** TTL for this record. */ 78 | public long ttl; 79 | 80 | /** Soft TTL for this record. */ 81 | public long softTtl; 82 | 83 | /** Immutable response headers as received from server; must be non-null. */ 84 | public Map responseHeaders = Collections.emptyMap(); 85 | 86 | /** True if the entry is expired. */ 87 | public boolean isExpired() { 88 | return this.ttl < System.currentTimeMillis(); 89 | } 90 | 91 | /** True if a refresh is needed from the original data source. */ 92 | public boolean refreshNeeded() { 93 | return this.softTtl < System.currentTimeMillis(); 94 | } 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /Server/src/main/java/utils/RegModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Georgios Damaskinos 3 | * All rights reserved. 4 | * @author Georgios Damaskinos 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | 10 | package utils; 11 | 12 | import java.util.Arrays; 13 | 14 | import org.apache.commons.math3.stat.StatUtils; 15 | import org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression; 16 | import org.apache.commons.math3.stat.regression.RegressionResults; 17 | import org.apache.commons.math3.stat.regression.SimpleRegression; 18 | import org.apache.commons.math3.stat.regression.UpdatingMultipleLinearRegression; 19 | import org.apache.commons.math3.util.FastMath; 20 | import org.jblas.DoubleMatrix; 21 | 22 | import smile.regression.LASSO; 23 | 24 | public class RegModel { 25 | 26 | private double[][] features; 27 | private double[] targets; 28 | 29 | //private double[] means; 30 | //sprivate double[] vars; 31 | 32 | private double[] betas; 33 | //private RegressionResults regressResults; 34 | 35 | //private OLSMultipleLinearRegression regression; 36 | //private UpdatingMultipleLinearRegression regression; 37 | private LASSO regression; 38 | private LASSO.Trainer trainer; 39 | private double lasso_lambda=0.01; 40 | 41 | public RegModel(double[][] features, double[] targets){ 42 | 43 | //this.means = new double[features[0].length]; 44 | //this.vars = new double[features[0].length]; 45 | 46 | 47 | this.features = features; 48 | //this.features = normalize(features); 49 | this.targets = targets; 50 | 51 | //this.regression = new OLSMultipleLinearRegression(); 52 | //this.regression.setNoIntercept(true); 53 | 54 | this.trainer = new LASSO.Trainer(lasso_lambda);//new LASSO(features, targets); 55 | 56 | // System.out.println("Features"); 57 | // for(int ii=0;ii { 35 | 36 | /** 37 | * Creates a new request. 38 | * @param method the HTTP method to use 39 | * @param url URL to fetch the JSON from 40 | * @param jsonRequest A {@link JSONObject} to post with the request. Null is allowed and 41 | * indicates no parameters will be posted along with request. 42 | * @param listener Listener to receive the JSON response 43 | * @param errorListener Error listener, or null to ignore errors. 44 | */ 45 | public JsonObjectRequest(int method, String url, JSONObject jsonRequest, 46 | Listener listener, ErrorListener errorListener) { 47 | super(method, url, (jsonRequest == null) ? null : jsonRequest.toString(), listener, 48 | errorListener); 49 | } 50 | 51 | /** 52 | * Constructor which defaults to GET if jsonRequest is 53 | * null, POST otherwise. 54 | * 55 | * @see #JsonObjectRequest(int, String, JSONObject, Listener, ErrorListener) 56 | */ 57 | public JsonObjectRequest(String url, JSONObject jsonRequest, Listener listener, 58 | ErrorListener errorListener) { 59 | this(jsonRequest == null ? Method.GET : Method.POST, url, jsonRequest, 60 | listener, errorListener); 61 | } 62 | 63 | @Override 64 | protected Response parseNetworkResponse(NetworkResponse response) { 65 | try { 66 | String jsonString = 67 | new String(response.data, HttpHeaderParser.parseCharset(response.headers)); 68 | return Response.success(new JSONObject(jsonString), 69 | HttpHeaderParser.parseCacheHeaders(response)); 70 | } catch (UnsupportedEncodingException e) { 71 | return Response.error(new ParseError(e)); 72 | } catch (JSONException je) { 73 | return Response.error(new ParseError(je)); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Client/volley/toolbox/AndroidAuthenticator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley.toolbox; 18 | 19 | import com.android.volley.AuthFailureError; 20 | 21 | import android.accounts.Account; 22 | import android.accounts.AccountManager; 23 | import android.accounts.AccountManagerFuture; 24 | import android.content.Context; 25 | import android.content.Intent; 26 | import android.os.Bundle; 27 | 28 | /** 29 | * An Authenticator that uses {@link AccountManager} to get auth 30 | * tokens of a specified type for a specified account. 31 | */ 32 | public class AndroidAuthenticator implements Authenticator { 33 | private final Context mContext; 34 | private final Account mAccount; 35 | private final String mAuthTokenType; 36 | 37 | /** 38 | * Creates a new authenticator. 39 | * @param context Context for accessing AccountManager 40 | * @param account Account to authenticate as 41 | * @param authTokenType Auth token type passed to AccountManager 42 | */ 43 | public AndroidAuthenticator(Context context, Account account, String authTokenType) { 44 | mContext = context; 45 | mAccount = account; 46 | mAuthTokenType = authTokenType; 47 | } 48 | 49 | /** 50 | * Returns the Account being used by this authenticator. 51 | */ 52 | public Account getAccount() { 53 | return mAccount; 54 | } 55 | 56 | @Override 57 | public String getAuthToken() throws AuthFailureError { 58 | final AccountManager accountManager = AccountManager.get(mContext); 59 | AccountManagerFuture future = accountManager.getAuthToken(mAccount, 60 | mAuthTokenType, false, null, null); 61 | Bundle result; 62 | try { 63 | result = future.getResult(); 64 | } catch (Exception e) { 65 | throw new AuthFailureError("Error while retrieving auth token", e); 66 | } 67 | String authToken = null; 68 | if (future.isDone() && !future.isCancelled()) { 69 | if (result.containsKey(AccountManager.KEY_INTENT)) { 70 | Intent intent = result.getParcelable(AccountManager.KEY_INTENT); 71 | throw new AuthFailureError(intent); 72 | } 73 | authToken = result.getString(AccountManager.KEY_AUTHTOKEN); 74 | } 75 | if (authToken == null) { 76 | throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType); 77 | } 78 | 79 | return authToken; 80 | } 81 | 82 | @Override 83 | public void invalidateAuthToken(String authToken) { 84 | AccountManager.get(mContext).invalidateAuthToken(mAccount.type, authToken); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Client/volley/DefaultRetryPolicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley; 18 | 19 | /** 20 | * Default retry policy for requests. 21 | */ 22 | public class DefaultRetryPolicy implements RetryPolicy { 23 | /** The current timeout in milliseconds. */ 24 | private int mCurrentTimeoutMs; 25 | 26 | /** The current retry count. */ 27 | private int mCurrentRetryCount; 28 | 29 | /** The maximum number of attempts. */ 30 | private final int mMaxNumRetries; 31 | 32 | /** The backoff multiplier for for the policy. */ 33 | private final float mBackoffMultiplier; 34 | 35 | /** The default socket timeout in milliseconds */ 36 | public static final int DEFAULT_TIMEOUT_MS = 2500; 37 | 38 | /** The default number of retries */ 39 | public static final int DEFAULT_MAX_RETRIES = 1; 40 | 41 | /** The default backoff multiplier */ 42 | public static final float DEFAULT_BACKOFF_MULT = 1f; 43 | 44 | /** 45 | * Constructs a new retry policy using the default timeouts. 46 | */ 47 | public DefaultRetryPolicy() { 48 | this(DEFAULT_TIMEOUT_MS, DEFAULT_MAX_RETRIES, DEFAULT_BACKOFF_MULT); 49 | } 50 | 51 | /** 52 | * Constructs a new retry policy. 53 | * @param initialTimeoutMs The initial timeout for the policy. 54 | * @param maxNumRetries The maximum number of retries. 55 | * @param backoffMultiplier Backoff multiplier for the policy. 56 | */ 57 | public DefaultRetryPolicy(int initialTimeoutMs, int maxNumRetries, float backoffMultiplier) { 58 | mCurrentTimeoutMs = initialTimeoutMs; 59 | mMaxNumRetries = maxNumRetries; 60 | mBackoffMultiplier = backoffMultiplier; 61 | } 62 | 63 | /** 64 | * Returns the current timeout. 65 | */ 66 | @Override 67 | public int getCurrentTimeout() { 68 | return mCurrentTimeoutMs; 69 | } 70 | 71 | /** 72 | * Returns the current retry count. 73 | */ 74 | @Override 75 | public int getCurrentRetryCount() { 76 | return mCurrentRetryCount; 77 | } 78 | 79 | /** 80 | * Prepares for the next retry by applying a backoff to the timeout. 81 | * @param error The error code of the last attempt. 82 | */ 83 | @Override 84 | public void retry(VolleyError error) throws VolleyError { 85 | mCurrentRetryCount++; 86 | mCurrentTimeoutMs += (mCurrentTimeoutMs * mBackoffMultiplier); 87 | if (!hasAttemptRemaining()) { 88 | throw error; 89 | } 90 | } 91 | 92 | /** 93 | * Returns true if this policy has attempts remaining, false otherwise. 94 | */ 95 | protected boolean hasAttemptRemaining() { 96 | return mCurrentRetryCount <= mMaxNumRetries; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Client/volley/toolbox/PoolingByteArrayOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.volley.toolbox; 18 | 19 | import java.io.ByteArrayOutputStream; 20 | import java.io.IOException; 21 | 22 | /** 23 | * A variation of {@link java.io.ByteArrayOutputStream} that uses a pool of byte[] buffers instead 24 | * of always allocating them fresh, saving on heap churn. 25 | */ 26 | public class PoolingByteArrayOutputStream extends ByteArrayOutputStream { 27 | /** 28 | * If the {@link #PoolingByteArrayOutputStream(ByteArrayPool)} constructor is called, this is 29 | * the default size to which the underlying byte array is initialized. 30 | */ 31 | private static final int DEFAULT_SIZE = 256; 32 | 33 | private final ByteArrayPool mPool; 34 | 35 | /** 36 | * Constructs a new PoolingByteArrayOutputStream with a default size. If more bytes are written 37 | * to this instance, the underlying byte array will expand. 38 | */ 39 | public PoolingByteArrayOutputStream(ByteArrayPool pool) { 40 | this(pool, DEFAULT_SIZE); 41 | } 42 | 43 | /** 44 | * Constructs a new {@code ByteArrayOutputStream} with a default size of {@code size} bytes. If 45 | * more than {@code size} bytes are written to this instance, the underlying byte array will 46 | * expand. 47 | * 48 | * @param size initial size for the underlying byte array. The value will be pinned to a default 49 | * minimum size. 50 | */ 51 | public PoolingByteArrayOutputStream(ByteArrayPool pool, int size) { 52 | mPool = pool; 53 | buf = mPool.getBuf(Math.max(size, DEFAULT_SIZE)); 54 | } 55 | 56 | @Override 57 | public void close() throws IOException { 58 | mPool.returnBuf(buf); 59 | buf = null; 60 | super.close(); 61 | } 62 | 63 | @Override 64 | public void finalize() { 65 | mPool.returnBuf(buf); 66 | } 67 | 68 | /** 69 | * Ensures there is enough space in the buffer for the given number of additional bytes. 70 | */ 71 | private void expand(int i) { 72 | /* Can the buffer handle @i more bytes, if not expand it */ 73 | if (count + i <= buf.length) { 74 | return; 75 | } 76 | byte[] newbuf = mPool.getBuf((count + i) * 2); 77 | System.arraycopy(buf, 0, newbuf, 0, count); 78 | mPool.returnBuf(buf); 79 | buf = newbuf; 80 | } 81 | 82 | @Override 83 | public synchronized void write(byte[] buffer, int offset, int len) { 84 | expand(len); 85 | super.write(buffer, offset, len); 86 | } 87 | 88 | @Override 89 | public synchronized void write(int oneByte) { 90 | expand(1); 91 | super.write(oneByte); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Client/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 11 | 12 | 18 | 19 | 25 | 26 | 27 | 28 | 32 | 33 | 38 | 39 | 44 | 45 | 49 | 50 |