Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
cbb24136
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看板
未验证
提交
cbb24136
编写于
5月 25, 2022
作者:
F
fwenguang
提交者:
GitHub
5月 25, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[MLU] adapt coalesce_tensor op for mlu (#42873)
上级
71b046cd
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
134 addition
and
1 deletion
+134
-1
paddle/fluid/operators/coalesce_tensor_op.cc
paddle/fluid/operators/coalesce_tensor_op.cc
+19
-0
paddle/fluid/platform/device_memory_aligment.cc
paddle/fluid/platform/device_memory_aligment.cc
+3
-1
paddle/fluid/platform/device_memory_aligment.h
paddle/fluid/platform/device_memory_aligment.h
+3
-0
python/paddle/fluid/tests/unittests/mlu/test_coalesce_tensor_op_mlu.py
.../fluid/tests/unittests/mlu/test_coalesce_tensor_op_mlu.py
+109
-0
未找到文件。
paddle/fluid/operators/coalesce_tensor_op.cc
浏览文件 @
cbb24136
...
...
@@ -24,6 +24,9 @@
#include "paddle/fluid/platform/device/npu/npu_op_runner.h"
#endif
#include "paddle/fluid/framework/convert_utils.h"
#ifdef PADDLE_WITH_MLU
#include "paddle/fluid/operators/mlu/mlu_baseop.h"
#endif
namespace
paddle
{
namespace
operators
{
...
...
@@ -69,6 +72,13 @@ struct FillConstantVisitor {
phi
::
funcs
::
SetConstant
<
DeviceContext
,
T
>
set_constant
;
set_constant
(
dev_ctx_
,
tensor_
,
static_cast
<
T
>
(
value_
));
}
#elif defined(PADDLE_WITH_MLU)
if
(
platform
::
is_mlu_place
(
context_
.
GetPlace
()))
{
FillMLUTensorWithHostValue
<
T
>
(
context_
,
static_cast
<
T
>
(
value_
),
tensor_
);
}
else
{
phi
::
funcs
::
SetConstant
<
DeviceContext
,
T
>
set_constant
;
set_constant
(
dev_ctx_
,
tensor_
,
static_cast
<
T
>
(
value_
));
}
#else
phi
::
funcs
::
SetConstant
<
DeviceContext
,
T
>
set_constant
;
set_constant
(
dev_ctx_
,
tensor_
,
static_cast
<
T
>
(
value_
));
...
...
@@ -509,6 +519,15 @@ REGISTER_OP_NPU_KERNEL(
ops
::
CoalesceTensorOpKernel
<
paddle
::
platform
::
CPUDeviceContext
,
double
>
);
#endif
#if defined(PADDLE_WITH_MLU)
REGISTER_OP_MLU_KERNEL
(
coalesce_tensor
,
ops
::
CoalesceTensorOpKernel
<
paddle
::
platform
::
CPUDeviceContext
,
plat
::
float16
>
,
ops
::
CoalesceTensorOpKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int
>
,
ops
::
CoalesceTensorOpKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
);
#endif
REGISTER_OP_VERSION
(
coalesce_tensor
)
.
AddCheckpoint
(
R"ROC(
...
...
paddle/fluid/platform/device_memory_aligment.cc
浏览文件 @
cbb24136
...
...
@@ -31,9 +31,11 @@ size_t Alignment(size_t size, const platform::Place &place, int align_size) {
alignment
=
alignment
;
#elif defined(PADDLE_WITH_ASCEND_CL)
alignment
=
NPUMinChunkSize
();
#elif defined(PADDLE_WITH_MLU)
alignment
=
MLUMinChunkSize
();
#else
PADDLE_THROW
(
platform
::
errors
::
PreconditionNotMet
(
"Fluid is not compiled with CUDA/XPU/NPU."
));
"Fluid is not compiled with CUDA/XPU/NPU
/MLU
."
));
#endif
}
}
...
...
paddle/fluid/platform/device_memory_aligment.h
浏览文件 @
cbb24136
...
...
@@ -21,6 +21,9 @@ limitations under the License. */
#include "paddle/fluid/platform/device/npu/npu_info.h"
#endif
#include "paddle/fluid/platform/device/gpu/gpu_info.h"
#ifdef PADDLE_WITH_MLU
#include "paddle/fluid/platform/device/mlu/mlu_info.h"
#endif
namespace
paddle
{
namespace
platform
{
...
...
python/paddle/fluid/tests/unittests/mlu/test_coalesce_tensor_op_mlu.py
0 → 100644
浏览文件 @
cbb24136
# 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.
from
__future__
import
print_function
import
unittest
import
numpy
as
np
import
sys
sys
.
path
.
append
(
'..'
)
from
op_test
import
OpTest
from
paddle.fluid
import
core
import
paddle
alignment
=
256
paddle
.
enable_static
()
class
TestAllocContinuousSpace
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"coalesce_tensor"
self
.
dtype
,
self
.
fluid_dtype
=
self
.
init_dtype
()
attrs
=
self
.
init_attr
()
self
.
copy_data
=
attrs
[
"copy_data"
]
self
.
constant
=
attrs
[
"constant"
]
self
.
set_constant
=
attrs
[
"set_constant"
]
self
.
Inputs
=
self
.
init_input
()
self
.
Outputs
,
self
.
FusedOutput
=
self
.
init_output
(
self
.
Inputs
,
self
.
set_constant
,
self
.
constant
)
self
.
inputs
=
{
'Input'
:
self
.
Inputs
}
self
.
attrs
=
attrs
self
.
outputs
=
{
'Output'
:
self
.
Outputs
,
'FusedOutput'
:
self
.
FusedOutput
}
def
init_dtype
(
self
):
return
np
.
float32
,
int
(
core
.
VarDesc
.
VarType
.
FP32
)
def
init_input
(
self
):
inputs
=
[]
inputs
.
append
((
"x1"
,
np
.
random
.
random
([
20
,
3
]).
astype
(
self
.
dtype
)))
inputs
.
append
((
"x2"
,
np
.
random
.
random
([
20
]).
astype
(
self
.
dtype
)))
inputs
.
append
((
"x3"
,
np
.
random
.
random
([
1
]).
astype
(
self
.
dtype
)))
inputs
.
append
((
"x4"
,
np
.
random
.
random
([
200
,
30
]).
astype
(
self
.
dtype
)))
inputs
.
append
((
"x5"
,
np
.
random
.
random
([
30
]).
astype
(
self
.
dtype
)))
inputs
.
append
((
"x6"
,
np
.
random
.
random
([
1
]).
astype
(
self
.
dtype
)))
return
inputs
def
init_attr
(
self
):
return
{
"copy_data"
:
True
,
"set_constant"
:
False
,
"constant"
:
0.0
,
"dtype"
:
self
.
fluid_dtype
}
def
init_output
(
self
,
input_list
,
set_constant
,
constant
):
inputs
=
[]
outputs
=
input_list
for
input
in
input_list
:
length
=
len
(
input
[
1
].
flatten
())
aligned_len
=
(
length
+
alignment
)
/
alignment
*
alignment
out
=
np
.
zeros
(
int
(
aligned_len
))
out
[
0
:
length
]
=
input
[
1
].
flatten
()
inputs
.
append
(
out
)
coalesce_tensor_var
=
np
.
concatenate
([
input
for
input
in
inputs
])
if
set_constant
:
coalesce_tensor_var
=
np
.
ones
((
len
(
coalesce_tensor_var
)))
*
constant
outputs
=
[(
out
[
0
],
np
.
ones
(
out
[
1
].
shape
).
astype
(
self
.
dtype
)
*
constant
)
for
out
in
outputs
]
return
outputs
,
coalesce_tensor_var
def
test_check_output
(
self
):
self
.
check_output_with_place
(
place
=
paddle
.
device
.
MLUPlace
(
0
),
no_check_set
=
[
"FusedOutput"
],
atol
=
1e-5
)
class
TestAllocContinuousSpace2
(
TestAllocContinuousSpace
):
def
init_attr
(
self
):
return
{
"copy_data"
:
False
,
"set_constant"
:
True
,
"constant"
:
5
,
"dtype"
:
self
.
fluid_dtype
,
"user_defined_size_of_dtype"
:
2
}
def
test_check_output
(
self
):
self
.
check_output_with_place
(
place
=
paddle
.
device
.
MLUPlace
(
0
),
no_check_set
=
[
"FusedOutput"
],
atol
=
1e-5
)
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录