Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
e5ab9b35
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看板
提交
e5ab9b35
编写于
3月 12, 2019
作者:
L
liuruilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make pipline optional
上级
7d5d941e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
30 addition
and
20 deletion
+30
-20
metal/paddle-mobile/paddle-mobile/API/Net.swift
metal/paddle-mobile/paddle-mobile/API/Net.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/Base/Kernel.swift
...ile/paddle-mobile/Src/Operators/Kernels/Base/Kernel.swift
+15
-5
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddKernel.swift
...e/paddle-mobile/Src/Operators/Kernels/ConvAddKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/Scale.swift
...le-mobile/paddle-mobile/Src/Operators/Kernels/Scale.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/Texture2DTo2DArrayKernel.swift
...bile/Src/Operators/Kernels/Texture2DTo2DArrayKernel.swift
+10
-10
未找到文件。
metal/paddle-mobile/paddle-mobile/API/Net.swift
浏览文件 @
e5ab9b35
...
@@ -56,10 +56,10 @@ import Foundation
...
@@ -56,10 +56,10 @@ import Foundation
/// 输入维度,按照 n h w c 方式传入
/// 输入维度,按照 n h w c 方式传入
@objc
public
var
inputDim
:
Dim
=
Dim
.
init
(
inDim
:
[])
@objc
public
var
inputDim
:
Dim
=
Dim
.
init
(
inDim
:
[])
/// 是否使用 MetalPerformanceShaders 进行运算
/// 是否使用 MetalPerformanceShaders 进行运算
, 运算精度为 32 位时不支持开启 MPS
@objc
public
var
useMPS
:
Bool
=
false
@objc
public
var
useMPS
:
Bool
=
false
/// 模型精度
- 当使用模型精度为 Float 16 时 不要开启 useMPS, 暂不支持
/// 模型精度
@objc
public
var
paramPrecision
:
Precision
=
.
Float32
@objc
public
var
paramPrecision
:
Precision
=
.
Float32
@objc
public
init
(
device
:
MTLDevice
,
inParamPointer
:
UnsafeMutableRawPointer
,
inParamSize
:
Int
,
inModelPointer
:
UnsafeMutableRawPointer
,
inModelSize
:
Int
)
{
@objc
public
init
(
device
:
MTLDevice
,
inParamPointer
:
UnsafeMutableRawPointer
,
inParamSize
:
Int
,
inModelPointer
:
UnsafeMutableRawPointer
,
inModelSize
:
Int
)
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/Base/Kernel.swift
浏览文件 @
e5ab9b35
...
@@ -38,11 +38,21 @@ protocol KernelProtocol {
...
@@ -38,11 +38,21 @@ protocol KernelProtocol {
}
}
@objc
open
class
Kernel
:
NSObject
{
@objc
open
class
Kernel
:
NSObject
{
let
pipline
:
MTLComputePipelineState
let
functionName
:
String
private
var
_pipline
:
MTLComputePipelineState
?
=
nil
public
init
(
device
:
MTLDevice
,
inFunctionName
:
String
,
usePaddleMobileLib
:
Bool
=
false
,
initContext
:
InitContext
)
{
pipline
=
device
.
pipeLine
(
funcName
:
inFunctionName
,
metalLoadMode
:
initContext
.
metalLoadMode
,
metalLibPath
:
initContext
.
metalLibPath
)
var
pipline
:
MTLComputePipelineState
{
get
{
return
_pipline
?
!
" pipeline can't be nil "
}
}
let
functionName
:
String
?
public
init
(
device
:
MTLDevice
,
inFunctionName
:
String
?,
usePaddleMobileLib
:
Bool
=
false
,
initContext
:
InitContext
)
{
functionName
=
inFunctionName
functionName
=
inFunctionName
if
let
funcName
=
inFunctionName
{
_pipline
=
device
.
pipeLine
(
funcName
:
funcName
,
metalLoadMode
:
initContext
.
metalLoadMode
,
metalLibPath
:
initContext
.
metalLibPath
)
}
}
}
}
}
...
@@ -104,7 +114,7 @@ open class BufferToTextureKernel: Kernel {
...
@@ -104,7 +114,7 @@ open class BufferToTextureKernel: Kernel {
@objc
open
class
CusomKernel
:
Kernel
{
@objc
open
class
CusomKernel
:
Kernel
{
public
let
outputTexture
:
MTLTexture
public
let
outputTexture
:
MTLTexture
public
init
(
device
:
MTLDevice
,
inFunctionName
:
String
,
outputDim
:
Shape
,
metalLoadModel
:
MetalLoadMode
,
metalLibPath
:
String
?)
{
public
init
(
device
:
MTLDevice
,
inFunctionName
:
String
?
,
outputDim
:
Shape
,
metalLoadModel
:
MetalLoadMode
,
metalLibPath
:
String
?)
{
let
textureDesc
=
MTLTextureDescriptor
.
init
()
let
textureDesc
=
MTLTextureDescriptor
.
init
()
textureDesc
.
textureType
=
.
type2D
textureDesc
.
textureType
=
.
type2D
textureDesc
.
width
=
outputDim
.
width
textureDesc
.
width
=
outputDim
.
width
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddKernel.swift
浏览文件 @
e5ab9b35
...
@@ -145,7 +145,7 @@ class ConvAddKernel<P: PrecisionProtocol>: Kernel, Computable {
...
@@ -145,7 +145,7 @@ class ConvAddKernel<P: PrecisionProtocol>: Kernel, Computable {
convDic
[
key
]
=
conv
convDic
[
key
]
=
conv
imageDic
[
identifyingKey
+
"_input"
]
=
MPSImage
.
init
(
texture
:
param
.
input
.
metalTexture
,
featureChannels
:
param
.
input
.
tensorDim
[
1
])
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
])
imageDic
[
identifyingKey
+
"_output"
]
=
MPSImage
.
init
(
texture
:
param
.
output
.
metalTexture
,
featureChannels
:
param
.
output
.
tensorDim
[
1
])
super
.
init
(
device
:
device
,
inFunctionName
:
"place_holder"
,
initContext
:
initContext
)
super
.
init
(
device
:
device
,
inFunctionName
:
nil
,
initContext
:
initContext
)
return
return
}
}
}
}
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/Scale.swift
浏览文件 @
e5ab9b35
...
@@ -20,9 +20,9 @@ public class ScaleKernel: CusomKernel {
...
@@ -20,9 +20,9 @@ public class ScaleKernel: CusomKernel {
public
init
(
device
:
MTLDevice
,
shape
:
Shape
,
metalLoadMode
:
MetalLoadMode
,
metalLibPath
:
String
?)
{
public
init
(
device
:
MTLDevice
,
shape
:
Shape
,
metalLoadMode
:
MetalLoadMode
,
metalLibPath
:
String
?)
{
lanczos
=
MPSImageLanczosScale
(
device
:
device
)
lanczos
=
MPSImageLanczosScale
(
device
:
device
)
if
GlobalConfig
.
shared
.
computePrecision
==
.
Float32
{
if
GlobalConfig
.
shared
.
computePrecision
==
.
Float32
{
super
.
init
(
device
:
device
,
inFunctionName
:
"scale"
,
outputDim
:
shape
,
metalLoadModel
:
metalLoadMode
,
metalLibPath
:
metalLibPath
)
super
.
init
(
device
:
device
,
inFunctionName
:
nil
,
outputDim
:
shape
,
metalLoadModel
:
metalLoadMode
,
metalLibPath
:
metalLibPath
)
}
else
if
GlobalConfig
.
shared
.
computePrecision
==
.
Float16
{
}
else
if
GlobalConfig
.
shared
.
computePrecision
==
.
Float16
{
super
.
init
(
device
:
device
,
inFunctionName
:
"scale_half"
,
outputDim
:
shape
,
metalLoadModel
:
metalLoadMode
,
metalLibPath
:
metalLibPath
)
super
.
init
(
device
:
device
,
inFunctionName
:
nil
,
outputDim
:
shape
,
metalLoadModel
:
metalLoadMode
,
metalLibPath
:
metalLibPath
)
}
else
{
}
else
{
fatalError
(
" unsupport "
)
fatalError
(
" unsupport "
)
}
}
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/Texture2DTo2DArrayKernel.swift
浏览文件 @
e5ab9b35
...
@@ -23,15 +23,6 @@ struct Texture2DTo2DArrayParam {
...
@@ -23,15 +23,6 @@ struct Texture2DTo2DArrayParam {
}
}
class
Texture2DTo2DArrayKernel
<
P
:
PrecisionProtocol
>
:
Kernel
,
Computable
{
class
Texture2DTo2DArrayKernel
<
P
:
PrecisionProtocol
>
:
Kernel
,
Computable
{
func
compute
(
commandBuffer
:
MTLCommandBuffer
,
param
:
FeedParam
<
P
>
)
throws
{
guard
let
encoder
=
commandBuffer
.
makeComputeCommandEncoder
()
else
{
throw
PaddleMobileError
.
predictError
(
message
:
" encode is nil"
)
}
encoder
.
setTexture
(
param
.
input
.
mtlTexture
,
index
:
0
)
encoder
.
setTexture
(
param
.
output
.
metalTexture
,
index
:
1
)
encoder
.
dispatch
(
computePipline
:
pipline
,
outTexture
:
param
.
input
.
mtlTexture
)
encoder
.
endEncoding
()
}
required
init
(
device
:
MTLDevice
,
param
:
FeedParam
<
P
>
,
initContext
:
InitContext
)
{
required
init
(
device
:
MTLDevice
,
param
:
FeedParam
<
P
>
,
initContext
:
InitContext
)
{
param
.
output
.
initTexture
(
device
:
device
,
inTranspose
:
[
0
,
2
,
3
,
1
],
computePrecision
:
GlobalConfig
.
shared
.
computePrecision
)
param
.
output
.
initTexture
(
device
:
device
,
inTranspose
:
[
0
,
2
,
3
,
1
],
computePrecision
:
GlobalConfig
.
shared
.
computePrecision
)
...
@@ -42,6 +33,15 @@ class Texture2DTo2DArrayKernel<P: PrecisionProtocol>: Kernel, Computable{
...
@@ -42,6 +33,15 @@ class Texture2DTo2DArrayKernel<P: PrecisionProtocol>: Kernel, Computable{
}
else
{
}
else
{
fatalError
()
fatalError
()
}
}
}
func
compute
(
commandBuffer
:
MTLCommandBuffer
,
param
:
FeedParam
<
P
>
)
throws
{
guard
let
encoder
=
commandBuffer
.
makeComputeCommandEncoder
()
else
{
throw
PaddleMobileError
.
predictError
(
message
:
" encode is nil"
)
}
encoder
.
setTexture
(
param
.
input
.
mtlTexture
,
index
:
0
)
encoder
.
setTexture
(
param
.
output
.
metalTexture
,
index
:
1
)
encoder
.
dispatch
(
computePipline
:
pipline
,
outTexture
:
param
.
input
.
mtlTexture
)
encoder
.
endEncoding
()
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录