Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
53ef685e
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
332
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
53ef685e
编写于
3月 21, 2020
作者:
J
jackzhang235
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add mlu layout transform file
上级
c5e83404
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
236 addition
and
0 deletion
+236
-0
lite/kernels/mlu/layout_compute.cc
lite/kernels/mlu/layout_compute.cc
+91
-0
lite/kernels/mlu/layout_compute.h
lite/kernels/mlu/layout_compute.h
+145
-0
未找到文件。
lite/kernels/mlu/layout_compute.cc
0 → 100644
浏览文件 @
53ef685e
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.ddNod
//
// 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 "lite/kernels/mlu/layout_compute.h"
namespace
paddle
{
namespace
lite
{
namespace
kernels
{
namespace
mlu
{}
// namespace mlu
}
// namespace kernels
}
// namespace lite
}
// namespace paddle
REGISTER_LITE_KERNEL
(
layout
,
kMLU
,
kFloat
,
kNHWC
,
paddle
::
lite
::
kernels
::
mlu
::
LayoutNhwcToNchwCompute
<
PRECISION
(
kFloat
)
>
,
def_layout_nhwc2nchw_fp32
)
.
BindInput
(
"Inputs"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kMLU
),
PRECISION
(
kFloat
),
DATALAYOUT
(
kNHWC
))})
.
BindOutput
(
"Outputs"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kMLU
),
PRECISION
(
kFloat
),
DATALAYOUT
(
kNCHW
))})
.
Finalize
();
REGISTER_LITE_KERNEL
(
layout
,
kMLU
,
kFP16
,
kNHWC
,
paddle
::
lite
::
kernels
::
mlu
::
LayoutNhwcToNchwCompute
<
PRECISION
(
kFP16
)
>
,
def_layout_nhwc2nchw_fp16
)
.
BindInput
(
"Inputs"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kMLU
),
PRECISION
(
kFloat
),
DATALAYOUT
(
kNHWC
))})
.
BindOutput
(
"Outputs"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kMLU
),
PRECISION
(
kFloat
),
DATALAYOUT
(
kNCHW
))})
.
Finalize
();
REGISTER_LITE_KERNEL
(
layout
,
kMLU
,
kFloat
,
kNHWC
,
paddle
::
lite
::
kernels
::
mlu
::
LayoutNchwToNhwcCompute
<
PRECISION
(
kFloat
)
>
,
def_layout_nchw2nhwc_fp32
)
.
BindInput
(
"Inputs"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kMLU
),
PRECISION
(
kFloat
),
DATALAYOUT
(
kNCHW
))})
.
BindOutput
(
"Outputs"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kMLU
),
PRECISION
(
kFloat
),
DATALAYOUT
(
kNHWC
))})
.
Finalize
();
REGISTER_LITE_KERNEL
(
layout
,
kMLU
,
kFP16
,
kNHWC
,
paddle
::
lite
::
kernels
::
mlu
::
LayoutNchwToNhwcCompute
<
PRECISION
(
kFP16
)
>
,
def_layout_nchw2nhwc_fp16
)
.
BindInput
(
"Inputs"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kMLU
),
PRECISION
(
kFloat
),
DATALAYOUT
(
kNCHW
))})
.
BindOutput
(
"Outputs"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kMLU
),
PRECISION
(
kFloat
),
DATALAYOUT
(
kNHWC
))})
.
Finalize
();
lite/kernels/mlu/layout_compute.h
0 → 100644
浏览文件 @
53ef685e
// Copyright (c) 2019 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
#include <Eigen/Core>
#include <string>
#include <vector>
#include "lite/backends/x86/math/math_function.h"
#include "lite/core/kernel.h"
#include "lite/core/op_lite.h"
#include "lite/core/op_registry.h"
#include "lite/core/type_system.h"
#include "lite/operators/layout_op.h"
namespace
paddle
{
namespace
lite
{
namespace
kernels
{
namespace
mlu
{
template
<
lite
::
TargetType
Target
,
typename
T
>
inline
void
LayoutTransCompute
(
const
int
dim
,
const
lite
::
Context
<
Target
>&
context
,
const
lite
::
Tensor
&
in
,
lite
::
Tensor
*
out
,
const
std
::
vector
<
int
>&
axis
)
{
switch
(
dim
)
{
case
2
:
paddle
::
lite
::
x86
::
math
::
Transpose
<
lite
::
TargetType
::
kX86
,
T
,
2
>
trans2
;
trans2
(
context
,
in
,
out
,
axis
);
break
;
case
3
:
paddle
::
lite
::
x86
::
math
::
Transpose
<
lite
::
TargetType
::
kX86
,
T
,
3
>
trans3
;
trans3
(
context
,
in
,
out
,
axis
);
break
;
case
4
:
paddle
::
lite
::
x86
::
math
::
Transpose
<
lite
::
TargetType
::
kX86
,
T
,
4
>
trans4
;
trans4
(
context
,
in
,
out
,
axis
);
break
;
default:
CHECK
(
0
)
<<
(
"Unsupport dim in mlu layout"
);
}
}
template
<
PrecisionType
Precision
>
class
LayoutNchwToNhwcCompute
:
public
KernelLite
<
TARGET
(
kMLU
),
Precision
,
DATALAYOUT
(
kNHWC
)
>
{
public:
using
param_t
=
operators
::
LayoutParam
;
void
Run
()
override
{
auto
&
param
=
this
->
template
Param
<
param_t
>();
auto
*
x
=
param
.
x
;
auto
*
out
=
param
.
y
;
out
->
template
mutable_data
<
float
>();
auto
x_dims
=
param
.
x
->
dims
().
size
();
auto
&
context
=
this
->
ctx_
->
template
As
<
X86Context
>();
std
::
vector
<
int
>
axis
;
switch
(
x_dims
)
{
case
2
:
axis
=
{
0
,
1
};
break
;
case
3
:
axis
=
{
0
,
2
,
1
};
out
->
Resize
(
std
::
vector
<
int64_t
>
{
out
->
dims
()[
0
],
out
->
dims
()[
2
],
out
->
dims
()[
1
]});
break
;
case
4
:
axis
=
{
0
,
2
,
3
,
1
};
out
->
Resize
(
std
::
vector
<
int64_t
>
{
out
->
dims
()[
0
],
out
->
dims
()[
2
],
out
->
dims
()[
3
],
out
->
dims
()[
1
]});
break
;
default:
CHECK
(
0
)
<<
"Unsupport dim in mlu layout nchw to nhwc"
;
}
LayoutTransCompute
<
lite
::
TargetType
::
X86
,
float
>
(
x_dims
,
context
,
*
x
,
out
,
axis
);
)
}
std
::
string
doc
()
const
override
{
return
"Mlu layout transform nchw to nhwc"
;
}
};
template
<
PrecisionType
Precision
>
class
LayoutNhwcToNchwCompute
:
public
KernelLite
<
TARGET
(
kMLU
),
Precision
,
DATALAYOUT
(
kNHWC
)
>
{
public:
using
param_t
=
operators
::
LayoutParam
;
void
Run
()
override
{
auto
&
param
=
this
->
template
Param
<
param_t
>();
auto
*
x
=
param
.
x
;
auto
*
out
=
param
.
y
;
out
->
template
mutable_data
<
float
>();
auto
x_dims
=
param
.
x
->
dims
().
size
();
auto
&
context
=
this
->
ctx_
->
template
As
<
X86Context
>();
std
::
vector
<
int
>
axis
;
switch
(
x_dims
)
{
case
2
:
axis
=
{
0
,
1
};
break
;
case
3
:
axis
=
{
0
,
2
,
1
};
out
->
Resize
(
std
::
vector
<
int64_t
>
{
out
->
dims
()[
0
],
out
->
dims
()[
2
],
out
->
dims
()[
1
]});
break
;
case
4
:
axis
=
{
0
,
3
,
1
,
2
};
out
->
Resize
(
std
::
vector
<
int64_t
>
{
out
->
dims
()[
0
],
out
->
dims
()[
3
],
out
->
dims
()[
1
],
out
->
dims
()[
2
]});
break
;
default:
CHECK
(
0
)
<<
"Unsupport dim in mlu layout nhwc to nchw"
;
}
LayoutTransCompute
<
lite
::
TargetType
::
X86
,
float
>
(
x_dims
,
context
,
*
x
,
out
,
axis
);
)
}
std
::
string
doc
()
const
override
{
return
"Mlu layout transform nhwc to nchw"
;
}
};
}
// namespace mlu
}
// namespace kernels
}
// namespace lite
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录