Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
d0ce6a90
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d0ce6a90
编写于
3月 01, 2019
作者:
Y
Yan Chunwei
提交者:
root
3月 20, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix anakin converter registry (#15993)
上级
a5124ee0
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
40 addition
and
40 deletion
+40
-40
CMakeLists.txt
CMakeLists.txt
+2
-0
paddle/fluid/inference/CMakeLists.txt
paddle/fluid/inference/CMakeLists.txt
+4
-1
paddle/fluid/inference/anakin/convert/fc.cc
paddle/fluid/inference/anakin/convert/fc.cc
+2
-0
paddle/fluid/inference/anakin/convert/fc.h
paddle/fluid/inference/anakin/convert/fc.h
+0
-3
paddle/fluid/inference/anakin/convert/op_converter.h
paddle/fluid/inference/anakin/convert/op_converter.h
+20
-20
paddle/fluid/inference/anakin/convert/test_fc_op.cc
paddle/fluid/inference/anakin/convert/test_fc_op.cc
+3
-5
paddle/fluid/inference/anakin/convert/ut_helper.h
paddle/fluid/inference/anakin/convert/ut_helper.h
+2
-1
paddle/fluid/inference/tensorrt/convert/op_converter.h
paddle/fluid/inference/tensorrt/convert/op_converter.h
+3
-3
paddle/fluid/inference/utils/singleton.h
paddle/fluid/inference/utils/singleton.h
+4
-7
未找到文件。
CMakeLists.txt
浏览文件 @
d0ce6a90
...
@@ -64,7 +64,9 @@ option(WITH_DISTRIBUTE "Compile with distributed support" OFF)
...
@@ -64,7 +64,9 @@ option(WITH_DISTRIBUTE "Compile with distributed support" OFF)
option
(
WITH_PSLIB
"Compile with pslib support"
OFF
)
option
(
WITH_PSLIB
"Compile with pslib support"
OFF
)
option
(
WITH_CONTRIB
"Compile the third-party contributation"
OFF
)
option
(
WITH_CONTRIB
"Compile the third-party contributation"
OFF
)
option
(
REPLACE_ENFORCE_GLOG
"Replace PADDLE_ENFORCE with glog/CHECK for better debug."
OFF
)
option
(
REPLACE_ENFORCE_GLOG
"Replace PADDLE_ENFORCE with glog/CHECK for better debug."
OFF
)
# TODO(Superjomn) Remove WITH_ANAKIN option if not needed latter.
option
(
WITH_ANAKIN
"Compile with Anakin library"
OFF
)
option
(
WITH_ANAKIN
"Compile with Anakin library"
OFF
)
option
(
WITH_ANAKIN_SUBGRAPH
"Compile with Anakin subgraph library"
OFF
)
option
(
ANAKIN_BUILD_FAT_BIN
"Build anakin cuda fat-bin lib for all device plantform, ignored when WITH_ANAKIN=OFF"
OFF
)
option
(
ANAKIN_BUILD_FAT_BIN
"Build anakin cuda fat-bin lib for all device plantform, ignored when WITH_ANAKIN=OFF"
OFF
)
option
(
ANAKIN_BUILD_CROSS_PLANTFORM
"Build anakin lib for any nvidia device plantform. ignored when WITH_ANAKIN=OFF"
ON
)
option
(
ANAKIN_BUILD_CROSS_PLANTFORM
"Build anakin lib for any nvidia device plantform. ignored when WITH_ANAKIN=OFF"
ON
)
option
(
WITH_GRPC
"Use grpc as the default rpc framework"
${
WITH_DISTRIBUTE
}
)
option
(
WITH_GRPC
"Use grpc as the default rpc framework"
${
WITH_DISTRIBUTE
}
)
...
...
paddle/fluid/inference/CMakeLists.txt
浏览文件 @
d0ce6a90
...
@@ -16,7 +16,10 @@ add_subdirectory(utils)
...
@@ -16,7 +16,10 @@ add_subdirectory(utils)
if
(
TENSORRT_FOUND
)
if
(
TENSORRT_FOUND
)
add_subdirectory
(
tensorrt
)
add_subdirectory
(
tensorrt
)
endif
()
endif
()
# add_subdirectory(anakin)
if
(
WITH_ANAKIN_SUBGRAPH
)
add_subdirectory
(
anakin
)
endif
()
get_property
(
fluid_modules GLOBAL PROPERTY FLUID_MODULES
)
get_property
(
fluid_modules GLOBAL PROPERTY FLUID_MODULES
)
get_property
(
cuda_modules GLOBAL PROPERTY CUDA_MODULES
)
get_property
(
cuda_modules GLOBAL PROPERTY CUDA_MODULES
)
...
...
paddle/fluid/inference/anakin/convert/fc.cc
浏览文件 @
d0ce6a90
...
@@ -71,3 +71,5 @@ void FcOpConverter::operator()(const framework::proto::OpDesc &op,
...
@@ -71,3 +71,5 @@ void FcOpConverter::operator()(const framework::proto::OpDesc &op,
}
// namespace anakin
}
// namespace anakin
}
// namespace inference
}
// namespace inference
}
// namespace paddle
}
// namespace paddle
REGISTER_ANAKIN_OP_CONVERTER
(
fc
,
FcOpConverter
);
paddle/fluid/inference/anakin/convert/fc.h
浏览文件 @
d0ce6a90
...
@@ -28,11 +28,8 @@ class FcOpConverter : public AnakinOpConverter {
...
@@ -28,11 +28,8 @@ class FcOpConverter : public AnakinOpConverter {
const
framework
::
Scope
&
scope
,
const
framework
::
Scope
&
scope
,
bool
test_mode
)
override
;
bool
test_mode
)
override
;
virtual
~
FcOpConverter
()
{}
virtual
~
FcOpConverter
()
{}
private:
};
};
static
Registrar
<
FcOpConverter
>
register_fc_op_converter
(
"fc"
);
}
// namespace anakin
}
// namespace anakin
}
// namespace inference
}
// namespace inference
}
// namespace paddle
}
// namespace paddle
paddle/fluid/inference/anakin/convert/op_converter.h
浏览文件 @
d0ce6a90
...
@@ -46,19 +46,18 @@ class AnakinOpConverter {
...
@@ -46,19 +46,18 @@ class AnakinOpConverter {
bool
test_mode
=
false
)
{
bool
test_mode
=
false
)
{
framework
::
OpDesc
op_desc
(
op
,
nullptr
);
framework
::
OpDesc
op_desc
(
op
,
nullptr
);
std
::
string
op_type
=
op_desc
.
Type
();
std
::
string
op_type
=
op_desc
.
Type
();
std
::
shared_ptr
<
AnakinOpConverter
>
it
{
nullptr
}
;
AnakinOpConverter
*
it
=
nullptr
;
if
(
op_type
==
"mul"
)
{
if
(
op_type
==
"mul"
)
{
PADDLE_ENFORCE_EQ
(
op_desc
.
Input
(
"Y"
).
size
(),
1UL
);
PADDLE_ENFORCE_EQ
(
op_desc
.
Input
(
"Y"
).
size
(),
1UL
);
std
::
string
Y
=
op_desc
.
Input
(
"Y"
)[
0
];
std
::
string
Y
=
op_desc
.
Input
(
"Y"
)[
0
];
std
::
cout
<<
Y
<<
parameters
.
count
(
Y
)
<<
std
::
endl
;
if
(
parameters
.
count
(
Y
))
{
if
(
parameters
.
count
(
Y
))
{
it
=
OpRegister
::
instance
()
->
Get
(
"fc"
);
it
=
Registry
<
AnakinOpConverter
>::
Global
().
Lookup
(
"fc"
);
}
}
}
}
if
(
!
it
)
{
if
(
!
it
)
{
it
=
OpRegister
::
instance
()
->
Get
(
op_type
);
it
=
Registry
<
AnakinOpConverter
>::
Global
().
Lookup
(
op_type
);
}
}
PADDLE_ENFORCE_NOT_NULL
(
it
,
"no OpConverter for optype [%s]"
,
op_type
);
PADDLE_ENFORCE_NOT_NULL
(
it
,
"no OpConverter for optype [%s]"
,
op_type
);
it
->
SetEngine
(
engine
);
it
->
SetEngine
(
engine
);
...
@@ -95,9 +94,10 @@ class AnakinOpConverter {
...
@@ -95,9 +94,10 @@ class AnakinOpConverter {
struct anakin_##op_type__##_converter \
struct anakin_##op_type__##_converter \
: public ::paddle::framework::Registrar { \
: public ::paddle::framework::Registrar { \
anakin_##op_type__##_converter() { \
anakin_##op_type__##_converter() { \
::paddle::inference:: \
LOG(INFO) << "register convert " << #op_type__; \
Registry<paddle::inference::anakin::AnakinOpConverter>::Register< \
::paddle::inference::Registry< \
::paddle::inference::anakin::Converter__>(#op_type__); \
::paddle::inference::anakin::AnakinOpConverter>::Global() \
.Register<::paddle::inference::anakin::Converter__>(#op_type__); \
} \
} \
}; \
}; \
anakin_##op_type__##_converter anakin_##op_type__##_converter__; \
anakin_##op_type__##_converter anakin_##op_type__##_converter__; \
...
@@ -108,5 +108,5 @@ class AnakinOpConverter {
...
@@ -108,5 +108,5 @@ class AnakinOpConverter {
#define USE_ANAKIN_CONVERTER(op_type__) \
#define USE_ANAKIN_CONVERTER(op_type__) \
extern int TouchConverterRegister_anakin_##op_type__(); \
extern int TouchConverterRegister_anakin_##op_type__(); \
static
int use_op_converter_anakin_##op_type__ __attribute__((unused)) = \
int use_op_converter_anakin_##op_type__ __attribute__((unused)) = \
TouchConverterRegister_anakin_##op_type__();
TouchConverterRegister_anakin_##op_type__();
paddle/fluid/inference/anakin/convert/test_fc_op.cc
浏览文件 @
d0ce6a90
...
@@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
...
@@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include "paddle/fluid/inference/anakin/convert/fc.h"
#include "paddle/fluid/inference/anakin/convert/op_converter.h"
#include "paddle/fluid/inference/anakin/convert/op_converter.h"
#include "paddle/fluid/inference/anakin/convert/ut_helper.h"
#include "paddle/fluid/inference/anakin/convert/ut_helper.h"
...
@@ -22,10 +21,8 @@ namespace inference {
...
@@ -22,10 +21,8 @@ namespace inference {
namespace
anakin
{
namespace
anakin
{
TEST
(
fc_op
,
test
)
{
TEST
(
fc_op
,
test
)
{
auto
fc_converter
=
OpRegister
::
instance
()
->
Get
(
"fc"
);
auto
*
fc_converter
=
Registry
<
AnakinOpConverter
>::
Global
().
Lookup
(
"fc"
);
ASSERT_TRUE
(
fc_converter
!=
nullptr
);
ASSERT_TRUE
(
fc_converter
);
// Registrar<FcOpConverter> register_fc("fc");
// auto fc = std::make_shared<FcOpConverter>();
std
::
unordered_set
<
std
::
string
>
parameters
({
"mul_y"
});
std
::
unordered_set
<
std
::
string
>
parameters
({
"mul_y"
});
framework
::
Scope
scope
;
framework
::
Scope
scope
;
...
@@ -52,3 +49,4 @@ TEST(fc_op, test) {
...
@@ -52,3 +49,4 @@ TEST(fc_op, test) {
}
// namespace paddle
}
// namespace paddle
USE_OP
(
mul
);
USE_OP
(
mul
);
USE_ANAKIN_CONVERTER
(
fc
);
paddle/fluid/inference/anakin/convert/ut_helper.h
浏览文件 @
d0ce6a90
...
@@ -24,6 +24,7 @@ limitations under the License. */
...
@@ -24,6 +24,7 @@ limitations under the License. */
#include "paddle/fluid/framework/lod_tensor.h"
#include "paddle/fluid/framework/lod_tensor.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/fluid/inference/anakin/convert/op_converter.h"
#include "paddle/fluid/inference/anakin/engine.h"
#include "paddle/fluid/inference/anakin/engine.h"
#include "paddle/fluid/inference/analysis/helper.h"
#include "paddle/fluid/inference/analysis/helper.h"
#include "paddle/fluid/inference/utils/singleton.h"
#include "paddle/fluid/inference/utils/singleton.h"
...
@@ -82,7 +83,7 @@ class AnakinConvertValidation {
...
@@ -82,7 +83,7 @@ class AnakinConvertValidation {
AnakinConvertValidation
()
=
delete
;
AnakinConvertValidation
()
=
delete
;
AnakinConvertValidation
(
const
std
::
unordered_set
<
std
::
string
>&
parameters
,
AnakinConvertValidation
(
const
std
::
unordered_set
<
std
::
string
>&
parameters
,
const
framework
::
Scope
&
scope
)
framework
::
Scope
&
scope
)
:
parameters_
(
parameters
),
scope_
(
scope
),
place_
(
0
)
{
:
parameters_
(
parameters
),
scope_
(
scope
),
place_
(
0
)
{
PADDLE_ENFORCE_EQ
(
cudaStreamCreate
(
&
stream_
),
0
);
PADDLE_ENFORCE_EQ
(
cudaStreamCreate
(
&
stream_
),
0
);
engine_
.
reset
(
new
AnakinEngine
<
NV
,
Precision
::
FP32
>
(
true
));
engine_
.
reset
(
new
AnakinEngine
<
NV
,
Precision
::
FP32
>
(
true
));
...
...
paddle/fluid/inference/tensorrt/convert/op_converter.h
浏览文件 @
d0ce6a90
...
@@ -198,9 +198,9 @@ class OpConverter {
...
@@ -198,9 +198,9 @@ class OpConverter {
#define REGISTER_TRT_OP_CONVERTER(op_type__, Converter__) \
#define REGISTER_TRT_OP_CONVERTER(op_type__, Converter__) \
struct trt_##op_type__##_converter : public ::paddle::framework::Registrar { \
struct trt_##op_type__##_converter : public ::paddle::framework::Registrar { \
trt_##op_type__##_converter() { \
trt_##op_type__##_converter() { \
::paddle::inference::
\
::paddle::inference::
Registry<
\
Registry<paddle::inference::tensorrt::OpConverter>::Register<
\
paddle::inference::tensorrt::OpConverter>::Global()
\
::paddle::inference::tensorrt::Converter__>(#op_type__);
\
.Register<::paddle::inference::tensorrt::Converter__>(#op_type__);
\
} \
} \
}; \
}; \
trt_##op_type__##_converter trt_##op_type__##_converter__; \
trt_##op_type__##_converter trt_##op_type__##_converter__; \
...
...
paddle/fluid/inference/utils/singleton.h
浏览文件 @
d0ce6a90
...
@@ -45,12 +45,12 @@ struct Registry {
...
@@ -45,12 +45,12 @@ struct Registry {
}
}
template
<
typename
ItemChild
>
template
<
typename
ItemChild
>
static
void
Register
(
const
std
::
string
&
name
)
{
void
Register
(
const
std
::
string
&
name
)
{
PADDLE_ENFORCE_EQ
(
items_
.
count
(
name
),
0
);
PADDLE_ENFORCE_EQ
(
items_
.
count
(
name
),
0
);
items_
[
name
]
=
new
ItemChild
;
items_
[
name
]
=
new
ItemChild
;
}
}
static
ItemParent
*
Lookup
(
const
std
::
string
&
name
,
ItemParent
*
Lookup
(
const
std
::
string
&
name
,
const
std
::
string
&
default_name
=
""
)
{
const
std
::
string
&
default_name
=
""
)
{
auto
it
=
items_
.
find
(
name
);
auto
it
=
items_
.
find
(
name
);
if
(
it
==
items_
.
end
())
{
if
(
it
==
items_
.
end
())
{
...
@@ -70,11 +70,8 @@ struct Registry {
...
@@ -70,11 +70,8 @@ struct Registry {
private:
private:
Registry
()
=
default
;
Registry
()
=
default
;
st
atic
st
d
::
unordered_map
<
std
::
string
,
ItemParent
*>
items_
;
std
::
unordered_map
<
std
::
string
,
ItemParent
*>
items_
;
};
};
template
<
typename
ItemParent
>
std
::
unordered_map
<
std
::
string
,
ItemParent
*>
Registry
<
ItemParent
>::
items_
;
}
// namespace inference
}
// namespace inference
}
// namespace paddle
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录