Skip to content

Commit d6059ba

Browse files
authored
Merge pull request #5 from neuralize-ai/1-add-tflite-support
1 add tflite support
2 parents 6f3807a + 3f45861 commit d6059ba

21 files changed

+631
-59
lines changed

.clang-tidy

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ CheckOptions:
7171
- key: 'readability-identifier-naming.ConstexprVariableCase'
7272
value: 'camelBack'
7373
- key: 'readability-identifier-naming.EnumCase'
74-
value: 'camelBack'
74+
value: 'CamelCase'
7575
- key: 'readability-identifier-naming.EnumConstantCase'
76-
value: 'camelBack'
76+
value: 'CamelCase'
7777
- key: 'readability-identifier-naming.FunctionCase'
7878
value: 'camelBack'
7979
- key: 'readability-identifier-naming.GlobalConstantCase'
80-
value: 'camelBack'
80+
value: 'CamelCase'
8181
- key: 'readability-identifier-naming.GlobalConstantPointerCase'
82-
value: 'camelBack'
82+
value: 'CamelCase'
8383
- key: 'readability-identifier-naming.GlobalFunctionCase'
8484
value: 'camelBack'
8585
- key: 'readability-identifier-naming.GlobalPointerCase'
@@ -127,7 +127,7 @@ CheckOptions:
127127
- key: 'readability-identifier-naming.PublicMethodCase'
128128
value: 'camelBack'
129129
- key: 'readability-identifier-naming.ScopedEnumConstantCase'
130-
value: 'camelBack'
130+
value: 'CamelCase'
131131
- key: 'readability-identifier-naming.StaticConstantCase'
132132
value: 'camelBack'
133133
- key: 'readability-identifier-naming.StaticVariableCase'

.codespellrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ check-filenames =
44
check-hidden =
55
skip = */.git,*/build,*/prefix,*/conan
66
quiet-level = 2
7+
ignore-words-list=lite

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.tflite filter=lfs diff=lfs merge=lfs -text

.github/workflows/ci.yml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ name: Continuous Integration
33
on:
44
push:
55
branches:
6-
- master
6+
- main
77

88
pull_request:
99
branches:
10-
- master
10+
- main
1111

1212
jobs:
1313
lint:
@@ -43,6 +43,8 @@ jobs:
4343

4444
steps:
4545
- uses: actions/checkout@v4
46+
with:
47+
lfs: true
4648

4749
- name: Install LCov
4850
run: sudo apt-get update -q
@@ -69,7 +71,7 @@ jobs:
6971

7072
- name: Test
7173
working-directory: build/coverage
72-
run: ctest --output-on-failure --no-tests=error -j 2
74+
run: ctest --output-on-failure --no-tests=error -j 2 -R "CPU"
7375

7476
- name: Process coverage info
7577
run: cmake --build build/coverage -t coverage
@@ -87,8 +89,12 @@ jobs:
8789

8890
env: { CXX: clang++-14 }
8991

92+
if: false
93+
9094
steps:
9195
- uses: actions/checkout@v4
96+
with:
97+
lfs: true
9298

9399
- name: Install Python
94100
uses: actions/setup-python@v5
@@ -120,14 +126,14 @@ jobs:
120126
halt_on_error=1"
121127
UBSAN_OPTIONS: "print_stacktrace=1:\
122128
halt_on_error=1"
123-
run: ctest --output-on-failure --no-tests=error -j 2
129+
run: ctest --output-on-failure --no-tests=error -j 2 -R "CPU"
124130

125131
test:
126132
needs: [lint]
127133

128134
strategy:
129135
matrix:
130-
os: [macos-14, ubuntu-22.04, windows-2022]
136+
os: [macos-14, ubuntu-22.04] #, windows-2022]
131137

132138
type: [shared, static]
133139

@@ -139,6 +145,8 @@ jobs:
139145

140146
steps:
141147
- uses: actions/checkout@v4
148+
with:
149+
lfs: true
142150

143151
- name: Install static analyzers
144152
if: matrix.os == 'ubuntu-22.04'
@@ -184,9 +192,14 @@ jobs:
184192
- name: Install
185193
run: cmake --install build --config Release --prefix prefix
186194

195+
- name: Check
196+
run: |
197+
ls models/tflite
198+
ls build/test/models/tflite
199+
187200
- name: Test
188201
working-directory: build
189-
run: ctest --output-on-failure --no-tests=error -C Release -j 2
202+
run: ctest --output-on-failure --no-tests=error -C Release -j 2 -R "CPU"
190203

191204
docs:
192205
# Deploy docs only when builds succeed

CMakeLists.txt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ include(cmake/variables.cmake)
1717

1818
add_library(
1919
edgerunner_edgerunner
20-
source/edgerunner.cpp
20+
source/tflite/model.cpp
21+
source/tflite/tensor.cpp
2122
)
2223
add_library(edgerunner::edgerunner ALIAS edgerunner_edgerunner)
2324

@@ -30,7 +31,11 @@ generate_export_header(
3031
)
3132

3233
if(NOT BUILD_SHARED_LIBS)
33-
target_compile_definitions(edgerunner_edgerunner PUBLIC EDGERUNNER_STATIC_DEFINE)
34+
target_compile_definitions(
35+
edgerunner_edgerunner
36+
PUBLIC
37+
EDGERUNNER_STATIC_DEFINE
38+
)
3439
endif()
3540

3641
set_target_properties(
@@ -60,18 +65,32 @@ target_compile_features(edgerunner_edgerunner PUBLIC cxx_std_17)
6065
find_package(fmt REQUIRED)
6166
target_link_libraries(edgerunner_edgerunner PRIVATE fmt::fmt)
6267

68+
find_package(span-lite REQUIRED)
69+
target_link_libraries(edgerunner_edgerunner PUBLIC nonstd::span-lite)
70+
71+
find_package(tensorflowlite REQUIRED)
72+
target_link_libraries(edgerunner_edgerunner PUBLIC tensorflow::tensorflowlite)
73+
74+
if(edgerunner_ENABLE_GPU)
75+
target_compile_definitions(
76+
edgerunner_edgerunner
77+
PUBLIC
78+
EDGERUNNER_GPU
79+
)
80+
endif()
81+
6382
# ---- Install rules ----
6483

6584
if(NOT CMAKE_SKIP_INSTALL_RULES)
66-
include(cmake/install-rules.cmake)
85+
include(cmake/install-rules.cmake)
6786
endif()
6887

6988
# ---- Developer mode ----
7089

7190
if(NOT edgerunner_DEVELOPER_MODE)
72-
return()
91+
return()
7392
elseif(NOT PROJECT_IS_TOP_LEVEL)
74-
message(
93+
message(
7594
AUTHOR_WARNING
7695
"Developer mode is intended for developers of edgerunner"
7796
)

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# edgerunner
1+
# Edgerunner
22

3-
This is the edgerunner project.
3+
Edgerunner is a cross-platform, cross-runtime ML inference library for mobile devices. The motivation for Edgerunner is to facilitate quick and easy integration of arbitrary ML models that are targeted for consumer mobile devices (smartphones, laptops, wearables, etc). This is achieved through a convenient runtime-agnostic API.
44

5-
# Building and installing
5+
## Building and installing
66

77
See the [BUILDING](BUILDING.md) document.
88

9-
# Contributing
9+
## Contributing
1010

1111
See the [CONTRIBUTING](CONTRIBUTING.md) document.
1212

13-
# Licensing
13+
## Licensing
1414

1515
<!--
1616
Please go to https://choosealicense.com/licenses/ and choose a license that

cmake/install-config.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
include(CMakeFindDependencyMacro)
22
find_dependency(fmt)
3+
find_dependency(span-lite)
4+
find_dependency(tensorflowlite)
35

46
include("${CMAKE_CURRENT_LIST_DIR}/edgerunnerTargets.cmake")

cmake/variables.cmake

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# Targets necessary to build the project must be provided unconditionally, so
66
# consumers can trivially build and package the project
77
if(PROJECT_IS_TOP_LEVEL)
8-
option(edgerunner_DEVELOPER_MODE "Enable developer mode" OFF)
9-
option(BUILD_SHARED_LIBS "Build shared libs." OFF)
8+
option(edgerunner_DEVELOPER_MODE "Enable developer mode" OFF)
9+
option(BUILD_SHARED_LIBS "Build shared libs." OFF)
1010
endif()
1111

1212
# ---- Suppress C4251 on Windows ----
@@ -29,13 +29,15 @@ set(pragma_suppress_c4251 "
2929
# add_subdirectory or FetchContent is used to consume this project
3030
set(warning_guard "")
3131
if(NOT PROJECT_IS_TOP_LEVEL)
32-
option(
32+
option(
3333
edgerunner_INCLUDES_WITH_SYSTEM
3434
"Use SYSTEM modifier for edgerunner's includes, disabling warnings"
3535
ON
3636
)
37-
mark_as_advanced(edgerunner_INCLUDES_WITH_SYSTEM)
38-
if(edgerunner_INCLUDES_WITH_SYSTEM)
39-
set(warning_guard SYSTEM)
40-
endif()
37+
mark_as_advanced(edgerunner_INCLUDES_WITH_SYSTEM)
38+
if(edgerunner_INCLUDES_WITH_SYSTEM)
39+
set(warning_guard SYSTEM)
40+
endif()
4141
endif()
42+
43+
option(edgerunner_ENABLE_GPU "Enable GPU support" OFF)

conanfile.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ def layout(self):
1010

1111
def requirements(self):
1212
self.requires("fmt/10.2.1")
13+
self.requires("span-lite/0.11.0", transitive_headers=True)
14+
self.requires("tensorflow-lite/2.12.0")
1315

1416
def build_requirements(self):
1517
self.test_requires("catch2/3.6.0")

include/edgerunner/edgerunner.hpp renamed to include/edgerunner/model.hpp

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
#include <filesystem>
44
#include <string>
5-
#include <vector>
5+
6+
#include <nonstd/span.hpp>
67

78
#include "edgerunner/edgerunner_export.hpp"
9+
#include "tensor.hpp"
810

911
namespace edge {
1012

@@ -50,17 +52,24 @@ namespace edge {
5052
* they also solve some other problems that make them worth the time invested.
5153
*/
5254

55+
enum class DELEGATE {
56+
CPU,
57+
GPU,
58+
NPU,
59+
};
60+
61+
enum class STATUS {
62+
SUCCESS,
63+
FAIL
64+
};
65+
5366
/**
5467
* @brief Reports the name of the library
5568
*
5669
* Please see the note above for considerations when creating shared libraries.
5770
*/
58-
template<typename Tensor>
5971
class EDGERUNNER_EXPORT Model {
6072
public:
61-
/**
62-
* @brief Initializes the name field to the name of the project
63-
*/
6473
Model() = default;
6574

6675
Model(const Model&) = default;
@@ -76,21 +85,43 @@ class EDGERUNNER_EXPORT Model {
7685

7786
auto getNumOutputs() const -> size_t { return m_outputs.size(); }
7887

79-
auto getInput(size_t index) const -> Tensor&;
88+
auto getInput(size_t index) const -> std::shared_ptr<Tensor> {
89+
if (index < getNumInputs()) {
90+
return m_inputs[index];
91+
}
8092

81-
auto getOutput(size_t index) const -> Tensor&;
93+
return {};
94+
}
8295

83-
virtual void execute() = 0;
96+
auto getOutput(size_t index) const -> std::shared_ptr<Tensor> {
97+
if (index < getNumOutputs()) {
98+
return m_outputs[index];
99+
}
100+
101+
return {};
102+
}
103+
104+
void setDelegate(const DELEGATE& delegate) { m_delegate = delegate; }
105+
106+
auto getDelegate() const -> DELEGATE { return m_delegate; }
107+
108+
virtual auto applyDelegate() -> STATUS = 0;
109+
110+
virtual auto execute() -> STATUS = 0;
84111

85112
/**
86113
* @brief Returns a non-owning pointer to the string stored in this class
87114
*/
88115
auto name() const -> char const* { return m_name.c_str(); }
89116

90117
protected:
91-
auto accessInputs() -> std::vector<Tensor>& { return m_inputs; }
118+
auto accessInputs() -> std::vector<std::shared_ptr<Tensor>>& {
119+
return m_inputs;
120+
}
92121

93-
auto accessOutputs() -> std::vector<Tensor>& { return m_outputs; }
122+
auto accessOutputs() -> std::vector<std::shared_ptr<Tensor>>& {
123+
return m_outputs;
124+
}
94125

95126
void setName(const std::string& name) { m_name = name; }
96127

@@ -99,10 +130,13 @@ class EDGERUNNER_EXPORT Model {
99130
std::string m_name;
100131

101132
EDGERUNNER_SUPPRESS_C4251
102-
std::vector<Tensor> m_inputs;
133+
std::vector<std::shared_ptr<Tensor>> m_inputs;
134+
135+
EDGERUNNER_SUPPRESS_C4251
136+
std::vector<std::shared_ptr<Tensor>> m_outputs;
103137

104138
EDGERUNNER_SUPPRESS_C4251
105-
std::vector<Tensor> m_outputs;
139+
DELEGATE m_delegate = DELEGATE::CPU;
106140
};
107141

108142
} // namespace edge

0 commit comments

Comments
 (0)