Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
4e945c18
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
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看板
提交
4e945c18
编写于
9月 08, 2018
作者:
D
dolphin8
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
resize_bilinear
上级
d522cd52
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
193 addition
and
2 deletion
+193
-2
metal/paddle-mobile/paddle-mobile/Operators/Base/OpCreator.swift
...addle-mobile/paddle-mobile/Operators/Base/OpCreator.swift
+2
-1
metal/paddle-mobile/paddle-mobile/Operators/Base/Operator.swift
...paddle-mobile/paddle-mobile/Operators/Base/Operator.swift
+3
-1
metal/paddle-mobile/paddle-mobile/Operators/Kernels/ResizeBilinearKernel.swift
...addle-mobile/Operators/Kernels/ResizeBilinearKernel.swift
+49
-0
metal/paddle-mobile/paddle-mobile/Operators/Kernels/metal/ResizeBilinear.metal
...addle-mobile/Operators/Kernels/metal/ResizeBilinear.metal
+75
-0
metal/paddle-mobile/paddle-mobile/Operators/ResizeBilinearOp.swift
...dle-mobile/paddle-mobile/Operators/ResizeBilinearOp.swift
+64
-0
未找到文件。
metal/paddle-mobile/paddle-mobile/Operators/Base/OpCreator.swift
浏览文件 @
4e945c18
...
...
@@ -60,7 +60,8 @@ class OpCreator<P: PrecisionType> {
gTransposeType
:
TransposeOp
<
P
>.
creat
,
gPriorBoxType
:
PriorBoxOp
<
P
>.
creat
,
gPreluType
:
PreluOp
<
P
>.
creat
,
gConv2dTransposeType
:
ConvTransposeOp
<
P
>.
creat
]
gConv2dTransposeType
:
ConvTransposeOp
<
P
>.
creat
,
gResizeBilinearType
:
ResizeBilinearOp
<
P
>.
creat
]
private
init
(){}
}
metal/paddle-mobile/paddle-mobile/Operators/Base/Operator.swift
浏览文件 @
4e945c18
...
...
@@ -139,6 +139,7 @@ let gConvBnReluType = "conv_bn_relu"
let
gDwConvBnReluType
=
"depth_conv_bn_relu"
let
gPreluType
=
"prelu"
let
gConv2dTransposeType
=
"conv2d_transpose"
let
gResizeBilinearType
=
"resize_bilinear"
let
opInfos
=
[
gConvType
:
(
inputs
:
[
"Input"
],
outputs
:
[
"Output"
]),
...
...
@@ -161,5 +162,6 @@ let opInfos = [gConvType : (inputs: ["Input"], outputs: ["Out
gMulticlassNMSType
:
(
inputs
:
[
"BBoxes"
,
"Scores"
],
outputs
:
[
"Out"
]),
gPriorBoxType
:
(
inputs
:
[
"Input"
,
"Image"
],
outputs
:
[
"Boxes"
,
"Variances"
]),
gPreluType
:
(
inputs
:
[
"X"
],
outputs
:
[
"Out"
]),
gConv2dTransposeType
:
(
inputs
:
[
"Input"
],
outputs
:
[
"Output"
])
gConv2dTransposeType
:
(
inputs
:
[
"Input"
],
outputs
:
[
"Output"
]),
gResizeBilinearType
:
(
inputs
:
[
"X"
],
outputs
:
[
"Out"
])
]
metal/paddle-mobile/paddle-mobile/Operators/Kernels/ResizeBilinearKernel.swift
0 → 100644
浏览文件 @
4e945c18
/* Copyright (c) 2018 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. */
import
Foundation
struct
ResizeBilinearMetalParam
{
var
ratio_h
:
Float32
var
ratio_w
:
Float32
}
class
ResizeBilinearKernel
<
P
:
PrecisionType
>
:
Kernel
,
Computable
{
func
compute
(
commandBuffer
:
MTLCommandBuffer
,
param
:
ResizeBilinearParam
<
P
>
)
throws
{
guard
let
encoder
=
commandBuffer
.
makeComputeCommandEncoder
()
else
{
throw
PaddleMobileError
.
predictError
(
message
:
" encode is nil"
)
}
encoder
.
setTexture
(
param
.
input
.
metalTexture
,
index
:
0
)
encoder
.
setTexture
(
param
.
output
.
metalTexture
,
index
:
1
)
let
ratio_h
:
Float32
=
Float32
(
param
.
input
.
tensorDim
.
dims
[
2
])
/
Float32
(
param
.
output
.
tensorDim
.
dims
[
2
])
let
ratio_w
:
Float32
=
Float32
(
param
.
input
.
tensorDim
.
dims
[
3
])
/
Float32
(
param
.
output
.
tensorDim
.
dims
[
3
])
var
p
=
ResizeBilinearMetalParam
.
init
(
ratio_h
:
ratio_h
,
ratio_w
:
ratio_w
)
encoder
.
setBytes
(
&
p
,
length
:
MemoryLayout
<
ConcatMetalParam
>.
size
,
index
:
0
)
encoder
.
dispatch
(
computePipline
:
pipline
,
outTexture
:
param
.
output
.
metalTexture
)
encoder
.
endEncoding
()
}
required
init
(
device
:
MTLDevice
,
param
:
ResizeBilinearParam
<
P
>
)
{
param
.
output
.
initTexture
(
device
:
device
,
inTranspose
:
param
.
input
.
transpose
,
computePrecision
:
computePrecision
)
if
computePrecision
==
.
Float32
{
super
.
init
(
device
:
device
,
inFunctionName
:
"resize_bilinear"
)
}
else
if
computePrecision
==
.
Float16
{
super
.
init
(
device
:
device
,
inFunctionName
:
"resize_bilinear_half"
)
}
else
{
fatalError
()
}
}
}
metal/paddle-mobile/paddle-mobile/Operators/Kernels/metal/ResizeBilinear.metal
0 → 100644
浏览文件 @
4e945c18
/* Copyright (c) 2018 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 <metal_stdlib>
using namespace metal;
struct resize_bilinear_param {
// int32_t out_h;
// int32_t out_w;
float ratio_h;
float ratio_w;
};
kernel void resize_bilinear(texture2d_array<float, access::read> input [[texture(0)]],
texture2d_array<float, access::write> output [[texture(2)]],
constant resize_bilinear_param & pm [[buffer(0)]],
uint3 gid [[thread_position_in_grid]]) {
float4 r;
if ((input.get_width() == output.get_width()) && (input.get_height() == output.get_height())) {
r = input.read(gid.xy, gid.z)
} else {
float w = gid.x * pm.ratio_w;
float h = gid.y * pm.ratio_h;
uint w0 = w, h0 = h;
uint w1 = w0 + 1, h1 = h0 + 1;
float w1lambda = w - w0, h1lambda = h - h0;
float w2lambda = 1.0 - w1lambda, h2lambda = 1.0 - h1lambda;
if (w1 >= input.get_width()) w1 = w0;
if (h1 >= input.get_height()) h1 = h0;
float4 r0 = input.read(uint2(w0, h0), gid.z);
float4 r1 = input.read(uint2(w1, h0), gid.z);
float4 r2 = input.read(uint2(w0, h1), gid.z);
float4 r3 = input.read(uint2(w1, h1), gid.z);
r = h2lambda * (w2lambda * r0 + w1lambda * r1) + h1lambda * (w2lambda * r3 + w1lambda * r4);
}
output.write(r, gid.xy, gid.z);
}
kernel void resize_bilinear_half(texture2d_array<half, access::read> input [[texture(0)]],
texture2d_array<half, access::write> output [[texture(2)]],
constant resize_bilinear_param & pm [[buffer(0)]],
uint3 gid [[thread_position_in_grid]]) {
half4 r;
if ((input.get_width() == output.get_width()) && (input.get_height() == output.get_height())) {
r = input.read(gid.xy, gid.z)
} else {
half w = gid.x * pm.ratio_w;
half h = gid.y * pm.ratio_h;
uint w0 = w, h0 = h;
uint w1 = w0 + 1, h1 = h0 + 1;
half w1lambda = w - w0, h1lambda = h - h0;
half w2lambda = 1.0 - w1lambda, h2lambda = 1.0 - h1lambda;
if (w1 >= input.get_width()) w1 = w0;
if (h1 >= input.get_height()) h1 = h0;
half4 r0 = input.read(uint2(w0, h0), gid.z);
half4 r1 = input.read(uint2(w1, h0), gid.z);
half4 r2 = input.read(uint2(w0, h1), gid.z);
half4 r3 = input.read(uint2(w1, h1), gid.z);
r = h2lambda * (w2lambda * r0 + w1lambda * r1) + h1lambda * (w2lambda * r3 + w1lambda * r4);
}
output.write(r, gid.xy, gid.z);
output.write(r, gid.xy, gid.z);
}
metal/paddle-mobile/paddle-mobile/Operators/ResizeBilinearOp.swift
0 → 100644
浏览文件 @
4e945c18
///* Copyright (c) 2018 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. */
import
Foundation
class
ResizeBilinearParam
<
P
:
PrecisionType
>
:
OpParam
{
typealias
ParamPrecisionType
=
P
required
init
(
opDesc
:
OpDesc
,
inScope
:
Scope
)
throws
{
do
{
input
=
try
ResizeBilinearParam
.
inputX
(
inputs
:
opDesc
.
inputs
,
from
:
inScope
)
if
(
input
.
transpose
!=
[
0
,
2
,
3
,
1
])
||
(
input
.
tensorDim
.
cout
()
!=
4
)
{
fatalError
()
}
output
=
try
ResizeBilinearParam
.
outputOut
(
outputs
:
opDesc
.
outputs
,
from
:
inScope
)
out_h
=
try
ResizeBilinearParam
.
getAttr
(
key
:
"out_h"
,
attrs
:
opDesc
.
attrs
)
out_w
=
try
ResizeBilinearParam
.
getAttr
(
key
:
"out_w"
,
attrs
:
opDesc
.
attrs
)
}
catch
let
error
{
throw
error
}
}
let
input
:
Texture
<
P
>
var
output
:
Texture
<
P
>
let
out_h
:
Int32
let
out_w
:
Int32
}
class
ResizeBilinearOp
<
P
:
PrecisionType
>
:
Operator
<
ResizeBilinearKernel
<
P
>
,
ResizeBilinearParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
ResizeBilinearOp
<
P
>
func
inferShape
()
{
// para.output.dim = para.input.dim
}
func
runImpl
(
device
:
MTLDevice
,
buffer
:
MTLCommandBuffer
)
throws
{
do
{
try
kernel
.
compute
(
commandBuffer
:
buffer
,
param
:
para
)
}
catch
let
error
{
throw
error
}
}
func
delogOutput
()
{
print
(
"
\(
type
)
output: "
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录