Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zpye committed Apr 21, 2023
1 parent 9bf0a98 commit 01c9552
Show file tree
Hide file tree
Showing 110 changed files with 28,200 additions and 1 deletion.
213 changes: 213 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignArrayOfStructures: Left
AlignConsecutiveMacros: Consecutive
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros:
- __capability
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: true
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*\.h>'
Priority: 1
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 3
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '([-_](test|unittest))?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseLabels: true
IndentCaseBlocks: false
IndentGotoLabels: false
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PenaltyIndentedWhitespace: 0
PointerAlignment: Left
PPIndentWidth: -1
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
- ParseTestProto
- ParsePartialTestProto
CanonicalDelimiter: pb
BasedOnStyle: google
ReferenceAlignment: Pointer
ReflowComments: true
ShortNamespaceLines: 0
SortIncludes: CaseInsensitive
SortIncludes: true
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Auto
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode/
.xmake/
build/
18 changes: 18 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[submodule "3rdparty/abseil-cpp"]
path = 3rdparty/abseil-cpp
url = [email protected]:abseil/abseil-cpp.git
[submodule "3rdparty/CGraph"]
path = 3rdparty/CGraph
url = [email protected]:ChunelFeng/CGraph.git
[submodule "3rdparty/eigen"]
path = 3rdparty/eigen
url = https://gitlab.com/libeigen/eigen.git
[submodule "3rdparty/benchmark"]
path = 3rdparty/benchmark
url = [email protected]:google/benchmark.git
[submodule "3rdparty/tmp"]
path = 3rdparty/tmp
url = [email protected]:zjhellofss/tmp.git
[submodule "3rdparty/Catch2"]
path = 3rdparty/Catch2
url = [email protected]:catchorg/Catch2.git
1 change: 1 addition & 0 deletions 3rdparty/CGraph
Submodule CGraph added at fa73cf
1 change: 1 addition & 0 deletions 3rdparty/Catch2
Submodule Catch2 added at c35907
1 change: 1 addition & 0 deletions 3rdparty/abseil-cpp
Submodule abseil-cpp added at 069776
1 change: 1 addition & 0 deletions 3rdparty/benchmark
Submodule benchmark added at b17743
1 change: 1 addition & 0 deletions 3rdparty/eigen
Submodule eigen added at e88719
1 change: 1 addition & 0 deletions 3rdparty/tmp
Submodule tmp added at 1c9d2b
47 changes: 47 additions & 0 deletions 3rdparty/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
-- 3rdparty libs
-- set_languages("cxx20")

target("abseil-log")
set_kind("static")
add_defines("ABSL_BUILD_DLL=1")
add_defines("ABSL_CONSUME_DLL=1", "NOMINMAX", { public = true })
add_includedirs("abseil-cpp/", { public = true })
add_files("abseil-cpp/absl/log/*.cc|*_test.cc|*_benchmark.cc|*_mock_*.cc",
"abseil-cpp/absl/log/internal/*.cc|*_test.cc|test_*.cc",
"abseil-cpp/absl/strings/**.cc|**_test.cc|**_benchmark.cc",
"abseil-cpp/absl/time/**.cc|**_test.cc|**_benchmark.cc",
"abseil-cpp/absl/flags/**.cc|**_test.cc|**_benchmark.cc",
"abseil-cpp/absl/container/**.cc|**_test.cc|**_benchmark.cc",
"abseil-cpp/absl/synchronization/**.cc|**_test.cc|**_benchmark.cc",
"abseil-cpp/absl/debugging/**.cc|**_test.cc|**_benchmark.cc",
"abseil-cpp/absl/numeric/**.cc|**_test.cc|**_benchmark.cc",
"abseil-cpp/absl/crc/**.cc|**_test.cc|**_benchmark.cc",
"abseil-cpp/absl/hash/**.cc|**_test.cc|**_benchmark.cc",
"abseil-cpp/absl/base/**.cc|**_test.cc|**_testing.cc|**_test_common.cc|**_benchmark.cc")

target("cgraph")
set_kind("static")
add_includedirs("CGraph/src/", { public = true })
add_files("CGraph/src/**.cpp")

target("eigen")
set_kind("headeronly")
add_includedirs("eigen/", { public = true })
add_headerfiles("eigen/unsupported/Eigen/CXX11/**.h")
add_defines("EIGEN_USE_THREADS", { public = true })

target("catch2")
set_kind("headeronly")
add_includedirs("Catch2/single_include/", { public = true })
add_headerfiles("Catch2/single_include/catch2/catch.hpp")

target("benchmark")
set_kind("static")
add_rules("mode.release", "mode.debug")
add_includedirs("benchmark/include/", { public = true })
add_files("benchmark/src/**.cc")
add_defines("BENCHMARK_STATIC_DEFINE", { public = true })
set_optimize("fastest")
if is_plat("windows") then
add_syslinks("shlwapi")
end
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
# SimpleInfer
# SimpleInfer

SimpleInfer is a neural network inference framework based on [KuiperInfer](https://github.com/zjhellofss/KuiperInfer).

## Build

SimpleInfer uses [xmake](https://xmake.io/#/) to build library and tests.

```shell
git clone --recursive
cd SimpleInfer
xmake config -m release
xmake
```
## Run

After building successfully, run test-engin to check.

```shell
xmake run test-engine
```

## Reference

[KuiperInfer](https://github.com/zjhellofss/KuiperInfer) -> basic framework

[ncnn](https://github.com/Tencent/ncnn) -> pnnx ir, simpleocv and mat-pixel operations

[Eigen](https://gitlab.com/libeigen/eigen), [tensorflow](https://github.com/tensorflow/tensorflow) -> Eigen tensor

[abseil](https://github.com/abseil/abseil-cpp) -> logging, string format operations

[CGraph](https://github.com/ChunelFeng/CGraph) -> graph based pipeline

[benchmark](https://github.com/google/benchmark), [Catch2](https://github.com/catchorg/Catch2) -> benchmark and unit tests
2 changes: 2 additions & 0 deletions bench/bench_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include <benchmark/benchmark.h>
BENCHMARK_MAIN();
33 changes: 33 additions & 0 deletions bench/bench_yolo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <benchmark/benchmark.h>

#include <string>

#include "engine.h"

static void BM_Yolov5s_Batch8_640x640(benchmark::State &state) {
using namespace SimpleInfer;

const std::string model_path(MODEL_PATH);
const std::string param_file =
model_path + "/yolo/demo/yolov5s_batch8.pnnx.param";
const std::string bin_file =
model_path + "/yolo/demo/yolov5s_batch8.pnnx.bin";

InitializeContext();

Engine engine;
engine.LoadModel(param_file, bin_file);

Tensor input(SimpleInfer::DataType::kFloat32, {8, 640, 640, 3}, true);
engine.Input("0", input);

for (auto _ : state) {
engine.Forward();
// benchmark::DoNotOptimize(_);
}

Tensor output;
engine.Extract("140", output);
}

BENCHMARK(BM_Yolov5s_Batch8_640x640)->Unit(benchmark::kMillisecond);
Binary file added imgs/31.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/KuiperInfer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/bus.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/car.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/zidane.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 01c9552

Please sign in to comment.