Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
980b855d
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看板
提交
980b855d
编写于
4月 26, 2019
作者:
Y
Yanzhan Yang
提交者:
GitHub
4月 26, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1582 from yangyanzhan/develop
fix MPSCNN ConvAdd implementation.
上级
c2f69ebd
f3d4f1b8
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
14 addition
and
19 deletion
+14
-19
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddKernel.swift
...e/paddle-mobile/Src/Operators/Kernels/ConvAddKernel.swift
+14
-19
未找到文件。
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddKernel.swift
浏览文件 @
980b855d
...
...
@@ -17,8 +17,6 @@ import MetalPerformanceShaders
@available
(
iOS
10.0
,
*
)
var
convDic
:
[
String
:
MPSCNNConvolution
]
=
[:]
@available
(
iOS
10.0
,
*
)
var
imageDic
:
[
String
:
MPSImage
]
=
[:]
/// 获取唯一字符串
///
...
...
@@ -117,23 +115,22 @@ class ConvAddKernel<P: PrecisionProtocol>: Kernel, Computable {
if
#available(iOS 11.0, *)
{
var
desc
:
MPSCNNConvolutionDescriptor
?
// 如果不是 depth wise, 并且输入输出 tensor channel 都大于 4
if
!
(
param
.
filter
.
tensorDim
[
1
]
==
1
&&
param
.
filter
.
tensorDim
[
0
]
==
param
.
input
.
tensorDim
[
1
])
&&
param
.
input
.
tensorDim
[
1
]
>
4
&&
param
.
output
.
tensorDim
[
1
]
>
4
{
desc
=
MPSCNNConvolutionDescriptor
(
kernelWidth
:
param
.
filter
.
tensorDim
[
3
],
let
isDepthWise
=
param
.
filter
.
tensorDim
[
1
]
==
1
&&
param
.
filter
.
tensorDim
[
0
]
==
param
.
input
.
tensorDim
[
1
]
if
param
.
input
.
tensorDim
[
1
]
>
4
&&
param
.
output
.
tensorDim
[
1
]
>
4
{
if
isDepthWise
{
desc
=
MPSCNNDepthWiseConvolutionDescriptor
(
kernelWidth
:
param
.
filter
.
tensorDim
[
3
],
kernelHeight
:
param
.
filter
.
tensorDim
[
2
],
inputFeatureChannels
:
param
.
input
.
tensorDim
[
1
],
outputFeatureChannels
:
param
.
output
.
tensorDim
[
1
],
neuronFilter
:
nil
)
desc
?
.
strideInPixelsX
=
Int
(
param
.
stride
[
0
])
desc
?
.
strideInPixelsY
=
Int
(
param
.
stride
[
1
])
}
else
if
param
.
input
.
tensorDim
[
1
]
>
4
&&
param
.
output
.
tensorDim
[
1
]
>
4
{
desc
=
MPSCNNDepthWiseConvolutionDescriptor
(
kernelWidth
:
param
.
filter
.
tensorDim
[
3
],
}
else
{
desc
=
MPSCNNConvolutionDescriptor
(
kernelWidth
:
param
.
filter
.
tensorDim
[
3
],
kernelHeight
:
param
.
filter
.
tensorDim
[
2
],
inputFeatureChannels
:
param
.
input
.
tensorDim
[
1
],
outputFeatureChannels
:
param
.
output
.
tensorDim
[
1
],
neuronFilter
:
nil
)
}
}
desc
?
.
strideInPixelsX
=
Int
(
param
.
stride
[
0
])
desc
?
.
strideInPixelsY
=
Int
(
param
.
stride
[
1
])
if
let
inDesc
=
desc
{
...
...
@@ -143,8 +140,6 @@ class ConvAddKernel<P: PrecisionProtocol>: Kernel, Computable {
conv
.
offset
=
MPSOffset
.
init
(
x
:
offsetX
,
y
:
offsetY
,
z
:
0
)
conv
.
edgeMode
=
.
zero
convDic
[
key
]
=
conv
imageDic
[
identifyingKey
+
"_input"
]
=
MPSImage
.
init
(
texture
:
param
.
input
.
metalTexture
,
featureChannels
:
param
.
input
.
tensorDim
[
1
])
imageDic
[
identifyingKey
+
"_output"
]
=
MPSImage
.
init
(
texture
:
param
.
output
.
metalTexture
,
featureChannels
:
param
.
output
.
tensorDim
[
1
])
super
.
init
(
device
:
device
,
inFunctionName
:
nil
,
initContext
:
initContext
)
return
}
...
...
@@ -201,7 +196,9 @@ class ConvAddKernel<P: PrecisionProtocol>: Kernel, Computable {
func
compute
(
commandBuffer
:
MTLCommandBuffer
,
param
:
ConvAddParam
<
P
>
)
throws
{
if
#available(iOS 10.0, *)
{
if
let
conv
=
convDic
[
identifyingKey
],
let
inputImage
=
imageDic
[
identifyingKey
+
"_input"
],
let
outputImage
=
imageDic
[
identifyingKey
+
"_output"
]
{
if
let
conv
=
convDic
[
identifyingKey
]
{
let
inputImage
=
MPSImage
.
init
(
texture
:
param
.
input
.
metalTexture
,
featureChannels
:
param
.
input
.
tensorDim
[
1
])
let
outputImage
=
MPSImage
.
init
(
texture
:
param
.
output
.
metalTexture
,
featureChannels
:
param
.
output
.
tensorDim
[
1
])
conv
.
encode
(
commandBuffer
:
commandBuffer
,
sourceImage
:
inputImage
,
destinationImage
:
outputImage
)
return
;
}
...
...
@@ -222,8 +219,6 @@ class ConvAddKernel<P: PrecisionProtocol>: Kernel, Computable {
deinit
{
if
#available(iOS 10.0, *)
{
convDic
.
removeValue
(
forKey
:
identifyingKey
)
imageDic
.
removeValue
(
forKey
:
identifyingKey
+
"_input"
)
imageDic
.
removeValue
(
forKey
:
identifyingKey
+
"_output"
)
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录