Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
abe3c165
MegEngine
项目概览
MegEngine 天元
/
MegEngine
大约 1 年 前同步成功
通知
396
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,发现更多精彩内容 >>
提交
abe3c165
编写于
1月 14, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(mge): tensorrt runtime opr
GitOrigin-RevId: 2fdd00adcbbe272e79d53ba0ac879d2eedf471d0
上级
1b1ad56a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
107 addition
and
1 deletion
+107
-1
.gitattributes
.gitattributes
+1
-1
imperative/python/megengine/functional/external.py
imperative/python/megengine/functional/external.py
+22
-0
imperative/python/megengine/module/external.py
imperative/python/megengine/module/external.py
+37
-0
imperative/python/test/unit/module/test_external.py
imperative/python/test/unit/module/test_external.py
+8
-0
imperative/src/impl/ops/tensorrt_runtime.cpp
imperative/src/impl/ops/tensorrt_runtime.cpp
+32
-0
src/core/include/megbrain/ir/ops.td
src/core/include/megbrain/ir/ops.td
+7
-0
未找到文件。
.gitattributes
浏览文件 @
abe3c165
...
...
@@ -5,4 +5,4 @@ dnn/src/cuda/conv_bias/int8_imma/kimpl/* binary
dnn/src/cuda/batch_conv_bias/int8/kimpl/* binary
dnn/src/cuda/sass/prebuilt/map_defs.cpp binary
tools/mlir/mlir-tblgen filter=lfs diff=lfs merge=lfs -text
sdk/c-opr-loaders/mc40/example/sinopec_nv12_extra.neu
filter=lfs diff=lfs merge=lfs -text
*.caffemodel
filter=lfs diff=lfs merge=lfs -text
imperative/python/megengine/functional/external.py
0 → 100644
浏览文件 @
abe3c165
# -*- coding: utf-8 -*-
# MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
#
# Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# pylint: disable=redefined-builtin
from
typing
import
Sequence
from
..core._imperative_rt.core2
import
apply
from
..core.ops
import
builtin
def
tensorrt_runtime_opr
(
inputs
,
*
,
data
:
bytes
=
None
):
# empty model will give None result
if
data
is
None
:
return
None
op
=
builtin
.
TensorRTRuntime
(
data
,
len
(
data
))
# return sequence of outputs
return
apply
(
op
,
*
inputs
)
imperative/python/megengine/module/external.py
0 → 100644
浏览文件 @
abe3c165
# -*- coding: utf-8 -*-
# MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
#
# Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# pylint: disable=redefined-builtin
import
numpy
as
np
from
..functional.external
import
tensorrt_runtime_opr
from
.module
import
Module
class
TensorrtRuntimeSubgraph
(
Module
):
r
"""Load a serialized TensorrtRuntime subgraph.
See :func:`~.tensorrt_runtime_opr` for more details.
"""
def
__init__
(
self
,
data
,
):
super
(
TensorrtRuntimeSubgraph
,
self
).
__init__
()
self
.
_data
=
data
@
property
def
data
(
self
):
return
self
.
_data
@
data
.
setter
def
data
(
self
,
val
):
self
.
_data
=
np
.
frombuffer
(
val
,
dtype
=
np
.
uint8
)
def
forward
(
self
,
*
inputs
):
return
tensorrt_runtime_opr
(
inputs
,
data
=
self
.
_data
)
imperative/python/test/unit/module/test_external.py
浏览文件 @
abe3c165
...
...
@@ -6,14 +6,20 @@
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import
io
import
os
import
platform
import
numpy
as
np
import
pytest
import
megengine
as
mge
import
megengine.utils.comp_graph_tools
as
cgtools
from
megengine
import
Tensor
from
megengine.distributed.helper
import
get_device_count_by_fork
from
megengine.jit
import
trace
from
megengine.module
import
Module
from
megengine.module.external
import
TensorrtRuntimeSubgraph
class
MyModule
(
Module
):
...
...
@@ -44,3 +50,5 @@ def test_cambricon_module():
return
pred
pred
=
inference
([
inp
])
imperative/src/impl/ops/tensorrt_runtime.cpp
0 → 100644
浏览文件 @
abe3c165
/**
* \file imperative/src/impl/ops/tensorrt_runtime.cpp
* MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
*
* Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
#include "../op_trait.h"
#include "megbrain/imperative/ops/autogen.h"
#if MGB_ENABLE_TENSOR_RT
#include "megbrain/tensorrt/tensorrt_runtime_opr.h"
namespace
mgb
::
imperative
{
namespace
{
namespace
tensorrt_runtime
{
auto
apply_on_var_node
(
const
OpDef
&
def
,
const
VarNodeArray
&
inputs
)
{
auto
&&
op
=
static_cast
<
const
TensorRTRuntime
&>
(
def
);
SymbolVarArray
sinputs
(
inputs
.
begin
(),
inputs
.
end
());
return
opr
::
TensorRTRuntimeOpr
::
make
(
op
.
buf
.
c_str
(),
op
.
buf_size
,
sinputs
);
}
OP_TRAIT_REG
(
TensorRTRuntime
,
TensorRTRuntime
)
.
apply_on_var_node
(
apply_on_var_node
)
.
fallback
();
}}
// tensorrt_runtime
}
// namespace mgb::imperative
#endif // MGB_ENABLE_TENSOR_RT
src/core/include/megbrain/ir/ops.td
浏览文件 @
abe3c165
...
...
@@ -241,4 +241,11 @@ def ElemwiseMultiType: MgbHashableOp<"ElemwiseMultiType", [ElemwiseMultiTypePara
def InplaceAdd: MgbHashableOp<"InplaceAdd", [EmptyParam]>;
def TensorRTRuntime: MgbHashableOp<"TensorRTRuntime"> {
let extraArguments = (ins
MgbStringAttr:$buf,
MgbSizeTAddr:$buf_size
);
}
#endif // MGB_OPS
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录