Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
5a351346
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看板
未验证
提交
5a351346
编写于
5月 21, 2019
作者:
Y
Yanzhan Yang
提交者:
GitHub
5月 21, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1.check slice and nearest op result. 2.reshape output should have same layout as its input. (#1640)
上级
f7ebe337
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
37 addition
and
19 deletion
+37
-19
metal/paddle-mobile-metallib/paddle-mobile-metallib/ConcatKernel.metal
...mobile-metallib/paddle-mobile-metallib/ConcatKernel.metal
+2
-2
metal/paddle-mobile-metallib/paddle-mobile-metallib/NearestInterpKernel.metal
...metallib/paddle-mobile-metallib/NearestInterpKernel.metal
+4
-4
metal/paddle-mobile-metallib/paddle-mobile-metallib/SliceKernel.metal
...-mobile-metallib/paddle-mobile-metallib/SliceKernel.metal
+21
-9
metal/paddle-mobile/paddle-mobile/Src/Common/MetalExtension.swift
...ddle-mobile/paddle-mobile/Src/Common/MetalExtension.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ReshapeKernel.swift
...e/paddle-mobile/Src/Operators/Kernels/ReshapeKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/SliceKernel.swift
...ile/paddle-mobile/Src/Operators/Kernels/SliceKernel.swift
+8
-2
未找到文件。
metal/paddle-mobile-metallib/paddle-mobile-metallib/ConcatKernel.metal
浏览文件 @
5a351346
...
...
@@ -67,8 +67,8 @@ struct ConcatParam {
#undef R
#undef V
// lens: (R=4, N=3, V=
x
)
#define V V
X
// lens: (R=4, N=3, V=
y
)
#define V V
Y
#define R 4
#define N 3
#define P float
...
...
metal/paddle-mobile-metallib/paddle-mobile-metallib/NearestInterpKernel.metal
浏览文件 @
5a351346
...
...
@@ -28,8 +28,8 @@ kernel void nearest_interp(texture2d_array<float, access::sample> inTexture [[te
gid.z >= outTexture.get_array_size()) return;
constexpr sampler s(coord::pixel, filter::nearest, address::clamp_to_zero);
float scale = param.scale;
uint x = uint(
round
(float(gid.x) / scale));
uint y = uint(
round
(float(gid.y) / scale));
uint x = uint(
floor
(float(gid.x) / scale));
uint y = uint(
floor
(float(gid.y) / scale));
const float4 input = inTexture.read(uint2(x, y), gid.z);
outTexture.write(input, gid.xy, gid.z);
}
...
...
@@ -43,8 +43,8 @@ kernel void nearest_interp_half(texture2d_array<half, access::sample> inTexture
gid.z >= outTexture.get_array_size()) return;
constexpr sampler s(coord::pixel, filter::nearest, address::clamp_to_zero);
float scale = param.scale;
uint x = uint(
round
(float(gid.x) / scale));
uint y = uint(
round
(float(gid.y) / scale));
uint x = uint(
floor
(float(gid.x) / scale));
uint y = uint(
floor
(float(gid.y) / scale));
const half4 input = inTexture.read(uint2(x, y), gid.z);
outTexture.write(input, gid.xy, gid.z);
}
metal/paddle-mobile-metallib/paddle-mobile-metallib/SliceKernel.metal
浏览文件 @
5a351346
...
...
@@ -24,6 +24,8 @@ struct MetalSliceParam {
short end1;
short end2;
short end3;
int iC;
int oC;
};
kernel void slice(texture2d_array<float, access::sample> inTexture [[texture(0)]],
...
...
@@ -35,9 +37,14 @@ kernel void slice(texture2d_array<float, access::sample> inTexture [[texture(0)]
gid.z >= outTexture.get_array_size()) return;
constexpr sampler s(coord::pixel, filter::nearest, address::clamp_to_zero);
float4 output;
for (int i = 0; i < 4; i++) {
int input_c = gid.z * 4 + i + param.start1;
int input_z = input_c / 4;
for (int i = 0; i < 4; ++i) {
int tmp = gid.z * 4 + i;
int output_c = tmp % param.oC;
int output_n = tmp / param.oC;
int c = output_c + param.start1;
tmp = output_n * param.iC + c;
int input_z = tmp / 4;
int input_c = tmp % 4;
const float4 input = inTexture.read(gid.xy, input_z);
output[i] = input[input_c % 4];
}
...
...
@@ -52,12 +59,17 @@ kernel void slice_half(texture2d_array<half, access::sample> inTexture [[texture
gid.y >= outTexture.get_height() ||
gid.z >= outTexture.get_array_size()) return;
constexpr sampler s(coord::pixel, filter::nearest, address::clamp_to_zero);
float4 output;
for (int i = 0; i < 4; i++) {
int input_c = gid.z * 4 + i + param.start1;
int input_z = input_c / 4;
const float4 input = float4(inTexture.read(gid.xy, input_z));
half4 output;
for (int i = 0; i < 4; ++i) {
int tmp = gid.z * 4 + i;
int output_c = tmp % param.oC;
int output_n = tmp / param.oC;
int c = output_c + param.start1;
tmp = output_n * param.iC + c;
int input_z = tmp / 4;
int input_c = tmp % 4;
const half4 input = inTexture.read(gid.xy, input_z);
output[i] = input[input_c % 4];
}
outTexture.write(
half4(output)
, gid.xy, gid.z);
outTexture.write(
output
, gid.xy, gid.z);
}
metal/paddle-mobile/paddle-mobile/Src/Common/MetalExtension.swift
浏览文件 @
5a351346
...
...
@@ -534,7 +534,7 @@ public extension MTLTexture {
for
c
in
0
..<
4
{
for
h
in
0
..<
dim
.
h
{
for
w
in
0
..<
dim
.
w
{
if
(
s
*
4
+
c
)
<
dim
.
c
{
if
(
s
*
4
+
c
)
<
(
dim
.
c
*
dim
.
n
)
{
let
textureValue
=
textureArray
[
dim
.
w
*
dim
.
h
*
4
*
s
+
h
*
dim
.
w
*
4
+
w
*
4
+
c
]
output
.
append
(
textureValue
)
}
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ReshapeKernel.swift
浏览文件 @
5a351346
...
...
@@ -34,7 +34,7 @@ class ReshapeKernel<P: PrecisionProtocol>: Kernel, Computable{
required
init
(
device
:
MTLDevice
,
param
:
ReshapeParam
<
P
>
,
initContext
:
InitContext
)
throws
{
do
{
try
param
.
output
.
initTexture
(
device
:
device
,
computePrecision
:
GlobalConfig
.
shared
.
computePrecision
)
try
param
.
output
.
initTexture
(
device
:
device
,
inTranspose
:
param
.
input
.
transpose
,
computePrecision
:
GlobalConfig
.
shared
.
computePrecision
)
}
catch
let
error
{
throw
error
}
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/SliceKernel.swift
浏览文件 @
5a351346
...
...
@@ -23,6 +23,8 @@ public struct SliceMetalParam {
let
end1
:
Int16
let
end2
:
Int16
let
end3
:
Int16
let
iC
:
Int32
let
oC
:
Int32
}
class
SliceKernel
<
P
:
PrecisionProtocol
>
:
Kernel
,
Computable
{
...
...
@@ -40,7 +42,7 @@ class SliceKernel<P: PrecisionProtocol>: Kernel, Computable {
required
init
(
device
:
MTLDevice
,
param
:
SliceParam
<
P
>
,
initContext
:
InitContext
)
throws
{
do
{
try
param
.
output
.
initTexture
(
device
:
device
,
inTranspose
:
param
.
input
.
transpose
,
computePrecision
:
GlobalConfig
.
shared
.
computePrecision
)
try
param
.
output
.
initTexture
(
device
:
device
,
inTranspose
:
[
0
,
2
,
3
,
1
]
,
computePrecision
:
GlobalConfig
.
shared
.
computePrecision
)
}
catch
let
error
{
throw
error
}
...
...
@@ -60,7 +62,11 @@ class SliceKernel<P: PrecisionProtocol>: Kernel, Computable {
let
end1
=
ranges
[
1
][
1
]
let
end2
=
ranges
[
2
][
1
]
let
end3
=
ranges
[
3
][
1
]
metalParam
=
SliceMetalParam
.
init
(
start0
:
start0
,
start1
:
start1
,
start2
:
start2
,
start3
:
start3
,
end0
:
end0
,
end1
:
end1
,
end2
:
end2
,
end3
:
end3
)
let
iC
=
Int32
(
param
.
input
.
tensorDim
[
1
])
let
oC
=
Int32
(
param
.
output
.
tensorDim
[
1
])
metalParam
=
SliceMetalParam
.
init
(
start0
:
start0
,
start1
:
start1
,
start2
:
start2
,
start3
:
start3
,
end0
:
end0
,
end1
:
end1
,
end2
:
end2
,
end3
:
end3
,
iC
:
iC
,
oC
:
oC
)
if
GlobalConfig
.
shared
.
computePrecision
==
.
Float32
{
super
.
init
(
device
:
device
,
inFunctionName
:
"slice"
,
initContext
:
initContext
)
}
else
if
GlobalConfig
.
shared
.
computePrecision
==
.
Float16
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录