Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
abc85c50
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
abc85c50
编写于
9月 09, 2022
作者:
R
ronnywang
提交者:
GitHub
9月 09, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[CustomDevice] add dy2static support (#45878)
* [CustomDevice] add dy2static support * update
上级
d0096eaf
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
123 addition
and
2 deletion
+123
-2
paddle/fluid/framework/executor_cache.cc
paddle/fluid/framework/executor_cache.cc
+4
-0
paddle/fluid/framework/op_registry.h
paddle/fluid/framework/op_registry.h
+11
-0
paddle/fluid/operators/CMakeLists.txt
paddle/fluid/operators/CMakeLists.txt
+4
-0
paddle/fluid/operators/custom_device_common_op_registry.cc
paddle/fluid/operators/custom_device_common_op_registry.cc
+60
-0
paddle/fluid/operators/custom_device_common_op_registry.h
paddle/fluid/operators/custom_device_common_op_registry.h
+29
-0
paddle/fluid/platform/device_context.cc
paddle/fluid/platform/device_context.cc
+2
-0
paddle/fluid/platform/device_context.h
paddle/fluid/platform/device_context.h
+3
-1
paddle/fluid/pybind/CMakeLists.txt
paddle/fluid/pybind/CMakeLists.txt
+1
-0
paddle/fluid/pybind/pybind.cc
paddle/fluid/pybind/pybind.cc
+9
-1
未找到文件。
paddle/fluid/framework/executor_cache.cc
浏览文件 @
abc85c50
...
...
@@ -54,6 +54,10 @@ static ExecutionStrategy GetExecutionStrategy(const platform::Place &place) {
execution_strategy
.
num_threads_
=
1
;
break
;
}
case
platform
::
DeviceType
::
CUSTOM_DEVICE
:
{
execution_strategy
.
num_threads_
=
1
;
break
;
}
default:
PADDLE_THROW
(
platform
::
errors
::
Unavailable
(
"Unsupported Device type %d."
,
device_type
));
...
...
paddle/fluid/framework/op_registry.h
浏览文件 @
abc85c50
...
...
@@ -171,6 +171,17 @@ inline void RegisterKernelClass(const char* op_type,
if
(
library
==
"MKLDNN"
)
{
data_layout
=
"MKLDNNLAYOUT"
;
}
#ifdef PADDLE_WITH_CUSTOM_DEVICE
if
(
std
::
is_same
<
PlaceType
,
platform
::
CustomPlace
>::
value
)
{
OpKernelType
key
(
ToDataType
(
std
::
type_index
(
typeid
(
T
))),
platform
::
CustomPlace
(
library_type
),
StringToDataLayout
(
data_layout
),
LibraryType
::
kPlain
,
customized_type_value
);
OperatorWithKernel
::
AllOpKernels
()[
op_type
][
key
]
=
func
;
return
;
}
#endif
OpKernelType
key
(
ToDataType
(
std
::
type_index
(
typeid
(
T
))),
PlaceType
(),
StringToDataLayout
(
data_layout
),
...
...
paddle/fluid/operators/CMakeLists.txt
浏览文件 @
abc85c50
...
...
@@ -254,3 +254,7 @@ cc_test(copy_cross_scope_test SRCS copy_cross_scope_test.cc DEPS op_registry cop
endif
()
copy_if_different
(
${
pybind_file
}
${
pybind_file_final
}
)
if
(
WITH_CUSTOM_DEVICE
)
cc_library
(
custom_device_common_op_registry SRCS custom_device_common_op_registry.cc DEPS operator
)
endif
()
paddle/fluid/operators/custom_device_common_op_registry.cc
0 → 100644
浏览文件 @
abc85c50
/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/operators/custom_device_common_op_registry.h"
#include "paddle/fluid/operators/run_program_op.h"
#include "paddle/fluid/operators/save_combine_op.h"
#include "paddle/phi/backends/device_manager.h"
#define REGISTER_OP_CUSTOM_DEVICE_KERNEL(op_type, dev_type, ...) \
static paddle::framework::OpKernelRegistrar<phi::CustomPlace, __VA_ARGS__> \
__op_custom_device_kernel_registrar_##op_type##_##__acosf##__( \
#op_type, \
dev_type, \
paddle::framework::OpKernelType::kDefaultCustomizedTypeValue); \
__op_custom_device_kernel_registrar_##op_type##_##__acosf##__.Touch();
namespace
paddle
{
namespace
operators
{
void
RegisterCustomDeviceCommonKernel
(
const
std
::
string
&
dev_type
)
{
auto
device_type
=
dev_type
.
c_str
();
/* see [Why use single type kernel] */
REGISTER_OP_CUSTOM_DEVICE_KERNEL
(
run_program
,
device_type
,
paddle
::
operators
::
RunProgramOpKernel
<
paddle
::
platform
::
CustomDeviceContext
,
float
>
);
REGISTER_OP_CUSTOM_DEVICE_KERNEL
(
run_program_grad
,
device_type
,
paddle
::
operators
::
RunProgramGradOpKernel
<
paddle
::
platform
::
CustomDeviceContext
,
float
>
);
REGISTER_OP_CUSTOM_DEVICE_KERNEL
(
save_combine
,
device_type
,
paddle
::
operators
::
SaveCombineOpKernel
<
paddle
::
platform
::
CustomDeviceContext
,
float
>
,
paddle
::
operators
::
SaveCombineOpKernel
<
paddle
::
platform
::
CustomDeviceContext
,
double
>
,
paddle
::
operators
::
SaveCombineOpKernel
<
paddle
::
platform
::
CustomDeviceContext
,
int
>
,
paddle
::
operators
::
SaveCombineOpKernel
<
paddle
::
platform
::
CustomDeviceContext
,
int64_t
>
);
}
}
// namespace operators
}
// namespace paddle
#undef REGISTER_OP_CUSTOM_DEVICE_KERNEL
paddle/fluid/operators/custom_device_common_op_registry.h
0 → 100644
浏览文件 @
abc85c50
/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#ifdef PADDLE_WITH_CUSTOM_DEVICE
#include <string>
namespace
paddle
{
namespace
operators
{
void
RegisterCustomDeviceCommonKernel
(
const
std
::
string
&
device_type
);
}
// namespace operators
}
// namespace paddle
#endif
paddle/fluid/platform/device_context.cc
浏览文件 @
abc85c50
...
...
@@ -65,6 +65,8 @@ DeviceType Place2DeviceType(const platform::Place& place) {
return
platform
::
DeviceType
::
NPU
;
}
else
if
(
platform
::
is_mlu_place
(
place
))
{
return
platform
::
DeviceType
::
MLU
;
}
else
if
(
platform
::
is_custom_place
(
place
))
{
return
platform
::
DeviceType
::
CUSTOM_DEVICE
;
}
else
{
PADDLE_THROW
(
platform
::
errors
::
Unavailable
(
"Unsupported place %s to convert into platform::DeviceType."
,
place
));
...
...
paddle/fluid/platform/device_context.h
浏览文件 @
abc85c50
...
...
@@ -117,8 +117,9 @@ enum DeviceType {
XPU
=
3
,
IPU
=
4
,
MLU
=
5
,
CUSTOM_DEVICE
=
6
,
MAX_DEVICE_TYPES
=
6
,
MAX_DEVICE_TYPES
=
7
,
};
DeviceType
Place2DeviceType
(
const
platform
::
Place
&
place
);
...
...
@@ -129,6 +130,7 @@ constexpr DeviceType kXPU = DeviceType::XPU;
constexpr
DeviceType
kNPU
=
DeviceType
::
NPU
;
constexpr
DeviceType
kIPU
=
DeviceType
::
IPU
;
constexpr
DeviceType
kMLU
=
DeviceType
::
MLU
;
constexpr
DeviceType
kCUSOTM_DEVICE
=
DeviceType
::
CUSTOM_DEVICE
;
using
DeviceContext
=
phi
::
DeviceContext
;
...
...
paddle/fluid/pybind/CMakeLists.txt
浏览文件 @
abc85c50
...
...
@@ -137,6 +137,7 @@ set(PYBIND_SRCS
if
(
WITH_CUSTOM_DEVICE
)
set
(
PYBIND_DEPS
${
PYBIND_DEPS
}
phi_capi
)
set
(
PYBIND_DEPS
${
PYBIND_DEPS
}
custom_device_common_op_registry
)
endif
()
if
(
NOT ON_INFER
)
...
...
paddle/fluid/pybind/pybind.cc
浏览文件 @
abc85c50
...
...
@@ -155,6 +155,7 @@ limitations under the License. */
#endif
#ifdef PADDLE_WITH_CUSTOM_DEVICE
#include "paddle/fluid/operators/custom_device_common_op_registry.h"
#include "paddle/phi/capi/capi.h"
#endif
...
...
@@ -1694,7 +1695,14 @@ All parameter, weight, gradient are variables in Paddle.
egr
::
Controller
::
Instance
().
MergeOpMetaInfoMap
(
framework
::
LoadOpMetaInfoAndRegisterOp
(
dso_name
));
});
m
.
def
(
"init_devices"
,
[]()
{
framework
::
InitDevices
();
});
m
.
def
(
"init_devices"
,
[]()
{
framework
::
InitDevices
();
#ifdef PADDLE_WITH_CUSTOM_DEVICE
for
(
auto
&
dev_type
:
phi
::
DeviceManager
::
GetAllCustomDeviceTypes
())
{
paddle
::
operators
::
RegisterCustomDeviceCommonKernel
(
dev_type
);
}
#endif
});
m
.
def
(
"init_default_kernel_signatures"
,
[]()
{
framework
::
InitDefaultKernelSignatureMap
();
});
m
.
def
(
"is_compiled_with_cuda"
,
IsCompiledWithCUDA
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录