├── AccelerationClient ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.jdt.ui.prefs ├── AndroidManifest.xml ├── files │ └── template.st ├── lib │ ├── antlr-2.7.7.jar │ ├── javaparser-1.0.8.jar │ └── stringtemplate-3.2.1.jar ├── project.properties └── src │ └── eu │ └── project │ └── rapid │ ├── ac │ ├── DFE.java │ ├── DSE.java │ ├── QoS.java │ ├── RapidSettingsActivity.java │ ├── Remote.java │ ├── Remoteable.java │ ├── ResultContainer.java │ ├── d2d │ │ ├── D2DClientService.java │ │ ├── D2DMessage.java │ │ └── PhoneSpecs.java │ ├── db │ │ ├── DBCache.java │ │ └── DBEntry.java │ ├── profilers │ │ ├── DeviceProfiler.java │ │ ├── LocationProfiler.java │ │ ├── LogRecord.java │ │ ├── NetworkBWRecord.java │ │ ├── NetworkProfiler.java │ │ ├── Profiler.java │ │ ├── ProgramProfiler.java │ │ └── phone │ │ │ ├── Phone.java │ │ │ ├── PhoneAlcatelOneTouchPixi.java │ │ │ ├── PhoneFactory.java │ │ │ ├── PhoneHtcDream.java │ │ │ └── PhoneMotorolaMotoG.java │ └── utils │ │ ├── Constants.java │ │ ├── Utils.java │ │ └── ZipHandler.java │ └── gvirtusfe │ ├── Buffer.java │ ├── CudaDr_context.java │ ├── CudaDr_device.java │ ├── CudaDr_execution.java │ ├── CudaDr_initialization.java │ ├── CudaDr_memory.java │ ├── CudaDr_module.java │ ├── CudaRt_device.java │ ├── CudaRt_memory.java │ ├── Frontend.java │ ├── Result.java │ └── dim3.java ├── AccelerationServer ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.jdt.ui.prefs ├── AndroidManifest.xml ├── libs │ ├── core-1.51.0.0.jar │ └── prov-1.51.0.0.jar ├── lint.xml ├── project.properties ├── res │ ├── drawable-hdpi │ │ └── icon.png │ ├── drawable-ldpi │ │ └── icon.png │ ├── drawable-mdpi │ │ └── icon.png │ ├── drawable │ │ └── icon.png │ ├── layout │ │ └── main.xml │ └── values │ │ └── string.xml └── src │ └── eu │ └── project │ └── rapid │ └── as │ ├── AccelerationServer.java │ ├── AccelerationServerAutoStarter.java │ ├── AppHandler.java │ ├── DynamicObjectInputStream.java │ ├── NetworkProfilerServer.java │ └── RapidServerActivity.java ├── LICENSE ├── README.md └── Rapid-DemoApp ├── .classpath ├── .externalToolBuilders └── NDK Build.launch ├── .project ├── .settings ├── org.eclipse.jdt.core.prefs └── org.eclipse.jdt.ui.prefs ├── AndroidManifest.xml ├── assets └── cuda-kernels │ └── matrixMul_kernel64.ptx ├── jni ├── Android.mk ├── Application.mk ├── GmpUtil.c ├── GmpUtil.h └── hello-jni.c ├── libs ├── armeabi-v7a │ └── libhello-jni.so ├── armeabi │ └── libhello-jni.so ├── commons-compress-1.9.jar ├── core-1.51.0.0.jar ├── prov-1.51.0.0.jar ├── x86 │ └── libhello-jni.so └── x86_64 │ └── libhello-jni.so ├── lint.xml ├── project.properties ├── res ├── drawable-hdpi │ ├── icon.png │ └── icon_dark.png ├── drawable-ldpi │ ├── icon.png │ └── icon_dark.png ├── drawable-mdpi │ ├── icon.png │ └── icon_dark.png ├── drawable-xhdpi │ ├── icon.png │ └── icon_dark.png ├── drawable │ ├── icon.xcf │ ├── prove.jpg │ └── prove2.jpg ├── layout │ ├── activity_main.xml │ └── main.xml ├── menu │ └── main.xml ├── values-sw600dp │ └── dimens.xml ├── values-sw720dp-land │ └── dimens.xml └── values │ ├── arrays.xml │ ├── dimens.xml │ ├── strings.xml │ └── style.xml └── src └── eu └── project └── rapid ├── demo ├── GVirtusDemo.java ├── MainActivity.java └── StartExecution.java ├── queens └── NQueens.java ├── sudoku └── Sudoku.java ├── synthBenchmark ├── JniTest.java └── TestRemoteable.java └── virus └── VirusScanning.java /AccelerationClient/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /AccelerationClient/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | AccelerationClient 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /AccelerationClient/.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true 3 | formatter_profile=_GoogleStyle 4 | formatter_settings_version=12 5 | sp_cleanup.add_default_serial_version_id=true 6 | sp_cleanup.add_generated_serial_version_id=false 7 | sp_cleanup.add_missing_annotations=true 8 | sp_cleanup.add_missing_deprecated_annotations=true 9 | sp_cleanup.add_missing_methods=false 10 | sp_cleanup.add_missing_nls_tags=false 11 | sp_cleanup.add_missing_override_annotations=true 12 | sp_cleanup.add_missing_override_annotations_interface_methods=true 13 | sp_cleanup.add_serial_version_id=false 14 | sp_cleanup.always_use_blocks=true 15 | sp_cleanup.always_use_parentheses_in_expressions=false 16 | sp_cleanup.always_use_this_for_non_static_field_access=false 17 | sp_cleanup.always_use_this_for_non_static_method_access=false 18 | sp_cleanup.convert_functional_interfaces=false 19 | sp_cleanup.convert_to_enhanced_for_loop=false 20 | sp_cleanup.correct_indentation=false 21 | sp_cleanup.format_source_code=true 22 | sp_cleanup.format_source_code_changes_only=false 23 | sp_cleanup.insert_inferred_type_arguments=false 24 | sp_cleanup.make_local_variable_final=true 25 | sp_cleanup.make_parameters_final=false 26 | sp_cleanup.make_private_fields_final=true 27 | sp_cleanup.make_type_abstract_if_missing_method=false 28 | sp_cleanup.make_variable_declarations_final=false 29 | sp_cleanup.never_use_blocks=false 30 | sp_cleanup.never_use_parentheses_in_expressions=true 31 | sp_cleanup.on_save_use_additional_actions=false 32 | sp_cleanup.organize_imports=true 33 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false 34 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true 35 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true 36 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false 37 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false 38 | sp_cleanup.remove_private_constructors=true 39 | sp_cleanup.remove_redundant_type_arguments=true 40 | sp_cleanup.remove_trailing_whitespaces=false 41 | sp_cleanup.remove_trailing_whitespaces_all=true 42 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false 43 | sp_cleanup.remove_unnecessary_casts=true 44 | sp_cleanup.remove_unnecessary_nls_tags=false 45 | sp_cleanup.remove_unused_imports=false 46 | sp_cleanup.remove_unused_local_variables=false 47 | sp_cleanup.remove_unused_private_fields=true 48 | sp_cleanup.remove_unused_private_members=false 49 | sp_cleanup.remove_unused_private_methods=true 50 | sp_cleanup.remove_unused_private_types=true 51 | sp_cleanup.sort_members=false 52 | sp_cleanup.sort_members_all=false 53 | sp_cleanup.use_anonymous_class_creation=false 54 | sp_cleanup.use_blocks=false 55 | sp_cleanup.use_blocks_only_for_return_and_throw=false 56 | sp_cleanup.use_lambda=true 57 | sp_cleanup.use_parentheses_in_expressions=false 58 | sp_cleanup.use_this_for_non_static_field_access=false 59 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true 60 | sp_cleanup.use_this_for_non_static_method_access=false 61 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true 62 | sp_cleanup.use_type_arguments=false 63 | -------------------------------------------------------------------------------- /AccelerationClient/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 24 | 25 | 29 | 30 | 31 | 32 | 33 | 34 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /AccelerationClient/files/template.st: -------------------------------------------------------------------------------- 1 | $modifiers$ $returnType$ $methodName$ ($parameters$) { 2 | Method toExecute; 3 | Class[] paramTypes = {$parameterTypes$}; 4 | Object[] paramValues = {$parameterNames$}; 5 | $returnType$ result = null; 6 | try { 7 | toExecute = this.getClass().getDeclaredMethod("local$methodName$", paramTypes); 8 | result = ($returnType$) dfe.execute(toExecute, paramValues, this); 9 | } catch (SecurityException e) { 10 | // Should never get here 11 | e.printStackTrace(); 12 | throw e; 13 | } catch (NoSuchMethodException e) { 14 | // Should never get here 15 | e.printStackTrace(); 16 | } catch (Throwable e) { 17 | // TODO Auto-generated catch block 18 | e.printStackTrace(); 19 | } 20 | return result; 21 | } 22 | 23 | $modifiers$ $returnType$ local$methodName$ ($parameters$) { 24 | $originalCode$ 25 | } -------------------------------------------------------------------------------- /AccelerationClient/lib/antlr-2.7.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/AccelerationClient/lib/antlr-2.7.7.jar -------------------------------------------------------------------------------- /AccelerationClient/lib/javaparser-1.0.8.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/AccelerationClient/lib/javaparser-1.0.8.jar -------------------------------------------------------------------------------- /AccelerationClient/lib/stringtemplate-3.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/AccelerationClient/lib/stringtemplate-3.2.1.jar -------------------------------------------------------------------------------- /AccelerationClient/project.properties: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2015, 2016 RAPID EU Project 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2.1 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | ############################################################################### 18 | # This file is automatically generated by Android Tools. 19 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 20 | # 21 | # This file must be checked in Version Control Systems. 22 | # 23 | # To customize properties used by the Ant build system edit 24 | # "ant.properties", and override values to adapt the script to your 25 | # project structure. 26 | # 27 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 28 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 29 | 30 | android.library=true 31 | # Project target. 32 | target=android-23 33 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/QoS.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | *******************************************************************************/ 18 | package eu.project.rapid.ac; 19 | 20 | public @interface QoS { 21 | String[]terms() default ""; 22 | String[]operators() default ""; 23 | String[]thresholds() default ""; 24 | } -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/RapidSettingsActivity.java: -------------------------------------------------------------------------------- 1 | package eu.project.rapid.ac; 2 | 3 | /** 4 | * This activity will have the appropriate buttons to control the settings of the 5 | * AccelerationClient.
6 | * It will be be used to start and stop the D2DClientService, for example, and for much more. 7 | * 8 | * @author sokol 9 | * 10 | */ 11 | public class RapidSettingsActivity { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/Remote.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | *******************************************************************************/ 18 | package eu.project.rapid.ac; 19 | 20 | public @interface Remote { 21 | boolean computeIntensive() default true; // true if the task is computation intensive 22 | boolean dataIntensive() default false; // true if the task is data intensive 23 | boolean networkIntensive() default false; // true if the task is network intensive 24 | boolean gpuComputation() default false; // true if the task will perform GPU computation 25 | boolean nativeCode() default false; // true if the task will execute native code 26 | boolean parallelizable() default false; // true if the task is parallelizable 27 | } -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/Remoteable.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or modify it under the terms of the 5 | * GNU Lesser General Public License as published by the Free Software Foundation; either version 6 | * 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 9 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Lesser General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with this library; 13 | * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 14 | * 02110-1301 USA 15 | *******************************************************************************/ 16 | package eu.project.rapid.ac; 17 | 18 | import java.io.File; 19 | import java.io.Serializable; 20 | import java.util.LinkedList; 21 | 22 | import android.util.Log; 23 | 24 | public abstract class Remoteable implements Serializable { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | public abstract void copyState(Remoteable state); 29 | 30 | /** 31 | * Load all provided shared libraries - used when an exception is thrown on the server-side, 32 | * meaning that the necessary libraries have not been loaded. x86 version of the libraries 33 | * included in the APK of the remote application are then loaded and the operation is re-executed. 34 | * 35 | * @param libFiles 36 | */ 37 | public void loadLibraries(LinkedList libFiles) { 38 | for (File libFile : libFiles) { 39 | Log.d("Remoteable", 40 | "Loading library: " + libFile.getName() + " (" + libFile.getAbsolutePath() + ")"); 41 | System.load(libFile.getAbsolutePath()); 42 | } 43 | } 44 | 45 | /** 46 | * Override this method if you want to prepare the data before executing the method. 47 | * 48 | * This can be useful in case the class contains data that are not serializable but are needed by 49 | * the method when offloaded. Use this method to convert the data to some serializable form before 50 | * the method is offloaded. 51 | * 52 | * Do not explicitly call this method. It will be automatically called by the framework before 53 | * offloading. 54 | */ 55 | public void prepareDataOnClient() {}; 56 | 57 | /** 58 | * Override this method if you want to prepare the data before executing the method on the VM. 59 | * 60 | * This can be useful in case the class contains data that are not serializable and were 61 | * serialized using the method prepareDataOnClient. 62 | * 63 | * Do not explicitly call this method. It will be automatically called by the framework before 64 | * running the method on the VM. 65 | */ 66 | public void prepareDataOnServer() {}; 67 | } 68 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/ResultContainer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | *******************************************************************************/ 18 | package eu.project.rapid.ac; 19 | 20 | import java.io.Serializable; 21 | 22 | /** 23 | * Container of remote execution data - to send back results of the executed 24 | * operation, the state of the object and actual execution time 25 | * 26 | */ 27 | public class ResultContainer implements Serializable { 28 | 29 | /** 30 | * 31 | */ 32 | private static final long serialVersionUID = 6289277906217259082L; 33 | 34 | public Object objState; 35 | public Object functionResult; 36 | public Long getObjectDuration; 37 | public Long pureExecutionDuration; 38 | 39 | /** 40 | * Wrapper of results returned by remote server - state of the object the 41 | * call was executed on and function result itself 42 | * 43 | * @param state 44 | * state of the remoted object 45 | * @param result 46 | * result of the function executed on the object 47 | */ 48 | public ResultContainer(Object state, Object result, Long getObjectDuration, Long duration) { 49 | objState = state; 50 | functionResult = result; 51 | this.getObjectDuration = getObjectDuration; 52 | pureExecutionDuration = duration; 53 | } 54 | 55 | /** 56 | * Used when an exception happens, to return the exception as a result of 57 | * remote invocation 58 | * 59 | * @param result 60 | */ 61 | public ResultContainer(Object result, Long getObjectDuration) { 62 | objState = null; 63 | functionResult = result; 64 | this.getObjectDuration = getObjectDuration; 65 | pureExecutionDuration = null; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/d2d/D2DClientService.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or modify it under the terms of the 5 | * GNU Lesser General Public License as published by the Free Software Foundation; either version 6 | * 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 9 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Lesser General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with this library; 13 | * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 14 | * 02110-1301 USA 15 | *******************************************************************************/ 16 | package eu.project.rapid.ac.d2d; 17 | 18 | import java.io.IOException; 19 | import java.net.DatagramPacket; 20 | import java.net.MulticastSocket; 21 | import java.util.Iterator; 22 | import java.util.Set; 23 | import java.util.TreeSet; 24 | import java.util.concurrent.Executors; 25 | import java.util.concurrent.ScheduledThreadPoolExecutor; 26 | import java.util.concurrent.TimeUnit; 27 | 28 | import android.app.IntentService; 29 | import android.content.Context; 30 | import android.content.Intent; 31 | import android.net.wifi.WifiManager; 32 | import android.os.Build; 33 | import android.util.Log; 34 | import eu.project.rapid.ac.d2d.D2DMessage.MsgType; 35 | import eu.project.rapid.ac.utils.Constants; 36 | import eu.project.rapid.ac.utils.Utils; 37 | 38 | /** 39 | * This thread will be started by clients that run the DFE so that these clients can get the HELLO 40 | * messages sent by the devices that act as D2D Acceleration Server. 41 | * 42 | * @author sokol 43 | * 44 | */ 45 | public class D2DClientService extends IntentService { 46 | 47 | private static final String TAG = D2DClientService.class.getName(); 48 | ScheduledThreadPoolExecutor setWriterThread = 49 | (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(5); 50 | private D2DSetWriter setWriterRunnable; 51 | public static final int FREQUENCY_WRITE_D2D_SET = 5 * 60 * 1013; // Every 5 minutes save the set 52 | public static final int FREQUENCY_READ_D2D_SET = 1 * 60 * 1011; // Every 1 minute read the set 53 | // from the file 54 | private MulticastSocket receiveSocket; 55 | private Set setD2dPhones = new TreeSet(); // Sorted by specs 56 | 57 | public D2DClientService() { 58 | super(D2DClientService.class.getName()); 59 | } 60 | 61 | @Override 62 | protected void onHandleIntent(Intent intent) { 63 | if (setWriterRunnable == null) { 64 | setWriterRunnable = new D2DSetWriter(); 65 | } 66 | setWriterThread.scheduleWithFixedDelay(setWriterRunnable, FREQUENCY_WRITE_D2D_SET, 67 | FREQUENCY_WRITE_D2D_SET, TimeUnit.MILLISECONDS); 68 | 69 | try { 70 | Log.i(TAG, "Thread started"); 71 | writeSetOnFile(); 72 | 73 | WifiManager.MulticastLock lock = null; 74 | WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); 75 | Log.i(TAG, "Trying to acquire multicast lock..."); 76 | if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { 77 | if (lock == null) { 78 | Log.i(TAG, "lock was null, creating..."); 79 | lock = wifi.createMulticastLock("WiFi_Lock"); 80 | } 81 | lock.setReferenceCounted(true); 82 | lock.acquire(); 83 | Log.i(TAG, "Lock acquired!"); 84 | } 85 | 86 | receiveSocket = new MulticastSocket(Constants.D2D_BROADCAST_PORT); 87 | receiveSocket.setBroadcast(true); 88 | Log.i(TAG, "Started listening on multicast socket."); 89 | 90 | try { 91 | // This will be interrupted when the OS kills the service 92 | while (true) { 93 | Log.i(TAG, "Waiting for broadcasted data..."); 94 | byte[] data = new byte[1024]; 95 | DatagramPacket packet = new DatagramPacket(data, data.length); 96 | receiveSocket.receive(packet); 97 | Log.d(TAG, "Received a new broadcast packet from: " + packet.getAddress()); 98 | processPacket(packet); 99 | } 100 | } catch (IOException e) { 101 | Log.d(TAG, "The socket was closed."); 102 | } 103 | 104 | Log.i(TAG, "Stopped receiving data!"); 105 | } catch (IOException e) { 106 | // We expect this to happen when more than one DFE on the same phone will try to create 107 | // this service and the port will be busy. This way only one service will be listening for D2D 108 | // messages. This service will be responsible for writing the received messages on a file so 109 | // that the DFEs of all applications could read them. 110 | Log.d(TAG, 111 | "Could not create D2D multicast socket, maybe the service is already started by another DFE: " 112 | + e); 113 | // e.printStackTrace(); 114 | } 115 | } 116 | 117 | /** 118 | * Process the packet received by another device in a D2D scenario. Create a D2Dmessage and if 119 | * this is a HELLO message then store the specifics of the other device into the Map. If a new 120 | * device is added to the map and more than 5 minutes have passed since the last time we saved the 121 | * devices on the file, then save the set in the filesystem so that other DFEs can read it. 122 | * 123 | * @param packet 124 | */ 125 | private void processPacket(DatagramPacket packet) { 126 | try { 127 | D2DMessage msg = new D2DMessage(packet.getData()); 128 | Log.d(TAG, "Received: <== " + msg); 129 | if (msg.getMsgType() == MsgType.HELLO) { 130 | PhoneSpecs otherPhone = msg.getPhoneSpecs(); 131 | if (setD2dPhones.contains(otherPhone)) { 132 | setD2dPhones.remove(otherPhone); 133 | } 134 | otherPhone.setTimestamp(System.currentTimeMillis()); 135 | otherPhone.setIp(packet.getAddress().getHostAddress()); 136 | setD2dPhones.add(otherPhone); 137 | // FIXME writing the set here is too heavy but I want this just for the demo. Later fix this 138 | // with a smarter alternative. 139 | writeSetOnFile(); 140 | } 141 | } catch (IOException | ClassNotFoundException e) { 142 | Log.e(TAG, "Error while processing the packet: " + e); 143 | } 144 | } 145 | 146 | private class D2DSetWriter implements Runnable { 147 | @Override 148 | public void run() { 149 | // Write the set in the filesystem so that other DFEs can use the D2D phones when needed. 150 | Iterator it = setD2dPhones.iterator(); 151 | // First clean the set from devices that have not been pinging recently 152 | while (it.hasNext()) { 153 | // If the last time we have seen this device is 5 pings before, then remove it. 154 | if ((System.currentTimeMillis() - it.next().getTimestamp()) > 5 155 | * Constants.D2D_BROADCAST_INTERVAL) { 156 | it.remove(); 157 | } 158 | } 159 | writeSetOnFile(); 160 | } 161 | } 162 | 163 | private void writeSetOnFile() { 164 | 165 | try { 166 | Log.i(TAG, "Writing set of D2D devices on the sdcard file"); 167 | // This method is blocking, waiting for the lock on the file to be available. 168 | Utils.writeObjectToFile(Constants.FILE_D2D_PHONES, setD2dPhones); 169 | Log.i(TAG, "Finished writing set of D2D devices on the sdcard file"); 170 | } catch (IOException e) { 171 | Log.e(TAG, "Error while writing set of D2D devices on the sdcard file: " + e); 172 | } 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/d2d/D2DMessage.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or modify it under the terms of the 5 | * GNU Lesser General Public License as published by the Free Software Foundation; either version 6 | * 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 9 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Lesser General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with this library; 13 | * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 14 | * 02110-1301 USA 15 | *******************************************************************************/ 16 | package eu.project.rapid.ac.d2d; 17 | 18 | import java.io.IOException; 19 | import java.io.Serializable; 20 | import java.io.StreamCorruptedException; 21 | 22 | import android.content.Context; 23 | import eu.project.rapid.ac.utils.Utils; 24 | 25 | /** 26 | * The message that will be broadcasted by the devices that run the Acceleration Server and are 27 | * willing to participate in D2D offloading service. 28 | */ 29 | public class D2DMessage implements Serializable { 30 | private static final long serialVersionUID = -8833550140715953630L; 31 | 32 | private MsgType msgType; 33 | private PhoneSpecs phoneSpecs; 34 | 35 | public enum MsgType { 36 | HELLO; 37 | } 38 | 39 | /** 40 | * Message that will be sent usually in broadcast by the device running the AccelerationServer 41 | * 42 | * @param msgType 43 | */ 44 | public D2DMessage(Context context, MsgType msgType) { 45 | this.msgType = msgType; 46 | this.phoneSpecs = PhoneSpecs.getPhoneSpecs(context); 47 | } 48 | 49 | /** 50 | * Constructor that will be usually used by the device running the AccelerationClient 51 | * 52 | * @param byteArray 53 | * @throws ClassNotFoundException 54 | * @throws IOException 55 | * @throws StreamCorruptedException 56 | */ 57 | public D2DMessage(byte[] byteArray) 58 | throws StreamCorruptedException, IOException, ClassNotFoundException { 59 | D2DMessage otherDevice = (D2DMessage) Utils.byteArrayToObject(byteArray); 60 | this.msgType = otherDevice.getMsgType(); 61 | this.phoneSpecs = otherDevice.getPhoneSpecs(); 62 | } 63 | 64 | /** 65 | * @return the msgType 66 | */ 67 | public MsgType getMsgType() { 68 | return msgType; 69 | } 70 | 71 | /** 72 | * @param msgType the msgType to set 73 | */ 74 | public void setMsgType(MsgType msgType) { 75 | this.msgType = msgType; 76 | } 77 | 78 | public PhoneSpecs getPhoneSpecs() { 79 | return phoneSpecs; 80 | } 81 | 82 | public void setPhoneSpecs(PhoneSpecs phoneSpecs) { 83 | this.phoneSpecs = phoneSpecs; 84 | } 85 | 86 | @Override 87 | public String toString() { 88 | return "[" + this.msgType.toString() + this.phoneSpecs + "]"; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/d2d/PhoneSpecs.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or modify it under the terms of the 5 | * GNU Lesser General Public License as published by the Free Software Foundation; either version 6 | * 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 9 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Lesser General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with this library; 13 | * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 14 | * 02110-1301 USA 15 | *******************************************************************************/ 16 | package eu.project.rapid.ac.d2d; 17 | 18 | import java.io.Serializable; 19 | 20 | import android.content.Context; 21 | import android.util.Log; 22 | import eu.project.rapid.ac.utils.Utils; 23 | 24 | /** 25 | * This object contains the specifics of a phone. In a D2D communication scenario, we will receive 26 | * the specifics from the nearby phones and will sort them based on CPU, memory, GPU.
27 | * 28 | * @author sokol 29 | * 30 | */ 31 | public class PhoneSpecs implements Serializable, Comparable { 32 | private static final long serialVersionUID = -4918806738265004873L; 33 | 34 | private static final String TAG = "PhoneSpecs"; 35 | 36 | private String phoneId; 37 | private long timestamp; // TimeStamp to be used by the clients as a mean to measure the freshness 38 | // of this phone 39 | private String ip; 40 | private int nrCPUs; // number of CPU cores 41 | private int cpuFreqKHz; // CPU frequency in KHz 42 | private int ramMB; // Memory in MB 43 | private boolean hasGpu; 44 | 45 | private static PhoneSpecs phoneSpecs; 46 | 47 | /** 48 | * @param context Context of the application calling this method. 49 | */ 50 | private PhoneSpecs(Context context) throws NullPointerException { 51 | if (context == null) { 52 | throw new NullPointerException("Context cannot be null"); 53 | } 54 | 55 | // FIXME: On Android 6 we can't just read the ID directly, we need to ask for runtime 56 | // permission. 57 | phoneId = Utils.getDeviceIdHashHex(context); 58 | nrCPUs = Utils.getDeviceNrCPUs(); 59 | cpuFreqKHz = Utils.getDeviceCPUFreq(); 60 | try { 61 | ip = Utils.getIpAddress().getHostAddress(); 62 | } catch (Exception e) { 63 | Log.w(TAG, 64 | "Error while getting the IP (most probably we are not connected to WiFi network): " + e); 65 | } 66 | } 67 | 68 | public static PhoneSpecs getPhoneSpecs(Context context) { 69 | if (phoneSpecs == null) { 70 | phoneSpecs = new PhoneSpecs(context); 71 | } 72 | 73 | return phoneSpecs; 74 | } 75 | 76 | /** 77 | * @return the phoneId 78 | */ 79 | public String getPhoneId() { 80 | return phoneId; 81 | } 82 | 83 | /** 84 | * @param phoneId the phoneId to set 85 | */ 86 | public void setPhoneId(String phoneId) { 87 | this.phoneId = phoneId; 88 | } 89 | 90 | /** 91 | * @return the timestamp 92 | */ 93 | public long getTimestamp() { 94 | return timestamp; 95 | } 96 | 97 | /** 98 | * @param timestamp the timestamp to set 99 | */ 100 | public void setTimestamp(long timestamp) { 101 | this.timestamp = timestamp; 102 | } 103 | 104 | /** 105 | * @return the ip 106 | */ 107 | public String getIp() { 108 | return ip; 109 | } 110 | 111 | /** 112 | * @param ip the ip to set 113 | */ 114 | public void setIp(String ip) { 115 | this.ip = ip; 116 | } 117 | 118 | /** 119 | * @return the nrCPUs 120 | */ 121 | public int getNrCPUs() { 122 | return nrCPUs; 123 | } 124 | 125 | /** 126 | * @param nrCPUs the nrCPUs to set 127 | */ 128 | public void setNrCPUs(int nrCPUs) { 129 | this.nrCPUs = nrCPUs; 130 | } 131 | 132 | /** 133 | * @return the cpuFreqKHz 134 | */ 135 | public int getCpuPowerKHz() { 136 | return cpuFreqKHz; 137 | } 138 | 139 | /** 140 | * @param cpuFreqKHz the cpuFreqKHz to set 141 | */ 142 | public void setCpuPowerKHz(int cpuPowerKHz) { 143 | this.cpuFreqKHz = cpuPowerKHz; 144 | } 145 | 146 | /** 147 | * @return the ramMB 148 | */ 149 | public int getRamMB() { 150 | return ramMB; 151 | } 152 | 153 | /** 154 | * @param ramMB the ramMB to set 155 | */ 156 | public void setRamMB(int ramMB) { 157 | this.ramMB = ramMB; 158 | } 159 | 160 | /** 161 | * @return the hasGpu 162 | */ 163 | public boolean isHasGpu() { 164 | return hasGpu; 165 | } 166 | 167 | /** 168 | * @param hasGpu the hasGpu to set 169 | */ 170 | public void setHasGpu(boolean hasGpu) { 171 | this.hasGpu = hasGpu; 172 | } 173 | 174 | @Override 175 | public int hashCode() { 176 | final int prime = 31; 177 | int result = prime + ((phoneId == null) ? 0 : phoneId.hashCode()); 178 | return result; 179 | } 180 | 181 | @Override 182 | public boolean equals(Object obj) { 183 | if (this == obj) { 184 | return true; 185 | } 186 | if (obj == null) { 187 | return false; 188 | } 189 | if (getClass() != obj.getClass()) { 190 | return false; 191 | } 192 | 193 | final PhoneSpecs other = (PhoneSpecs) obj; 194 | if (phoneId == other.phoneId) { 195 | return true; 196 | } 197 | 198 | return false; 199 | } 200 | 201 | 202 | @Override 203 | public int compareTo(PhoneSpecs otherPhone) { 204 | if (otherPhone == null) { 205 | return 1; 206 | } 207 | 208 | if (this.phoneId == otherPhone.phoneId) { 209 | return 0; 210 | } 211 | 212 | if (this.nrCPUs > otherPhone.nrCPUs || this.cpuFreqKHz > otherPhone.cpuFreqKHz) { 213 | return 1; 214 | } else if (this.cpuFreqKHz < otherPhone.cpuFreqKHz) { 215 | return -1; 216 | } else { 217 | return this.ramMB - otherPhone.ramMB; 218 | } 219 | } 220 | 221 | @Override 222 | public String toString() { 223 | return "ID=" + this.phoneId + ", nrCPUs=" + this.nrCPUs + ", CPU=" + this.cpuFreqKHz + " KHz" 224 | + ", RAM=" + this.ramMB + " MB" + ", GPU=" + this.hasGpu + ", IP=" + this.ip; 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/db/DBCache.java: -------------------------------------------------------------------------------- 1 | package eu.project.rapid.ac.db; 2 | 3 | import java.io.IOException; 4 | import java.util.Deque; 5 | import java.util.HashMap; 6 | import java.util.LinkedList; 7 | import java.util.Map; 8 | 9 | import android.util.Log; 10 | import eu.project.rapid.ac.utils.Constants; 11 | import eu.project.rapid.ac.utils.Utils; 12 | 13 | /** 14 | * While RAPID is running there is no need to access the database. We use this class to keep the 15 | * needed information so that the offloading decision is faster. When the app is closed the entries 16 | * of this cached DB are saved. 17 | * 18 | * @author sokol 19 | * 20 | */ 21 | public class DBCache { 22 | 23 | private static final String TAG = "DBCache"; 24 | 25 | private static int nrElements; 26 | private static DBCache dbCache; 27 | private static Map> dbMap; // appName is the key 28 | 29 | @SuppressWarnings("unchecked") 30 | private DBCache() { 31 | try { 32 | Log.i(TAG, "Reading the dbCache from file: " + Constants.FILE_DB_CACHE); 33 | dbMap = (Map>) Utils.readObjectFromFile(Constants.FILE_DB_CACHE); 34 | } catch (ClassNotFoundException | IOException e) { 35 | Log.w(TAG, "Could not read the dbCache from file: " + e); 36 | } 37 | 38 | if (dbMap == null) { 39 | dbMap = new HashMap<>(); 40 | } 41 | }; 42 | 43 | public static DBCache getDbCache() { 44 | if (dbCache == null) { 45 | Log.i(TAG, "Creating the dbCache object"); 46 | dbCache = new DBCache(); 47 | } 48 | 49 | return dbCache; 50 | } 51 | 52 | public void insertEntry(DBEntry entry) { 53 | String key = entry.getMethodName(); 54 | if (!dbMap.containsKey(key)) { 55 | dbMap.put(key, new LinkedList()); 56 | } 57 | 58 | while (dbMap.get(key).size() >= Constants.MAX_METHOD_EXEC_HISTORY) { 59 | dbMap.get(key).removeLast(); 60 | nrElements--; 61 | } 62 | 63 | dbMap.get(key).addFirst(entry); 64 | nrElements++; 65 | } 66 | 67 | /** 68 | * To be used to retrieve all entries. 69 | * 70 | * @param methodName 71 | * @return 72 | */ 73 | public Deque getAllEntriesFilteredOn(String methodName) { 74 | if (dbMap.containsKey(methodName)) { 75 | return dbMap.get(methodName); 76 | } else { 77 | return new LinkedList<>(); 78 | } 79 | } 80 | 81 | /** 82 | * To be used for retrieving the entries of LOCAL execution. The elements are sorted in 83 | * incremental order based on timestamp. 84 | * 85 | * @param methodName 86 | * @param appName 87 | * @param execLocation 88 | * @return 89 | */ 90 | public Deque getAllEntriesFilteredOn(String appName, String methodName, 91 | String execLocation) { 92 | 93 | assert dbMap != null; 94 | 95 | Deque tempList = new LinkedList<>(); 96 | if (dbMap.containsKey(methodName)) { 97 | for (DBEntry e : dbMap.get(methodName)) { 98 | // Log.i(TAG, "Checking entry: " + e.getAppName() + ", " + e.getMethodName() + ", " 99 | // + e.getExecLocation() + ", " + e.getTimestamp()); 100 | if (e.getAppName().equals(appName) && e.getExecLocation().equals(execLocation)) { 101 | tempList.addLast(e); 102 | } 103 | } 104 | } 105 | 106 | return tempList; 107 | } 108 | 109 | /** 110 | * To be used for retrieving the entries of REMOTE execution. The elements are sorted in 111 | * incremental order based on timestamp. 112 | * 113 | * @param methodName 114 | * @param appName 115 | * @param execLocation 116 | * @param networkType 117 | * @param networkSubtype 118 | * @return 119 | */ 120 | public Deque getAllEntriesFilteredOn(String appName, String methodName, 121 | String execLocation, String networkType, String networkSubtype) { 122 | 123 | assert dbMap != null; 124 | 125 | Deque tempList = new LinkedList<>(); 126 | if (dbMap.containsKey(methodName)) { 127 | for (DBEntry e : dbMap.get(methodName)) { 128 | if (e.getAppName().equals(appName) && e.getExecLocation().equals(execLocation) 129 | && e.getNetworkType().equals(networkType) 130 | && e.getNetworkSubType().equals(networkSubtype)) { 131 | tempList.addLast(e); 132 | } 133 | } 134 | } 135 | 136 | return tempList; 137 | } 138 | 139 | public void clearDbCache() { 140 | dbMap.clear(); 141 | nrElements = 0; 142 | } 143 | 144 | /** 145 | * To be called by the DFE when the (Rapid) application is closed. 146 | */ 147 | public static void saveDbCache() { 148 | try { 149 | Utils.writeObjectToFile(Constants.FILE_DB_CACHE, dbMap); 150 | } catch (IOException e) { 151 | Log.e(TAG, "Could not save the dbCache on the file: " + e); 152 | } 153 | } 154 | 155 | /** 156 | * Returns the number of entries in the DB cache, i.e. the number of different methods insterted 157 | * in the DB. 158 | * 159 | * @return 160 | */ 161 | public int size() { 162 | if (dbMap == null) { 163 | return 0; 164 | } 165 | 166 | return dbMap.size(); 167 | } 168 | 169 | /** 170 | * Returns the number of total elements in the DB cache, i.e.: nrMethods * measurementsPerMethod. 171 | * 172 | * @return 173 | */ 174 | public int nrElements() { 175 | return nrElements; 176 | } 177 | 178 | public int getByteSize() { 179 | int bytes = -1; 180 | try { 181 | bytes = Utils.objectToByteArray(dbMap).length; 182 | } catch (IOException e) { 183 | Log.e(TAG, "Error while converting the DB cache map to byte array: " + e); 184 | } 185 | 186 | return bytes; 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/db/DBEntry.java: -------------------------------------------------------------------------------- 1 | package eu.project.rapid.ac.db; 2 | 3 | import java.io.Serializable; 4 | 5 | public class DBEntry implements Serializable { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | private String appName; 10 | private String methodName; 11 | private String execLocation; 12 | private String networkType; 13 | private String networkSubType; 14 | private int ulRate; 15 | private int dlRate; 16 | private long execDuration; 17 | private long execEnergy; 18 | private long timestamp; 19 | 20 | public DBEntry(String appName, String methodName, String execLocation, String networkType, 21 | String networkSubType, int ulRate, int dlRate, long execDuration, long execEnergy) { 22 | 23 | this.appName = appName; 24 | this.methodName = methodName; 25 | this.execLocation = execLocation; 26 | this.networkType = networkType; 27 | this.networkSubType = networkSubType; 28 | this.ulRate = ulRate; 29 | this.dlRate = dlRate; 30 | this.execDuration = execDuration; 31 | this.execEnergy = execEnergy; 32 | this.timestamp = System.currentTimeMillis(); 33 | } 34 | 35 | /** 36 | * @return the appName 37 | */ 38 | public String getAppName() { 39 | return appName; 40 | } 41 | 42 | /** 43 | * @param appName the appName to set 44 | */ 45 | public void setAppName(String appName) { 46 | this.appName = appName; 47 | } 48 | 49 | /** 50 | * @return the methodName 51 | */ 52 | public String getMethodName() { 53 | return methodName; 54 | } 55 | 56 | /** 57 | * @param methodName the methodName to set 58 | */ 59 | public void setMethodName(String methodName) { 60 | this.methodName = methodName; 61 | } 62 | 63 | /** 64 | * @return the execLocation 65 | */ 66 | public String getExecLocation() { 67 | return execLocation; 68 | } 69 | 70 | /** 71 | * @param execLocation the execLocation to set 72 | */ 73 | public void setExecLocation(String execLocation) { 74 | this.execLocation = execLocation; 75 | } 76 | 77 | /** 78 | * @return the networkType 79 | */ 80 | public String getNetworkType() { 81 | return networkType; 82 | } 83 | 84 | /** 85 | * @param networkType the networkType to set 86 | */ 87 | public void setNetworkType(String networkType) { 88 | this.networkType = networkType; 89 | } 90 | 91 | /** 92 | * @return the networkSubType 93 | */ 94 | public String getNetworkSubType() { 95 | return networkSubType; 96 | } 97 | 98 | /** 99 | * @param networkSubType the networkSubType to set 100 | */ 101 | public void setNetworkSubType(String networkSubType) { 102 | this.networkSubType = networkSubType; 103 | } 104 | 105 | /** 106 | * @return the ulRate 107 | */ 108 | public int getUlRate() { 109 | return ulRate; 110 | } 111 | 112 | /** 113 | * @param ulRate the ulRate to set 114 | */ 115 | public void setUlRate(int ulRate) { 116 | this.ulRate = ulRate; 117 | } 118 | 119 | /** 120 | * @return the dlRate 121 | */ 122 | public int getDlRate() { 123 | return dlRate; 124 | } 125 | 126 | /** 127 | * @param dlRate the dlRate to set 128 | */ 129 | public void setDlRate(int dlRate) { 130 | this.dlRate = dlRate; 131 | } 132 | 133 | /** 134 | * @return the execDuration 135 | */ 136 | public long getExecDuration() { 137 | return execDuration; 138 | } 139 | 140 | /** 141 | * @param execDuration the execDuration to set 142 | */ 143 | public void setExecDuration(long execDuration) { 144 | this.execDuration = execDuration; 145 | } 146 | 147 | /** 148 | * @return the execEnergy 149 | */ 150 | public long getExecEnergy() { 151 | return execEnergy; 152 | } 153 | 154 | /** 155 | * @param execEnergy the execEnergy to set 156 | */ 157 | public void setExecEnergy(long execEnergy) { 158 | this.execEnergy = execEnergy; 159 | } 160 | 161 | /** 162 | * @return the timestamp 163 | */ 164 | public long getTimestamp() { 165 | return timestamp; 166 | } 167 | 168 | /** 169 | * @param timestamp the timestamp to set 170 | */ 171 | public void setTimestamp(long timestamp) { 172 | this.timestamp = timestamp; 173 | } 174 | 175 | } 176 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/profilers/LocationProfiler.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | *******************************************************************************/ 18 | package eu.project.rapid.ac.profilers; 19 | 20 | import android.location.Location; 21 | import android.location.LocationListener; 22 | import android.os.Bundle; 23 | import android.util.Log; 24 | 25 | public class LocationProfiler implements LocationListener { 26 | 27 | private static final String TAG = "LocationProfiler"; 28 | 29 | @Override 30 | public void onLocationChanged(Location location) { 31 | 32 | Log.i(TAG, "User location changed: (" + location.getLatitude() + "," + location.getLongitude()); 33 | 34 | } 35 | 36 | @Override 37 | public void onProviderDisabled(String provider) { 38 | // TODO Auto-generated method stub 39 | 40 | } 41 | 42 | @Override 43 | public void onProviderEnabled(String provider) { 44 | // TODO Auto-generated method stub 45 | 46 | } 47 | 48 | @Override 49 | public void onStatusChanged(String provider, int status, Bundle extras) { 50 | // TODO Auto-generated method stub 51 | 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/profilers/LogRecord.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | *******************************************************************************/ 18 | package eu.project.rapid.ac.profilers; 19 | 20 | /** 21 | * Log record of the profiler. 22 | * 23 | * Structure of a log record: 24 | * 25 | * Method Name, Execution Location, PrepareDataDuration (nanoseconds), Execution Duration (nanoseconds), Execution 26 | * Duration (excl. overheads),Thread CPU time,Instruction Count,Method 27 | * Invocation Count,Thread Allocation Size,Garbage Collector invocation count 28 | * (thread),Garbage Collector invocation count (global),Current Network 29 | * Type,Current Network Subtype,Current RTT,Current UlRate, Current DlRate, Bytes 30 | * Received(RX),Bytes Transmitted(TX),Battery Voltage Change,Timestamp 31 | * 32 | */ 33 | public class LogRecord { 34 | public String appName; 35 | public String methodName; 36 | public String execLocation; 37 | public long prepareDataDuration; 38 | public long execDuration; 39 | public long pureDuration; 40 | public long energyConsumption; 41 | public double cpuEnergy; 42 | public double screenEnergy; 43 | public double wifiEnergy; 44 | public double threeGEnergy; 45 | 46 | public Long threadCpuTime; 47 | public int instructionCount; 48 | public int methodCount; 49 | public int threadAllocSize; 50 | public int threadGcInvocationCount; 51 | public int globalGcInvocationCount; 52 | 53 | public String networkType; 54 | public String networkSubtype; 55 | public int rtt; 56 | public int ulRate = -1; 57 | public int dlRate = -1; 58 | public long rxBytes = -1; 59 | public long txBytes = -1; 60 | 61 | public long batteryVoltageChange; 62 | public long logRecordTime; 63 | 64 | public static final String LOG_HEADERS = "#MethodName,ExecLocation,PrepareDataDuration,ExecDuration,PureDuration," + 65 | "EnergyConsumption,CpuEnergy,ScreenEnergy,WifiEnergy,3GEnergy," + 66 | "ThreadCpuTime,InstructionCount,MethodCount,ThreadAllocSize,ThreadGcInvocCount,GlobalGcInvocCount," + 67 | "NetType,NetSubtype,RTT,UlRate,DlRate,RxBytes,TxBytes," + 68 | "BatteryVoltChange,LogRecordTime"; 69 | 70 | /** 71 | * Collect readings of the different profilers together from the different 72 | * running profilers 73 | * 74 | * @param progProfiler 75 | * instace of ProgramProfiler 76 | * @param netProfiler 77 | * instance of NetworkProfiler 78 | * @param devProfiler 79 | * instance of DeviceProfiler 80 | */ 81 | public LogRecord(ProgramProfiler progProfiler, NetworkProfiler netProfiler, 82 | DeviceProfiler devProfiler) { 83 | appName = progProfiler.appName; 84 | methodName = progProfiler.methodName; 85 | execDuration = progProfiler.execTime; 86 | threadCpuTime = progProfiler.threadCpuTime; 87 | 88 | instructionCount = progProfiler.instructionCount; 89 | methodCount = progProfiler.methodInvocationCount; 90 | 91 | threadAllocSize = progProfiler.threadAllocSize; 92 | threadGcInvocationCount = progProfiler.gcThreadInvocationCount; 93 | globalGcInvocationCount = progProfiler.gcGlobalInvocationCount; 94 | 95 | networkType = NetworkProfiler.currentNetworkTypeName; 96 | networkSubtype = NetworkProfiler.currentNetworkSubtypeName; 97 | rtt = NetworkProfiler.rtt; 98 | 99 | if (NetworkProfiler.lastUlRate != null) 100 | ulRate = NetworkProfiler.lastUlRate.getBw(); 101 | 102 | if (NetworkProfiler.lastDlRate != null) 103 | dlRate = NetworkProfiler.lastDlRate.getBw(); 104 | 105 | if (netProfiler != null) { 106 | rxBytes = netProfiler.rxBytes; 107 | txBytes = netProfiler.txBytes; 108 | } else { 109 | rxBytes = -1; 110 | txBytes = -1; 111 | } 112 | 113 | batteryVoltageChange = devProfiler.batteryVoltageDelta; 114 | } 115 | 116 | /** 117 | * Convert the log record to string for storing 118 | */ 119 | public String toString() { 120 | 121 | logRecordTime = System.currentTimeMillis(); 122 | String progProfilerRecord = methodName + "," + execLocation + "," + prepareDataDuration + "," 123 | + execDuration + "," + pureDuration + "," + energyConsumption + "," + 124 | cpuEnergy + "," + screenEnergy + "," + wifiEnergy + "," + threeGEnergy 125 | + "," + threadCpuTime + "," 126 | + instructionCount + "," + methodCount + "," + threadAllocSize 127 | + "," + threadGcInvocationCount + "," + globalGcInvocationCount; 128 | 129 | String netProfilerRecord = " , , , , , , "; 130 | 131 | if (execLocation == "REMOTE") 132 | netProfilerRecord = networkType + ", " + networkSubtype + "," + rtt 133 | + "," + ulRate + "," + dlRate + "," + rxBytes + "," + txBytes; 134 | 135 | String devProfilerRecord = "" + batteryVoltageChange; 136 | 137 | return progProfilerRecord + "," + netProfilerRecord + "," 138 | + devProfilerRecord + "," + logRecordTime; 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/profilers/NetworkBWRecord.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | *******************************************************************************/ 18 | package eu.project.rapid.ac.profilers; 19 | 20 | public class NetworkBWRecord { 21 | 22 | private int bw; 23 | private long timestamp; 24 | 25 | public NetworkBWRecord() { 26 | this(-1, -1); 27 | } 28 | 29 | /** 30 | * 31 | * @param ulRate 32 | * @param dlRate 33 | * @param timestamp 34 | * @param location 35 | */ 36 | public NetworkBWRecord(int bw, long timestamp) { 37 | this.bw = bw; 38 | this.timestamp = timestamp; 39 | } 40 | 41 | /** 42 | * @return the bw 43 | */ 44 | public int getBw() { 45 | return bw; 46 | } 47 | 48 | /** 49 | * @param bw the bw to set 50 | */ 51 | public void setBw(int bw) { 52 | this.bw = bw; 53 | } 54 | 55 | /** 56 | * @return the timestamp 57 | */ 58 | public long getTimestamp() { 59 | return timestamp; 60 | } 61 | /** 62 | * @param timestamp the timestamp to set 63 | */ 64 | public void setTimestamp(long timestamp) { 65 | this.timestamp = timestamp; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/profilers/Profiler.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or modify it under the terms of the 5 | * GNU Lesser General Public License as published by the Free Software Foundation; either version 6 | * 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 9 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Lesser General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with this library; 13 | * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 14 | * 02110-1301 USA 15 | *******************************************************************************/ 16 | package eu.project.rapid.ac.profilers; 17 | 18 | import java.io.File; 19 | import java.io.FileWriter; 20 | import java.io.IOException; 21 | 22 | import android.util.Log; 23 | import eu.project.rapid.ac.db.DBCache; 24 | import eu.project.rapid.ac.db.DBEntry; 25 | import eu.project.rapid.ac.profilers.phone.Phone; 26 | import eu.project.rapid.ac.profilers.phone.PhoneFactory; 27 | import eu.project.rapid.ac.utils.Constants; 28 | 29 | 30 | public class Profiler { 31 | 32 | private static final String TAG = "Profiler"; 33 | 34 | Phone phone; 35 | 36 | private ProgramProfiler progProfiler; 37 | private NetworkProfiler netProfiler; 38 | private DeviceProfiler devProfiler; 39 | private int mRegime; 40 | public static final int REGIME_CLIENT = 1; 41 | public static final int REGIME_SERVER = 2; 42 | 43 | private static FileWriter logFileWriter; 44 | 45 | private String mLocation; 46 | 47 | private LogRecord lastLogRecord; 48 | 49 | public Profiler(int regime, ProgramProfiler progProfiler, NetworkProfiler netProfiler, 50 | DeviceProfiler devProfiler) { 51 | this.progProfiler = progProfiler; 52 | this.netProfiler = netProfiler; 53 | this.devProfiler = devProfiler; 54 | this.mRegime = regime; 55 | 56 | if (mRegime == REGIME_CLIENT) { 57 | // this.devProfiler.trackBatteryLevel(); 58 | } 59 | } 60 | 61 | public void startExecutionInfoTracking() { 62 | 63 | if (netProfiler != null) { 64 | netProfiler.startTransmittedDataCounting(); 65 | mLocation = "REMOTE"; 66 | } else { 67 | mLocation = "LOCAL"; 68 | } 69 | Log.d(TAG, mLocation + " " + progProfiler.methodName); 70 | progProfiler.startExecutionInfoTracking(); 71 | 72 | if (mRegime == REGIME_CLIENT) { 73 | devProfiler.startDeviceProfiling(); 74 | } 75 | } 76 | 77 | private void stopProfilers() { 78 | 79 | if (mRegime == REGIME_CLIENT) { 80 | devProfiler.stopAndCollectDeviceProfiling(); 81 | } 82 | 83 | progProfiler.stopAndCollectExecutionInfoTracking(); 84 | 85 | if (netProfiler != null) { 86 | netProfiler.stopAndCollectTransmittedData(); 87 | } 88 | } 89 | 90 | /** 91 | * Stop running profilers and discard current information 92 | * 93 | */ 94 | public void stopAndDiscardExecutionInfoTracking() { 95 | stopProfilers(); 96 | } 97 | 98 | /** 99 | * Stop running profilers and log current information 100 | * 101 | */ 102 | public void stopAndLogExecutionInfoTracking(long prepareDataDuration, Long pureExecTime) { 103 | 104 | stopProfilers(); 105 | 106 | lastLogRecord = new LogRecord(progProfiler, netProfiler, devProfiler); 107 | lastLogRecord.prepareDataDuration = prepareDataDuration; 108 | lastLogRecord.pureDuration = pureExecTime; 109 | lastLogRecord.execLocation = mLocation; 110 | 111 | if (mRegime == REGIME_CLIENT) { 112 | phone = PhoneFactory.getPhone(devProfiler, netProfiler, progProfiler); 113 | phone.estimateEnergyConsumption(); 114 | lastLogRecord.energyConsumption = phone.getTotalEstimatedEnergy(); 115 | lastLogRecord.cpuEnergy = phone.getEstimatedCpuEnergy(); 116 | lastLogRecord.screenEnergy = phone.getEstimatedScreenEnergy(); 117 | lastLogRecord.wifiEnergy = phone.getEstimatedWiFiEnergy(); 118 | lastLogRecord.threeGEnergy = phone.getEstimated3GEnergy(); 119 | 120 | Log.d(TAG, "Log record - " + lastLogRecord.toString()); 121 | 122 | try { 123 | synchronized (this) { 124 | if (logFileWriter == null) { 125 | File logFile = new File(Constants.LOG_FILE_NAME); 126 | // Try creating new, if doesn't exist 127 | boolean logFileCreated = logFile.createNewFile(); 128 | logFileWriter = new FileWriter(logFile, true); 129 | if (logFileCreated) { 130 | logFileWriter.append(LogRecord.LOG_HEADERS + "\n"); 131 | } 132 | } 133 | 134 | logFileWriter.append(lastLogRecord.toString() + "\n"); 135 | logFileWriter.flush(); 136 | } 137 | } catch (IOException e) { 138 | Log.w(TAG, "Not able to create the logFile " + Constants.LOG_FILE_NAME + ": " + e); 139 | } 140 | 141 | updateDbCache(); 142 | } 143 | } 144 | 145 | private void updateDbCache() { 146 | DBCache dbCache = DBCache.getDbCache(); 147 | // public DBEntry(String appName, String methodName, String execLocation, String networkType, 148 | // String networkSubType, int ulRate, int dlRate, long execDuration, long execEnergy) 149 | DBEntry dbEntry = 150 | new DBEntry(lastLogRecord.appName, lastLogRecord.methodName, lastLogRecord.execLocation, 151 | lastLogRecord.networkType, lastLogRecord.networkSubtype, lastLogRecord.ulRate, 152 | lastLogRecord.dlRate, lastLogRecord.execDuration, lastLogRecord.energyConsumption); 153 | dbCache.insertEntry(dbEntry); 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/profilers/phone/PhoneAlcatelOneTouchPixi.java: -------------------------------------------------------------------------------- 1 | package eu.project.rapid.ac.profilers.phone; 2 | 3 | import eu.project.rapid.ac.profilers.DeviceProfiler; 4 | import eu.project.rapid.ac.profilers.NetworkProfiler; 5 | import eu.project.rapid.ac.profilers.ProgramProfiler; 6 | 7 | public class PhoneAlcatelOneTouchPixi extends Phone { 8 | 9 | public PhoneAlcatelOneTouchPixi(DeviceProfiler devProfiler, NetworkProfiler netProfiler, 10 | ProgramProfiler progProfiler) { 11 | super(devProfiler, netProfiler, progProfiler); 12 | 13 | // CPU 14 | MIN_FREQ = 598000; // The minimum frequency (KHz) 15 | MAX_FREQ = 1000000; // The maximum frequency (KHz) 16 | betaUh = 0.1232; // (mW/MHz) 17 | betaUl = 0.094; // (mW/MHz) 18 | betaCpu = 18.438; // (mW) 19 | 20 | // Screen 21 | betaBrightness = 0.591; // (mW) 22 | 23 | // WiFi 24 | betaWiFiLow = 5; // (mW) 25 | betaWiFiHigh = 155; // (mW) 26 | 27 | // 3G 28 | beta3GIdle = 10; // (mW) 29 | beta3GFACH = 510; // (mW) 30 | beta3GDCH = 672; // (mW) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/profilers/phone/PhoneFactory.java: -------------------------------------------------------------------------------- 1 | package eu.project.rapid.ac.profilers.phone; 2 | 3 | import eu.project.rapid.ac.profilers.DeviceProfiler; 4 | import eu.project.rapid.ac.profilers.NetworkProfiler; 5 | import eu.project.rapid.ac.profilers.ProgramProfiler; 6 | import eu.project.rapid.ac.utils.Constants; 7 | 8 | public class PhoneFactory { 9 | 10 | private PhoneFactory() {}; 11 | 12 | public static Phone getPhone(DeviceProfiler devProfiler, NetworkProfiler netProfiler, 13 | ProgramProfiler progProfiler) { 14 | if (android.os.Build.MODEL.equals(Constants.PHONE_NAME_HTC_G1)) { 15 | return new PhoneHtcDream(devProfiler, netProfiler, progProfiler); 16 | } 17 | // Add here all the cases for the other phones. 18 | else { 19 | // By default, if the current phone's call is not implemented yet, use the htc dream. 20 | return new PhoneHtcDream(devProfiler, netProfiler, progProfiler); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/profilers/phone/PhoneHtcDream.java: -------------------------------------------------------------------------------- 1 | package eu.project.rapid.ac.profilers.phone; 2 | 3 | import eu.project.rapid.ac.profilers.DeviceProfiler; 4 | import eu.project.rapid.ac.profilers.NetworkProfiler; 5 | import eu.project.rapid.ac.profilers.ProgramProfiler; 6 | 7 | public class PhoneHtcDream extends Phone { 8 | 9 | public PhoneHtcDream(DeviceProfiler devProfiler, NetworkProfiler netProfiler, 10 | ProgramProfiler progProfiler) { 11 | super(devProfiler, netProfiler, progProfiler); 12 | 13 | // CPU 14 | MIN_FREQ = 245760; // The minimum frequency for HTC Dream CPU 15 | MAX_FREQ = 352000; // The maximum frequency for HTC Dream CPU 16 | betaUh = 4.34; 17 | betaUl = 3.42; 18 | betaCpu = 121.46; 19 | 20 | // Screen 21 | betaBrightness = 2.4; 22 | 23 | // WiFi 24 | betaWiFiLow = 20; 25 | 26 | // 3G 27 | beta3GIdle = 10; 28 | beta3GFACH = 401; 29 | beta3GDCH = 570; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/profilers/phone/PhoneMotorolaMotoG.java: -------------------------------------------------------------------------------- 1 | package eu.project.rapid.ac.profilers.phone; 2 | 3 | import eu.project.rapid.ac.profilers.DeviceProfiler; 4 | import eu.project.rapid.ac.profilers.NetworkProfiler; 5 | import eu.project.rapid.ac.profilers.ProgramProfiler; 6 | 7 | public class PhoneMotorolaMotoG extends Phone { 8 | 9 | public PhoneMotorolaMotoG(DeviceProfiler devProfiler, NetworkProfiler netProfiler, 10 | ProgramProfiler progProfiler) { 11 | super(devProfiler, netProfiler, progProfiler); 12 | // TODO Auto-generated constructor stub 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/utils/Constants.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or modify it under the terms of the 5 | * GNU Lesser General Public License as published by the Free Software Foundation; either version 6 | * 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 9 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Lesser General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with this library; 13 | * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 14 | * 02110-1301 USA 15 | *******************************************************************************/ 16 | package eu.project.rapid.ac.utils; 17 | 18 | import java.io.File; 19 | 20 | import android.os.Environment; 21 | 22 | public class Constants { 23 | 24 | public static final int MAX_NUM_CLIENTS = 32; 25 | 26 | public static final String DEFAULT_DB_NAME = "Rapid-DB.db"; 27 | // The number of recent method executions to keep in DB so that they can be used for offloading 28 | // decision. 29 | public static final int MAX_METHOD_EXEC_HISTORY = 50; 30 | 31 | // Offloading decision related variables 32 | // public static final int LOCATION_NOT_DECIDED = -1; 33 | public static final int LOCATION_LOCAL = 1; 34 | public static final int LOCATION_REMOTE = 2; 35 | public static final int LOCATION_HYBRID = 3; 36 | public static final int LOCATION_DYNAMIC_TIME = 4; 37 | public static final int LOCATION_DYNAMIC_ENERGY = 5; 38 | public static final int LOCATION_DYNAMIC_TIME_ENERGY = 6; 39 | 40 | // TODO: check the real device name as returned by android for the HTC G1 phone 41 | public static final String PHONE_NAME_HTC_G1 = "HTC G1"; 42 | public static final String PHONE_MODEL_HTC_DESIRE = "HTC Desire"; 43 | public static final String PHONE_MODEL_SAMSUNG_GALAXY_S = "samsung GT-I9000"; 44 | public static final String PHONE_MODEL_MOTOROLA_MOTO_G = "Motorola Moto G"; 45 | 46 | public enum SETUP_TYPE { 47 | KVM, VIRTUALBOX, AMAZON, HYBRID 48 | } 49 | 50 | public static final String RAPID_SETTINGS = "rapid_settings"; 51 | public static final String MY_OLD_ID = "MY_OLD_ID"; 52 | public static final String PREV_VM_IP = "PREV_VM_IP"; 53 | public static final String PREV_VMM_IP = "PREV_VMM_IP"; 54 | public static final String MY_OLD_ID_WITH_DS = "MY_OLD_ID_WITH_DS"; 55 | 56 | public static final String MNT_SDCARD = 57 | Environment.getExternalStorageDirectory().getAbsolutePath(); 58 | // public static final String MNT_SDCARD = "/mnt/sdcard/"; 59 | 60 | public static final String RAPID_FOLDER = MNT_SDCARD + File.separator + "rapid"; 61 | public static final String CLONE_CONFIG_FILE = RAPID_FOLDER + File.separator + "config-clone.cfg"; 62 | public static final String PHONE_CONFIG_FILE = RAPID_FOLDER + File.separator + "config-phone.cfg"; 63 | public static final String TEST_LOGS_FOLDER = 64 | RAPID_FOLDER + File.separator + "test_logs" + File.separator; 65 | public static final String LOG_FILE_NAME = RAPID_FOLDER + File.separator + "rapid-log.csv"; 66 | public static final String SSL_KEYSTORE = RAPID_FOLDER + File.separator + "keystore.bks"; 67 | public static final String SSL_CA_TRUSTSTORE = 68 | RAPID_FOLDER + File.separator + "ca_truststore.bks"; 69 | public static final String SSL_CERT_ALIAS = "cert"; 70 | public static final String SSL_DEFAULT_PASSW = "changeme"; 71 | 72 | public static final String FILE_OFFLOADED = RAPID_FOLDER + File.separator + "offloaded"; 73 | public static final String FILE_D2D_PHONES = RAPID_FOLDER + File.separator + "d2d-phones-set.ser"; 74 | public static final String FILE_DB_CACHE = RAPID_FOLDER + File.separator + "dbCache.ser"; 75 | public static final String CLONE_ID_FILE = RAPID_FOLDER + File.separator + "cloneId"; 76 | public static final String FACE_PICTURE_FOLDER = RAPID_FOLDER + File.separator + "faceDetection"; 77 | // Memory space problem for amazon clones 78 | public static final String FACE_PICTURE_FOLDER_CLONE = "/system/etc/faceDetection/"; 79 | public static final String FACE_PICTURE_TEST = RAPID_FOLDER + "/faceDetection/test.jpg"; 80 | 81 | public static final String VIRUS_DB_PATH = RAPID_FOLDER + File.separator + "virusDB"; 82 | public static final String VIRUS_FOLDER_TO_SCAN = 83 | RAPID_FOLDER + File.separator + "virusFolderToScan_big"; 84 | public static final String VIRUS_FILES_EXCLUDE_ZIP = 85 | RAPID_FOLDER + File.separator + "filesExcludeZip.txt"; 86 | public static final String VIRUS_FOLDER_TAR_GZ = VIRUS_FOLDER_TO_SCAN + ".tar.gz"; 87 | public static final String VIRUS_FOLDER_ZIP = VIRUS_FOLDER_TO_SCAN + ".zip"; 88 | 89 | // The constants of the configuration files 90 | public static final String DEMO_SERVER_IP = "[DEMO SERVER IP]"; 91 | public static final String DEMO_SERVER_PORT = "[DEMO SERVER PORT]"; 92 | public static final String DS_IP = "[DS IP]"; 93 | public static final String DS_PORT = "[DS PORT]"; 94 | public static final String MANAGER_IP = "[MANAGER IP]"; 95 | public static final String MANAGER_PORT = "[MANAGER PORT]"; 96 | public static final String CLONE_TYPES = "[CLONE TYPES]"; // Type has to be one of: Local, Amazon, 97 | // or Hybrid 98 | public static final String NR_CLONES_KVM_TO_START = "[NUMBER OF KVM CLONES TO START ON STARTUP]"; 99 | public static final String NR_CLONES_VB_TO_START = "[NUMBER OF VB CLONES TO START ON STARTUP]"; 100 | public static final String NR_CLONES_AMAZON_TO_START = 101 | "[NUMBER OF AMAZON CLONES TO START ON STARTUP]"; 102 | public static final String KVM_CLONES = "[KVM CLONES]"; 103 | public static final String VB_CLONES = "[VIRTUALBOX CLONES]"; 104 | public static final String AMAZON_CLONES = "[AMAZON CLONES]"; 105 | public static final String CLONE_PORT = "[CLONE PORT]"; 106 | public static final String CLONE_SSL_PORT = "[CLONE SSL PORT]"; 107 | public static final String CLONE_BW_TEST_PORT = "[CLONE BW TEST PORT]"; 108 | public static final String CLONE_NAME = "[CLONE NAME]"; 109 | public static final String CLONE_ID = "[CLONE ID]"; 110 | 111 | public static final int D2D_BROADCAST_PORT = 7654; 112 | public static final int D2D_BROADCAST_INTERVAL = 60 * 1000; // frequency (ms) to broadcast the 113 | // hello message 114 | 115 | public static final String MANAGER_CONFIG_FILE = "config-manager.cfg"; 116 | public static final String DS_CONFIG_FILE = "config-ds.cfg"; 117 | } 118 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/ac/utils/ZipHandler.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | *******************************************************************************/ 18 | package eu.project.rapid.ac.utils; 19 | 20 | import java.io.BufferedInputStream; 21 | import java.io.BufferedOutputStream; 22 | import java.io.ByteArrayInputStream; 23 | import java.io.ByteArrayOutputStream; 24 | import java.io.File; 25 | import java.io.FileInputStream; 26 | import java.io.FileOutputStream; 27 | import java.io.IOException; 28 | import java.util.Enumeration; 29 | import java.util.zip.ZipEntry; 30 | import java.util.zip.ZipException; 31 | import java.util.zip.ZipFile; 32 | import java.util.zip.ZipInputStream; 33 | import java.util.zip.ZipOutputStream; 34 | 35 | import android.util.Log; 36 | 37 | /** 38 | * Utility class used to handle zip folders. 39 | */ 40 | public class ZipHandler { 41 | 42 | static public void zipFolder(String srcFolder, String destZipFile, int start, int end) 43 | throws Exception { 44 | FileOutputStream fileWriter = new FileOutputStream(destZipFile); 45 | ZipOutputStream zip = new ZipOutputStream(fileWriter); 46 | 47 | addFolderToZip("", srcFolder, zip, start, end); 48 | zip.flush(); 49 | zip.close(); 50 | } 51 | 52 | static public byte[] zipFolder(ByteArrayOutputStream baos, String srcFolder, int start, int end) 53 | throws Exception { 54 | // ByteArrayOutputStream baos = new ByteArrayOutputStream(); 55 | ZipOutputStream zip = new ZipOutputStream(baos); 56 | 57 | addFolderToZip("", srcFolder, zip, start, end); 58 | zip.flush(); 59 | zip.close(); 60 | 61 | return baos.toByteArray(); 62 | } 63 | 64 | static private void addFileToZip(String path, String srcFile, ZipOutputStream zip) 65 | throws Exception { 66 | 67 | File folder = new File(srcFile); 68 | if (folder.isDirectory()) { 69 | addFolderToZip(path, srcFile, zip, -1, -1); 70 | } else { 71 | byte[] buf = new byte[1024]; 72 | int len; 73 | FileInputStream in = new FileInputStream(srcFile); 74 | zip.putNextEntry(new ZipEntry(path + "/" + folder.getName())); 75 | while ((len = in.read(buf)) > 0) { 76 | zip.write(buf, 0, len); 77 | } 78 | in.close(); 79 | } 80 | } 81 | 82 | static private void addFolderToZip(String path, String srcFolder, ZipOutputStream zip, int start, 83 | int end) throws Exception { 84 | File folder = new File(srcFolder); 85 | 86 | System.out.println("Start: " + start + ", End: " + end); 87 | 88 | for (String fileName : folder.list()) { 89 | 90 | if (Integer.parseInt(fileName) < start || Integer.parseInt(fileName) > end) 91 | continue; 92 | 93 | if (path.equals("")) { 94 | addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip); 95 | } else { 96 | addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip); 97 | } 98 | } 99 | } 100 | 101 | static public String extractBytes(byte[] zipBytes) { 102 | 103 | Log.i("ZipHandler", "Extracting files in: " + Constants.MNT_SDCARD); 104 | 105 | String destParent = null; 106 | try { 107 | ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(zipBytes)); 108 | 109 | ZipEntry entry = null; 110 | while ((entry = zipStream.getNextEntry()) != null) { 111 | String currentEntry = Constants.MNT_SDCARD + entry.getName(); 112 | File destFile = new File(currentEntry); 113 | destParent = destFile.getParent(); 114 | 115 | new File(destParent).mkdirs(); 116 | Log.i("ZipHandler", "Creating file: " + currentEntry); 117 | FileOutputStream out = new FileOutputStream(currentEntry); 118 | byte[] buf = new byte[4096]; 119 | int bytesRead = 0; 120 | while ((bytesRead = zipStream.read(buf)) != -1) { 121 | out.write(buf, 0, bytesRead); 122 | } 123 | out.close(); 124 | zipStream.closeEntry(); 125 | } 126 | 127 | // TODO: this should work only if there are not subfolders 128 | return destParent; 129 | 130 | } catch (ZipException e) { 131 | // TODO Auto-generated catch block 132 | e.printStackTrace(); 133 | } catch (IOException e) { 134 | // TODO Auto-generated catch block 135 | e.printStackTrace(); 136 | } 137 | return null; 138 | } 139 | 140 | static public void extractFolder(String zipFile) throws ZipException, IOException { 141 | System.out.println(zipFile); 142 | 143 | ZipFile zip = new ZipFile(new File(zipFile)); 144 | String newPath = zipFile.substring(0, zipFile.length() - ".zip".length()); 145 | 146 | new File(newPath).mkdir(); 147 | Enumeration zipFileEntries = zip.entries(); 148 | 149 | // Process each entry 150 | while (zipFileEntries.hasMoreElements()) { 151 | // grab a zip file entry 152 | ZipEntry entry = (ZipEntry) zipFileEntries.nextElement(); 153 | String currentEntry = entry.getName(); 154 | 155 | File destFile = new File(newPath, currentEntry.substring(currentEntry.indexOf("/") + 1)); 156 | File destinationParent = destFile.getParentFile(); 157 | 158 | // create the parent directory structure if needed 159 | destinationParent.mkdirs(); 160 | 161 | if (!entry.isDirectory()) { 162 | extractZipEntry(zip, entry, destFile); 163 | } 164 | 165 | if (currentEntry.endsWith(".zip")) { 166 | // found a zip file, try to open 167 | extractFolder(destFile.getAbsolutePath()); 168 | } 169 | } 170 | } 171 | 172 | static void extractZipEntry(ZipFile zip, ZipEntry entry, File destFile) { 173 | 174 | // System.out.println("Extracting: " + destFile.getAbsolutePath()); 175 | 176 | int BUFFER = 2048; 177 | BufferedInputStream is; 178 | try { 179 | is = new BufferedInputStream(zip.getInputStream(entry)); 180 | int currentByte; 181 | // establish buffer for writing file 182 | byte data[] = new byte[BUFFER]; 183 | 184 | // write the current file to disk 185 | FileOutputStream fos = new FileOutputStream(destFile); 186 | BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER); 187 | 188 | // read and write until last byte is encountered 189 | while ((currentByte = is.read(data, 0, BUFFER)) != -1) { 190 | dest.write(data, 0, currentByte); 191 | } 192 | dest.flush(); 193 | dest.close(); 194 | is.close(); 195 | } catch (IOException e) { 196 | // TODO Auto-generated catch block 197 | e.printStackTrace(); 198 | } 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/gvirtusfe/Buffer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. To change this 3 | * template file, choose Tools | Templates and open the template in the editor. 4 | */ 5 | package eu.project.rapid.gvirtusfe; 6 | 7 | import eu.project.rapid.ac.utils.Utils; 8 | 9 | /** 10 | * 11 | * @author cferraro 12 | */ 13 | public class Buffer { 14 | 15 | String mpBuffer; 16 | int mLenght; 17 | int mBackOffset; 18 | int mOffset; 19 | 20 | public Buffer() { 21 | mpBuffer = ""; 22 | mLenght = 0; 23 | mBackOffset = 0; 24 | mOffset = 0; 25 | } 26 | 27 | 28 | 29 | public void AddPointerNull() { 30 | byte[] bites = {(byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0}; 31 | // Sokol: DatatypeConverter does not exist in Android. 32 | // mpBuffer += javax.xml.bind.DatatypeConverter.printHexBinary(bites); 33 | mpBuffer += Utils.bytesToHex(bites); 34 | mLenght += Long.SIZE / 8; 35 | mBackOffset = mLenght; 36 | } 37 | 38 | public void Add(int item) { 39 | byte[] bites = 40 | {(byte) item, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0}; 41 | mpBuffer += Utils.bytesToHex(bites); 42 | mLenght += Integer.SIZE / 8; 43 | mBackOffset = mLenght; 44 | } 45 | 46 | public void Add(long item) { 47 | byte[] bites = 48 | {(byte) item, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0}; 49 | mpBuffer += Utils.bytesToHex(bites); 50 | mLenght += Long.SIZE / 8; 51 | mBackOffset = mLenght; 52 | } 53 | 54 | public void Add(String item) { 55 | // Sokol 56 | // byte[] bites = DatatypeConverter.parseHexBinary(item); 57 | byte[] bites = Utils.hexToBytes(item); 58 | mpBuffer += Utils.bytesToHex(bites); 59 | mLenght += bites.length; 60 | mBackOffset = mLenght; 61 | } 62 | 63 | public void Add(float[] item) { 64 | // byte bites[] = new byte[item.length*4]; 65 | for (int i = 0; i < item.length; i++) { 66 | String s = String.format("%8s", Integer.toHexString(Float.floatToRawIntBits(item[i]))) 67 | .replace(' ', '0'); 68 | StringBuilder out2 = new StringBuilder(); 69 | String ss = ""; 70 | for (int j = s.length() - 1; j > 0; j -= 2) { 71 | String str = s.substring(j - 1, j + 1); 72 | out2.append(str); 73 | ss = out2.toString(); 74 | } 75 | mpBuffer += ss; 76 | } 77 | // mpBuffer+=Utils.bytesToHex(bites); 78 | mLenght += Long.SIZE / 8 * item.length; 79 | mBackOffset = mLenght; 80 | } 81 | 82 | public void Add(int[] item) { 83 | // byte bites[] = new byte[item.length*4]; 84 | Add(item.length * 4); 85 | 86 | 87 | for (int i = 0; i < item.length; i++) { 88 | AddInt(item[i]); 89 | } 90 | mLenght += Integer.SIZE / 8 * item.length; 91 | mBackOffset = mLenght; 92 | } 93 | 94 | public void AddInt(int item) { 95 | byte[] bites = {(byte) item, (byte) 0, (byte) 0, (byte) 0}; 96 | mpBuffer += Utils.bytesToHex(bites); 97 | mLenght += Integer.SIZE / 8; 98 | mBackOffset = mLenght; 99 | } 100 | 101 | public void AddPointer(int item) { 102 | byte[] bites = {(byte) item, (byte) 0, (byte) 0, (byte) 0}; 103 | int size = (Integer.SIZE / 8); 104 | this.Add(size); 105 | mpBuffer += Utils.bytesToHex(bites); 106 | mLenght += size; 107 | mBackOffset = mLenght; 108 | } 109 | 110 | public String GetString() { 111 | return mpBuffer; 112 | } 113 | 114 | public long Size() { 115 | return mpBuffer.length(); 116 | } 117 | 118 | void AddStruct(CudaRt_device.cudaDeviceProp struct) { 119 | byte[] bites = new byte[640]; 120 | bites[0] = (byte) 0x78; 121 | bites[1] = (byte) 0x02; 122 | for (int i = 2; i < 640; i++) { 123 | bites[i] = (byte) 0; 124 | 125 | } 126 | mpBuffer += Utils.bytesToHex(bites); 127 | mLenght += bites.length; 128 | mBackOffset = mLenght; 129 | 130 | 131 | } 132 | 133 | void AddByte(int i) { 134 | byte[] bites = new byte[1]; 135 | bites[0] = (byte) i; 136 | mpBuffer += Utils.bytesToHex(bites); 137 | mLenght += bites.length; 138 | mBackOffset = mLenght; 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/gvirtusfe/CudaDr_context.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. To change this 3 | * template file, choose Tools | Templates and open the template in the editor. 4 | */ 5 | package eu.project.rapid.gvirtusfe; 6 | 7 | import java.io.IOException; 8 | 9 | import eu.project.rapid.ac.utils.Utils; 10 | 11 | /** 12 | * 13 | * @author cferraro 14 | */ 15 | public class CudaDr_context { 16 | 17 | public CudaDr_context() {} 18 | 19 | public String cuCtxCreate(Frontend fe, Result res, int flags, int dev) throws IOException { 20 | 21 | Buffer b = new Buffer(); 22 | b.AddInt(flags); 23 | b.AddInt(dev); 24 | String outbuffer = ""; 25 | fe.Execute("cuCtxCreate", b, res); 26 | return getHex(res, 8); 27 | } 28 | 29 | public int cuCtxDestroy(Frontend fe, Result res, String ctx) throws IOException { 30 | 31 | Buffer b = new Buffer(); 32 | b.Add(ctx); 33 | fe.Execute("cuCtxDestroy", b, res); 34 | return 0; 35 | } 36 | 37 | 38 | 39 | private String getHex(Result res, int size) throws IOException { 40 | 41 | byte[] array = new byte[size]; 42 | for (int i = 0; i < size; i++) { 43 | byte bit = res.getInput_stream().readByte(); 44 | array[i] = bit; 45 | } 46 | // Sokol 47 | // String hex = DatatypeConverter.printHexBinary(array); 48 | String hex = Utils.bytesToHex(array); 49 | return hex; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/gvirtusfe/CudaDr_device.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. To change this 3 | * template file, choose Tools | Templates and open the template in the editor. 4 | */ 5 | package eu.project.rapid.gvirtusfe; 6 | 7 | import java.io.IOException; 8 | 9 | /** 10 | * 11 | * @author cferraro 12 | */ 13 | public class CudaDr_device { 14 | 15 | public CudaDr_device() {} 16 | 17 | public int cuDeviceGet(Frontend fe, Result res, int devID) throws IOException { 18 | 19 | Buffer b = new Buffer(); 20 | b.AddPointer(0); 21 | b.AddInt(devID); 22 | String outputbuffer = ""; 23 | StringBuilder output = new StringBuilder(); 24 | fe.Execute("cuDeviceGet", b, res); 25 | int sizeType = res.getInput_stream().readByte(); 26 | for (int i = 0; i < 7; i++) 27 | res.getInput_stream().readByte(); 28 | for (int i = 0; i < sizeType; i++) { 29 | if (i == 0 || i == 1) { 30 | byte bb = res.getInput_stream().readByte(); 31 | outputbuffer += Integer.toHexString(bb & 0xFF); 32 | } else 33 | res.getInput_stream().readByte(); 34 | } 35 | StringBuilder out2 = new StringBuilder(); 36 | if (outputbuffer.length() > 2) { 37 | for (int i = 0; i < outputbuffer.length() - 1; i += 2) { 38 | String str = outputbuffer.substring(i, i + 2); 39 | out2.insert(0, str); 40 | } 41 | outputbuffer = String.valueOf(Integer.parseInt(out2.toString(), 16)); 42 | } 43 | return Integer.valueOf(outputbuffer); 44 | 45 | } 46 | 47 | 48 | public String cuDeviceGetName(Frontend fe, Result res, int len, int dev) throws IOException { 49 | 50 | Buffer b = new Buffer(); 51 | b.AddByte(1); 52 | for (int i = 0; i < 8; i++) 53 | b.AddByte(0); 54 | b.AddByte(1); 55 | for (int i = 0; i < 7; i++) 56 | b.AddByte(0); 57 | b.AddInt(len); 58 | b.AddInt(dev); 59 | 60 | 61 | String outbuffer = ""; 62 | StringBuilder output = new StringBuilder(); 63 | fe.Execute("cuDeviceGetName", b, res); 64 | int sizeType = res.getInput_stream().readByte(); 65 | 66 | for (int i = 0; i < 7; i++) 67 | res.getInput_stream().readByte(); 68 | res.getInput_stream().readByte(); 69 | 70 | for (int i = 0; i < 7; i++) 71 | res.getInput_stream().readByte(); 72 | 73 | 74 | for (int i = 0; i < sizeType; i++) { 75 | byte bit = res.getInput_stream().readByte(); 76 | outbuffer += Integer.toHexString(bit); 77 | } 78 | for (int i = 0; i < outbuffer.length() - 1; i += 2) { 79 | String str = outbuffer.substring(i, i + 2); 80 | output.append((char) Integer.parseInt(str, 16)); 81 | 82 | } 83 | return output.toString(); 84 | 85 | } 86 | 87 | 88 | public int cuDeviceGetCount(Frontend fe, Result res) throws IOException { 89 | 90 | Buffer b = new Buffer(); 91 | b.AddPointer(0); 92 | String outputbuffer = ""; 93 | fe.Execute("cuDeviceGetCount", b, res); 94 | int sizeType = res.getInput_stream().readByte(); 95 | for (int i = 0; i < 7; i++) 96 | res.getInput_stream().readByte(); 97 | for (int i = 0; i < sizeType; i++) { 98 | if (i == 0) { 99 | byte bb = res.getInput_stream().readByte(); 100 | outputbuffer += Integer.toHexString(bb & 0xFF); 101 | } else 102 | res.getInput_stream().readByte(); 103 | } 104 | StringBuilder out2 = new StringBuilder(); 105 | if (outputbuffer.length() > 2) { 106 | for (int i = 0; i < outputbuffer.length() - 1; i += 2) { 107 | String str = outputbuffer.substring(i, i + 2); 108 | out2.insert(0, str); 109 | } 110 | outputbuffer = String.valueOf(Integer.parseInt(out2.toString(), 16)); 111 | } 112 | 113 | return Integer.valueOf(outputbuffer); 114 | 115 | } 116 | 117 | public int[] cuDeviceComputeCapability(Frontend fe, Result res, int device) throws IOException { 118 | 119 | Buffer b = new Buffer(); 120 | b.AddPointer(0); 121 | b.AddPointer(0); 122 | b.AddInt(device); 123 | String outputbuffer = ""; 124 | fe.Execute("cuDeviceComputeCapability", b, res); 125 | int sizeType = res.getInput_stream().readByte(); 126 | for (int i = 0; i < 7; i++) 127 | res.getInput_stream().readByte(); 128 | for (int i = 0; i < sizeType; i++) { 129 | if (i == 0) { 130 | byte bb = res.getInput_stream().readByte(); 131 | outputbuffer += Integer.toHexString(bb & 0xFF); 132 | } else 133 | res.getInput_stream().readByte(); 134 | } 135 | StringBuilder out2 = new StringBuilder(); 136 | if (outputbuffer.length() > 2) { 137 | for (int i = 0; i < outputbuffer.length() - 1; i += 2) { 138 | String str = outputbuffer.substring(i, i + 2); 139 | out2.insert(0, str); 140 | } 141 | outputbuffer = String.valueOf(Integer.parseInt(out2.toString(), 16)); 142 | } 143 | 144 | int[] majorminor = new int[2]; 145 | 146 | majorminor[0] = Integer.valueOf(outputbuffer); 147 | outputbuffer = ""; 148 | sizeType = res.getInput_stream().readByte(); 149 | for (int i = 0; i < 7; i++) 150 | res.getInput_stream().readByte(); 151 | for (int i = 0; i < sizeType; i++) { 152 | if (i == 0) { 153 | byte bb = res.getInput_stream().readByte(); 154 | outputbuffer += Integer.toHexString(bb & 0xFF); 155 | } else 156 | res.getInput_stream().readByte(); 157 | } 158 | StringBuilder out3 = new StringBuilder(); 159 | if (outputbuffer.length() > 2) { 160 | for (int i = 0; i < outputbuffer.length() - 1; i += 2) { 161 | String str = outputbuffer.substring(i, i + 2); 162 | out3.insert(0, str); 163 | } 164 | outputbuffer = String.valueOf(Integer.parseInt(out3.toString(), 16)); 165 | } 166 | majorminor[1] = Integer.valueOf(outputbuffer); 167 | return majorminor; 168 | 169 | } 170 | 171 | public int cuDeviceGetAttribute(Frontend fe, Result res, int attribute, int device) 172 | throws IOException { 173 | Buffer b = new Buffer(); 174 | b.AddPointer(0); 175 | b.AddInt(attribute); 176 | b.AddInt(device); 177 | String outputbuffer = ""; 178 | fe.Execute("cuDeviceGetAttribute", b, res); 179 | int sizeType = res.getInput_stream().readByte(); 180 | for (int i = 0; i < 7; i++) 181 | res.getInput_stream().readByte(); 182 | for (int i = 0; i < sizeType; i++) { 183 | if (i == 0) { 184 | byte bb = res.getInput_stream().readByte(); 185 | outputbuffer += Integer.toHexString(bb & 0xFF); 186 | } else 187 | res.getInput_stream().readByte(); 188 | } 189 | StringBuilder out2 = new StringBuilder(); 190 | if (outputbuffer.length() > 2) { 191 | for (int i = 0; i < outputbuffer.length() - 1; i += 2) { 192 | String str = outputbuffer.substring(i, i + 2); 193 | out2.insert(0, str); 194 | } 195 | outputbuffer = String.valueOf(Integer.parseInt(out2.toString(), 16)); 196 | } 197 | 198 | return Integer.valueOf(outputbuffer); 199 | 200 | } 201 | 202 | public long cuDeviceTotalMem(Frontend fe, Result res, int dev) throws IOException { 203 | 204 | Buffer b = new Buffer(); 205 | b.AddByte(8); 206 | for (int i = 0; i < 16; i++) 207 | b.AddByte(0); 208 | b.AddInt(dev); 209 | fe.Execute("cuDeviceTotalMem", b, res); 210 | for (int i = 0; i < 8; i++) 211 | res.getInput_stream().readByte(); 212 | long x = getLong(res); 213 | return x; 214 | 215 | } 216 | 217 | private long getLong(Result res) throws IOException { 218 | 219 | StringBuilder output = new StringBuilder(); 220 | for (int i = 0; i < 8; i++) { 221 | byte bit = res.getInput_stream().readByte(); 222 | int a = bit & 0xFF; 223 | if (a == 0) { 224 | output.insert(0, Integer.toHexString(a)); 225 | output.insert(0, Integer.toHexString(a)); 226 | } else { 227 | output.insert(0, Integer.toHexString(a)); 228 | } 229 | } 230 | return Long.parseLong(output.toString(), 16); 231 | } 232 | } 233 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/gvirtusfe/CudaDr_execution.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. To change this 3 | * template file, choose Tools | Templates and open the template in the editor. 4 | */ 5 | package eu.project.rapid.gvirtusfe; 6 | 7 | import java.io.IOException; 8 | 9 | /** 10 | * 11 | * @author cferraro 12 | */ 13 | public class CudaDr_execution { 14 | 15 | public CudaDr_execution() {} 16 | 17 | public void cuParamSetv(Frontend fe, Result res, String hfunc, int offset, String ptr, 18 | int numbytes) throws IOException { 19 | 20 | Buffer b = new Buffer(); 21 | b.AddInt(offset); 22 | b.AddInt(numbytes); 23 | long sizeofp = 8; 24 | b.Add(sizeofp); 25 | b.Add(ptr); 26 | b.Add(hfunc); 27 | fe.Execute("cuParamSetv", b, res); 28 | 29 | } 30 | 31 | public void cuParamSeti(Frontend FE, Result res, String hfunc, int offset, int value) 32 | throws IOException { 33 | 34 | Buffer b = new Buffer(); 35 | b.AddInt(offset); 36 | b.AddInt(value); 37 | b.Add(hfunc); 38 | FE.Execute("cuParamSeti", b, res); 39 | } 40 | 41 | public void cuParamSetSize(Frontend FE, Result res, String hfunc, int numbytes) 42 | throws IOException { 43 | 44 | Buffer b = new Buffer(); 45 | b.AddInt(numbytes); 46 | b.Add(hfunc); 47 | FE.Execute("cuParamSetSize", b, res); 48 | } 49 | 50 | public void cuFuncSetBlockShape(Frontend FE, Result res, String hfunc, int x, int y, int z) 51 | throws IOException { 52 | 53 | Buffer b = new Buffer(); 54 | b.AddInt(x); 55 | b.AddInt(y); 56 | b.AddInt(z); 57 | b.Add(hfunc); 58 | FE.Execute("cuFuncSetBlockShape", b, res); 59 | } 60 | 61 | public void cuFuncSetSharedSize(Frontend FE, Result res, String hfunc, int bytes) 62 | throws IOException { 63 | 64 | Buffer b = new Buffer(); 65 | byte[] bits = this.intToByteArray(bytes); 66 | for (int i = 0; i < bits.length; i++) { 67 | b.AddByte(bits[i] & 0xFF); 68 | } 69 | b.Add(hfunc); 70 | FE.Execute("cuFuncSetSharedSize", b, res); 71 | } 72 | 73 | public void cuLaunchGrid(Frontend FE, Result res, String hfunc, int grid_width, int grid_height) 74 | throws IOException { 75 | 76 | Buffer b = new Buffer(); 77 | b.AddInt(grid_width); 78 | b.AddInt(grid_height); 79 | b.Add(hfunc); 80 | FE.Execute("cuLaunchGrid", b, res); 81 | } 82 | 83 | public byte[] intToByteArray(int value) { 84 | return new byte[] {(byte) value, (byte) (value >> 8), (byte) (value >> 16), 85 | (byte) (value >> 24)}; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/gvirtusfe/CudaDr_initialization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. To change this 3 | * template file, choose Tools | Templates and open the template in the editor. 4 | */ 5 | package eu.project.rapid.gvirtusfe; 6 | 7 | import java.io.IOException; 8 | 9 | /** 10 | * 11 | * @author cferraro 12 | */ 13 | public class CudaDr_initialization { 14 | 15 | public CudaDr_initialization() {} 16 | 17 | public int cuInit(Frontend fe, Result res, int flags) throws IOException { 18 | Buffer b = new Buffer(); 19 | b.AddInt(flags); 20 | fe.Execute("cuInit", b, res); 21 | return 0; 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/gvirtusfe/CudaDr_memory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. To change this 3 | * template file, choose Tools | Templates and open the template in the editor. 4 | */ 5 | package eu.project.rapid.gvirtusfe; 6 | 7 | import java.io.IOException; 8 | 9 | import eu.project.rapid.ac.utils.Utils; 10 | 11 | /** 12 | * 13 | * @author cferraro 14 | */ 15 | public class CudaDr_memory { 16 | 17 | public CudaDr_memory() {} 18 | 19 | public String cuMemAlloc(Frontend fe, Result res, long size) throws IOException { 20 | 21 | Buffer b = new Buffer(); 22 | byte[] bits = this.longToByteArray(size); 23 | for (int i = 0; i < bits.length; i++) { 24 | b.AddByte(bits[i] & 0xFF); 25 | } 26 | String pointer = ""; 27 | fe.Execute("cuMemAlloc", b, res); 28 | pointer = getHex(res, 8); 29 | return pointer; 30 | } 31 | 32 | 33 | private String getHex(Result res, int size) throws IOException { 34 | 35 | byte[] array = new byte[size]; 36 | for (int i = 0; i < size; i++) { 37 | byte bit = res.getInput_stream().readByte(); 38 | array[i] = bit; 39 | } 40 | // String hex = DatatypeConverter.printHexBinary(array); 41 | String hex = Utils.bytesToHex(array); 42 | return hex; 43 | } 44 | 45 | 46 | public void cuMemcpyHtoD(Frontend fe, Result res, String dst, float[] src, int count) 47 | throws IOException { 48 | 49 | Buffer b = new Buffer(); 50 | byte[] bits = this.longToByteArray(count); 51 | for (int i = 0; i < bits.length; i++) { 52 | b.AddByte(bits[i] & 0xFF); 53 | } 54 | b.Add(dst); 55 | for (int i = 0; i < bits.length; i++) { 56 | b.AddByte(bits[i] & 0xFF); 57 | } 58 | b.Add(src); 59 | fe.Execute("cuMemcpyHtoD", b, res); 60 | 61 | } 62 | 63 | 64 | public float[] cuMemcpyDtoH(Frontend fe, Result res, String srcDevice, long ByteCount) 65 | throws IOException { 66 | 67 | Buffer b = new Buffer(); 68 | b.Add(srcDevice); 69 | 70 | byte[] bits = this.longToByteArray(ByteCount); 71 | for (int i = 0; i < bits.length; i++) { 72 | b.AddByte(bits[i] & 0xFF); 73 | } 74 | fe.Execute("cuMemcpyDtoH", b, res); 75 | for (int i = 0; i <= 7; i++) { 76 | byte bb = res.getInput_stream().readByte(); 77 | } 78 | int sizeType = 98304; 79 | float[] result = new float[sizeType / 4]; 80 | for (int i = 0; i < sizeType / 4; i++) { 81 | result[i] = getFloat(res); 82 | } 83 | 84 | return result; 85 | 86 | } 87 | 88 | public void cuMemFree(Frontend fe, Result res, String ptr) throws IOException { 89 | Buffer b = new Buffer(); 90 | b.Add(ptr); 91 | fe.Execute("cuMemFree", b, res); 92 | 93 | } 94 | 95 | 96 | private float getFloat(Result res) throws IOException { 97 | 98 | byte bytes[] = new byte[4]; 99 | for (int i = 3; i >= 0; i--) { 100 | bytes[i] = res.getInput_stream().readByte(); 101 | } 102 | // Sokol 103 | // String output = javax.xml.bind.DatatypeConverter.printHexBinary(bytes); 104 | String output = Utils.bytesToHex(bytes); 105 | Long i = Long.parseLong(output, 16); 106 | Float f = Float.intBitsToFloat(i.intValue()); 107 | return f; 108 | } 109 | 110 | public byte[] longToByteArray(long value) { 111 | return new byte[] {(byte) value, (byte) (value >> 8), (byte) (value >> 16), 112 | (byte) (value >> 24), (byte) (value >> 32), (byte) (value >> 40), (byte) (value >> 48), 113 | (byte) (value >> 56) 114 | 115 | }; 116 | } 117 | 118 | 119 | } 120 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/gvirtusfe/CudaDr_module.java: -------------------------------------------------------------------------------- 1 | package eu.project.rapid.gvirtusfe; 2 | 3 | import java.io.IOException; 4 | 5 | import eu.project.rapid.ac.utils.Utils; 6 | 7 | 8 | /** 9 | * 10 | * @author cferraro 11 | */ 12 | public class CudaDr_module { 13 | 14 | public CudaDr_module() {} 15 | 16 | public String cuModuleGetFunction(Frontend FE, Result res, String cmodule, String str) 17 | throws IOException { 18 | 19 | Buffer b = new Buffer(); 20 | str = str + "\0"; 21 | long size = str.length(); 22 | byte[] bits = this.longToByteArray(size); 23 | 24 | for (int i = 0; i < bits.length; i++) { 25 | b.AddByte(bits[i] & 0xFF); 26 | } 27 | for (int i = 0; i < bits.length; i++) { 28 | b.AddByte(bits[i] & 0xFF); 29 | } 30 | for (int i = 0; i < size; i++) { 31 | b.AddByte(str.charAt(i)); 32 | } 33 | 34 | b.Add(cmodule); 35 | 36 | FE.Execute("cuModuleGetFunction", b, res); 37 | String pointer = ""; 38 | pointer = getHex(res, 8); 39 | for (int i = 0; i < res.getSizebuffer() - 8; i++) { 40 | res.getInput_stream().readByte(); 41 | } 42 | 43 | return pointer; 44 | 45 | } 46 | 47 | public String cuModuleLoadDataEx(Frontend FE, Result res, String ptxSource, int jitNumOptions, 48 | int[] jitOptions, long jitOptVals0, char[] jitOptVals1, long jitOptVals2) throws IOException { 49 | Buffer b = new Buffer(); 50 | b.AddInt(jitNumOptions); 51 | b.Add(jitOptions); 52 | // addStringForArgument 53 | ptxSource = ptxSource + "\0"; 54 | long sizePtxSource = ptxSource.length(); 55 | long size = sizePtxSource; 56 | byte[] bits = this.longToByteArray(size); 57 | 58 | for (int i = 0; i < bits.length; i++) { 59 | b.AddByte(bits[i] & 0xFF); 60 | } 61 | for (int i = 0; i < bits.length; i++) { 62 | b.AddByte(bits[i] & 0xFF); 63 | } 64 | for (int i = 0; i < sizePtxSource; i++) 65 | b.AddByte(ptxSource.charAt(i)); 66 | b.Add(8); 67 | long OptVals0 = jitOptVals0; 68 | byte[] bit = this.longToByteArray(OptVals0); 69 | for (int i = 0; i < bit.length; i++) { 70 | b.AddByte(bit[i] & 0xFF); 71 | } 72 | b.Add(8); 73 | b.AddByte(160); 74 | b.AddByte(159); 75 | b.AddByte(236); 76 | b.AddByte(1); 77 | b.AddByte(0); 78 | b.AddByte(0); 79 | b.AddByte(0); 80 | b.AddByte(0); 81 | 82 | b.Add(8); 83 | long OptVals2 = jitOptVals2; 84 | byte[] bit2 = this.longToByteArray(OptVals2); 85 | for (int i = 0; i < bit.length; i++) { 86 | b.AddByte(bit2[i] & 0xFF); 87 | } 88 | 89 | FE.Execute("cuModuleLoadDataEx", b, res); 90 | String pointer = ""; 91 | pointer = getHex(res, 8); 92 | for (int i = 0; i < res.getSizebuffer() - 8; i++) 93 | res.getInput_stream().readByte(); 94 | 95 | return pointer; 96 | } 97 | 98 | 99 | private String getHex(Result res, int size) throws IOException { 100 | 101 | byte[] array = new byte[size]; 102 | for (int i = 0; i < size; i++) { 103 | byte bit = res.getInput_stream().readByte(); 104 | array[i] = bit; 105 | } 106 | // Sokol 107 | // String hex = DatatypeConverter.printHexBinary(array); 108 | String hex = Utils.bytesToHex(array); 109 | return hex; 110 | } 111 | 112 | public byte[] longToByteArray(long value) { 113 | return new byte[] {(byte) value, (byte) (value >> 8), (byte) (value >> 16), 114 | (byte) (value >> 24), (byte) (value >> 32), (byte) (value >> 40), (byte) (value >> 48), 115 | (byte) (value >> 56) 116 | 117 | }; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/gvirtusfe/CudaRt_memory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. To change this 3 | * template file, choose Tools | Templates and open the template in the editor. 4 | */ 5 | package eu.project.rapid.gvirtusfe; 6 | 7 | import java.io.IOException; 8 | 9 | import eu.project.rapid.ac.utils.Utils; 10 | 11 | /** 12 | * 13 | * @author cferraro 14 | */ 15 | public class CudaRt_memory { 16 | 17 | public CudaRt_memory() {} 18 | 19 | 20 | 21 | public String cudaMalloc(Frontend fe, Result res, long size) throws IOException { 22 | 23 | Buffer b = new Buffer(); 24 | b.Add((int) size); 25 | String pointer = ""; 26 | fe.Execute("cudaMalloc", b, res); 27 | pointer = getHex(res, 8); 28 | return pointer; 29 | } 30 | 31 | public void cudaMemcpy(Frontend fe, Result res, String dst, float[] src, int count, int kind) 32 | throws IOException { 33 | 34 | Buffer b = new Buffer(); 35 | b.Add(dst); 36 | b.Add(count * 4); 37 | b.Add(src); 38 | b.Add(count * 4); 39 | b.AddInt(kind); 40 | fe.Execute("cudaMemcpy", b, res); 41 | 42 | 43 | } 44 | 45 | 46 | private String getHex(Result res, int size) throws IOException { 47 | 48 | byte[] array = new byte[size]; 49 | for (int i = 0; i < size; i++) { 50 | byte bit = res.getInput_stream().readByte(); 51 | array[i] = bit; 52 | } 53 | // String hex = DatatypeConverter.printHexBinary(array); 54 | String hex = Utils.bytesToHex(array); 55 | return hex; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/gvirtusfe/Frontend.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. To change this 3 | * template file, choose Tools | Templates and open the template in the editor. 4 | */ 5 | package eu.project.rapid.gvirtusfe; 6 | 7 | import java.io.DataInputStream; 8 | import java.io.DataOutputStream; 9 | import java.io.IOException; 10 | import java.net.InetSocketAddress; 11 | import java.net.Socket; 12 | 13 | import android.util.Log; 14 | import eu.project.rapid.ac.utils.Utils; 15 | 16 | /** 17 | * 18 | * @author cferraro 19 | */ 20 | public final class Frontend { 21 | 22 | private static final String TAG = Frontend.class.getName(); 23 | 24 | String serverIpAddress; 25 | int port; 26 | Socket socket, clientSocket; 27 | DataOutputStream outputStream, clientOutputStream; 28 | DataInputStream in, clientIn; 29 | 30 | public Frontend(String url, int port) { 31 | 32 | this.serverIpAddress = url; 33 | this.port = port; 34 | try { 35 | this.socket = new Socket(); 36 | socket.connect(new InetSocketAddress(this.serverIpAddress, this.port), 10 * 1000); 37 | this.outputStream = new DataOutputStream(this.socket.getOutputStream()); 38 | this.in = new DataInputStream(this.socket.getInputStream()); 39 | } catch (IOException e) { 40 | Log.e(TAG, "Could not connect to GVirtuS backend server!" + e); 41 | } 42 | } 43 | 44 | public int Execute(String routine, Buffer input_buffer, Result res) throws IOException { 45 | 46 | for (int i = 0; i < routine.length(); i++) 47 | this.outputStream.writeByte(routine.charAt(i)); 48 | this.outputStream.writeByte(0); 49 | long size = input_buffer.Size() / 2; 50 | byte[] bits = this.longToByteArray(size); 51 | for (int i = 0; i < bits.length; i++) { 52 | this.outputStream.write(bits[i] & 0xFF); 53 | } 54 | 55 | // byte[] bytes2 = DatatypeConverter.parseHexBinary(input_buffer.GetString()); 56 | byte[] bytes2 = Utils.hexToBytes(input_buffer.GetString()); 57 | 58 | for (int i = 0; i < bytes2.length; i++) { 59 | this.outputStream.write(bytes2[i] & 0xFF); 60 | } 61 | int message = this.in.readByte(); 62 | this.in.readByte(); 63 | this.in.readByte(); 64 | this.in.readByte(); 65 | res.setExit_code(message); 66 | int sizes = (int) this.in.readByte(); 67 | res.setSizeBuffer(sizes); 68 | for (int i = 0; i < 7; i++) 69 | this.in.readByte(); 70 | res.setInput_stream(this.in); 71 | return 0; 72 | } 73 | 74 | // 75 | // public int ExecuteMultiThread(String routine,Buffer input_buffer,Result res) throws 76 | // IOException{ 77 | // 78 | // for (int i =0; i< routine.length();i++)this.outputStream.writeByte(routine.charAt(i)); 79 | // this.outputStream.writeByte(0); 80 | // this.clientSocket = new Socket(this.serverIpAddress,9998); 81 | // this.clientIn = new DataInputStream(this.clientSocket.getInputStream()); 82 | // this.clientOutputStream = new DataOutputStream(this.clientSocket.getOutputStream()); 83 | // long size = input_buffer.Size()/2; 84 | // byte[] bits = this.longToByteArray(size); 85 | // for (int i =0; i< bits.length;i++){ 86 | // this.clientOutputStream.write(bits[i] & 0xFF); 87 | // } 88 | // 89 | // byte[] bytes2 = DatatypeConverter.parseHexBinary(input_buffer.GetString()); 90 | // 91 | // for (int i =0; i< bytes2.length;i++){ 92 | // this.clientOutputStream.write(bytes2[i] & 0xFF); 93 | // } 94 | // 95 | // int message = this.clientIn.readByte(); 96 | // this.clientIn.readByte(); 97 | // this.clientIn.readByte(); 98 | // this.clientIn.readByte(); 99 | // res.setExit_code(message); 100 | // long size_buffer = this.clientIn.readByte(); 101 | // for (int i =0 ; i< 7; i++) this.clientIn.readByte(); 102 | // res.setInput_stream(this.clientIn); 103 | // return 0; 104 | // } 105 | // 106 | public void writeLong(DataOutputStream os, long l) throws IOException { 107 | os.write((byte) l); 108 | os.write((byte) (l >> 56)); 109 | os.write((byte) (l >> 48)); 110 | os.write((byte) (l >> 40)); 111 | os.write((byte) (l >> 32)); 112 | os.write((byte) (l >> 24)); 113 | os.write((byte) (l >> 16)); 114 | os.write((byte) (l >> 8)); 115 | } 116 | 117 | public void writeChar(DataOutputStream os, char l) throws IOException { 118 | os.write((byte) l); 119 | os.write((byte) (l >> 56)); 120 | os.write((byte) (l >> 48)); 121 | os.write((byte) (l >> 40)); 122 | os.write((byte) (l >> 32)); 123 | os.write((byte) (l >> 24)); 124 | os.write((byte) (l >> 16)); 125 | os.write((byte) (l >> 8)); 126 | } 127 | 128 | public char readChar(DataInputStream os) throws IOException { 129 | int x; 130 | x = os.readByte(); 131 | x = x >> 56; 132 | x = os.readByte(); 133 | x = x >> 48; 134 | x = os.readByte(); 135 | x = x >> 40; 136 | x = os.readByte(); 137 | x = x >> 32; 138 | x = os.readByte(); 139 | x = x >> 24; 140 | x = os.readByte(); 141 | x = x >> 16; 142 | x = os.readByte(); 143 | x = x >> 8; 144 | x = os.readByte(); 145 | return (char) x; 146 | 147 | } 148 | 149 | public void writeInt(DataOutputStream os, int l) throws IOException { 150 | os.write((byte) l); 151 | os.write((byte) (l >> 24)); 152 | os.write((byte) (l >> 16)); 153 | os.write((byte) (l >> 8)); 154 | } 155 | 156 | public void writeHex(DataOutputStream os, long x) throws IOException { 157 | String hex = Integer.toHexString((int) (x)); 158 | StringBuilder out2 = new StringBuilder(); 159 | int scarto = 0; 160 | if (hex.length() > 2) { 161 | for (int i = hex.length() - 1; i > 0; i -= 2) { 162 | String str = hex.substring(i - 1, i + 1); 163 | out2.insert(0, str); 164 | os.write((byte) Integer.parseInt(out2.toString(), 16)); 165 | scarto += 2; 166 | } 167 | if (scarto != hex.length()) { 168 | os.write((byte) Integer.parseInt(hex.substring(0, 1), 16)); 169 | } 170 | } 171 | os.write((byte) (0)); 172 | os.write((byte) (0)); 173 | os.write((byte) (0)); 174 | os.write((byte) (0)); 175 | os.write((byte) (0)); 176 | os.write((byte) (0)); 177 | } 178 | 179 | public byte[] longToByteArray(long value) { 180 | return new byte[] {(byte) value, (byte) (value >> 8), (byte) (value >> 16), 181 | (byte) (value >> 24), (byte) (value >> 32), (byte) (value >> 40), (byte) (value >> 48), 182 | (byte) (value >> 56) 183 | 184 | 185 | }; 186 | } 187 | 188 | } 189 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/gvirtusfe/Result.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. To change this 3 | * template file, choose Tools | Templates and open the template in the editor. 4 | */ 5 | package eu.project.rapid.gvirtusfe; 6 | 7 | import java.io.DataInputStream; 8 | 9 | /** 10 | * 11 | * @author cferraro 12 | */ 13 | public class Result { 14 | int exit_code; 15 | String output_buffer; 16 | DataInputStream input_stream; 17 | int sizebuffer; 18 | 19 | 20 | public DataInputStream getInput_stream() { 21 | return input_stream; 22 | } 23 | 24 | public void setInput_stream(DataInputStream input_stream) { 25 | this.input_stream = input_stream; 26 | } 27 | 28 | public String getOutput_buffer() { 29 | return output_buffer; 30 | } 31 | 32 | public void setOutput_buffer(String output_buffer) { 33 | this.output_buffer = output_buffer; 34 | } 35 | 36 | public Result() { 37 | this.output_buffer = ""; 38 | } 39 | 40 | public int getExit_code() { 41 | return exit_code; 42 | } 43 | 44 | public void setExit_code(int exit_code) { 45 | this.exit_code = exit_code; 46 | } 47 | 48 | void setSizeBuffer(int sizes) { 49 | this.sizebuffer = sizes; 50 | } 51 | 52 | public int getSizebuffer() { 53 | return sizebuffer; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /AccelerationClient/src/eu/project/rapid/gvirtusfe/dim3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. To change this 3 | * template file, choose Tools | Templates and open the template in the editor. 4 | */ 5 | package eu.project.rapid.gvirtusfe; 6 | 7 | /** 8 | * 9 | * @author cferraro 10 | */ 11 | public class dim3 { 12 | 13 | int x; 14 | int y; 15 | int z; 16 | 17 | public dim3(int x, int y, int z) { 18 | this.x = x; 19 | this.y = y; 20 | this.z = z; 21 | } 22 | 23 | /** 24 | * @return the x 25 | */ 26 | public int getX() { 27 | return x; 28 | } 29 | 30 | /** 31 | * @param x the x to set 32 | */ 33 | public void setX(int x) { 34 | this.x = x; 35 | } 36 | 37 | /** 38 | * @return the y 39 | */ 40 | public int getY() { 41 | return y; 42 | } 43 | 44 | /** 45 | * @param y the y to set 46 | */ 47 | public void setY(int y) { 48 | this.y = y; 49 | } 50 | 51 | /** 52 | * @return the z 53 | */ 54 | public int getZ() { 55 | return z; 56 | } 57 | 58 | /** 59 | * @param z the z to set 60 | */ 61 | public void setZ(int z) { 62 | this.z = z; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /AccelerationServer/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /AccelerationServer/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | AccelerationServer 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /AccelerationServer/.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true 3 | formatter_profile=_GoogleStyle 4 | formatter_settings_version=12 5 | sp_cleanup.add_default_serial_version_id=true 6 | sp_cleanup.add_generated_serial_version_id=false 7 | sp_cleanup.add_missing_annotations=true 8 | sp_cleanup.add_missing_deprecated_annotations=true 9 | sp_cleanup.add_missing_methods=false 10 | sp_cleanup.add_missing_nls_tags=false 11 | sp_cleanup.add_missing_override_annotations=true 12 | sp_cleanup.add_missing_override_annotations_interface_methods=true 13 | sp_cleanup.add_serial_version_id=false 14 | sp_cleanup.always_use_blocks=true 15 | sp_cleanup.always_use_parentheses_in_expressions=false 16 | sp_cleanup.always_use_this_for_non_static_field_access=false 17 | sp_cleanup.always_use_this_for_non_static_method_access=false 18 | sp_cleanup.convert_functional_interfaces=false 19 | sp_cleanup.convert_to_enhanced_for_loop=false 20 | sp_cleanup.correct_indentation=false 21 | sp_cleanup.format_source_code=true 22 | sp_cleanup.format_source_code_changes_only=false 23 | sp_cleanup.insert_inferred_type_arguments=false 24 | sp_cleanup.make_local_variable_final=true 25 | sp_cleanup.make_parameters_final=false 26 | sp_cleanup.make_private_fields_final=true 27 | sp_cleanup.make_type_abstract_if_missing_method=false 28 | sp_cleanup.make_variable_declarations_final=false 29 | sp_cleanup.never_use_blocks=false 30 | sp_cleanup.never_use_parentheses_in_expressions=true 31 | sp_cleanup.on_save_use_additional_actions=false 32 | sp_cleanup.organize_imports=true 33 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false 34 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true 35 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true 36 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false 37 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false 38 | sp_cleanup.remove_private_constructors=true 39 | sp_cleanup.remove_redundant_type_arguments=true 40 | sp_cleanup.remove_trailing_whitespaces=false 41 | sp_cleanup.remove_trailing_whitespaces_all=true 42 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false 43 | sp_cleanup.remove_unnecessary_casts=true 44 | sp_cleanup.remove_unnecessary_nls_tags=false 45 | sp_cleanup.remove_unused_imports=false 46 | sp_cleanup.remove_unused_local_variables=false 47 | sp_cleanup.remove_unused_private_fields=true 48 | sp_cleanup.remove_unused_private_members=false 49 | sp_cleanup.remove_unused_private_methods=true 50 | sp_cleanup.remove_unused_private_types=true 51 | sp_cleanup.sort_members=false 52 | sp_cleanup.sort_members_all=false 53 | sp_cleanup.use_anonymous_class_creation=false 54 | sp_cleanup.use_blocks=false 55 | sp_cleanup.use_blocks_only_for_return_and_throw=false 56 | sp_cleanup.use_lambda=true 57 | sp_cleanup.use_parentheses_in_expressions=false 58 | sp_cleanup.use_this_for_non_static_field_access=false 59 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true 60 | sp_cleanup.use_this_for_non_static_method_access=false 61 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true 62 | sp_cleanup.use_type_arguments=false 63 | -------------------------------------------------------------------------------- /AccelerationServer/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 24 | 25 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /AccelerationServer/libs/core-1.51.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/AccelerationServer/libs/core-1.51.0.0.jar -------------------------------------------------------------------------------- /AccelerationServer/libs/prov-1.51.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/AccelerationServer/libs/prov-1.51.0.0.jar -------------------------------------------------------------------------------- /AccelerationServer/lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /AccelerationServer/project.properties: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2015, 2016 RAPID EU Project 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2.1 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | ############################################################################### 18 | # This file is automatically generated by Android Tools. 19 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 20 | # 21 | # This file must be checked in Version Control Systems. 22 | # 23 | # To customize properties used by the Ant build system edit 24 | # "ant.properties", and override values to adapt the script to your 25 | # project structure. 26 | # 27 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 28 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 29 | 30 | # Project target. 31 | target=android-23 32 | android.library.reference.1=../AccelerationClient 33 | -------------------------------------------------------------------------------- /AccelerationServer/res/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/AccelerationServer/res/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /AccelerationServer/res/drawable-ldpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/AccelerationServer/res/drawable-ldpi/icon.png -------------------------------------------------------------------------------- /AccelerationServer/res/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/AccelerationServer/res/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /AccelerationServer/res/drawable/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/AccelerationServer/res/drawable/icon.png -------------------------------------------------------------------------------- /AccelerationServer/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 25 | 30 | 31 | -------------------------------------------------------------------------------- /AccelerationServer/res/values/string.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | RAPID-Server 22 | RAPID-Server 23 | 24 | -------------------------------------------------------------------------------- /AccelerationServer/src/eu/project/rapid/as/AccelerationServerAutoStarter.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or modify it under the terms of the 5 | * GNU Lesser General Public License as published by the Free Software Foundation; either version 6 | * 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 9 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Lesser General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with this library; 13 | * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 14 | * 02110-1301 USA 15 | *******************************************************************************/ 16 | package eu.project.rapid.as; 17 | 18 | import android.content.BroadcastReceiver; 19 | import android.content.Context; 20 | import android.content.Intent; 21 | import android.util.Log; 22 | 23 | /** 24 | * Listens to android.intent.action.BOOT_COMPLETED (defined in AndroidManifest.xml) and starts the 25 | * execution server when the system has finished booting 26 | * 27 | */ 28 | public class AccelerationServerAutoStarter extends BroadcastReceiver { 29 | private static final String TAG = AccelerationServerAutoStarter.class.getName(); 30 | 31 | @Override 32 | public void onReceive(Context context, Intent intent) { 33 | Log.d(TAG, "onReceiveIntent: Start Execution Service"); 34 | 35 | Intent serviceIntent = new Intent(); 36 | serviceIntent.setAction("eu.project.rapid.as.AccelerationServer"); 37 | context.startService(serviceIntent); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /AccelerationServer/src/eu/project/rapid/as/DynamicObjectInputStream.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | *******************************************************************************/ 18 | package eu.project.rapid.as; 19 | 20 | import java.io.File; 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | import java.io.ObjectInputStream; 24 | import java.io.ObjectStreamClass; 25 | 26 | import dalvik.system.DexClassLoader; 27 | 28 | /** 29 | * Custom object input stream to also deal with dynamically loaded classes. The classes can be 30 | * retrieved from Android Dex files, provided in Apk (android application) files. 31 | * 32 | */ 33 | public class DynamicObjectInputStream extends ObjectInputStream { 34 | private static final String TAG = "DynamicObjectInputStream"; 35 | 36 | private ClassLoader mCurrent = null; 37 | private DexClassLoader mCurrentDexLoader = null; 38 | 39 | public DynamicObjectInputStream(InputStream in) throws IOException { 40 | super(in); 41 | } 42 | 43 | /** 44 | * Server side only. Need to have the server's classloaders otherwise if the classloaders are 45 | * initialized here it doesn't work correctly. 46 | * 47 | * @param classLoader 48 | * @param dexClassLoader 49 | */ 50 | public void setClassLoaders(ClassLoader classLoader, DexClassLoader dexClassLoader) { 51 | mCurrent = classLoader; 52 | mCurrentDexLoader = dexClassLoader; 53 | } 54 | 55 | /** 56 | * Override the method resolving a class to also look into the constructed DexClassLoader 57 | */ 58 | @Override 59 | protected Class resolveClass(ObjectStreamClass desc) 60 | throws IOException, ClassNotFoundException { 61 | // Log.i(TAG, "Resolving class: " + desc.getName()); 62 | 63 | try { 64 | try { 65 | return mCurrent.loadClass(desc.getName()); 66 | } catch (ClassNotFoundException e) { 67 | return mCurrentDexLoader.loadClass(desc.getName()); 68 | } 69 | } catch (ClassNotFoundException e) { 70 | return super.resolveClass(desc); 71 | } catch (NullPointerException e) { 72 | // Thrown when currentDexLoader is 73 | // not yet set up 74 | return super.resolveClass(desc); 75 | } 76 | } 77 | 78 | /** 79 | * Add a Dex file to the Class Loader for dynamic class loading for clients 80 | * 81 | * @param apkFile the apk package 82 | */ 83 | public DexClassLoader addDex(final File apkFile) { 84 | 85 | if (mCurrentDexLoader == null) { 86 | mCurrentDexLoader = new DexClassLoader(apkFile.getAbsolutePath(), 87 | apkFile.getParentFile().getAbsolutePath(), null, mCurrent); 88 | } else { 89 | mCurrentDexLoader = new DexClassLoader(apkFile.getAbsolutePath(), 90 | apkFile.getParentFile().getAbsolutePath(), null, mCurrentDexLoader); 91 | } 92 | 93 | return mCurrentDexLoader; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /AccelerationServer/src/eu/project/rapid/as/NetworkProfilerServer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or modify it under the terms of the 5 | * GNU Lesser General Public License as published by the Free Software Foundation; either version 6 | * 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 9 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Lesser General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with this library; 13 | * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 14 | * 02110-1301 USA 15 | *******************************************************************************/ 16 | package eu.project.rapid.as; 17 | 18 | import java.io.DataOutputStream; 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | import java.io.OutputStream; 22 | import java.net.ServerSocket; 23 | import java.net.Socket; 24 | import java.util.Random; 25 | 26 | import android.util.Log; 27 | import eu.project.rapid.common.Configuration; 28 | import eu.project.rapid.common.RapidMessages; 29 | import eu.project.rapid.common.RapidUtils; 30 | 31 | /** 32 | * Listen for phone connections for measuring the data rate. The phone will send/receive some data 33 | * for 3 seconds. 34 | * 35 | */ 36 | public class NetworkProfilerServer implements Runnable { 37 | 38 | private static final String TAG = "NetworkProfilerServer"; 39 | public static final int uid = android.os.Process.myUid(); 40 | 41 | private Configuration config; 42 | private ServerSocket serverSocket; 43 | 44 | private long totalBytesRead; 45 | private long totalTimeBytesRead; 46 | private static final int BUFFER_SIZE = 10 * 1024; 47 | private byte[] buffer; 48 | 49 | public NetworkProfilerServer(Configuration config) { 50 | this.config = config; 51 | buffer = new byte[BUFFER_SIZE]; 52 | } 53 | 54 | @Override 55 | public void run() { 56 | try { 57 | serverSocket = new ServerSocket(config.getClonePortBandwidthTest()); 58 | while (true) { 59 | Socket clientSocket = serverSocket.accept(); 60 | new Thread(new ClientThread(clientSocket)).start(); 61 | } 62 | } catch (IOException e) { 63 | Log.e(TAG, 64 | "Could not start server on port " + config.getClonePortBandwidthTest() + " (" + e + ")"); 65 | } 66 | } 67 | 68 | private class ClientThread implements Runnable { 69 | 70 | private Socket clientSocket; 71 | 72 | public ClientThread(Socket clientSocket) { 73 | this.clientSocket = clientSocket; 74 | } 75 | 76 | @Override 77 | public void run() { 78 | int request = 0; 79 | 80 | InputStream is = null; 81 | OutputStream os = null; 82 | DataOutputStream dos = null; 83 | try { 84 | is = clientSocket.getInputStream(); 85 | os = clientSocket.getOutputStream(); 86 | dos = new DataOutputStream(os); 87 | 88 | while (request != -1) { 89 | request = is.read(); 90 | 91 | switch (request) { 92 | 93 | case RapidMessages.UPLOAD_FILE: 94 | new Thread(new Runnable() { 95 | 96 | @Override 97 | public void run() { 98 | long t0 = System.nanoTime(); 99 | long elapsed = 0; 100 | while (elapsed < 3000) { 101 | try { 102 | Thread.sleep(3000 - elapsed); 103 | } catch (InterruptedException e1) { 104 | } finally { 105 | elapsed = (System.nanoTime() - t0) / 1000000; 106 | } 107 | } 108 | RapidUtils.closeQuietly(clientSocket); 109 | } 110 | 111 | }).start(); 112 | 113 | totalTimeBytesRead = System.nanoTime(); 114 | totalBytesRead = 0; 115 | while (true) { 116 | totalBytesRead += is.read(buffer); 117 | os.write(1); 118 | } 119 | 120 | case RapidMessages.UPLOAD_FILE_RESULT: 121 | dos.writeLong(totalBytesRead); 122 | dos.writeLong(totalTimeBytesRead); 123 | dos.flush(); 124 | break; 125 | 126 | case RapidMessages.DOWNLOAD_FILE: 127 | new Random().nextBytes(buffer); 128 | // Used for measuring the dlRate on the phone 129 | while (true) { 130 | os.write(buffer); 131 | is.read(); 132 | } 133 | } 134 | } 135 | 136 | } catch (IOException e) { 137 | } finally { 138 | Log.i(TAG, "Client finished bandwidth measurement: " + request); 139 | 140 | if (request == RapidMessages.UPLOAD_FILE) 141 | totalTimeBytesRead = System.nanoTime() - totalTimeBytesRead; 142 | 143 | RapidUtils.closeQuietly(os); 144 | RapidUtils.closeQuietly(dos); 145 | RapidUtils.closeQuietly(is); 146 | } 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /AccelerationServer/src/eu/project/rapid/as/RapidServerActivity.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or modify it under the terms of the 5 | * GNU Lesser General Public License as published by the Free Software Foundation; either version 6 | * 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 9 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Lesser General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public License along with this library; 13 | * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 14 | * 02110-1301 USA 15 | *******************************************************************************/ 16 | package eu.project.rapid.as; 17 | 18 | import android.app.Activity; 19 | import android.content.ComponentName; 20 | import android.content.Intent; 21 | import android.os.Bundle; 22 | import android.util.Log; 23 | 24 | public class RapidServerActivity extends Activity { 25 | 26 | private static final String TAG = RapidServerActivity.class.getName(); 27 | 28 | @Override 29 | public void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | 32 | Log.d(TAG, "onCreate"); 33 | 34 | ComponentName comp = new ComponentName(getPackageName(), AccelerationServer.class.getName()); 35 | startService(new Intent().setComponent(comp)); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rapid - Android Offloading Framework 2 | This is part of the [Rapid Project](http://www.rapid-project.eu) and is an ongoing work. While Rapid envisions to support heteregenous devices, this is the component that enables code offloading on Android devices. 3 | Check the other Rapid repositories for code offloading on other platforms. 4 | 5 | >The main goal of the RAPID framework is to allow low-power devices to support compute-intensive tasks and applications at reasonable time. Hence, RAPID aspires to enable devices such as smartphones, notebooks, tablets, wearable devices, etc. to deliver both Central Processing Unit (CPU) and GPU intensive tasks, exploiting resources of more capable devices, or even the cloud, participating in the RAPID ecosystem. In this perspective, RAPID is developing an efficient heterogeneous CPU-GPU cloud computing infrastructure, which can be used to seamlessly offload CPU-based and GPU-based (using CUDA) tasks of applications to more powerful devices over a heterogeneous network (HetNet). 6 | 7 | ## Terminology 8 | * **User Device (UD):** is the low-power device (phone, e.g.) that will be accelerated by code offloading. In our scenario it will be a phone running Android (version 4.1+ is recommended). 9 | * **Clone:** is a Virtual Machine (**VM**) running on virtualized software, with the same operating system as the UD. In our scenario it will be an Android-x86 instance (version 4.0+ is recommended) running on VirtualBox. 10 | * **Acceleration Server (AS):** is an Android application that runs on the clone and is responsible for executing the offloaded code by the client. 11 | * **Acceleration Client (AC):** is an Android library that enables code offloading on Android applications. 12 | * **Rapid Common:** is a library that should be included by the AC project. 13 | * **Rapid-DemoApp:** is an Android app that implements some simple applications that use code offloading. 14 | 15 | # Installation 16 | We have implemented two ways of deploying the framework. 17 | The first one is fast and is meant to be a simple setup for testing the offloading framework. 18 | The second one requires all components of the Rapid project to be up and running. 19 | 20 | ## Quick setup without Rapid infrastructure 21 | Just following the simple steps described below you should be able to run the demo applications included in this repo in less than one hour. 22 | 23 | ### What you need 24 | * A computer running any operating system able to run a virtualization software such as [VirtualBox](https://www.virtualbox.org/). 25 | * An Android phone running Android 4.1+ (recommended). 26 | * A WiFi router where both computer and phone are connected. 27 | * The phone should be able to ping the computer, as shown in the figure below. 28 | ![](https://dl.dropboxusercontent.com/u/7728796/img-quick-setup.png "An example of a simple setup.") 29 | 30 | ### Download the components 31 | * Download the following projects from github and build them using Eclipse. 32 | * **AccelerationServer** is an Android application and is the component that will run on the *clone*. It will be responsible for executing the offloaded code. 33 | * **AccelerationClient** is an *Android library* that should be included by the applications that want to perform code offloading. It should also be included by the Acceleration Server. 34 | * This component should include the [RapidCommon](https://github.com/RapidProjectH2020/rapid-common) project. 35 | * **Rapid-DemoApp** implements some demo apps to demonstrate how to use the offloading framework. It includes the AccelerationClient android library. 36 | 37 | ### Download and deploy Android-x86 38 | * Download the Android-x86 iso from [here](http://www.android-x86.org/) (4.0+ is recommended). 39 | * Install Android-x86 on a virtualization software (e.g. [VirtualBox](https://www.virtualbox.org/)) on a computer that is connected to the same router as the phone. 40 | * After installing the VM, make sure the network interface of Android-x86 is correctly configured and is up. 41 | * We recommend to configure networking as _Bridged_ adapter on VirtualBox. For more information on how to install and configure Android-x86 on VirtualBox please refer to [this page](http://www.android-x86.org/documents/virtualboxhowto). 42 | * Get the IP address of the Android-x86 VM by accessing the _Terminal Emulator_ app on the VM and using the ```netcfg``` command. 43 | * Make sure the Android phone and the Android-x86 VM are on the same network (e.g. they can ping each other). 44 | 45 | ### Install _AccelerationServer_ component on Android-x86 46 | * First connect to the Android-x86 instance from your computer using ```adb connect [VM_IP]```. 47 | * Install the AccelerationServer project on the Android-x86 *clone*. To do so, use Eclipse to launch the project as an Android app and select the Android-x86 as the target device. 48 | * The AS will automatically start running on the VM and will start listening by default on port 4322. 49 | 50 | ### Install _Rapid-DemoApp_ on the Android phone 51 | * Attach your phone to the computer using the usb cable. 52 | * Now your device should be recognized by adb. You can check it from the terminal using the ```adb devices``` command. 53 | * Install the Rapid-DemoApp application on the phone. From Eclipse run the application as Android app and choose the phone as target device when asked where to install it. 54 | * The app should automatically start and a graphical application will appear. 55 | * We built a graphical interface to easily interact with the application and with the framework. 56 | * Try to run the simple built-in applications and check the Android logcat for errors or for info messages. 57 | 58 | ![](https://dl.dropboxusercontent.com/u/7728796/rapid1.png "The first activity used to insert the IP of the VM and start the connection.") 59 | ![](https://dl.dropboxusercontent.com/u/7728796/rapid2.png "The activity with some testing applications ready to run.") 60 | 61 | ## Full setup with Rapid infrastructure 62 | **TODO** 63 | 64 | 65 | -------------------------------------------------------------------------------- /Rapid-DemoApp/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Rapid-DemoApp/.externalToolBuilders/NDK Build.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Rapid-DemoApp/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Rapid-DemoApp 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.ui.externaltools.ExternalToolBuilder 30 | auto,full,incremental, 31 | 32 | 33 | LaunchConfigHandle 34 | <project>/.externalToolBuilders/NDK Build.launch 35 | 36 | 37 | 38 | 39 | 40 | com.android.ide.eclipse.adt.AndroidNature 41 | org.eclipse.jdt.core.javanature 42 | 43 | 44 | -------------------------------------------------------------------------------- /Rapid-DemoApp/.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true 3 | formatter_profile=_GoogleStyle 4 | formatter_settings_version=12 5 | sp_cleanup.add_default_serial_version_id=true 6 | sp_cleanup.add_generated_serial_version_id=false 7 | sp_cleanup.add_missing_annotations=true 8 | sp_cleanup.add_missing_deprecated_annotations=true 9 | sp_cleanup.add_missing_methods=false 10 | sp_cleanup.add_missing_nls_tags=false 11 | sp_cleanup.add_missing_override_annotations=true 12 | sp_cleanup.add_missing_override_annotations_interface_methods=true 13 | sp_cleanup.add_serial_version_id=false 14 | sp_cleanup.always_use_blocks=true 15 | sp_cleanup.always_use_parentheses_in_expressions=false 16 | sp_cleanup.always_use_this_for_non_static_field_access=false 17 | sp_cleanup.always_use_this_for_non_static_method_access=false 18 | sp_cleanup.convert_functional_interfaces=false 19 | sp_cleanup.convert_to_enhanced_for_loop=false 20 | sp_cleanup.correct_indentation=false 21 | sp_cleanup.format_source_code=true 22 | sp_cleanup.format_source_code_changes_only=false 23 | sp_cleanup.insert_inferred_type_arguments=false 24 | sp_cleanup.make_local_variable_final=true 25 | sp_cleanup.make_parameters_final=false 26 | sp_cleanup.make_private_fields_final=true 27 | sp_cleanup.make_type_abstract_if_missing_method=false 28 | sp_cleanup.make_variable_declarations_final=false 29 | sp_cleanup.never_use_blocks=false 30 | sp_cleanup.never_use_parentheses_in_expressions=true 31 | sp_cleanup.on_save_use_additional_actions=false 32 | sp_cleanup.organize_imports=true 33 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false 34 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true 35 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true 36 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false 37 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false 38 | sp_cleanup.remove_private_constructors=true 39 | sp_cleanup.remove_redundant_type_arguments=true 40 | sp_cleanup.remove_trailing_whitespaces=false 41 | sp_cleanup.remove_trailing_whitespaces_all=true 42 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false 43 | sp_cleanup.remove_unnecessary_casts=true 44 | sp_cleanup.remove_unnecessary_nls_tags=false 45 | sp_cleanup.remove_unused_imports=false 46 | sp_cleanup.remove_unused_local_variables=false 47 | sp_cleanup.remove_unused_private_fields=true 48 | sp_cleanup.remove_unused_private_members=false 49 | sp_cleanup.remove_unused_private_methods=true 50 | sp_cleanup.remove_unused_private_types=true 51 | sp_cleanup.sort_members=false 52 | sp_cleanup.sort_members_all=false 53 | sp_cleanup.use_anonymous_class_creation=false 54 | sp_cleanup.use_blocks=false 55 | sp_cleanup.use_blocks_only_for_return_and_throw=false 56 | sp_cleanup.use_lambda=true 57 | sp_cleanup.use_parentheses_in_expressions=false 58 | sp_cleanup.use_this_for_non_static_field_access=false 59 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true 60 | sp_cleanup.use_this_for_non_static_method_access=false 61 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true 62 | sp_cleanup.use_type_arguments=false 63 | -------------------------------------------------------------------------------- /Rapid-DemoApp/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 24 | 25 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 44 | 47 | 48 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /Rapid-DemoApp/jni/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2009 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | LOCAL_PATH := $(call my-dir) 17 | 18 | include $(CLEAR_VARS) 19 | 20 | LOCAL_CFLAGS := -DANDROID_NDK 21 | 22 | LOCAL_MODULE := hello-jni 23 | LOCAL_SRC_FILES := hello-jni.c 24 | 25 | include $(BUILD_SHARED_LIBRARY) 26 | 27 | #include $(CLEAR_VARS) 28 | 29 | #LOCAL_CFLAGS := -DANDROID_NDK 30 | 31 | #LOCAL_MODULE := jpargmp 32 | #LOCAL_SRC_FILES := GmpUtil.c 33 | 34 | #include $(BUILD_SHARED_LIBRARY) 35 | -------------------------------------------------------------------------------- /Rapid-DemoApp/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_ABI := armeabi armeabi-v7a x86 x86_64 -------------------------------------------------------------------------------- /Rapid-DemoApp/jni/GmpUtil.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | *******************************************************************************/ 18 | #include "GmpUtil.h" 19 | #include "gmp.h" 20 | 21 | /* 22 | * Class: GmpUtil 23 | * Method: mpz_init 24 | * Signature: ()J 25 | */ 26 | JNIEXPORT jlong JNICALL Java_GmpUtil_mpz_1init 27 | (JNIEnv *x, jclass y) 28 | { 29 | mpz_t *p = malloc( sizeof(__mpz_struct) ); 30 | __gmpz_init( *p ); 31 | 32 | return (jlong)p; 33 | } 34 | 35 | /* 36 | * Class: GmpUtil 37 | * Method: mpz_clear 38 | * Signature: (J)V 39 | */ 40 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1clear 41 | (JNIEnv *x, jclass y, jlong o) 42 | { 43 | mpz_t* p = (mpz_t*)o; 44 | __gmpz_clear( *p ); 45 | free( p ); 46 | } 47 | 48 | /* 49 | * Class: GmpUtil 50 | * Method: mpz_set_si 51 | * Signature: (JI)V 52 | */ 53 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1set_1si 54 | (JNIEnv *x, jclass y, jlong dest, jint val) 55 | { 56 | __gmpz_set_si( *((mpz_t*)dest), (long) val); 57 | } 58 | 59 | /* 60 | * Class: GmpUtil 61 | * Method: mpz_get_si 62 | * Signature: (J)I 63 | */ 64 | JNIEXPORT jint JNICALL Java_GmpUtil_mpz_1get_1si 65 | (JNIEnv *x, jclass y, jlong dest) 66 | { 67 | return (jint)__gmpz_get_si( *((mpz_t*)dest)); 68 | } 69 | 70 | /* 71 | * Class: GmpUtil 72 | * Method: mpz_cmp 73 | * Signature: (JJ)I 74 | */ 75 | JNIEXPORT jint JNICALL Java_GmpUtil_mpz_1cmp 76 | (JNIEnv *x, jclass y, jlong op1, jlong op2) 77 | { 78 | return (jint) __gmpz_cmp( *((mpz_t*)op1), *((mpz_t*)op2) ); 79 | } 80 | 81 | /* 82 | * Class: GmpUtil 83 | * Method: mpz_add 84 | * Signature: (JJJ)V 85 | */ 86 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1add 87 | (JNIEnv *x, jclass y, jlong dest, jlong src, jlong val) 88 | { 89 | __gmpz_add( *((mpz_t*)dest), *((mpz_t*)src), *((mpz_t*)val) ); 90 | } 91 | 92 | /* 93 | * Class: GmpUtil 94 | * Method: mpz_sub 95 | * Signature: (JJJ)V 96 | */ 97 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1sub 98 | (JNIEnv *x, jclass y, jlong dest, jlong src, jlong val) 99 | { 100 | __gmpz_sub( *((mpz_t*)dest), *((mpz_t*)src), *((mpz_t*)val) ); 101 | } 102 | 103 | /* 104 | * Class: GmpUtil 105 | * Method: mpz_mul_si 106 | * Signature: (JJI)V 107 | */ 108 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1mul_1si 109 | (JNIEnv *x, jclass y, jlong dest, jlong src, jint val) 110 | { 111 | __gmpz_mul_si( *((mpz_t*)dest), *((mpz_t*)src), (long) val); 112 | } 113 | 114 | /* 115 | * Class: GmpUtil 116 | * Method: mpz_addmul_ui 117 | * Signature: (JJI)V 118 | */ 119 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1addmul_1ui 120 | (JNIEnv *x, jclass y, jlong dest, jlong a, jint b) 121 | { 122 | __gmpz_addmul_ui( *((mpz_t*)dest), *((mpz_t*)a), (long)b); 123 | } 124 | 125 | /* 126 | * Class: GmpUtil 127 | * Method: mpz_submul_ui 128 | * Signature: (JJI)V 129 | */ 130 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1submul_1ui 131 | (JNIEnv *x, jclass y, jlong dest, jlong a, jint b) 132 | { 133 | __gmpz_submul_ui( *((mpz_t*)dest), *((mpz_t*)a), (long)b); 134 | } 135 | 136 | /* 137 | * Class: GmpUtil 138 | * Method: mpz_divexact 139 | * Signature: (JJJ)V 140 | */ 141 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1divexact 142 | (JNIEnv *x, jclass y, jlong quot, jlong n, jlong d) 143 | { 144 | __gmpz_divexact( *((mpz_t*)quot), *((mpz_t*)n), *((mpz_t*)d)); 145 | } 146 | 147 | /* 148 | * Class: GmpUtil 149 | * Method: mpz_tdiv_qr 150 | * Signature: (JJJJ)V 151 | */ 152 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1tdiv_1qr 153 | (JNIEnv *x, jclass y, jlong q, jlong r, jlong n, jlong d) 154 | { 155 | __gmpz_tdiv_qr( *((mpz_t*)q), *((mpz_t*)r), *((mpz_t*)n), *((mpz_t*)d) ); 156 | } 157 | 158 | /* 159 | * Class: GmpUtil 160 | * Method: mpz_gcd 161 | * Signature: (JJJ)V 162 | */ 163 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1gcd 164 | (JNIEnv *x, jclass y, jlong r, jlong a, jlong b) 165 | { 166 | __gmpz_gcd( *((mpz_t*)r), *((mpz_t*)a), *((mpz_t*)b) ); 167 | } 168 | -------------------------------------------------------------------------------- /Rapid-DemoApp/jni/GmpUtil.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | *******************************************************************************/ 18 | /* DO NOT EDIT THIS FILE - it is machine generated */ 19 | #include 20 | /* Header for class GmpUtil */ 21 | 22 | #ifndef _Included_GmpUtil 23 | #define _Included_GmpUtil 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | /* 28 | * Class: GmpUtil 29 | * Method: mpz_init 30 | * Signature: ()J 31 | */ 32 | JNIEXPORT jlong JNICALL Java_GmpUtil_mpz_1init 33 | (JNIEnv *, jclass); 34 | 35 | /* 36 | * Class: GmpUtil 37 | * Method: mpz_clear 38 | * Signature: (J)V 39 | */ 40 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1clear 41 | (JNIEnv *, jclass, jlong); 42 | 43 | /* 44 | * Class: GmpUtil 45 | * Method: mpz_set_si 46 | * Signature: (JI)V 47 | */ 48 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1set_1si 49 | (JNIEnv *, jclass, jlong, jint); 50 | 51 | /* 52 | * Class: GmpUtil 53 | * Method: mpz_get_si 54 | * Signature: (J)I 55 | */ 56 | JNIEXPORT jint JNICALL Java_GmpUtil_mpz_1get_1si 57 | (JNIEnv *, jclass, jlong); 58 | 59 | /* 60 | * Class: GmpUtil 61 | * Method: mpz_cmp 62 | * Signature: (JJ)I 63 | */ 64 | JNIEXPORT jint JNICALL Java_GmpUtil_mpz_1cmp 65 | (JNIEnv *, jclass, jlong, jlong); 66 | 67 | /* 68 | * Class: GmpUtil 69 | * Method: mpz_add 70 | * Signature: (JJJ)V 71 | */ 72 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1add 73 | (JNIEnv *, jclass, jlong, jlong, jlong); 74 | 75 | /* 76 | * Class: GmpUtil 77 | * Method: mpz_sub 78 | * Signature: (JJJ)V 79 | */ 80 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1sub 81 | (JNIEnv *, jclass, jlong, jlong, jlong); 82 | 83 | /* 84 | * Class: GmpUtil 85 | * Method: mpz_mul_si 86 | * Signature: (JJI)V 87 | */ 88 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1mul_1si 89 | (JNIEnv *, jclass, jlong, jlong, jint); 90 | 91 | /* 92 | * Class: GmpUtil 93 | * Method: mpz_addmul_ui 94 | * Signature: (JJI)V 95 | */ 96 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1addmul_1ui 97 | (JNIEnv *x, jclass y, jlong dest, jlong a, jint b); 98 | 99 | /* 100 | * Class: GmpUtil 101 | * Method: mpz_submul_ui 102 | * Signature: (JJI)V 103 | */ 104 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1submul_1ui 105 | (JNIEnv *x, jclass y, jlong dest, jlong a, jint b); 106 | 107 | /* 108 | * Class: GmpUtil 109 | * Method: mpz_divexact 110 | * Signature: (JJJ)V 111 | */ 112 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1divexact 113 | (JNIEnv *, jclass, jlong, jlong, jlong); 114 | 115 | /* 116 | * Class: GmpUtil 117 | * Method: mpz_tdiv_qr 118 | * Signature: (JJJJ)V 119 | */ 120 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1tdiv_1qr 121 | (JNIEnv *, jclass, jlong, jlong, jlong, jlong); 122 | 123 | /* 124 | * Class: GmpUtil 125 | * Method: mpz_gcd 126 | * Signature: (JJJ)V 127 | */ 128 | JNIEXPORT void JNICALL Java_GmpUtil_mpz_1gcd 129 | (JNIEnv *, jclass, jlong, jlong, jlong); 130 | 131 | #ifdef __cplusplus 132 | } 133 | #endif 134 | #endif -------------------------------------------------------------------------------- /Rapid-DemoApp/jni/hello-jni.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2015, 2016 RAPID EU Project 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | *******************************************************************************/ 18 | #include 19 | #include 20 | 21 | 22 | 23 | /* This is a trivial JNI example where we use a native method 24 | * to return a new VM String. 25 | */ 26 | 27 | //JavaVM *g_vm; // Can't have globals - SIGSEGV on server 28 | 29 | JNIEXPORT jstring JNICALL 30 | Java_eu_project_rapid_synthBenchmark_JniTest_stringFromJNI( JNIEnv* env, 31 | jobject thiz ) 32 | { 33 | return (*env)->NewStringUTF(env, "Hello from JNI !"); 34 | } 35 | 36 | jint JNI_OnLoad(JavaVM* vm, void* reserved) 37 | { 38 | //g_vm = vm; 39 | return JNI_VERSION_1_4; 40 | } 41 | -------------------------------------------------------------------------------- /Rapid-DemoApp/libs/armeabi-v7a/libhello-jni.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/libs/armeabi-v7a/libhello-jni.so -------------------------------------------------------------------------------- /Rapid-DemoApp/libs/armeabi/libhello-jni.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/libs/armeabi/libhello-jni.so -------------------------------------------------------------------------------- /Rapid-DemoApp/libs/commons-compress-1.9.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/libs/commons-compress-1.9.jar -------------------------------------------------------------------------------- /Rapid-DemoApp/libs/core-1.51.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/libs/core-1.51.0.0.jar -------------------------------------------------------------------------------- /Rapid-DemoApp/libs/prov-1.51.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/libs/prov-1.51.0.0.jar -------------------------------------------------------------------------------- /Rapid-DemoApp/libs/x86/libhello-jni.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/libs/x86/libhello-jni.so -------------------------------------------------------------------------------- /Rapid-DemoApp/libs/x86_64/libhello-jni.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/libs/x86_64/libhello-jni.so -------------------------------------------------------------------------------- /Rapid-DemoApp/lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Rapid-DemoApp/project.properties: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2015, 2016 RAPID EU Project 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2.1 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | ############################################################################### 18 | # This file is automatically generated by Android Tools. 19 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 20 | # 21 | # This file must be checked in Version Control Systems. 22 | # 23 | # To customize properties used by the Ant build system edit 24 | # "ant.properties", and override values to adapt the script to your 25 | # project structure. 26 | # 27 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 28 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 29 | 30 | # Project target. 31 | target=android-19 32 | android.library.reference.1=../AccelerationClient 33 | -------------------------------------------------------------------------------- /Rapid-DemoApp/res/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /Rapid-DemoApp/res/drawable-hdpi/icon_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable-hdpi/icon_dark.png -------------------------------------------------------------------------------- /Rapid-DemoApp/res/drawable-ldpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable-ldpi/icon.png -------------------------------------------------------------------------------- /Rapid-DemoApp/res/drawable-ldpi/icon_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable-ldpi/icon_dark.png -------------------------------------------------------------------------------- /Rapid-DemoApp/res/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /Rapid-DemoApp/res/drawable-mdpi/icon_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable-mdpi/icon_dark.png -------------------------------------------------------------------------------- /Rapid-DemoApp/res/drawable-xhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable-xhdpi/icon.png -------------------------------------------------------------------------------- /Rapid-DemoApp/res/drawable-xhdpi/icon_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable-xhdpi/icon_dark.png -------------------------------------------------------------------------------- /Rapid-DemoApp/res/drawable/icon.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable/icon.xcf -------------------------------------------------------------------------------- /Rapid-DemoApp/res/drawable/prove.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable/prove.jpg -------------------------------------------------------------------------------- /Rapid-DemoApp/res/drawable/prove2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable/prove2.jpg -------------------------------------------------------------------------------- /Rapid-DemoApp/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 25 | 26 | 32 | 33 | 34 | 35 | 43 | 44 | 49 | 50 | 56 | 57 | 62 | 63 | 64 | 65 | 66 | 74 | 75 | 81 | 82 | 89 | 90 | 96 | 97 | 104 | 105 | 106 | 107 | 108 | 116 | 117 | 122 | 123 | 129 | 130 | 135 | 136 | 141 | 142 | 143 | 151 | 152 | 153 | 154 | 155 | 180 | 181 | 182 | 194 | 195 |