Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
cb945ceb
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看板
提交
cb945ceb
编写于
5月 09, 2019
作者:
Y
Yanzhan Yang
提交者:
GitHub
5月 09, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add useAggresiveOptimization param to control newly added optimization code branch (#1612)
上级
048a8ebe
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
22 addition
and
10 deletion
+22
-10
metal/paddle-mobile/paddle-mobile/API/Net.swift
metal/paddle-mobile/paddle-mobile/API/Net.swift
+3
-0
metal/paddle-mobile/paddle-mobile/API/Runner.swift
metal/paddle-mobile/paddle-mobile/API/Runner.swift
+1
-0
metal/paddle-mobile/paddle-mobile/Src/Operators/Base/Operator.swift
...le-mobile/paddle-mobile/Src/Operators/Base/Operator.swift
+3
-0
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddKernel.swift
...e/paddle-mobile/Src/Operators/Kernels/ConvAddKernel.swift
+6
-5
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddReluKernel.swift
...ddle-mobile/Src/Operators/Kernels/ConvAddReluKernel.swift
+9
-5
未找到文件。
metal/paddle-mobile/paddle-mobile/API/Net.swift
浏览文件 @
cb945ceb
...
...
@@ -59,6 +59,9 @@ import Foundation
/// 是否使用 MetalPerformanceShaders 进行运算, 运算精度为 32 位时不支持开启 MPS
@objc
public
var
useMPS
:
Bool
=
false
/// 是否使用最高等级的加速策略
@objc
public
var
useAggressiveOptimization
:
Bool
=
false
/// 模型精度
@objc
public
var
paramPrecision
:
Precision
=
.
Float32
...
...
metal/paddle-mobile/paddle-mobile/API/Runner.swift
浏览文件 @
cb945ceb
...
...
@@ -95,6 +95,7 @@ import Foundation
initContext
.
metalLoadMode
=
net
.
metalLoadMode
initContext
.
metalLibPath
=
net
.
metalLibPath
initContext
.
useMPS
=
net
.
useMPS
initContext
.
useAggresiveOptimization
=
net
.
useAggressiveOptimization
switch
net
.
paramPrecision
{
case
.
Float16
:
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Base/Operator.swift
浏览文件 @
cb945ceb
...
...
@@ -70,6 +70,9 @@ public class InitContext {
/// 是否使用 MetalPerformanceShaders 进行运算
var
useMPS
:
Bool
=
false
/// 是否使用最高等级的加速策略
var
useAggresiveOptimization
:
Bool
=
false
init
()
{
metalLoadMode
=
.
LoadMetalInDefaultLib
metalLibPath
=
nil
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddKernel.swift
浏览文件 @
cb945ceb
...
...
@@ -110,9 +110,11 @@ class ConvAddKernel<P: PrecisionProtocol>: Kernel, Computable {
}
var
shouldUseMPS
=
false
let
functionName
=
type
(
of
:
self
)
.
kernelFunctionName
(
param
:
param
)
if
#available(iOS 11.0, *)
,
initContext
.
useMPS
{
shouldUseMPS
=
true
let
functionName
=
type
(
of
:
self
)
.
kernelFunctionName
(
param
:
param
,
useAggressiveOptimization
:
initContext
.
useAggresiveOptimization
)
if
#available(iOS 11.0, *)
,
(
initContext
.
useMPS
||
initContext
.
useAggresiveOptimization
)
{
if
(
param
.
input
.
tensorDim
[
1
]
==
1
||
param
.
input
.
tensorDim
[
1
]
>
4
)
&&
(
param
.
output
.
tensorDim
[
1
]
==
1
||
param
.
output
.
tensorDim
[
1
]
>
4
)
{
shouldUseMPS
=
true
}
}
if
type
(
of
:
self
)
.
isWinoGrad
(
functionName
:
functionName
)
{
shouldUseMPS
=
false
...
...
@@ -121,7 +123,6 @@ class ConvAddKernel<P: PrecisionProtocol>: Kernel, Computable {
super
.
init
(
device
:
device
,
inFunctionName
:
nil
,
initContext
:
initContext
)
setupWithMPS
(
device
:
device
,
param
:
param
)
}
else
{
if
functionName
==
nil
{
fatalError
(
" unsupport yet "
)
}
...
...
@@ -203,7 +204,7 @@ class ConvAddKernel<P: PrecisionProtocol>: Kernel, Computable {
param
.
y
.
initBuffer
(
device
:
device
,
precision
:
GlobalConfig
.
shared
.
computePrecision
)
}
open
class
func
kernelFunctionName
(
param
:
ConvAddParam
<
P
>
)
->
String
?
{
open
class
func
kernelFunctionName
(
param
:
ConvAddParam
<
P
>
,
useAggressiveOptimization
:
Bool
=
false
)
->
String
?
{
if
GlobalConfig
.
shared
.
computePrecision
==
.
Float16
{
if
param
.
filter
.
width
==
1
&&
param
.
filter
.
height
==
1
{
return
"conv_add_1x1_half"
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddReluKernel.swift
浏览文件 @
cb945ceb
...
...
@@ -10,16 +10,20 @@ import Foundation
import
MetalPerformanceShaders
class
ConvAddReluKernel
<
P
:
PrecisionProtocol
>
:
ConvAddKernel
<
P
>
{
override
class
func
kernelFunctionName
(
param
:
ConvAddParam
<
P
>
)
->
String
?
{
override
class
func
kernelFunctionName
(
param
:
ConvAddParam
<
P
>
,
useAggressiveOptimization
:
Bool
=
false
)
->
String
?
{
if
GlobalConfig
.
shared
.
computePrecision
==
.
Float16
{
if
param
.
filter
.
width
==
1
&&
param
.
filter
.
height
==
1
{
return
"conv_add_relu_1x1_half"
}
else
if
param
.
filter
.
channel
==
1
&&
param
.
filter
.
n
==
param
.
input
.
tensorDim
[
1
]
{
if
param
.
filter
.
width
==
3
&&
param
.
filter
.
height
==
3
&&
param
.
stride
[
0
]
==
1
&&
param
.
stride
[
1
]
==
1
&&
param
.
filter
.
n
==
16
{
return
"depthwise_conv_add_relu_3x3_half_winograd"
}
else
{
return
"depthwise_conv_add_relu_3x3_half"
if
useAggressiveOptimization
{
let
couldUseWinograd
=
param
.
filter
.
width
==
3
&&
param
.
filter
.
height
==
3
&&
param
.
filter
.
n
==
16
&&
param
.
stride
[
0
]
==
1
&&
param
.
stride
[
1
]
==
1
&&
param
.
dilations
[
0
]
==
1
&&
param
.
dilations
[
1
]
==
1
if
couldUseWinograd
{
return
"depthwise_conv_add_relu_3x3_half_winograd"
}
}
return
"depthwise_conv_add_relu_3x3_half"
}
else
if
param
.
filter
.
width
==
3
&&
param
.
filter
.
height
==
3
{
return
"conv_add_relu_3x3_half"
}
else
if
param
.
filter
.
width
==
1
&&
param
.
filter
.
height
==
5
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录