Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
d23bf89c
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
未验证
提交
d23bf89c
编写于
3月 01, 2021
作者:
L
Leo Chen
提交者:
GitHub
3月 01, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support list of list attribute for NPU (#31299)
* support list of list attribute for NPU * fix compile problem * fix reference
上级
77a0c41c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
32 addition
and
8 deletion
+32
-8
paddle/fluid/framework/type_defs.h
paddle/fluid/framework/type_defs.h
+11
-0
paddle/fluid/operators/npu_op_runner.cc
paddle/fluid/operators/npu_op_runner.cc
+13
-3
paddle/fluid/operators/npu_op_runner.h
paddle/fluid/operators/npu_op_runner.h
+8
-5
未找到文件。
paddle/fluid/framework/type_defs.h
浏览文件 @
d23bf89c
...
@@ -45,6 +45,17 @@ using Attribute = boost::variant<
...
@@ -45,6 +45,17 @@ using Attribute = boost::variant<
using
AttributeMap
=
std
::
unordered_map
<
std
::
string
,
Attribute
>
;
using
AttributeMap
=
std
::
unordered_map
<
std
::
string
,
Attribute
>
;
#ifdef PADDLE_WITH_ASCEND_CL
using
NPUAttribute
=
boost
::
variant
<
boost
::
blank
,
int
,
float
,
std
::
string
,
std
::
vector
<
int
>
,
std
::
vector
<
float
>
,
std
::
vector
<
std
::
string
>
,
bool
,
std
::
vector
<
bool
>
,
BlockDesc
*
,
int64_t
,
std
::
vector
<
BlockDesc
*>
,
std
::
vector
<
int64_t
>
,
std
::
vector
<
double
>
,
std
::
vector
<
std
::
vector
<
int64_t
>>>
;
using
NPUAttributeMap
=
std
::
unordered_map
<
std
::
string
,
NPUAttribute
>
;
#endif
using
OpCreator
=
std
::
function
<
OperatorBase
*
(
using
OpCreator
=
std
::
function
<
OperatorBase
*
(
const
std
::
string
&
/*type*/
,
const
VariableNameMap
&
/*inputs*/
,
const
std
::
string
&
/*type*/
,
const
VariableNameMap
&
/*inputs*/
,
const
VariableNameMap
&
/*outputs*/
,
const
AttributeMap
&
/*attrs*/
)
>
;
const
VariableNameMap
&
/*outputs*/
,
const
AttributeMap
&
/*attrs*/
)
>
;
...
...
paddle/fluid/operators/npu_op_runner.cc
浏览文件 @
d23bf89c
...
@@ -70,7 +70,7 @@ NpuOpRunner::NpuOpRunner(std::string op_type) : op_type_(op_type) {
...
@@ -70,7 +70,7 @@ NpuOpRunner::NpuOpRunner(std::string op_type) : op_type_(op_type) {
NpuOpRunner
::
NpuOpRunner
(
std
::
string
op_type
,
const
std
::
vector
<
Tensor
>
&
inputs
,
NpuOpRunner
::
NpuOpRunner
(
std
::
string
op_type
,
const
std
::
vector
<
Tensor
>
&
inputs
,
const
std
::
vector
<
Tensor
>
&
outputs
,
const
std
::
vector
<
Tensor
>
&
outputs
,
const
AttributeMap
&
attrs
)
const
NPU
AttributeMap
&
attrs
)
:
op_type_
(
op_type
)
{
:
op_type_
(
op_type
)
{
attr_
=
aclopCreateAttr
();
attr_
=
aclopCreateAttr
();
AddInputs
(
inputs
);
AddInputs
(
inputs
);
...
@@ -85,7 +85,7 @@ NpuOpRunner::~NpuOpRunner() {
...
@@ -85,7 +85,7 @@ NpuOpRunner::~NpuOpRunner() {
const
std
::
string
&
NpuOpRunner
::
Type
()
{
return
op_type_
;
}
const
std
::
string
&
NpuOpRunner
::
Type
()
{
return
op_type_
;
}
NpuOpRunner
&
NpuOpRunner
::
AddAttr
(
const
std
::
string
&
name
,
NpuOpRunner
&
NpuOpRunner
::
AddAttr
(
const
std
::
string
&
name
,
const
Attribute
&
attr
)
{
const
NPU
Attribute
&
attr
)
{
if
(
attr
.
type
()
==
typeid
(
bool
))
{
if
(
attr
.
type
()
==
typeid
(
bool
))
{
PADDLE_ENFORCE_NPU_SUCCESS
(
PADDLE_ENFORCE_NPU_SUCCESS
(
aclopSetAttrBool
(
attr_
,
name
.
c_str
(),
BOOST_GET_CONST
(
bool
,
attr
)));
aclopSetAttrBool
(
attr_
,
name
.
c_str
(),
BOOST_GET_CONST
(
bool
,
attr
)));
...
@@ -135,6 +135,16 @@ NpuOpRunner &NpuOpRunner::AddAttr(const std::string &name,
...
@@ -135,6 +135,16 @@ NpuOpRunner &NpuOpRunner::AddAttr(const std::string &name,
}
}
PADDLE_ENFORCE_NPU_SUCCESS
(
PADDLE_ENFORCE_NPU_SUCCESS
(
aclopSetAttrListString
(
attr_
,
name
.
c_str
(),
s
.
size
(),
s
.
data
()));
aclopSetAttrListString
(
attr_
,
name
.
c_str
(),
s
.
size
(),
s
.
data
()));
}
else
if
(
attr
.
type
()
==
typeid
(
std
::
vector
<
std
::
vector
<
int64_t
>>
))
{
auto
a
=
BOOST_GET_CONST
(
std
::
vector
<
std
::
vector
<
int64_t
>>
,
attr
);
std
::
vector
<
int64_t
*>
data
;
std
::
vector
<
int
>
num
;
for
(
auto
&&
v
:
a
)
{
data
.
push_back
(
v
.
data
());
num
.
push_back
(
v
.
size
());
}
PADDLE_ENFORCE_NPU_SUCCESS
(
aclopSetAttrListListInt
(
attr_
,
name
.
c_str
(),
data
.
size
(),
num
.
data
(),
data
.
data
()));
}
else
{
}
else
{
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
"Can not convert attribubte '%s' to convert to aclopAttr"
,
name
));
"Can not convert attribubte '%s' to convert to aclopAttr"
,
name
));
...
@@ -142,7 +152,7 @@ NpuOpRunner &NpuOpRunner::AddAttr(const std::string &name,
...
@@ -142,7 +152,7 @@ NpuOpRunner &NpuOpRunner::AddAttr(const std::string &name,
return
*
this
;
return
*
this
;
}
}
NpuOpRunner
&
NpuOpRunner
::
AddAttrs
(
const
AttributeMap
&
attrs
)
{
NpuOpRunner
&
NpuOpRunner
::
AddAttrs
(
const
NPU
AttributeMap
&
attrs
)
{
for
(
const
auto
&
pair
:
attrs
)
{
for
(
const
auto
&
pair
:
attrs
)
{
AddAttr
(
pair
.
first
,
pair
.
second
);
AddAttr
(
pair
.
first
,
pair
.
second
);
}
}
...
...
paddle/fluid/operators/npu_op_runner.h
浏览文件 @
d23bf89c
...
@@ -12,8 +12,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -12,8 +12,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#ifdef PADDLE_WITH_ASCEND_CL
#pragma once
#pragma once
#include <paddle/fluid/framework/operator.h>
#include <paddle/fluid/framework/operator.h>
#include <paddle/fluid/framework/type_defs.h>
#include <string>
#include <string>
#include <vector>
#include <vector>
...
@@ -26,8 +28,8 @@ namespace operators {
...
@@ -26,8 +28,8 @@ namespace operators {
using
Tensor
=
framework
::
Tensor
;
using
Tensor
=
framework
::
Tensor
;
using
DataLayout
=
framework
::
DataLayout
;
using
DataLayout
=
framework
::
DataLayout
;
using
Attribute
=
framework
::
Attribute
;
using
NPUAttribute
=
framework
::
NPU
Attribute
;
using
AttributeMap
=
framework
::
AttributeMap
;
using
NPUAttributeMap
=
framework
::
NPU
AttributeMap
;
class
NpuOpRunner
{
class
NpuOpRunner
{
public:
public:
...
@@ -35,15 +37,15 @@ class NpuOpRunner {
...
@@ -35,15 +37,15 @@ class NpuOpRunner {
explicit
NpuOpRunner
(
std
::
string
op_type
,
explicit
NpuOpRunner
(
std
::
string
op_type
,
const
std
::
vector
<
Tensor
>
&
inputs
=
{},
const
std
::
vector
<
Tensor
>
&
inputs
=
{},
const
std
::
vector
<
Tensor
>
&
outputs
=
{},
const
std
::
vector
<
Tensor
>
&
outputs
=
{},
const
AttributeMap
&
attrs
=
{});
const
NPU
AttributeMap
&
attrs
=
{});
~
NpuOpRunner
();
~
NpuOpRunner
();
const
std
::
string
&
Type
();
const
std
::
string
&
Type
();
NpuOpRunner
&
AddAttr
(
const
std
::
string
&
name
,
const
Attribute
&
attr
);
NpuOpRunner
&
AddAttr
(
const
std
::
string
&
name
,
const
NPU
Attribute
&
attr
);
NpuOpRunner
&
AddAttrs
(
const
AttributeMap
&
attrs
);
NpuOpRunner
&
AddAttrs
(
const
NPU
AttributeMap
&
attrs
);
NpuOpRunner
&
AddInput
(
const
Tensor
&
tensor
);
NpuOpRunner
&
AddInput
(
const
Tensor
&
tensor
);
...
@@ -82,3 +84,4 @@ class NpuOpRunner {
...
@@ -82,3 +84,4 @@ class NpuOpRunner {
}
// namespace operators
}
// namespace operators
}
// namespace paddle
}
// namespace paddle
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录