Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
9be6d7b6
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
403
Star
4705
Fork
582
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MegEngine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
9be6d7b6
编写于
6月 29, 2022
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(lite): fix lite header
GitOrigin-RevId: e255597121f1fba1920b6909596ba56c7e40f888
上级
ab8f6398
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
193 addition
and
38 deletion
+193
-38
lite/CMakeLists.txt
lite/CMakeLists.txt
+10
-9
lite/build_config/lite_build_config.h
lite/build_config/lite_build_config.h
+10
-8
lite/build_config/lite_build_config.h.in
lite/build_config/lite_build_config.h.in
+7
-0
lite/example/cpp_example/helper.h
lite/example/cpp_example/helper.h
+150
-0
lite/example/cpp_example/mge/basic.cpp
lite/example/cpp_example/mge/basic.cpp
+8
-8
lite/example/cpp_example/mge/cv/detect_yolox.cpp
lite/example/cpp_example/mge/cv/detect_yolox.cpp
+0
-2
lite/example/cpp_example/mge/cv/picture_classification.cpp
lite/example/cpp_example/mge/cv/picture_classification.cpp
+0
-2
lite/example/cpp_example/mge/device_io.cpp
lite/example/cpp_example/mge/device_io.cpp
+0
-1
lite/example/cpp_example/mge/lite_c_interface.cpp
lite/example/cpp_example/mge/lite_c_interface.cpp
+8
-8
未找到文件。
lite/CMakeLists.txt
浏览文件 @
9be6d7b6
...
...
@@ -28,11 +28,13 @@ if(MGE_WITH_MINIMUM_SIZE)
set
(
LITE_ENABLE_EXCEPTION OFF
)
endif
()
if
(
LITE_BUILD_WITH_MGE
)
set
(
LITE_BUILD_WITH_MGE ON
)
endif
()
# Write out lite_build_config.h It defines macros needed by lite
configure_file
(
src
/lite_build_config.h.in
configure_file
(
build_config
/lite_build_config.h.in
${
CMAKE_CURRENT_BINARY_DIR
}
/genfiles/lite_build_config.h
)
install
(
FILES
${
CMAKE_CURRENT_BINARY_DIR
}
/genfiles/lite_build_config.h
DESTINATION
${
CMAKE_INSTALL_PREFIX
}
/lite/include
)
# begin config lite
if
(
LITE_BUILD_WITH_MGE
...
...
@@ -47,7 +49,6 @@ include_directories($<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/genfiles>)
if
(
LITE_BUILD_WITH_MGE
)
target_link_libraries
(
lite_static PRIVATE megbrain megdnn
${
MGE_CUDA_LIBS
}
)
add_compile_definitions
(
LITE_BUILD_WITH_MGE=1
)
message
(
STATUS
"build lite with MegEngine."
)
else
()
target_link_libraries
(
lite_static PUBLIC flatbuffers
)
...
...
@@ -154,7 +155,10 @@ if(UNIX AND NOT APPLE)
set_target_properties
(
lite_shared_whl PROPERTIES LINK_DEPENDS
${
LITE_VERSION_SCRIPT
}
)
endif
()
# config install
# config install, please keep all install file with lite/BUILD:hdrs_public
install
(
FILES
${
CMAKE_CURRENT_BINARY_DIR
}
/genfiles/lite_build_config.h
DESTINATION
${
CMAKE_INSTALL_PREFIX
}
/lite/build_config
)
install
(
TARGETS lite_static
LIBRARY DESTINATION lite/lib/
${
MGE_ARCH
}
...
...
@@ -176,9 +180,6 @@ if(NOT WIN32)
ARCHIVE DESTINATION lite/lib/
${
MGE_ARCH
}
)
endif
()
install
(
FILES
${
PROJECT_SOURCE_DIR
}
/lite/include/lite/common_enum_c.h
DESTINATION
${
CMAKE_INSTALL_PREFIX
}
/lite/include/lite-c
)
install
(
DIRECTORY
${
PROJECT_SOURCE_DIR
}
/lite/include
DESTINATION
${
CMAKE_INSTALL_PREFIX
}
/lite
...
...
@@ -187,7 +188,7 @@ install(
install
(
DIRECTORY
${
PROJECT_SOURCE_DIR
}
/lite/lite-c/include
DESTINATION
${
CMAKE_INSTALL_PREFIX
}
/lite
DESTINATION
${
CMAKE_INSTALL_PREFIX
}
/lite
/lite-c
FILES_MATCHING
PATTERN
"*.h"
)
...
...
lite/build_config/lite_build_config.h
浏览文件 @
9be6d7b6
/**
* \file lite/build_config/lite_build_config.h
*
* This file is part of MegEngine, a deep learning framework developed by
* Megvii.
*
* \copyright Copyright (c) 2020-2021 Megvii Inc. All rights reserved.
*/
//! this file always for bazel
#ifndef _HEADER_LITE_BUILD_CONFIG
#define _HEADER_LITE_BUILD_CONFIG
...
...
@@ -28,4 +22,12 @@
#ifndef LITE_ASSERT_LOC
#define LITE_ASSERT_LOC 1
#endif
#ifndef LITE_BUILD_WITH_MGE
#define LITE_BUILD_WITH_MGE 1
#endif
#ifndef LITE_BUILD_WITH_RKNPU
#define LITE_BUILD_WITH_RKNPU 0
#endif
#endif // _HEADER_LITE_BUILD_CONFIG
lite/
src
/lite_build_config.h.in
→
lite/
build_config
/lite_build_config.h.in
浏览文件 @
9be6d7b6
//! this file always for cmake
#ifndef _HEADER_LITE_BUILD_CONFIG
#define _HEADER_LITE_BUILD_CONFIG
#cmakedefine01 LITE_ENABLE_LOGGING
#cmakedefine01 LITE_ENABLE_EXCEPTION
#cmakedefine01 LITE_BUILD_WITH_MGE
#cmakedefine01 LITE_WITH_CUDA
#cmakedefine01 LITE_ASSERT_LOC
...
...
@@ -26,4 +29,8 @@
#ifndef LITE_ASSERT_LOC
#define LITE_ASSERT_LOC 0
#endif
#ifndef LITE_BUILD_WITH_MGE
#define LITE_BUILD_WITH_MGE 0
#endif
#endif // _HEADER_LITE_BUILD_CONFIG
lite/example/cpp_example/helper.h
0 → 100644
浏览文件 @
9be6d7b6
#pragma once
//! helper function like define: lite/src/misc.h, but we need example code just
//! depends on install header, not depends any lite src file
#include <chrono>
#include <cstdio>
#include <stdexcept>
#include <string>
std
::
string
exampe_ssprintf
(
const
char
*
fmt
=
0
,
...)
__attribute__
((
format
(
printf
,
1
,
2
)));
#define LITE_EXAMPLE_THROW(msg) \
do { \
std::string msg_str(msg); \
printf("%s\n", msg_str.c_str()); \
__builtin_trap(); \
} while (0)
//! branch prediction hint: likely to take
#define lite_example_likely(v) __builtin_expect(static_cast<bool>(v), 1)
//! branch prediction hint: unlikely to take
#define lite_example_unlikely(v) __builtin_expect(static_cast<bool>(v), 0)
#define LITE_EXAMPLE_ASSERT(expr, msg...) \
do { \
if (lite_example_unlikely(!(expr))) { \
auto info = exampe_ssprintf(msg); \
LITE_EXAMPLE_THROW(exampe_ssprintf( \
"Assert \' %s \' failed at file : %s \n" \
"line %d : %s,\nextra " \
"message: %s", \
#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__, info.c_str())); \
} \
} while (0)
#define LITE_EXAMPLE_MARK_USED_VAR(var) ((void)var)
namespace
lite_example_helper
{
class
ScopedTimer
{
public:
typedef
std
::
chrono
::
system_clock
Clock
;
typedef
std
::
chrono
::
nanoseconds
Nsec
;
ScopedTimer
(
std
::
string
name
)
:
m_name
(
name
)
{
m_start
=
Clock
::
now
();
}
~
ScopedTimer
()
{
m_stop
=
Clock
::
now
();
std
::
chrono
::
duration
<
double
>
elapsed
=
m_stop
-
m_start
;
Nsec
u
=
std
::
chrono
::
duration_cast
<
Nsec
>
(
elapsed
);
auto
msg
=
exampe_ssprintf
(
"%s used time %fms."
,
m_name
.
c_str
(),
static_cast
<
double
>
(
u
.
count
())
/
1000000.
f
);
printf
(
"%s"
,
msg
.
c_str
());
}
private:
std
::
chrono
::
time_point
<
std
::
chrono
::
system_clock
>
m_start
,
m_stop
;
const
std
::
string
m_name
;
};
class
Timer
{
public:
typedef
std
::
chrono
::
system_clock
Clock
;
typedef
std
::
chrono
::
nanoseconds
Nsec
;
Timer
(
std
::
string
name
)
:
m_name
(
name
)
{
m_start
=
Clock
::
now
();
}
double
get_used_time
()
{
m_stop
=
Clock
::
now
();
std
::
chrono
::
duration
<
double
>
elapsed
=
m_stop
-
m_start
;
Nsec
u
=
std
::
chrono
::
duration_cast
<
Nsec
>
(
elapsed
);
return
static_cast
<
double
>
(
u
.
count
())
/
1000000.0
;
}
void
print_used_time
(
int
iter
)
{
m_stop
=
Clock
::
now
();
std
::
chrono
::
duration
<
double
>
elapsed
=
m_stop
-
m_start
;
Nsec
u
=
std
::
chrono
::
duration_cast
<
Nsec
>
(
elapsed
);
printf
(
"%s used time %f ms
\n
"
,
(
m_name
+
std
::
to_string
(
iter
)).
c_str
(),
static_cast
<
double
>
(
u
.
count
())
/
1000000.0
);
}
void
reset_start
()
{
m_start
=
Clock
::
now
();
}
private:
std
::
chrono
::
time_point
<
std
::
chrono
::
system_clock
>
m_start
,
m_stop
;
const
std
::
string
m_name
;
};
inline
void
mark_used_variable
()
{}
template
<
typename
T
,
typename
...
Arg
>
inline
void
mark_used_variable
(
T
firstArg
,
Arg
...
args
)
{
LITE_EXAMPLE_MARK_USED_VAR
(
firstArg
);
mark_used_variable
(
args
...);
}
}
// namespace lite_example_helper
#if defined(_WIN32)
#include <io.h>
#include <windows.h>
#undef CONST
#define F_OK 0
#define RTLD_LAZY 0
// On the windows platform we use a lib_filename without a full path so
// the win-api "LoadLibrary" would uses a standard search strategy to
// find the lib module. As we cannot access to the lib_filename without a
// full path, we should not use "access(a, b)" to verify it.
#define access(a, b) false
static
inline
void
*
dlopen
(
const
char
*
file
,
int
)
{
return
static_cast
<
void
*>
(
LoadLibrary
(
file
));
}
static
inline
char
*
dlerror
()
{
const
char
*
errmsg
=
"dlerror not aviable in windows"
;
return
const_cast
<
char
*>
(
errmsg
);
}
static
inline
void
*
dlsym
(
void
*
handle
,
const
char
*
name
)
{
FARPROC
symbol
=
GetProcAddress
((
HMODULE
)
handle
,
name
);
return
reinterpret_cast
<
void
*>
(
symbol
);
}
#elif __linux__ || __unix__ || __APPLE__
#include <dlfcn.h>
#include <unistd.h>
#endif
#if __DEPLOY_ON_XP_SP2__
//! refer to
//! https://docs.microsoft.com/en-us/cpp/build/configuring-programs-for-windows-xp?view=msvc-160
//! xp sp2 do not support vc runtime fully, casused by KERNEL32.dll do not
//! implement some base apis for c++ std function, for example,
//! std::mutex/std::thread/std::condition_variable as a workround, we will
//! disable some MegEngine feature on xp sp2 env, for exampe, multi-thread etc!
#define LITE_MUTEX size_t
#define LITE_RECURSIVE_MUTEX size_t
#define LITE_LOCK_GUARD(mtx) LITE_EXAMPLE_MARK_USED_VAR(mtx)
#define LITE_LOCK_GUARD_UNIQUE(mtx) LITE_EXAMPLE_MARK_USED_VAR(mtx)
#define LITE_LOCK_GUARD_SHARED(mtx) \
LITE_EXAMPLE_MARK_USED_VAR(LITE_EXAMPLE_MARK_USED_VAR)
#else
#define LITE_MUTEX std::mutex
#define LITE_RECURSIVE_MUTEX std::recursive_mutex
#define LITE_LOCK_GUARD(mtx) std::lock_guard<decltype(mtx)> LITE_LOCK_GUARD_CTOR(mtx)
#define LITE_LOCK_GUARD_UNIQUE(mtx) \
std::unique_lock<decltype(mtx)> LITE_LOCK_GUARD_CTOR(mtx)
#define LITE_LOCK_GUARD_SHARED(mtx) \
std::shared_lock<decltype(mtx)> LITE_LOCK_GUARD_CTOR(mtx)
#endif
// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}
lite/example/cpp_example/mge/basic.cpp
浏览文件 @
9be6d7b6
...
...
@@ -3,7 +3,7 @@
#if LITE_BUILD_WITH_MGE
#include <cstdio>
#include "
misc
.h"
#include "
helper
.h"
using
namespace
lite
;
using
namespace
example
;
...
...
@@ -96,12 +96,12 @@ bool basic_load_from_path(const Args& args) {
//! forward
{
lite
::
Timer
ltimer
(
"warmup"
);
lite
_example_helper
::
Timer
ltimer
(
"warmup"
);
network
->
forward
();
network
->
wait
();
ltimer
.
print_used_time
(
0
);
}
lite
::
Timer
ltimer
(
"forward_iter"
);
lite
_example_helper
::
Timer
ltimer
(
"forward_iter"
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
network
->
forward
();
network
->
wait
();
...
...
@@ -110,7 +110,7 @@ bool basic_load_from_path(const Args& args) {
//! forward
{
lite
::
Timer
ltimer
(
"warmup"
);
lite
_example_helper
::
Timer
ltimer
(
"warmup"
);
network
->
forward
();
network
->
wait
();
ltimer
.
print_used_time
(
0
);
...
...
@@ -167,12 +167,12 @@ bool basic_load_from_path_with_loader(const Args& args) {
//! forward
{
lite
::
Timer
ltimer
(
"warmup"
);
lite
_example_helper
::
Timer
ltimer
(
"warmup"
);
network
->
forward
();
network
->
wait
();
ltimer
.
print_used_time
(
0
);
}
lite
::
Timer
ltimer
(
"forward_iter"
);
lite
_example_helper
::
Timer
ltimer
(
"forward_iter"
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
ltimer
.
reset_start
();
network
->
forward
();
...
...
@@ -481,12 +481,12 @@ bool load_from_path_run_cuda(const Args& args) {
//! forward
{
lite
::
Timer
ltimer
(
"warmup"
);
lite
_example_helper
::
Timer
ltimer
(
"warmup"
);
network
->
forward
();
network
->
wait
();
ltimer
.
print_used_time
(
0
);
}
lite
::
Timer
ltimer
(
"forward_iter"
);
lite
_example_helper
::
Timer
ltimer
(
"forward_iter"
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
ltimer
.
reset_start
();
network
->
forward
();
...
...
lite/example/cpp_example/mge/cv/detect_yolox.cpp
浏览文件 @
9be6d7b6
...
...
@@ -3,8 +3,6 @@
#if LITE_BUILD_WITH_MGE
#include <cstdio>
#include "misc.h"
#define STB_IMAGE_STATIC
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
...
...
lite/example/cpp_example/mge/cv/picture_classification.cpp
浏览文件 @
9be6d7b6
...
...
@@ -3,8 +3,6 @@
#if LITE_BUILD_WITH_MGE
#include <cstdio>
#include "misc.h"
#define STB_IMAGE_STATIC
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
...
...
lite/example/cpp_example/mge/device_io.cpp
浏览文件 @
9be6d7b6
#include <thread>
#include "example.h"
#if LITE_BUILD_WITH_MGE
#include "misc.h"
using
namespace
lite
;
using
namespace
example
;
...
...
lite/example/cpp_example/mge/lite_c_interface.cpp
浏览文件 @
9be6d7b6
#include "example.h"
#include "
misc
.h"
#include "
helper
.h"
#if LITE_BUILD_WITH_MGE
#include "lite-c/global_c.h"
#include "lite-c/network_c.h"
...
...
@@ -7,12 +7,12 @@
#include <thread>
#define LITE_CAPI_CHECK(_expr) \
do { \
int _ret = (_expr); \
if (_ret) { \
LITE_THROW(LITE_get_last_error()); \
} \
#define LITE_CAPI_CHECK(_expr)
\
do {
\
int _ret = (_expr);
\
if (_ret) {
\
LITE_
EXAMPLE_
THROW(LITE_get_last_error()); \
}
\
} while (0)
bool
basic_c_interface
(
const
lite
::
example
::
Args
&
args
)
{
...
...
@@ -95,7 +95,7 @@ bool device_io_c_interface(const lite::example::Args& args) {
LITE_CAPI_CHECK
(
LITE_get_tensor_total_size_in_byte
(
c_input_tensor
,
&
length_tensor_in
));
if
(
length_read_in
!=
length_tensor_in
)
{
LITE_THROW
(
LITE_
EXAMPLE_
THROW
(
"The input data size is not match the network input tensro "
"size,
\n
"
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录