Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
eb3c6473
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看板
提交
eb3c6473
编写于
2月 28, 2023
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(jit): fix the JIT shallow copy error
GitOrigin-RevId: 513b7acf52e95e100583cb91a6fe04be09642a2f
上级
99040dbe
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
64 addition
and
1 deletion
+64
-1
imperative/src/impl/transformations/trace.cpp
imperative/src/impl/transformations/trace.cpp
+2
-0
src/jit/impl/jit.sereg.h
src/jit/impl/jit.sereg.h
+5
-1
src/jit/test/codegen.cpp
src/jit/test/codegen.cpp
+57
-0
未找到文件。
imperative/src/impl/transformations/trace.cpp
浏览文件 @
eb3c6473
...
...
@@ -479,6 +479,8 @@ void CompiledTransformation::compile() {
}
}
m_executable
=
m_graph
->
compile
(
output_specs
);
mgb_assert
(
m_executable
!=
nullptr
,
"The compiled executable is nullptr."
);
m_var_accessors
=
var_accessors
;
m_output_spec
=
output_specs
;
}
...
...
src/jit/impl/jit.sereg.h
浏览文件 @
eb3c6473
...
...
@@ -35,8 +35,12 @@ cg::OperatorNodeBase* opr_shallow_copy_jit_executor_opr(
};
cg
::
DepOprIter
iter
{
on_opr
};
for
(
size_t
i
=
0
;
i
<
inputs
.
size
();
++
i
)
{
var_replace_map
[
opr
.
input
(
i
)]
=
inputs
[
i
];
auto
input_opr
=
opr
.
input
(
i
)
->
owner_opr
();
for
(
size_t
j
=
0
;
j
<
input_opr
->
output
().
size
();
j
++
)
{
var_replace_map
[
input_opr
->
output
(
j
)]
=
input_opr
->
output
(
j
);
}
iter
.
set_visited
(
opr
.
input
(
i
)
->
owner_opr
());
var_replace_map
[
opr
.
input
(
i
)]
=
inputs
[
i
];
}
if
(
shape_infer
)
{
iter
.
add
(
shape_infer
);
...
...
src/jit/test/codegen.cpp
浏览文件 @
eb3c6473
...
...
@@ -6,7 +6,9 @@
#include "megbrain/jit/executor_opr.h"
#include "megbrain/opr/basic_arith.h"
#include "megbrain/opr/basic_arith_wrapper.h"
#include "megbrain/opr/dnn/layer_norm.h"
#include "megbrain/opr/tensor_manip.h"
#include "megbrain/serialization/opr_shallow_copy.h"
#include "megbrain/test/helper.h"
#include "megdnn/dtype.h"
...
...
@@ -554,6 +556,61 @@ TEST(TestJITMlirDimshuffle, BasicGPU) {
#endif // MGB_JIT_MLIR
TEST
(
TestJITExecutor
,
TestJITExecutorShallowCopy
)
{
REQUIRE_GPU
(
1
);
set_backend
(
Backend
::
NVRTC
);
auto
cn
=
CompNode
::
load
(
"gpu0"
);
auto
graph
=
ComputingGraph
::
make
();
HostTensorGenerator
<>
gen
;
auto
host_x0
=
gen
({
23
,
42
},
cn
),
host_x1
=
gen
({
1
,
42
},
cn
);
auto
a
=
opr
::
Host2DeviceCopy
::
make
(
*
graph
,
host_x0
);
using
Param
=
opr
::
LayerNormForward
::
Param
;
Param
param
;
param
.
eps
=
1e-5
;
param
.
affine
=
false
;
param
.
normalized_dim
=
1
;
param
.
normalized_size
=
42
;
auto
out_array
=
opr
::
LayerNormForward
::
make
(
a
,
param
);
a
=
out_array
[
1
];
auto
shape
=
out_array
[
2
];
a
=
opr
::
TypeCvt
::
make
(
a
,
dtype
::
Float16
{});
auto
y
=
a
+
2
;
y
=
opr
::
TypeCvt
::
make
(
y
,
dtype
::
Float16
{});
y
=
opr
::
TypeCvt
::
make
((
y
+
y
.
make_scalar_dt
(
1.
f
)),
dtype
::
Float32
{});
auto
ig_gen
=
std
::
make_unique
<
InternalGraphGenerator
>
(
y
.
node
()
->
owner_opr
());
for
(
auto
i
:
get_rev_topo_order
(
y
))
{
if
(
!
(
i
->
same_type
<
opr
::
Host2DeviceCopy
>
()
||
i
->
same_type
<
opr
::
LayerNormForward
>
()
||
i
->
same_type
<
opr
::
SharedDeviceTensor
>
()))
{
ig_gen
->
add_opr
(
i
);
}
}
auto
igraph_0
=
ig_gen
->
generate
();
auto
igraph_1
=
std
::
make_shared
<
InternalGraph
>
(
igraph_0
->
output
(),
shape
.
node
(),
igraph_0
->
value_infer
(),
igraph_0
->
placeholders
());
auto
y_jit
=
JITExecutor
::
make
(
igraph_1
,
ig_gen
->
orig_inps
());
auto
opr_ori
=
y_jit
.
node
()
->
owner_opr
();
auto
opr_copy
=
serialization
::
copy_opr_shallow
(
*
opr_ori
,
opr_ori
->
input
());
auto
out_var
=
opr_copy
->
output
(
0
);
HostTensorND
host_y
,
host_y_jit
;
auto
func
=
graph
->
compile
(
{
make_callback_copy
(
y
,
host_y
),
make_callback_copy
(
out_var
,
host_y_jit
)});
func
->
execute
().
wait
();
MGB_ASSERT_TENSOR_NEAR
(
host_y
,
host_y_jit
,
5e-3
);
}
#endif // MGB_JIT
// 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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录