Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
42ec91aa
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
404
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看板
提交
42ec91aa
编写于
11月 30, 2022
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(serialization): adapted to dummy extern opr loader for MegCC
GitOrigin-RevId: 9cb32215204b822d47a0a9d72bab314ad6fb5a6d
上级
2a2c1275
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
64 addition
and
2 deletion
+64
-2
src/serialization/impl/extern_c_opr.cpp
src/serialization/impl/extern_c_opr.cpp
+45
-2
src/serialization/test/extern_c_opr.cpp
src/serialization/test/extern_c_opr.cpp
+19
-0
未找到文件。
src/serialization/impl/extern_c_opr.cpp
浏览文件 @
42ec91aa
...
@@ -13,6 +13,7 @@ using namespace opr;
...
@@ -13,6 +13,7 @@ using namespace opr;
namespace
{
namespace
{
const
char
PLACEHOLDER_TYPE_NAME
[]
=
"placeholder"
;
const
char
PLACEHOLDER_TYPE_NAME
[]
=
"placeholder"
;
const
char
*
DUMMY_LOADER_NAME
=
"extern_opr_dummy"
;
typedef
MGBOprDesc
*
(
*
opr_desc_transformer_t
)(
void
*
input
);
typedef
MGBOprDesc
*
(
*
opr_desc_transformer_t
)(
void
*
input
);
...
@@ -437,6 +438,14 @@ cg::OperatorNodeBase* ExternCOprRunner::make_placeholder(
...
@@ -437,6 +438,14 @@ cg::OperatorNodeBase* ExternCOprRunner::make_placeholder(
const
SymbolVarArray
&
inputs
,
const
TensorShapeArray
&
output_shapes
,
const
SymbolVarArray
&
inputs
,
const
TensorShapeArray
&
output_shapes
,
const
char
*
name
,
const
void
*
data
,
size_t
data_len
,
const
char
*
name
,
const
void
*
data
,
size_t
data_len
,
const
OperatorNodeConfig
&
config
,
const
SmallVector
<
DType
>&
output_dtypes
)
{
const
OperatorNodeConfig
&
config
,
const
SmallVector
<
DType
>&
output_dtypes
)
{
std
::
string
_name
(
name
);
size_t
pos
=
0
;
if
((
pos
=
_name
.
find
(
':'
))
!=
std
::
string
::
npos
)
{
_name
=
_name
.
substr
(
0
,
pos
);
}
mgb_throw_if
(
_name
.
compare
(
DUMMY_LOADER_NAME
)
==
0
,
MegBrainError
,
"The
\"
extern_opr_dummy[:xxx]
\"
is a reserved loader name.
\n
"
);
auto
desc
=
PlaceholderMGBOprDesc
::
make
(
auto
desc
=
PlaceholderMGBOprDesc
::
make
(
inputs
.
size
(),
name
,
output_shapes
,
output_dtypes
,
data
,
data_len
);
inputs
.
size
(),
name
,
output_shapes
,
output_dtypes
,
data
,
data_len
);
...
@@ -492,11 +501,45 @@ cg::OperatorNodeBase* ExternCOprRunner::load(
...
@@ -492,11 +501,45 @@ cg::OperatorNodeBase* ExternCOprRunner::load(
name
=
name
.
substr
(
0
,
index
);
name
=
name
.
substr
(
0
,
index
);
auto
&&
map
=
loader_map
();
auto
&&
map
=
loader_map
();
auto
iter
=
map
.
find
(
name
);
auto
iter
=
map
.
find
(
name
);
// !!For MegCC loader.
// If MegCC compiles a model containing an extern opr, it needs to use an extern
// opr loader. In order to make MegCC's compiler not dependent on the extern opr
// loader, MegCC registers a dummy loader with the name "extern_opr_dummy".
bool
dummy_loader
=
false
;
if
(
iter
==
map
.
end
())
{
mgb_log_debug
(
"Can NOT find loader '%s', try to find the dummy loader '%s'
\n
"
,
name
.
c_str
(),
DUMMY_LOADER_NAME
);
iter
=
map
.
find
(
DUMMY_LOADER_NAME
);
if
(
iter
!=
map
.
end
())
{
dummy_loader
=
true
;
mgb_log_debug
(
"Found the dummy extern opr loader.
\n
"
);
}
else
{
mgb_log_debug
(
"Can NOT find the dummy loader '%s'
\n
"
,
DUMMY_LOADER_NAME
);
}
}
mgb_assert
(
mgb_assert
(
iter
!=
map
.
end
(),
"can not find loader for ExternCOprRunner
`
%s'"
,
iter
!=
map
.
end
(),
"can not find loader for ExternCOprRunner
'
%s'"
,
name
.
c_str
());
name
.
c_str
());
auto
data
=
ctx
.
load_shared_buf_with_len
();
auto
data
=
ctx
.
load_shared_buf_with_len
();
auto
desc
=
iter
->
second
.
first
.
create_desc
(
inputs
.
size
(),
data
.
data
(),
data
.
size
());
MGBOprDesc
*
desc
=
nullptr
;
// For MegCC loader.
// If the loader is a MegCC dummy loader, copy the 'dump_name' in front of the
// 'data' to relate 'data' to 'name'. So multi loaders and multi extern oprs in
// single loader are supported.
if
(
dummy_loader
)
{
size_t
buf_len
=
data
.
size
()
+
sizeof
(
size_t
)
+
dump_name
.
size
();
std
::
shared_ptr
<
void
>
buf
{
malloc
(
buf_len
),
free
};
char
*
buf_ptr
=
reinterpret_cast
<
char
*>
(
buf
.
get
());
*
(
size_t
*
)
buf_ptr
=
dump_name
.
size
();
buf_ptr
+=
sizeof
(
size_t
);
memmove
(
buf_ptr
,
dump_name
.
c_str
(),
dump_name
.
size
());
buf_ptr
+=
dump_name
.
size
();
memmove
(
buf_ptr
,
data
.
data
(),
data
.
size
());
desc
=
iter
->
second
.
first
.
create_desc
(
inputs
.
size
(),
buf
.
get
(),
buf_len
);
}
else
desc
=
iter
->
second
.
first
.
create_desc
(
inputs
.
size
(),
data
.
data
(),
data
.
size
());
mgb_throw_if
(
nullptr
==
desc
,
MegBrainError
,
"loader create desc returns nullptr"
);
mgb_throw_if
(
nullptr
==
desc
,
MegBrainError
,
"loader create desc returns nullptr"
);
...
...
src/serialization/test/extern_c_opr.cpp
浏览文件 @
42ec91aa
...
@@ -497,4 +497,23 @@ TEST(TestExternCOpr, Dedup) {
...
@@ -497,4 +497,23 @@ TEST(TestExternCOpr, Dedup) {
ASSERT_EQ
(
0
,
MGBOprDescImpl
<>::
nr_inst
);
ASSERT_EQ
(
0
,
MGBOprDescImpl
<>::
nr_inst
);
}
}
TEST
(
TestExternCOpr
,
DummyLoaderName
)
{
float
bias
=
0.0
f
;
ASSERT_THROW
(
opr
::
ExternCOprRunner
::
make_placeholder
(
{
SymbolVar
()},
{
TensorShape
{
1
},
TensorShape
{
1
}},
"extern_opr_dummy"
,
&
bias
,
sizeof
(
bias
)),
MegBrainError
);
ASSERT_THROW
(
opr
::
ExternCOprRunner
::
make_placeholder
(
{
SymbolVar
()},
{
TensorShape
{
1
},
TensorShape
{
1
}},
"extern_opr_dummy:opr0"
,
&
bias
,
sizeof
(
bias
)),
MegBrainError
);
ASSERT_THROW
(
opr
::
ExternCOprRunner
::
make_placeholder
(
{
SymbolVar
()},
{
TensorShape
{
1
},
TensorShape
{
1
}},
"extern_opr_dummy:opr1"
,
&
bias
,
sizeof
(
bias
)),
MegBrainError
);
}
// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}
// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录