├── .DS_Store
├── Client-Android
├── .gitignore
├── .idea
│ ├── .gitignore
│ ├── codeStyles
│ │ └── Project.xml
│ ├── compiler.xml
│ ├── gradle.xml
│ ├── jarRepositories.xml
│ ├── misc.xml
│ ├── runConfigurations.xml
│ └── vcs.xml
├── app
│ ├── .gitignore
│ ├── CMakeLists.txt
│ ├── build.gradle
│ ├── includes
│ │ ├── MNN
│ │ │ ├── AutoTime.hpp
│ │ │ ├── ErrorCode.hpp
│ │ │ ├── HalideRuntime.h
│ │ │ ├── ImageProcess.hpp
│ │ │ ├── Interpreter.hpp
│ │ │ ├── MNNDefine.h
│ │ │ ├── MNNForwardType.h
│ │ │ ├── Matrix.h
│ │ │ ├── Rect.h
│ │ │ ├── Tensor.hpp
│ │ │ ├── expr
│ │ │ │ ├── Executor.hpp
│ │ │ │ ├── Expr.hpp
│ │ │ │ ├── ExprCreator.hpp
│ │ │ │ ├── MathOp.hpp
│ │ │ │ ├── NeuralNetWorkOp.hpp
│ │ │ │ └── Optimizer.hpp
│ │ │ └── plugin
│ │ │ │ ├── PluginContext.hpp
│ │ │ │ ├── PluginKernel.hpp
│ │ │ │ └── PluginShapeInference.hpp
│ │ └── MNNTrain
│ │ │ ├── BlockingQueue.hpp
│ │ │ ├── DataLoader.hpp
│ │ │ ├── DataLoaderConfig.hpp
│ │ │ ├── Dataset.hpp
│ │ │ ├── Distributions.hpp
│ │ │ ├── Example.hpp
│ │ │ ├── ImageDataset.hpp
│ │ │ ├── LearningRateScheduler.hpp
│ │ │ ├── Lenet.hpp
│ │ │ ├── Loss.hpp
│ │ │ ├── MnistDataset.hpp
│ │ │ ├── Module.hpp
│ │ │ ├── NN.hpp
│ │ │ ├── ParameterOptimizer.hpp
│ │ │ ├── PipelineModule.hpp
│ │ │ ├── SGD.hpp
│ │ │ └── Transformer.hpp
│ ├── libs
│ │ └── arm64-v8a
│ │ │ ├── libMNN.so
│ │ │ ├── libMNNTrain.so
│ │ │ └── libMNN_Express.so
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── websocket
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ ├── demo
│ │ │ │ ├── App.java
│ │ │ │ ├── EmptyActivity.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── MnnTrainFragment.java
│ │ │ │ └── example
│ │ │ │ ├── MainActivity_test.java
│ │ │ │ ├── nativemnn
│ │ │ │ ├── mnn
│ │ │ │ │ └── MNNDataNative.java
│ │ │ │ └── utils
│ │ │ │ │ └── Common.java
│ │ │ │ └── websocket
│ │ │ │ ├── client
│ │ │ │ └── ClientWebSocketListener.java
│ │ │ │ ├── constants
│ │ │ │ └── Constants.java
│ │ │ │ ├── service
│ │ │ │ ├── ClientWebSocketService.java
│ │ │ │ └── MnnTrainService.java
│ │ │ │ └── utils
│ │ │ │ ├── CommonUtil.java
│ │ │ │ ├── DeviceUtil.java
│ │ │ │ └── FileUtil.java
│ │ ├── jni
│ │ │ └── mnndatanative.cpp
│ │ └── res
│ │ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── drawable
│ │ │ └── ic_launcher_background.xml
│ │ │ ├── layout
│ │ │ ├── activity_empty.xml
│ │ │ ├── activity_main.xml
│ │ │ └── fragment_mnn_train.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── websocket
│ │ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── README.md
├── README_CN.md
├── Server-Python
├── model
│ ├── init.mnn
│ └── mnist.snapshot.mnn
├── py
│ ├── __pycache__
│ │ ├── clientThread.cpython-38.pyc
│ │ ├── parameter.cpython-38.pyc
│ │ └── utils.cpython-38.pyc
│ ├── aggregateModel.out
│ ├── clientThread.py
│ ├── parameter.py
│ ├── server.py
│ └── utils.py
├── result
│ ├── acc.npy
│ └── time.npy
├── static
│ └── picture
│ │ ├── 0.bmp
│ │ ├── 2.bmp
│ │ ├── 4.bmp
│ │ ├── 6.bmp
│ │ └── 8.bmp
└── test.html
└── data
├── mnist.snapshot.mnn
└── mnist_data
├── .DS_Store
├── t10k-images-idx3-ubyte
├── t10k-labels-idx1-ubyte
├── train-images-idx3-ubyte
└── train-labels-idx1-ubyte
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UbiquitousLearning/End2end-Federated-Learning/e2cdcd9829779798fc56f2f63b19ee6cdc2307d0/.DS_Store
--------------------------------------------------------------------------------
/Client-Android/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 |
--------------------------------------------------------------------------------
/Client-Android/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/Client-Android/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | xmlns:android
32 |
33 | ^$
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | xmlns:.*
43 |
44 | ^$
45 |
46 |
47 | BY_NAME
48 |
49 |
50 |
51 |
52 |
53 |
54 | .*:id
55 |
56 | http://schemas.android.com/apk/res/android
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | .*:name
66 |
67 | http://schemas.android.com/apk/res/android
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | name
77 |
78 | ^$
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 | style
88 |
89 | ^$
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 | .*
99 |
100 | ^$
101 |
102 |
103 | BY_NAME
104 |
105 |
106 |
107 |
108 |
109 |
110 | .*
111 |
112 | http://schemas.android.com/apk/res/android
113 |
114 |
115 | ANDROID_ATTRIBUTE_ORDER
116 |
117 |
118 |
119 |
120 |
121 |
122 | .*
123 |
124 | .*
125 |
126 |
127 | BY_NAME
128 |
129 |
130 |
131 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/Client-Android/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Client-Android/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
20 |
21 |
--------------------------------------------------------------------------------
/Client-Android/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Client-Android/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Client-Android/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Client-Android/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Client-Android/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/Client-Android/app/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.4.1)
2 |
3 | set(lib_DIR ${CMAKE_SOURCE_DIR}/libs)
4 | include_directories(${CMAKE_SOURCE_DIR}/includes)
5 |
6 | add_library( MNN SHARED IMPORTED )
7 | set_target_properties(
8 | MNN
9 | PROPERTIES IMPORTED_LOCATION
10 | ${lib_DIR}/${ANDROID_ABI}/libMNN.so
11 | )
12 |
13 | add_library( MNNTrain SHARED IMPORTED )
14 | set_target_properties(
15 | MNNTrain
16 | PROPERTIES IMPORTED_LOCATION
17 | ${lib_DIR}/${ANDROID_ABI}/libMNNTrain.so
18 | )
19 |
20 | add_library( MNN_Express SHARED IMPORTED )
21 | set_target_properties(
22 | MNN_Express
23 | PROPERTIES IMPORTED_LOCATION
24 | ${lib_DIR}/${ANDROID_ABI}/libMNN_Express.so
25 | )
26 |
27 | #file(GLOB_RECURSE CPP_SRCS src/main/jni/*.cpp)
28 | file(GLOB_RECURSE CPP_SRCS src/main/jni/mnndatanative.cpp)
29 | add_library( mnncore SHARED ${CPP_SRCS} )
30 |
31 | find_library( log-lib log )
32 | find_library( jnigraphics-lib jnigraphics )
33 |
34 | add_definitions(-DMNN_USE_LOGCAT)
35 | target_link_libraries( mnncore MNN ${log-lib} ${jnigraphics-lib})
36 | target_link_libraries( mnncore MNNTrain ${log-lib} ${jnigraphics-lib})
37 | target_link_libraries( mnncore MNN_Express ${log-lib} ${jnigraphics-lib})
--------------------------------------------------------------------------------
/Client-Android/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 30
5 | buildToolsVersion "30.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.demo"
9 | minSdkVersion 16
10 | targetSdkVersion 30
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 |
16 | externalNativeBuild {
17 | cmake {
18 | cppFlags ""
19 | abiFilters 'arm64-v8a'
20 | }
21 | }
22 | ndk{
23 | abiFilters 'arm64-v8a'
24 | }
25 | }
26 |
27 | buildTypes {
28 | debug {
29 | ndk {
30 | abiFilters 'arm64-v8a'
31 | }
32 | }
33 | release {
34 | minifyEnabled false
35 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
36 | }
37 | }
38 |
39 | externalNativeBuild {
40 | cmake {
41 | path "CMakeLists.txt"
42 | }
43 | }
44 |
45 | sourceSets {
46 | main {
47 | jniLibs.srcDirs = ['libs']
48 | }
49 | }
50 |
51 | packagingOptions {
52 | pickFirst 'lib/arm64-v8a/libMNNTrain.so'
53 | pickFirst 'lib/arm64-v8a/libMNN_Express.so'
54 | pickFirst 'lib/arm64-v8a/libMNN.so'
55 | }
56 |
57 | dataBinding{
58 | enabled = true
59 | }
60 | }
61 |
62 | dependencies {
63 | implementation fileTree(dir: "libs", include: ["*.jar"])
64 | implementation 'androidx.appcompat:appcompat:1.1.0'
65 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
66 | testImplementation 'junit:junit:4.12'
67 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
68 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
69 | implementation 'com.google.code.gson:gson:2.8.6'
70 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
71 | implementation 'com.google.android.material:material:1.0.0'
72 | implementation 'androidx.cardview:cardview:1.0.0'
73 |
74 | implementation("com.squareup.okhttp3:okhttp:4.9.0")
75 |
76 |
77 | }
--------------------------------------------------------------------------------
/Client-Android/app/includes/MNN/AutoTime.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // AutoTime.hpp
3 | // MNN
4 | //
5 | // Created by MNN on 2018/07/27.
6 | // Copyright © 2018, Alibaba Group Holding Limited
7 | //
8 |
9 | #ifndef AutoTime_hpp
10 | #define AutoTime_hpp
11 |
12 | #include
13 | #include
14 | #include
15 |
16 | namespace MNN {
17 |
18 | /** time tracing util. prints duration between init and deinit. */
19 | class MNN_PUBLIC AutoTime {
20 | public:
21 | AutoTime(int line, const char* func);
22 | ~AutoTime();
23 | AutoTime(const AutoTime&) = delete;
24 | AutoTime(const AutoTime&&) = delete;
25 | AutoTime& operator=(const AutoTime&) = delete;
26 | AutoTime& operator=(const AutoTime&&) = delete;
27 |
28 | private:
29 | int mLine;
30 | char* mName;
31 | uint64_t mCurrentTime;
32 | };
33 | } // namespace MNN
34 |
35 | #ifdef MNN_OPEN_TIME_TRACE
36 | #define AUTOTIME MNN::AutoTime ___t(__LINE__, __func__)
37 | #else
38 | #define AUTOTIME
39 | #endif
40 |
41 | #endif /* AutoTime_hpp */
42 |
--------------------------------------------------------------------------------
/Client-Android/app/includes/MNN/ErrorCode.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // ErrorCode.hpp
3 | // MNN
4 | //
5 | // Created by MNN on 2018/09/18.
6 | // Copyright © 2018, Alibaba Group Holding Limited
7 | //
8 |
9 | #ifndef ErrorCode_h
10 | #define ErrorCode_h
11 |
12 | namespace MNN {
13 | enum ErrorCode {
14 | #ifdef NO_ERROR
15 | #undef NO_ERROR
16 | #endif //NO_ERROR
17 | NO_ERROR = 0,
18 | OUT_OF_MEMORY = 1,
19 | NOT_SUPPORT = 2,
20 | COMPUTE_SIZE_ERROR = 3,
21 | NO_EXECUTION = 4,
22 |
23 | // User error
24 | INPUT_DATA_ERROR = 10,
25 | CALL_BACK_STOP = 11,
26 |
27 | // Op Resize Error
28 | TENSOR_NOT_SUPPORT = 20,
29 | TENSOR_NEED_DIVIDE = 21,
30 | };
31 | }
32 |
33 | #endif /* ErrorCode_h */
34 |
--------------------------------------------------------------------------------
/Client-Android/app/includes/MNN/HalideRuntime.h:
--------------------------------------------------------------------------------
1 | #ifndef HALIDE_HALIDERUNTIME_H
2 | #define HALIDE_HALIDERUNTIME_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | #ifdef __cplusplus
9 | extern "C" {
10 | #endif
11 |
12 | // Note that you should not use "inline" along with HALIDE_ALWAYS_INLINE;
13 | // it is not necessary, and may produce warnings for some build configurations.
14 | #ifdef _MSC_VER
15 | #define HALIDE_ALWAYS_INLINE __forceinline
16 | #define HALIDE_NEVER_INLINE __declspec(noinline)
17 | #else
18 | #define HALIDE_ALWAYS_INLINE __attribute__((always_inline)) inline
19 | #define HALIDE_NEVER_INLINE __attribute__((noinline))
20 | #endif
21 |
22 | /** \file
23 | *
24 | * This file declares the routines used by Halide internally in its
25 | * runtime. On platforms that support weak linking, these can be
26 | * replaced with user-defined versions by defining an extern "C"
27 | * function with the same name and signature.
28 | *
29 | * When doing Just In Time (JIT) compilation methods on the Func being
30 | * compiled must be called instead. The corresponding methods are
31 | * documented below.
32 | *
33 | * All of these functions take a "void *user_context" parameter as their
34 | * first argument; if the Halide kernel that calls back to any of these
35 | * functions has been compiled with the UserContext feature set on its Target,
36 | * then the value of that pointer passed from the code that calls the
37 | * Halide kernel is piped through to the function.
38 | *
39 | * Some of these are also useful to call when using the default
40 | * implementation. E.g. halide_shutdown_thread_pool.
41 | *
42 | * Note that even on platforms with weak linking, some linker setups
43 | * may not respect the override you provide. E.g. if the override is
44 | * in a shared library and the halide object files are linked directly
45 | * into the output, the builtin versions of the runtime functions will
46 | * be called. See your linker documentation for more details. On
47 | * Linux, LD_DYNAMIC_WEAK=1 may help.
48 | *
49 | */
50 |
51 | // Forward-declare to suppress warnings if compiling as C.
52 | struct halide_buffer_t;
53 |
54 | /** Types in the halide type system. They can be ints, unsigned ints,
55 | * or floats (of various bit-widths), or a handle (which is always 64-bits).
56 | * Note that the int/uint/float values do not imply a specific bit width
57 | * (the bit width is expected to be encoded in a separate value).
58 | */
59 | typedef enum halide_type_code_t
60 | {
61 | halide_type_int = 0, //!< signed integers
62 | halide_type_uint = 1, //!< unsigned integers
63 | halide_type_float = 2, //!< floating point numbers
64 | halide_type_handle = 3 //!< opaque pointer type (void *)
65 | } halide_type_code_t;
66 |
67 | // Note that while __attribute__ can go before or after the declaration,
68 | // __declspec apparently is only allowed before.
69 | #ifndef HALIDE_ATTRIBUTE_ALIGN
70 | #ifdef _MSC_VER
71 | #define HALIDE_ATTRIBUTE_ALIGN(x) __declspec(align(x))
72 | #else
73 | #define HALIDE_ATTRIBUTE_ALIGN(x) __attribute__((aligned(x)))
74 | #endif
75 | #endif
76 |
77 | /** A runtime tag for a type in the halide type system. Can be ints,
78 | * unsigned ints, or floats of various bit-widths (the 'bits'
79 | * field). Can also be vectors of the same (by setting the 'lanes'
80 | * field to something larger than one). This struct should be
81 | * exactly 32-bits in size. */
82 | struct halide_type_t {
83 | /** The basic type code: signed integer, unsigned integer, or floating point. */
84 | #if __cplusplus >= 201103L
85 | HALIDE_ATTRIBUTE_ALIGN(1) halide_type_code_t code; // halide_type_code_t
86 | #else
87 | HALIDE_ATTRIBUTE_ALIGN(1) uint8_t code; // halide_type_code_t
88 | #endif
89 |
90 | /** The number of bits of precision of a single scalar value of this type. */
91 | HALIDE_ATTRIBUTE_ALIGN(1) uint8_t bits;
92 |
93 | /** How many elements in a vector. This is 1 for scalar types. */
94 | HALIDE_ATTRIBUTE_ALIGN(2) uint16_t lanes;
95 |
96 | #ifdef __cplusplus
97 | /** Construct a runtime representation of a Halide type from:
98 | * code: The fundamental type from an enum.
99 | * bits: The bit size of one element.
100 | * lanes: The number of vector elements in the type. */
101 | HALIDE_ALWAYS_INLINE halide_type_t(halide_type_code_t code, uint8_t bits, uint16_t lanes = 1)
102 | : code(code), bits(bits), lanes(lanes) {
103 | }
104 |
105 | /** Default constructor is required e.g. to declare halide_trace_event
106 | * instances. */
107 | HALIDE_ALWAYS_INLINE halide_type_t() : code((halide_type_code_t)0), bits(0), lanes(0) {}
108 |
109 | /** Compare two types for equality. */
110 | HALIDE_ALWAYS_INLINE bool operator==(const halide_type_t &other) const {
111 | return (code == other.code &&
112 | bits == other.bits &&
113 | lanes == other.lanes);
114 | }
115 |
116 | HALIDE_ALWAYS_INLINE bool operator!=(const halide_type_t &other) const {
117 | return !(*this == other);
118 | }
119 |
120 | /** Size in bytes for a single element, even if width is not 1, of this type. */
121 | HALIDE_ALWAYS_INLINE int bytes() const { return (bits + 7) / 8; }
122 | #endif
123 | };
124 |
125 | /** An opaque struct containing per-GPU API implementations of the
126 | * device functions. */
127 | struct halide_device_interface_impl_t;
128 |
129 | /** Each GPU API provides a halide_device_interface_t struct pointing
130 | * to the code that manages device allocations. You can access these
131 | * functions directly from the struct member function pointers, or by
132 | * calling the functions declared below. Note that the global
133 | * functions are not available when using Halide as a JIT compiler.
134 | * If you are using raw halide_buffer_t in that context you must use
135 | * the function pointers in the device_interface struct.
136 | *
137 | * The function pointers below are currently the same for every GPU
138 | * API; only the impl field varies. These top-level functions do the
139 | * bookkeeping that is common across all GPU APIs, and then dispatch
140 | * to more API-specific functions via another set of function pointers
141 | * hidden inside the impl field.
142 | */
143 | struct halide_device_interface_t {
144 | int (*device_malloc)(void *user_context, struct halide_buffer_t *buf,
145 | const struct halide_device_interface_t *device_interface);
146 | int (*device_free)(void *user_context, struct halide_buffer_t *buf);
147 | int (*device_sync)(void *user_context, struct halide_buffer_t *buf);
148 | void (*device_release)(void *user_context,
149 | const struct halide_device_interface_t *device_interface);
150 | int (*copy_to_host)(void *user_context, struct halide_buffer_t *buf);
151 | int (*copy_to_device)(void *user_context, struct halide_buffer_t *buf,
152 | const struct halide_device_interface_t *device_interface);
153 | int (*device_and_host_malloc)(void *user_context, struct halide_buffer_t *buf,
154 | const struct halide_device_interface_t *device_interface);
155 | int (*device_and_host_free)(void *user_context, struct halide_buffer_t *buf);
156 | int (*buffer_copy)(void *user_context, struct halide_buffer_t *src,
157 | const struct halide_device_interface_t *dst_device_interface, struct halide_buffer_t *dst);
158 | int (*device_crop)(void *user_context, const struct halide_buffer_t *src,
159 | struct halide_buffer_t *dst);
160 | int (*device_release_crop)(void *user_context, struct halide_buffer_t *buf);
161 | int (*wrap_native)(void *user_context, struct halide_buffer_t *buf, uint64_t handle,
162 | const struct halide_device_interface_t *device_interface);
163 | int (*detach_native)(void *user_context, struct halide_buffer_t *buf);
164 | const struct halide_device_interface_impl_t *impl;
165 | };
166 |
167 | typedef struct halide_dimension_t {
168 | int32_t min, extent, stride;
169 |
170 | // Per-dimension flags. None are defined yet (This is reserved for future use).
171 | uint32_t flags;
172 |
173 | #ifdef __cplusplus
174 | HALIDE_ALWAYS_INLINE halide_dimension_t() : min(0), extent(0), stride(0), flags(0) {}
175 | HALIDE_ALWAYS_INLINE halide_dimension_t(int32_t m, int32_t e, int32_t s, uint32_t f = 0) :
176 | min(m), extent(e), stride(s), flags(f) {}
177 |
178 | HALIDE_ALWAYS_INLINE bool operator==(const halide_dimension_t &other) const {
179 | return (min == other.min) &&
180 | (extent == other.extent) &&
181 | (stride == other.stride) &&
182 | (flags == other.flags);
183 | }
184 |
185 | HALIDE_ALWAYS_INLINE bool operator!=(const halide_dimension_t &other) const {
186 | return !(*this == other);
187 | }
188 | #endif
189 | } halide_dimension_t;
190 |
191 | #ifdef __cplusplus
192 | } // extern "C"
193 | #endif
194 |
195 | typedef enum {halide_buffer_flag_host_dirty = 1,
196 | halide_buffer_flag_device_dirty = 2} halide_buffer_flags;
197 |
198 | /**
199 | * The raw representation of an image passed around by generated
200 | * Halide code. It includes some stuff to track whether the image is
201 | * not actually in main memory, but instead on a device (like a
202 | * GPU). For a more convenient C++ wrapper, use Halide::Buffer. */
203 | typedef struct halide_buffer_t {
204 | /** A device-handle for e.g. GPU memory used to back this buffer. */
205 | uint64_t device;
206 |
207 | /** The interface used to interpret the above handle. */
208 | const struct halide_device_interface_t *device_interface;
209 |
210 | /** A pointer to the start of the data in main memory. In terms of
211 | * the Halide coordinate system, this is the address of the min
212 | * coordinates (defined below). */
213 | uint8_t* host;
214 |
215 | /** flags with various meanings. */
216 | uint64_t flags;
217 |
218 | /** The type of each buffer element. */
219 | struct halide_type_t type;
220 |
221 | /** The dimensionality of the buffer. */
222 | int32_t dimensions;
223 |
224 | /** The shape of the buffer. Halide does not own this array - you
225 | * must manage the memory for it yourself. */
226 | halide_dimension_t *dim;
227 |
228 | /** Pads the buffer up to a multiple of 8 bytes */
229 | void *padding;
230 | } halide_buffer_t;
231 |
232 |
233 | #ifdef __cplusplus
234 |
235 | namespace {
236 | template struct check_is_pointer;
237 | template struct check_is_pointer {};
238 | }
239 |
240 | /** Construct the halide equivalent of a C type */
241 | template
242 | HALIDE_ALWAYS_INLINE halide_type_t halide_type_of() {
243 | // Create a compile-time error if T is not a pointer (without
244 | // using any includes - this code goes into the runtime).
245 | check_is_pointer check;
246 | (void)check;
247 | return halide_type_t(halide_type_handle, 64);
248 | }
249 |
250 | template<>
251 | HALIDE_ALWAYS_INLINE halide_type_t halide_type_of() {
252 | return halide_type_t(halide_type_float, 32);
253 | }
254 |
255 | template<>
256 | HALIDE_ALWAYS_INLINE halide_type_t halide_type_of() {
257 | return halide_type_t(halide_type_float, 64);
258 | }
259 |
260 | template<>
261 | HALIDE_ALWAYS_INLINE halide_type_t halide_type_of() {
262 | return halide_type_t(halide_type_uint, 1);
263 | }
264 |
265 | template<>
266 | HALIDE_ALWAYS_INLINE halide_type_t halide_type_of() {
267 | return halide_type_t(halide_type_uint, 8);
268 | }
269 |
270 | template<>
271 | HALIDE_ALWAYS_INLINE halide_type_t halide_type_of() {
272 | return halide_type_t(halide_type_uint, 16);
273 | }
274 |
275 | template<>
276 | HALIDE_ALWAYS_INLINE halide_type_t halide_type_of() {
277 | return halide_type_t(halide_type_uint, 32);
278 | }
279 |
280 | template<>
281 | HALIDE_ALWAYS_INLINE halide_type_t halide_type_of() {
282 | return halide_type_t(halide_type_uint, 64);
283 | }
284 |
285 | template<>
286 | HALIDE_ALWAYS_INLINE halide_type_t halide_type_of() {
287 | return halide_type_t(halide_type_int, 8);
288 | }
289 |
290 | template<>
291 | HALIDE_ALWAYS_INLINE halide_type_t halide_type_of() {
292 | return halide_type_t(halide_type_int, 16);
293 | }
294 |
295 | template<>
296 | HALIDE_ALWAYS_INLINE halide_type_t halide_type_of() {
297 | return halide_type_t(halide_type_int, 32);
298 | }
299 |
300 | template<>
301 | HALIDE_ALWAYS_INLINE halide_type_t halide_type_of() {
302 | return halide_type_t(halide_type_int, 64);
303 | }
304 |
305 | #endif
306 |
307 | #endif // HALIDE_HALIDERUNTIME_H
308 |
--------------------------------------------------------------------------------
/Client-Android/app/includes/MNN/ImageProcess.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // ImageProcess.hpp
3 | // MNN
4 | //
5 | // Created by MNN on 2018/09/19.
6 | // Copyright © 2018, Alibaba Group Holding Limited
7 | //
8 |
9 | #ifndef ImageProcess_hpp
10 | #define ImageProcess_hpp
11 |
12 | #include
13 | #include "Matrix.h"
14 | #include
15 |
16 | namespace MNN {
17 | namespace CV {
18 | enum ImageFormat {
19 | RGBA = 0,
20 | RGB,
21 | BGR,
22 | GRAY,
23 | BGRA,
24 | YUV_NV21 = 11,
25 | };
26 |
27 | enum Filter { NEAREST = 0, BILINEAR = 1, BICUBIC = 2 };
28 |
29 | enum Wrap { CLAMP_TO_EDGE = 0, ZERO = 1, REPEAT = 2 };
30 |
31 | /**
32 | * handle image process for tensor.
33 | * step:
34 | * 1: Do transform compute and get points
35 | * 2: Sample line and do format convert
36 | * 3: Turn RGBA to float tensor, and do sub and normalize
37 | */
38 | class MNN_PUBLIC ImageProcess {
39 | public:
40 | struct Inside;
41 | struct Config {
42 | /** data filter */
43 | Filter filterType = NEAREST;
44 | /** format of source data */
45 | ImageFormat sourceFormat = RGBA;
46 | /** format of destination data */
47 | ImageFormat destFormat = RGBA;
48 |
49 | // Only valid if the dest type is float
50 | float mean[4] = {0.0f, 0.0f, 0.0f, 0.0f};
51 | float normal[4] = {1.0f, 1.0f, 1.0f, 1.0f};
52 |
53 | /** edge wrapper */
54 | Wrap wrap = CLAMP_TO_EDGE;
55 | };
56 |
57 | public:
58 | /**
59 | * @brief create image process with given config for given tensor.
60 | * @param config given config.
61 | * @param dstTensor given tensor.
62 | * @return image processor.
63 | */
64 | static ImageProcess* create(const Config& config, const Tensor* dstTensor = nullptr);
65 |
66 | /**
67 | * @brief create image process with given config for given tensor.
68 | * @param means given means
69 | * @param meanCount given means count
70 | * @param normals given normals
71 | * @param normalCount given normal count
72 | * @param sourceFormat format of source data
73 | * @param destFormat format of destination data
74 | * @param dstTensor given tensor.
75 | * @return image processor.
76 | */
77 | static ImageProcess* create(const ImageFormat sourceFormat = RGBA, const ImageFormat destFormat = RGBA,
78 | const float* means = nullptr, const int meanCount = 0, const float* normals = nullptr,
79 | const int normalCount = 0, const Tensor* dstTensor = nullptr);
80 |
81 | ~ImageProcess();
82 |
83 | /**
84 | * @brief get affine transform matrix.
85 | * @return affine transform matrix.
86 | */
87 | inline const Matrix& matrix() const {
88 | return mTransform;
89 | }
90 | void setMatrix(const Matrix& matrix);
91 |
92 | /**
93 | * @brief convert source data to given tensor.
94 | * @param source source data.
95 | * @param iw source width.
96 | * @param ih source height.
97 | * @param stride number of elements per row. eg: 100 width RGB contains at least 300 elements.
98 | * @param dest given tensor.
99 | * @return result code.
100 | */
101 | ErrorCode convert(const uint8_t* source, int iw, int ih, int stride, Tensor* dest);
102 |
103 | /**
104 | * @brief create tensor with given data.
105 | * @param w image width.
106 | * @param h image height.
107 | * @param bpp bytes per pixel.
108 | * @param p pixel data pointer.
109 | * @return created tensor.
110 | */
111 | template
112 | static Tensor* createImageTensor(int w, int h, int bpp, void* p = nullptr) {
113 | return createImageTensor(halide_type_of(), w, h, bpp, p);
114 | }
115 | static Tensor* createImageTensor(halide_type_t type, int w, int h, int bpp, void* p = nullptr);
116 |
117 | private:
118 | ImageProcess(const Config& config);
119 | Matrix mTransform;
120 | Matrix mTransformInvert;
121 | Inside* mInside;
122 | };
123 | } // namespace CV
124 | } // namespace MNN
125 |
126 | #endif /* ImageProcess_hpp */
127 |
--------------------------------------------------------------------------------
/Client-Android/app/includes/MNN/Interpreter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Interpreter.hpp
3 | // MNN
4 | //
5 | // Created by MNN on 2018/07/23.
6 | // Copyright © 2018, Alibaba Group Holding Limited
7 | //
8 |
9 | #ifndef Interpreter_hpp
10 | #define Interpreter_hpp
11 |
12 | #include
13 | #include