Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
597efed4
MegEngine
项目概览
MegEngine 天元
/
MegEngine
大约 1 年 前同步成功
通知
399
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
597efed4
编写于
2月 25, 2022
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(lite): add get last error code interface in lite c
GitOrigin-RevId: 280cc88092a8357565e5b3f2037529891ed750f3
上级
90c8a58c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
47 addition
and
5 deletion
+47
-5
lite/include/lite/common_enum_c.h
lite/include/lite/common_enum_c.h
+9
-0
lite/lite-c/include/lite-c/global_c.h
lite/lite-c/include/lite-c/global_c.h
+9
-0
lite/lite-c/include/lite-c/network_c.h
lite/lite-c/include/lite-c/network_c.h
+3
-3
lite/lite-c/src/global.cpp
lite/lite-c/src/global.cpp
+22
-2
lite/test/test_tensor_c.cpp
lite/test/test_tensor_c.cpp
+4
-0
未找到文件。
lite/include/lite/common_enum_c.h
浏览文件 @
597efed4
...
@@ -22,6 +22,15 @@ typedef enum {
...
@@ -22,6 +22,15 @@ typedef enum {
ERROR
=
3
,
/*!< Print only errors */
ERROR
=
3
,
/*!< Print only errors */
}
LiteLogLevel
;
}
LiteLogLevel
;
/*!
* \brief The Error Code
*/
typedef
enum
{
OK
=
0
,
LITE_INTERNAL_ERROR
=
1
,
LITE_UNKNOWN_ERROR
=
2
,
}
ErrorCode
;
typedef
enum
{
typedef
enum
{
LITE_DEFAULT
=
0
,
//! default backend is mge
LITE_DEFAULT
=
0
,
//! default backend is mge
}
LiteBackend
;
}
LiteBackend
;
...
...
lite/lite-c/include/lite-c/global_c.h
浏览文件 @
597efed4
...
@@ -23,6 +23,15 @@ extern "C" {
...
@@ -23,6 +23,15 @@ extern "C" {
*/
*/
LITE_API
int
LITE_get_version
(
int
*
major
,
int
*
minor
,
int
*
patch
);
LITE_API
int
LITE_get_version
(
int
*
major
,
int
*
minor
,
int
*
patch
);
/*! \brief Get the last error code.
* \return the current error code
*/
LITE_API
ErrorCode
LITE_get_last_error_code
();
/*! \brief Clear the last error code and error message.
*/
LITE_API
void
LITE_clear_last_error
();
/*! \brief Get the last error message.
/*! \brief Get the last error message.
* \return the message pointer
* \return the message pointer
*/
*/
...
...
lite/lite-c/include/lite-c/network_c.h
浏览文件 @
597efed4
...
@@ -75,7 +75,7 @@ extern "C" {
...
@@ -75,7 +75,7 @@ extern "C" {
* mask 0b10: async if there are multiple comp nodes with
* mask 0b10: async if there are multiple comp nodes with
* mask 0b100: always async
* mask 0b100: always async
*/
*/
typedef
struct
Options
{
typedef
struct
{
int
weight_preprocess
;
int
weight_preprocess
;
int
fuse_preprocess
;
int
fuse_preprocess
;
int
fake_next_exec
;
int
fake_next_exec
;
...
@@ -128,7 +128,7 @@ LITE_API LiteConfig* default_config();
...
@@ -128,7 +128,7 @@ LITE_API LiteConfig* default_config();
* \brief config the network input and output item
* \brief config the network input and output item
*
*
*/
*/
typedef
struct
LiteIO
{
typedef
struct
{
//! the tensor name in the graph corresponding to the IO
//! the tensor name in the graph corresponding to the IO
const
char
*
name
;
const
char
*
name
;
...
@@ -157,7 +157,7 @@ extern LITE_API const LiteIO default_io;
...
@@ -157,7 +157,7 @@ extern LITE_API const LiteIO default_io;
* \brief the input and output information when load the network
* \brief the input and output information when load the network
* the NetworkIO will remain in the network until the network is destroyed
* the NetworkIO will remain in the network until the network is destroyed
*/
*/
typedef
struct
LiteNetworkIO
{
typedef
struct
{
LiteIO
*
inputs
;
LiteIO
*
inputs
;
LiteIO
*
outputs
;
LiteIO
*
outputs
;
size_t
input_size
;
//! the number IO in inputs
size_t
input_size
;
//! the number IO in inputs
...
...
lite/lite-c/src/global.cpp
浏览文件 @
597efed4
...
@@ -17,10 +17,20 @@ namespace {
...
@@ -17,10 +17,20 @@ namespace {
class
ErrorMsg
{
class
ErrorMsg
{
public:
public:
std
::
string
&
get_error_msg
()
{
return
error_msg
;
}
std
::
string
&
get_error_msg
()
{
return
error_msg
;
}
void
set_error_msg
(
const
std
::
string
&
msg
)
{
error_msg
=
msg
;
}
ErrorCode
get_error_code
()
{
return
error_code
;
}
void
set_error_msg
(
const
std
::
string
&
msg
,
ErrorCode
code
)
{
error_msg
=
msg
+
", Error Code: "
+
std
::
to_string
(
code
);
error_code
=
code
;
}
void
clear_error
()
{
error_code
=
ErrorCode
::
OK
;
error_msg
.
clear
();
}
private:
private:
std
::
string
error_msg
;
std
::
string
error_msg
;
ErrorCode
error_code
;
};
};
static
LITE_MUTEX
mtx_error
;
static
LITE_MUTEX
mtx_error
;
...
@@ -32,10 +42,20 @@ ErrorMsg& get_global_error() {
...
@@ -32,10 +42,20 @@ ErrorMsg& get_global_error() {
int
LiteHandleException
(
const
std
::
exception
&
e
)
{
int
LiteHandleException
(
const
std
::
exception
&
e
)
{
LITE_LOCK_GUARD
(
mtx_error
);
LITE_LOCK_GUARD
(
mtx_error
);
get_global_error
().
set_error_msg
(
e
.
what
());
get_global_error
().
set_error_msg
(
e
.
what
()
,
ErrorCode
::
LITE_INTERNAL_ERROR
);
return
-
1
;
return
-
1
;
}
}
ErrorCode
LITE_get_last_error_code
()
{
LITE_LOCK_GUARD
(
mtx_error
);
return
get_global_error
().
get_error_code
();
}
void
LITE_clear_last_error
()
{
LITE_LOCK_GUARD
(
mtx_error
);
get_global_error
().
clear_error
();
}
const
char
*
LITE_get_last_error
()
{
const
char
*
LITE_get_last_error
()
{
LITE_LOCK_GUARD
(
mtx_error
);
LITE_LOCK_GUARD
(
mtx_error
);
return
get_global_error
().
get_error_msg
().
c_str
();
return
get_global_error
().
get_error_msg
().
c_str
();
...
...
lite/test/test_tensor_c.cpp
浏览文件 @
597efed4
...
@@ -56,7 +56,11 @@ TEST(TestCapiTensor, Basic) {
...
@@ -56,7 +56,11 @@ TEST(TestCapiTensor, Basic) {
//! test error
//! test error
ASSERT_EQ
(
LITE_is_pinned_host
(
c_tensor0
,
nullptr
),
-
1
);
ASSERT_EQ
(
LITE_is_pinned_host
(
c_tensor0
,
nullptr
),
-
1
);
ASSERT_NE
(
strlen
(
LITE_get_last_error
()),
0
);
ASSERT_NE
(
strlen
(
LITE_get_last_error
()),
0
);
ASSERT_EQ
(
LITE_get_last_error_code
(),
ErrorCode
::
LITE_INTERNAL_ERROR
);
printf
(
"The last error is: %s
\n
"
,
LITE_get_last_error
());
printf
(
"The last error is: %s
\n
"
,
LITE_get_last_error
());
LITE_clear_last_error
();
ASSERT_EQ
(
strlen
(
LITE_get_last_error
()),
0
);
ASSERT_EQ
(
LITE_get_last_error_code
(),
ErrorCode
::
OK
);
LITE_destroy_tensor
(
c_tensor0
);
LITE_destroy_tensor
(
c_tensor0
);
LITE_destroy_tensor
(
c_tensor1
);
LITE_destroy_tensor
(
c_tensor1
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录