Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
e2e2614d
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看板
提交
e2e2614d
编写于
3月 08, 2019
作者:
J
Jiaying Zhao
提交者:
GitHub
3月 08, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' into develop
上级
f566d061
9cde4488
变更
71
隐藏空白更改
内联
并排
Showing
71 changed file
with
245 addition
and
231 deletion
+245
-231
metal/paddle-mobile-demo/paddle-mobile-demo.xcodeproj/project.pbxproj
...-mobile-demo/paddle-mobile-demo.xcodeproj/project.pbxproj
+16
-0
metal/paddle-mobile-demo/paddle-mobile-demo/Net/YoloNet.swift
...l/paddle-mobile-demo/paddle-mobile-demo/Net/YoloNet.swift
+4
-3
metal/paddle-mobile/paddle-mobile/API/GlobalConfig.swift
metal/paddle-mobile/paddle-mobile/API/GlobalConfig.swift
+2
-2
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
+17
-3
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/Common/Tools.swift
metal/paddle-mobile/paddle-mobile/Src/Common/Tools.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Common/Types.swift
metal/paddle-mobile/paddle-mobile/Src/Common/Types.swift
+25
-82
metal/paddle-mobile/paddle-mobile/Src/Framework/Executor.swift
.../paddle-mobile/paddle-mobile/Src/Framework/Executor.swift
+6
-1
metal/paddle-mobile/paddle-mobile/Src/Framework/Loader.swift
metal/paddle-mobile/paddle-mobile/Src/Framework/Loader.swift
+8
-3
metal/paddle-mobile/paddle-mobile/Src/Framework/Tensor.swift
metal/paddle-mobile/paddle-mobile/Src/Framework/Tensor.swift
+71
-44
metal/paddle-mobile/paddle-mobile/Src/Framework/Texture.swift
...l/paddle-mobile/paddle-mobile/Src/Framework/Texture.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/Base/OpCreator.swift
...e-mobile/paddle-mobile/Src/Operators/Base/OpCreator.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Base/OpParam.swift
...dle-mobile/paddle-mobile/Src/Operators/Base/OpParam.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/BatchNormOp.swift
...ddle-mobile/paddle-mobile/Src/Operators/BatchNormOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/BilinearInterpOp.swift
...mobile/paddle-mobile/Src/Operators/BilinearInterpOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/BoxcoderOp.swift
...addle-mobile/paddle-mobile/Src/Operators/BoxcoderOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/ConcatOp.swift
.../paddle-mobile/paddle-mobile/Src/Operators/ConcatOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddAddPreluOp.swift
...obile/paddle-mobile/Src/Operators/ConvAddAddPreluOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddBatchNormReluOp.swift
.../paddle-mobile/Src/Operators/ConvAddBatchNormReluOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddOp.swift
...paddle-mobile/paddle-mobile/Src/Operators/ConvAddOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddPreluOp.swift
...e-mobile/paddle-mobile/Src/Operators/ConvAddPreluOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/ConvBNReluOp.swift
...dle-mobile/paddle-mobile/Src/Operators/ConvBNReluOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/ConvOp.swift
metal/paddle-mobile/paddle-mobile/Src/Operators/ConvOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/ConvTransposeOp.swift
...-mobile/paddle-mobile/Src/Operators/ConvTransposeOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/DepthwiseConvOp.swift
...-mobile/paddle-mobile/Src/Operators/DepthwiseConvOp.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/DwConvBNReluOp.swift
...e-mobile/paddle-mobile/Src/Operators/DwConvBNReluOp.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/ElementwiseAddOp.swift
...mobile/paddle-mobile/Src/Operators/ElementwiseAddOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/ElementwiseAddPreluOp.swift
...e/paddle-mobile/Src/Operators/ElementwiseAddPreluOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/FeedOp.swift
metal/paddle-mobile/paddle-mobile/Src/Operators/FeedOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/FetchOp.swift
...l/paddle-mobile/paddle-mobile/Src/Operators/FetchOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/FlattenOp.swift
...paddle-mobile/paddle-mobile/Src/Operators/FlattenOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/BatchNormKernel.swift
...paddle-mobile/Src/Operators/Kernels/BatchNormKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/BilinearInterpKernel.swift
...e-mobile/Src/Operators/Kernels/BilinearInterpKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/BoxcoderKernel.swift
.../paddle-mobile/Src/Operators/Kernels/BoxcoderKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConcatKernel.swift
...le/paddle-mobile/Src/Operators/Kernels/ConcatKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddAddPreluKernel.swift
...-mobile/Src/Operators/Kernels/ConvAddAddPreluKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddBatchNormReluKernel.swift
...le/Src/Operators/Kernels/ConvAddBatchNormReluKernel.swift
+1
-1
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/ConvAddPreluKernel.swift
...dle-mobile/Src/Operators/Kernels/ConvAddPreluKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvBNReluKernel.swift
...addle-mobile/Src/Operators/Kernels/ConvBNReluKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvKernel.swift
...bile/paddle-mobile/Src/Operators/Kernels/ConvKernel.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvTransposeKernel.swift
...le-mobile/Src/Operators/Kernels/ConvTransposeKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ElementwiseAddKernel.swift
...e-mobile/Src/Operators/Kernels/ElementwiseAddKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ElementwiseAddPreluKernel.swift
...ile/Src/Operators/Kernels/ElementwiseAddPreluKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/FetchKernel.swift
...ile/paddle-mobile/Src/Operators/Kernels/FetchKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/FlattenKernel.swift
...e/paddle-mobile/Src/Operators/Kernels/FlattenKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/MulticlassNMSKernel.swift
...le-mobile/Src/Operators/Kernels/MulticlassNMSKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/PoolKernel.swift
...bile/paddle-mobile/Src/Operators/Kernels/PoolKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/PreluKernel.swift
...ile/paddle-mobile/Src/Operators/Kernels/PreluKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/PriorBoxKernel.swift
.../paddle-mobile/Src/Operators/Kernels/PriorBoxKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ReluKernel.swift
...bile/paddle-mobile/Src/Operators/Kernels/ReluKernel.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/ResizeBilinearKernel.swift
...e-mobile/Src/Operators/Kernels/ResizeBilinearKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ShapeKernel.swift
...ile/paddle-mobile/Src/Operators/Kernels/ShapeKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/SoftmaxKernel.swift
...e/paddle-mobile/Src/Operators/Kernels/SoftmaxKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/SplitKernel.swift
...ile/paddle-mobile/Src/Operators/Kernels/SplitKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/Texture2DTo2DArrayKernel.swift
...bile/Src/Operators/Kernels/Texture2DTo2DArrayKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/TransposeKernel.swift
...paddle-mobile/Src/Operators/Kernels/TransposeKernel.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Src/Operators/MulticlassNMSOp.swift
...-mobile/paddle-mobile/Src/Operators/MulticlassNMSOp.swift
+4
-4
metal/paddle-mobile/paddle-mobile/Src/Operators/PoolOp.swift
metal/paddle-mobile/paddle-mobile/Src/Operators/PoolOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/PreluOp.swift
...l/paddle-mobile/paddle-mobile/Src/Operators/PreluOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/PriorBoxOp.swift
...addle-mobile/paddle-mobile/Src/Operators/PriorBoxOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/ReluOp.swift
metal/paddle-mobile/paddle-mobile/Src/Operators/ReluOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/ReshapeOp.swift
...paddle-mobile/paddle-mobile/Src/Operators/ReshapeOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/ResizeBilinearOp.swift
...mobile/paddle-mobile/Src/Operators/ResizeBilinearOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/ShapeOp.swift
...l/paddle-mobile/paddle-mobile/Src/Operators/ShapeOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/SoftmaxOp.swift
...paddle-mobile/paddle-mobile/Src/Operators/SoftmaxOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/SplitOp.swift
...l/paddle-mobile/paddle-mobile/Src/Operators/SplitOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Operators/TransposeOp.swift
...ddle-mobile/paddle-mobile/Src/Operators/TransposeOp.swift
+2
-2
metal/paddle-mobile/paddle-mobile/Src/Program/ProgramOptimize.swift
...le-mobile/paddle-mobile/Src/Program/ProgramOptimize.swift
+1
-1
未找到文件。
metal/paddle-mobile-demo/paddle-mobile-demo.xcodeproj/project.pbxproj
浏览文件 @
e2e2614d
...
...
@@ -44,6 +44,8 @@
FC9797C321D608E000F2FD90
/* mobilenet_params in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC9797C121D608DF00F2FD90
/* mobilenet_params */
;
};
FC9797C721D609FB00F2FD90
/* synset.txt in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC9797C621D609FB00F2FD90
/* synset.txt */
;
};
FC9797CF21D6506F00F2FD90
/* mingren.jpg in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC9797CE21D6506F00F2FD90
/* mingren.jpg */
;
};
FCAFD84B2231614200496A36
/* yolo_16_param in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FCAFD8492231614200496A36
/* yolo_16_param */
;
};
FCAFD84C2231614200496A36
/* yolo_16_model in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FCAFD84A2231614200496A36
/* yolo_16_model */
;
};
FCBCCC552122EF5500D94F7E
/* MetalHelper.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FCBCCC542122EF5400D94F7E
/* MetalHelper.swift */
;
};
FCC15E15221E716500DC3CB2
/* paddle-mobile-metallib.metallib in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FCC15E14221E716400DC3CB2
/* paddle-mobile-metallib.metallib */
;
};
FCCED60521D7646E00BE8D5F
/* test_image_super in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FCCED60421D7646E00BE8D5F
/* test_image_super */
;
};
...
...
@@ -114,6 +116,8 @@
FC9797C121D608DF00F2FD90
/* mobilenet_params */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file
;
path
=
mobilenet_params
;
sourceTree
=
"<group>"
;
};
FC9797C621D609FB00F2FD90
/* synset.txt */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
text
;
path
=
synset.txt
;
sourceTree
=
"<group>"
;
};
FC9797CE21D6506F00F2FD90
/* mingren.jpg */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
image.jpeg
;
path
=
mingren.jpg
;
sourceTree
=
"<group>"
;
};
FCAFD8492231614200496A36
/* yolo_16_param */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file
;
path
=
yolo_16_param
;
sourceTree
=
"<group>"
;
};
FCAFD84A2231614200496A36
/* yolo_16_model */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file
;
path
=
yolo_16_model
;
sourceTree
=
"<group>"
;
};
FCBCCC542122EF5400D94F7E
/* MetalHelper.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MetalHelper.swift
;
sourceTree
=
"<group>"
;
};
FCC15E14221E716400DC3CB2
/* paddle-mobile-metallib.metallib */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
"archive.metal-library"
;
name
=
"paddle-mobile-metallib.metallib"
;
path
=
"../../../../Library/Developer/Xcode/DerivedData/paddle-mobile-hdsimtkoxoondndnjczkbkchcwyh/Build/Products/Release-iphoneos/paddle-mobile-metallib.metallib"
;
sourceTree
=
"<group>"
;
};
FCCED60421D7646E00BE8D5F
/* test_image_super */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file
;
path
=
test_image_super
;
sourceTree
=
"<group>"
;
};
...
...
@@ -263,6 +267,7 @@
FC704C1B21D237FC00F98BAB
/* vision_model */
=
{
isa
=
PBXGroup
;
children
=
(
FCAFD8482231614200496A36
/* yolo_16 */
,
FC704C1C21D237FC00F98BAB
/* mobilenet */
,
FC704C1F21D237FC00F98BAB
/* yolo */
,
);
...
...
@@ -322,6 +327,15 @@
path
=
mobilenet
;
sourceTree
=
"<group>"
;
};
FCAFD8482231614200496A36
/* yolo_16 */
=
{
isa
=
PBXGroup
;
children
=
(
FCAFD8492231614200496A36
/* yolo_16_param */
,
FCAFD84A2231614200496A36
/* yolo_16_model */
,
);
path
=
yolo_16
;
sourceTree
=
"<group>"
;
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
...
...
@@ -388,6 +402,7 @@
FC039B8C20E11C560081E9F8
/* LaunchScreen.storyboard in Resources */
,
FC9797CF21D6506F00F2FD90
/* mingren.jpg in Resources */
,
FC704C2221D237FC00F98BAB
/* combined_mobilenet_params in Resources */
,
FCAFD84B2231614200496A36
/* yolo_16_param in Resources */
,
FC704C1921D2375300F98BAB
/* super_params in Resources */
,
FC2BFCBE21DF15D900C262B2
/* 123.jpg in Resources */
,
FC039B8920E11C560081E9F8
/* Assets.xcassets in Resources */
,
...
...
@@ -397,6 +412,7 @@
FC704C1A21D2375300F98BAB
/* super_model in Resources */
,
FC039B8720E11C550081E9F8
/* Main.storyboard in Resources */
,
FC9797C221D608E000F2FD90
/* mobilenet_model in Resources */
,
FCAFD84C2231614200496A36
/* yolo_16_model in Resources */
,
FC2BFCC021DF279900C262B2
/* classify-img-output.png in Resources */
,
FC203FB221CBFDBA00B37166
/* test.jpg in Resources */
,
FCC15E15221E716500DC3CB2
/* paddle-mobile-metallib.metallib in Resources */
,
...
...
metal/paddle-mobile-demo/paddle-mobile-demo/Net/YoloNet.swift
浏览文件 @
e2e2614d
...
...
@@ -20,12 +20,13 @@ public class YoloNet: Net {
@objc
public
override
init
(
device
:
MTLDevice
)
{
super
.
init
(
device
:
device
)
except
=
0
modelPath
=
Bundle
.
main
.
path
(
forResource
:
"yolo_model"
,
ofType
:
nil
)
?
!
"model null"
paramPath
=
Bundle
.
main
.
path
(
forResource
:
"yolo_
params
"
,
ofType
:
nil
)
?
!
"para null"
modelPath
=
Bundle
.
main
.
path
(
forResource
:
"yolo_
16_
model"
,
ofType
:
nil
)
?
!
"model null"
paramPath
=
Bundle
.
main
.
path
(
forResource
:
"yolo_
16_param
"
,
ofType
:
nil
)
?
!
"para null"
inputDim
=
Dim
.
init
(
inDim
:
[
1
,
416
,
416
,
3
])
metalLoadMode
=
.
LoadMetalInCustomMetalLib
metalLibPath
=
Bundle
.
main
.
path
(
forResource
:
"paddle-mobile-metallib"
,
ofType
:
"metallib"
)
useMPS
=
true
useMPS
=
false
paramPrecision
=
.
Float16
}
override
public
func
resultStr
(
res
:
[
ResultHolder
])
->
String
{
...
...
metal/paddle-mobile/paddle-mobile/API/GlobalConfig.swift
浏览文件 @
e2e2614d
...
...
@@ -21,7 +21,7 @@ import Foundation
LoadMetalInCustomMetalLib
=
3
// 使用 metal 库文件
}
@objc
public
enum
Compute
Precision
:
Int
{
@objc
public
enum
Precision
:
Int
{
case
Float32
=
1
,
Float16
=
2
...
...
@@ -33,7 +33,7 @@ import Foundation
@objc
public
static
let
shared
:
GlobalConfig
=
GlobalConfig
.
init
()
/// 运算精度, runner 生命周期中不可变
@objc
public
var
computePrecision
:
Compute
Precision
=
.
Float16
@objc
public
var
computePrecision
:
Precision
=
.
Float16
/// 是否开启 log
@objc
public
var
debug
:
Bool
=
false
...
...
metal/paddle-mobile/paddle-mobile/API/Net.swift
浏览文件 @
e2e2614d
...
...
@@ -59,6 +59,9 @@ import Foundation
/// 是否使用 MetalPerformanceShaders 进行运算
@objc
public
var
useMPS
:
Bool
=
false
/// 模型精度 - 当使用模型精度为 Float 16 时 不要开启 useMPS, 暂不支持
@objc
public
var
paramPrecision
:
Precision
=
.
Float32
@objc
public
init
(
device
:
MTLDevice
,
inParamPointer
:
UnsafeMutableRawPointer
,
inParamSize
:
Int
,
inModelPointer
:
UnsafeMutableRawPointer
,
inModelSize
:
Int
)
{
self
.
paramPointer
=
inParamPointer
self
.
paramSize
=
inParamSize
...
...
metal/paddle-mobile/paddle-mobile/API/Runner.swift
浏览文件 @
e2e2614d
...
...
@@ -34,7 +34,7 @@ import Foundation
@objc
public
class
Runner
:
NSObject
{
var
program
:
Program
?
var
executor
:
Executor
<
Float32
>
?
var
executor
:
Executor
able
?
var
queue
:
MTLCommandQueue
?
var
textureLoader
:
MTKTextureLoader
?
public
let
net
:
Net
...
...
@@ -68,7 +68,14 @@ import Foundation
print
(
" paddle mobile gpu load error, need MTLCommandQueue"
)
return
false
}
let
loader
=
Loader
<
Float32
>.
init
()
var
loader
:
Loaderable
switch
net
.
paramPrecision
{
case
.
Float16
:
loader
=
Loader
<
Float16
>.
init
()
case
.
Float32
:
loader
=
Loader
<
Float32
>.
init
()
}
do
{
if
let
inParamPointer
=
net
.
paramPointer
,
let
inModelPointer
=
net
.
modelPointer
{
...
...
@@ -89,7 +96,13 @@ import Foundation
initContext
.
metalLibPath
=
net
.
metalLibPath
initContext
.
useMPS
=
net
.
useMPS
executor
=
try
Executor
<
Float32
>.
init
(
inDevice
:
inDevice
,
inQueue
:
inQueue
,
inProgram
:
program
!
,
initContext
:
initContext
)
switch
net
.
paramPrecision
{
case
.
Float16
:
executor
=
try
Executor
<
Float16
>.
init
(
inDevice
:
inDevice
,
inQueue
:
inQueue
,
inProgram
:
program
!
,
initContext
:
initContext
)
case
.
Float32
:
executor
=
try
Executor
<
Float32
>.
init
(
inDevice
:
inDevice
,
inQueue
:
inQueue
,
inProgram
:
program
!
,
initContext
:
initContext
)
}
net
.
updateProgram
(
program
:
program
!
)
}
catch
let
error
{
print
(
error
)
...
...
@@ -105,6 +118,7 @@ import Foundation
/// - completion: 结果回调, 当 success 为 true 时 result 不为 nil
@objc
public
func
predict
(
texture
:
MTLTexture
,
completion
:
@escaping
(
_
success
:
Bool
,
_
result
:
[
ResultHolder
]?)
->
Void
)
{
do
{
try
self
.
executor
?
.
predict
(
input
:
texture
,
dim
:
self
.
net
.
inputDim
,
completionHandle
:
{
[
weak
self
]
(
res
)
in
guard
let
SSelf
=
self
else
{
fatalError
(
" self nil "
)
...
...
metal/paddle-mobile/paddle-mobile/Src/Common/MetalExtension.swift
浏览文件 @
e2e2614d
...
...
@@ -254,7 +254,7 @@ extension MTLDevice {
return
tensor
}
func
tensor2texture
<
P
>
(
value
:
[
P
],
dim
:
[
Int
],
transpose
:
[
Int
]
=
[
0
,
1
,
2
,
3
],
inComputePrecision
:
Compute
Precision
=
.
Float32
)
->
MTLTexture
{
func
tensor2texture
<
P
>
(
value
:
[
P
],
dim
:
[
Int
],
transpose
:
[
Int
]
=
[
0
,
1
,
2
,
3
],
inComputePrecision
:
Precision
=
.
Float32
)
->
MTLTexture
{
if
value
.
count
>
0
{
assert
(
value
.
count
==
dim
.
reduce
(
1
)
{
$0
*
$1
})
}
...
...
metal/paddle-mobile/paddle-mobile/Src/Common/Tools.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
func
writeToLibrary
<
P
:
Precision
Type
>
(
fileName
:
String
,
array
:
[
P
])
{
func
writeToLibrary
<
P
:
Precision
Protocol
>
(
fileName
:
String
,
array
:
[
P
])
{
let
libraryPath
=
NSSearchPathForDirectoriesInDomains
(
.
libraryDirectory
,
.
userDomainMask
,
true
)
.
last
?
!
" library path get error "
let
filePath
=
libraryPath
+
"/"
+
fileName
let
fileManager
=
FileManager
.
init
()
...
...
metal/paddle-mobile/paddle-mobile/Src/Common/Types.swift
浏览文件 @
e2e2614d
...
...
@@ -20,20 +20,28 @@ public protocol SummableMultipliable: Equatable {
static
func
*
(
lhs
:
Self
,
rhs
:
Self
)
->
Self
static
func
-
(
lhs
:
Self
,
rhs
:
Self
)
->
Self
}
public
protocol
PrecisionType
:
SummableMultipliable
{
public
protocol
PrecisionProtocol
:
SummableMultipliable
{
init
(
inFloat
:
Float32
)
init
(
inFloat16
:
Float16
)
init
<
P
:
Precision
Type
>
(
_
inP
:
P
)
init
<
P
:
Precision
Protocol
>
(
_
inP
:
P
)
static
var
bitSize
:
UInt
{
get
}
static
func
initializeValue
()
->
Self
static
var
precisionType
:
Precision
{
get
}
}
public
typealias
Float16
=
Int16
extension
Float16
:
PrecisionType
{
public
static
func
*
(
prefix
:
Float16
,
postfix
:
Float16
)
{
return
prefix
*
postfix
extension
Float16
:
PrecisionProtocol
{
public
static
var
precisionType
:
Precision
{
return
.
Float16
}
public
init
<
P
>
(
_
inP
:
P
)
where
P
:
PrecisionType
{
public
static
func
initializeValue
()
->
Int16
{
return
0
}
public
init
<
P
>
(
_
inP
:
P
)
where
P
:
PrecisionProtocol
{
if
P
.
bitSize
==
Float32
.
bitSize
{
self
=
Float16
(
inFloat
:
inP
as!
Float32
)
}
else
if
P
.
bitSize
==
Float16
.
bitSize
{
...
...
@@ -55,8 +63,17 @@ extension Float16: PrecisionType {
}
}
extension
Float32
:
PrecisionType
{
public
init
<
P
>
(
_
inP
:
P
)
where
P
:
PrecisionType
{
extension
Float32
:
PrecisionProtocol
{
public
static
var
precisionType
:
Precision
{
return
.
Float32
}
public
static
func
initializeValue
()
->
Float
{
return
0.0
}
public
init
<
P
>
(
_
inP
:
P
)
where
P
:
PrecisionProtocol
{
if
P
.
bitSize
==
Float32
.
bitSize
{
self
=
inP
as!
Float32
}
else
if
P
.
bitSize
==
Float16
.
bitSize
{
...
...
@@ -116,80 +133,6 @@ struct DataLayout {
return
layoutWithDim
.
count
}
var
N
:
Int
?
{
get
{
for
layoutDim
in
layoutWithDim
{
if
layoutDim
.
0
==
.
N
{
return
layoutDim
.
1
}
}
return
nil
}
set
{
var
newN
=
(
Layout
.
N
,
newValue
)
if
let
index
=
layoutWithDim
.
index
(
where
:
{
(
layout
:
Layout
,
dim
:
Int
)
->
Bool
in
return
layout
==
.
N
})
{
fatalError
()
}
}
}
var
C
:
Int
?
{
get
{
for
layoutDim
in
layoutWithDim
{
if
layoutDim
.
0
==
.
C
{
return
layoutDim
.
1
}
}
return
nil
}
set
{
var
newN
=
(
Layout
.
C
,
newValue
)
if
let
index
=
layoutWithDim
.
index
(
where
:
{
(
layout
:
Layout
,
dim
:
Int
)
->
Bool
in
return
layout
==
.
N
})
{
fatalError
()
}
}
}
var
H
:
Int
?
{
get
{
for
layoutDim
in
layoutWithDim
{
if
layoutDim
.
0
==
.
H
{
return
layoutDim
.
1
}
}
return
nil
}
set
{
var
newN
=
(
Layout
.
H
,
newValue
)
if
let
index
=
layoutWithDim
.
index
(
where
:
{
(
layout
:
Layout
,
dim
:
Int
)
->
Bool
in
return
layout
==
.
H
})
{
fatalError
()
}
}
}
var
W
:
Int
?
{
get
{
for
layoutDim
in
layoutWithDim
{
if
layoutDim
.
0
==
.
W
{
return
layoutDim
.
1
}
}
return
nil
}
set
{
var
newN
=
(
Layout
.
W
,
newValue
)
if
let
index
=
layoutWithDim
.
index
(
where
:
{
(
layout
:
Layout
,
dim
:
Int
)
->
Bool
in
return
layout
==
.
W
})
{
fatalError
()
}
}
}
init
(
_
inLayout
:
[(
Layout
,
Int
)])
{
layoutWithDim
=
inLayout
}
...
...
metal/paddle-mobile/paddle-mobile/Src/Framework/Executor.swift
浏览文件 @
e2e2614d
...
...
@@ -41,7 +41,12 @@ var isTest = false
}
public
class
Executor
<
P
:
PrecisionType
>
{
protocol
Executorable
{
func
predict
(
input
:
MTLTexture
,
dim
:
Dim
,
completionHandle
:
@escaping
([
GPUResultHolder
])
->
Void
,
preProcessKernle
:
CusomKernel
?,
except
:
Int
)
throws
func
clear
()
}
public
class
Executor
<
P
:
PrecisionProtocol
>
:
Executorable
{
var
ops
:
[
Runable
&
InferShaperable
]
=
[]
var
preInputDim
:
Dim
=
Dim
.
init
(
inDim
:
[])
let
program
:
Program
...
...
metal/paddle-mobile/paddle-mobile/Src/Framework/Loader.swift
浏览文件 @
e2e2614d
...
...
@@ -15,7 +15,12 @@
import
Foundation
//import SwiftProtobuf
public
class
Loader
<
P
:
PrecisionType
>
{
protocol
Loaderable
{
func
load
(
device
:
MTLDevice
,
paramPointer
:
UnsafeMutableRawPointer
,
paramSize
:
Int
,
modePointer
:
UnsafeMutableRawPointer
,
modelSize
:
Int
)
throws
->
Program
func
load
(
device
:
MTLDevice
,
modelPath
:
String
,
paraPath
:
String
)
throws
->
Program
}
public
class
Loader
<
P
:
PrecisionProtocol
>
:
Loaderable
{
class
ParaLoader
{
let
file
:
UnsafeMutablePointer
<
FILE
>
let
fileSize
:
Int
...
...
@@ -143,7 +148,7 @@ public class Loader<P: PrecisionType> {
}
}
public
init
(){}
func
loadModelandParam
(
_
device
:
MTLDevice
,
_
modelData
:
Data
,
_
paraLoaderPointer
:
ParaLoaderWithPointer
?,
_
paraLoader
:
ParaLoader
?)
throws
->
Program
{
private
func
loadModelandParam
(
_
device
:
MTLDevice
,
_
modelData
:
Data
,
_
paraLoaderPointer
:
ParaLoaderWithPointer
?,
_
paraLoader
:
ParaLoader
?)
throws
->
Program
{
do
{
/// swift protobuf serialized Data to instance class
// let protoProgram = try PaddleMobile_Framework_Proto_ProgramDesc.init(
...
...
@@ -248,7 +253,7 @@ public class Loader<P: PrecisionType> {
}
}
public
func
load
(
device
:
MTLDevice
,
modelPath
:
String
,
paraPath
:
String
)
throws
->
Program
{
public
func
load
(
device
:
MTLDevice
,
modelPath
:
String
,
paraPath
:
String
)
throws
->
Program
{
guard
let
modelData
=
try
?
Data
.
init
(
contentsOf
:
URL
.
init
(
fileURLWithPath
:
modelPath
))
else
{
throw
PaddleMobileError
.
loaderError
(
message
:
"load "
+
modelPath
+
" failed !"
)
}
...
...
metal/paddle-mobile/paddle-mobile/Src/Framework/Tensor.swift
浏览文件 @
e2e2614d
...
...
@@ -28,7 +28,7 @@ extension Tensorial {
}
}
class
DataConverter
<
P
:
Precision
Type
>
{
class
DataConverter
<
P
:
Precision
Protocol
>
{
func
convert
(
from
:
UnsafeMutablePointer
<
P
>
,
to
:
UnsafeMutablePointer
<
P
>
,
fromDim
:
Dim
)
{
fatalError
(
" need imp"
)
}
...
...
@@ -40,7 +40,7 @@ class DataConverter<P: PrecisionType> {
/// [ outputChannels ][ inputChannels ][ kernelHeight ][ kernelWidth ] ->
/// [ outputChannels ][ kernelHeight ][ kernelWidth ][ inputChannels ]
class
MPSPointerConverter
<
P
:
Precision
Type
>
:
DataConverter
<
P
>
{
class
MPSPointerConverter
<
P
:
Precision
Protocol
>
:
DataConverter
<
P
>
{
/// [ outputChannels ][ inputChannels ][ kernelHeight ][ kernelWidth ] ->
/// [ outputChannels ][ kernelHeight ][ kernelWidth ][ inputChannels ]
...
...
@@ -81,7 +81,7 @@ class MPSPointerConverter<P: PrecisionType>: DataConverter<P>{
}
}
class
Tensor
<
P
:
Precision
Type
>
:
Tensorial
{
class
Tensor
<
P
:
Precision
Protocol
>
:
Tensorial
{
var
data
:
Data
var
dim
:
Dim
...
...
@@ -169,14 +169,15 @@ class Tensor<P: PrecisionType>: Tensorial {
layout
=
to
}
func
initBuffer
(
device
:
MTLDevice
,
precision
:
ComputePrecision
=
.
Float16
,
padWhenOneC
:
Bool
=
false
,
convertToNHWC
:
Bool
=
true
,
withTranspose
:
Bool
=
false
)
{
func
initBuffer
(
device
:
MTLDevice
,
precision
computePrecision
:
Precision
=
.
Float16
,
padWhenOneC
:
Bool
=
false
,
convertToNHWC
:
Bool
=
true
,
withTranspose
:
Bool
=
false
)
{
if
convertToNHWC
{
// print(layout)
convert
(
to
:
DataLayout
.
NHWC
())
}
if
P
.
precisionType
==
.
Float16
&&
computePrecision
==
.
Float32
{
fatalError
(
" 不支持: 16位模型不能按照 32 位进行运算"
)
}
if
withTranspose
{
let
transposePointer
=
UnsafeMutablePointer
<
P
>.
allocate
(
capacity
:
numel
())
let
n
=
dim
[
0
]
...
...
@@ -193,12 +194,8 @@ class Tensor<P: PrecisionType>: Tensorial {
data
=
Data
.
init
(
inCount
:
data
.
count
,
inPointer
:
transposePointer
)
}
guard
let
floatPointer
=
data
.
pointer
as?
UnsafeMutablePointer
<
Float32
>
else
{
fatalError
(
" not support yet "
)
}
let
precisionSize
:
Int
switch
p
recision
{
switch
computeP
recision
{
case
.
Float32
:
precisionSize
=
4
case
.
Float16
:
...
...
@@ -213,44 +210,58 @@ class Tensor<P: PrecisionType>: Tensorial {
let
count
=
paddedC
*
dim
[
0
]
*
dim
[
1
]
*
dim
[
2
]
if
C
==
paddedC
{
buffer
=
device
.
makeBuffer
(
length
:
count
*
precisionSize
)
switch
precision
{
case
.
Float32
:
buffer
?
.
contents
()
.
copyMemory
(
from
:
data
.
pointer
,
byteCount
:
count
*
MemoryLayout
<
P
>.
stride
)
switch
P
.
precisionType
{
case
.
Float16
:
float32ToFloat16
(
input
:
floatPointer
,
output
:
buffer
.
contents
(),
count
:
count
)
buffer
?
.
contents
()
.
copyMemory
(
from
:
data
.
pointer
,
byteCount
:
count
*
MemoryLayout
<
P
>.
stride
)
case
.
Float32
:
switch
computePrecision
{
case
.
Float32
:
buffer
?
.
contents
()
.
copyMemory
(
from
:
data
.
pointer
,
byteCount
:
count
*
MemoryLayout
<
P
>.
stride
)
case
.
Float16
:
float32ToFloat16
(
input
:
data
.
pointer
as!
UnsafeMutablePointer
<
Float32
>
,
output
:
buffer
.
contents
(),
count
:
count
)
}
}
}
else
if
C
==
1
&&
!
padWhenOneC
{
buffer
=
device
.
makeBuffer
(
length
:
numel
()
*
precisionSize
)
switch
precision
{
case
.
Float32
:
buffer
?
.
contents
()
.
copyMemory
(
from
:
data
.
pointer
,
byteCount
:
numel
()
*
MemoryLayout
<
P
>.
stride
)
switch
P
.
precisionType
{
case
.
Float16
:
float32ToFloat16
(
input
:
floatPointer
,
output
:
buffer
.
contents
(),
count
:
numel
())
buffer
?
.
contents
()
.
copyMemory
(
from
:
data
.
pointer
,
byteCount
:
numel
()
*
MemoryLayout
<
P
>.
stride
)
case
.
Float32
:
switch
computePrecision
{
case
.
Float32
:
buffer
?
.
contents
()
.
copyMemory
(
from
:
data
.
pointer
,
byteCount
:
numel
()
*
MemoryLayout
<
P
>.
stride
)
case
.
Float16
:
float32ToFloat16
(
input
:
data
.
pointer
as!
UnsafeMutablePointer
<
Float32
>
,
output
:
buffer
.
contents
(),
count
:
numel
())
}
}
}
else
{
buffer
=
device
.
makeBuffer
(
length
:
count
*
precisionSize
)
let
convertedPointer
=
UnsafeMutablePointer
<
Float32
>.
allocate
(
capacity
:
count
)
var
tmpPointer
=
floatP
ointer
let
convertedPointer
=
UnsafeMutablePointer
<
P
>.
allocate
(
capacity
:
count
)
var
tmpPointer
=
data
.
p
ointer
var
dstPtr
=
convertedPointer
for
_
in
0
..<
dim
[
0
]
*
dim
[
1
]
*
dim
[
2
]
{
for
j
in
0
..<
paddedC
{
if
j
<
C
{
dstPtr
[
j
]
=
tmpPointer
[
j
]
}
else
{
dstPtr
[
j
]
=
0
dstPtr
[
j
]
=
P
.
initializeValue
()
}
}
tmpPointer
+=
C
dstPtr
+=
paddedC
}
switch
precision
{
case
.
Float32
:
buffer
?
.
contents
()
.
copyMemory
(
from
:
convertedPointer
,
byteCount
:
count
*
MemoryLayout
<
P
>.
stride
)
switch
P
.
precisionType
{
case
.
Float16
:
float32ToFloat16
(
input
:
convertedPointer
,
output
:
buffer
.
contents
(),
count
:
count
)
buffer
?
.
contents
()
.
copyMemory
(
from
:
convertedPointer
,
byteCount
:
count
*
MemoryLayout
<
P
>.
stride
)
case
.
Float32
:
switch
computePrecision
{
case
.
Float32
:
buffer
?
.
contents
()
.
copyMemory
(
from
:
convertedPointer
,
byteCount
:
count
*
MemoryLayout
<
P
>.
stride
)
case
.
Float16
:
float32ToFloat16
(
input
:
convertedPointer
as!
UnsafeMutablePointer
<
Float32
>
,
output
:
buffer
.
contents
(),
count
:
count
)
}
}
convertedPointer
.
deinitialize
(
count
:
count
)
convertedPointer
.
deallocate
()
}
...
...
@@ -261,36 +272,46 @@ class Tensor<P: PrecisionType>: Tensorial {
let
count
=
paddedC
*
dim
[
0
]
*
dim
[
1
]
*
dim
[
2
]
if
C
==
paddedC
{
buffer
=
device
.
makeBuffer
(
length
:
count
*
precisionSize
)
switch
precision
{
case
.
Float32
:
buffer
?
.
contents
()
.
copyMemory
(
from
:
data
.
pointer
,
byteCount
:
count
*
MemoryLayout
<
P
>.
stride
)
switch
P
.
precisionType
{
case
.
Float16
:
float32ToFloat16
(
input
:
floatPointer
,
output
:
buffer
.
contents
(),
count
:
count
)
buffer
?
.
contents
()
.
copyMemory
(
from
:
data
.
pointer
,
byteCount
:
count
*
MemoryLayout
<
P
>.
stride
)
case
.
Float32
:
switch
computePrecision
{
case
.
Float32
:
buffer
?
.
contents
()
.
copyMemory
(
from
:
data
.
pointer
,
byteCount
:
count
*
MemoryLayout
<
P
>.
stride
)
case
.
Float16
:
float32ToFloat16
(
input
:
data
.
pointer
as!
UnsafeMutablePointer
<
Float32
>
,
output
:
buffer
.
contents
(),
count
:
count
)
}
}
}
else
if
C
==
1
{
fatalError
(
" not support "
)
}
else
{
buffer
=
device
.
makeBuffer
(
length
:
count
*
precisionSize
)
let
convertedPointer
=
UnsafeMutablePointer
<
Float32
>.
allocate
(
capacity
:
count
)
var
tmpPointer
=
floatP
ointer
let
convertedPointer
=
UnsafeMutablePointer
<
P
>.
allocate
(
capacity
:
count
)
var
tmpPointer
=
data
.
p
ointer
var
dstPtr
=
convertedPointer
for
_
in
0
..<
dim
[
0
]
*
dim
[
1
]
*
dim
[
2
]
{
for
j
in
0
..<
paddedC
{
if
j
<
C
{
dstPtr
[
j
]
=
tmpPointer
[
j
]
}
else
{
dstPtr
[
j
]
=
0
dstPtr
[
j
]
=
P
.
initializeValue
()
}
}
tmpPointer
+=
C
dstPtr
+=
paddedC
}
switch
precision
{
case
.
Float
32
:
switch
P
.
precisionType
{
case
.
Float
16
:
// 模型精度为 32 位
buffer
?
.
contents
()
.
copyMemory
(
from
:
convertedPointer
,
byteCount
:
count
*
MemoryLayout
<
P
>.
stride
)
case
.
Float16
:
float32ToFloat16
(
input
:
convertedPointer
,
output
:
buffer
.
contents
(),
count
:
count
)
case
.
Float32
:
// 模型精度为 16 位
switch
computePrecision
{
case
.
Float32
:
buffer
?
.
contents
()
.
copyMemory
(
from
:
convertedPointer
,
byteCount
:
count
*
MemoryLayout
<
P
>.
stride
)
case
.
Float16
:
float32ToFloat16
(
input
:
convertedPointer
as!
UnsafeMutablePointer
<
Float32
>
,
output
:
buffer
.
contents
(),
count
:
count
)
}
}
convertedPointer
.
deinitialize
(
count
:
count
)
convertedPointer
.
deallocate
()
...
...
@@ -299,11 +320,17 @@ class Tensor<P: PrecisionType>: Tensorial {
}
else
if
dim
.
cout
()
==
1
{
let
num
=
((
numel
()
+
3
)
/
4
)
*
4
buffer
=
device
.
makeBuffer
(
length
:
num
*
precisionSize
)
switch
precision
{
case
.
Float32
:
buffer
?
.
contents
()
.
copyMemory
(
from
:
data
.
pointer
,
byteCount
:
num
*
MemoryLayout
<
P
>.
stride
)
switch
P
.
precisionType
{
case
.
Float16
:
float32ToFloat16
(
input
:
floatPointer
,
output
:
buffer
.
contents
(),
count
:
num
)
buffer
?
.
contents
()
.
copyMemory
(
from
:
data
.
pointer
,
byteCount
:
num
*
MemoryLayout
<
P
>.
stride
)
case
.
Float32
:
switch
computePrecision
{
case
.
Float32
:
buffer
?
.
contents
()
.
copyMemory
(
from
:
data
.
pointer
,
byteCount
:
num
*
MemoryLayout
<
P
>.
stride
)
case
.
Float16
:
float32ToFloat16
(
input
:
data
.
pointer
as!
UnsafeMutablePointer
<
Float32
>
,
output
:
buffer
.
contents
(),
count
:
num
)
}
}
}
else
{
fatalError
(
" not support !"
)
...
...
@@ -404,7 +431,7 @@ extension Tensor {
var
debugDescription
:
String
{
var
str
=
"dim:
\(
dim
)
\n
"
str
+=
"MTLBuffer:
\(
self
.
buffer
)
\n
"
str
+=
"MTLBuffer:
\(
self
.
buffer
.
description
)
\n
"
for
i
in
0
..<
buffer
.
length
/
MemoryLayout
<
P
>.
size
{
str
+=
"
\(
buffer
.
contents
()
.
assumingMemoryBound
(
to
:
P
.
self
)[
i
]
)
"
}
...
...
metal/paddle-mobile/paddle-mobile/Src/Framework/Texture.swift
浏览文件 @
e2e2614d
...
...
@@ -96,7 +96,7 @@ public class Texture: Tensorial {
return
metalTexture
.
realNHWC
(
dim
:
(
n
:
padToFourDim
[
0
],
h
:
padToFourDim
[
1
],
w
:
padToFourDim
[
2
],
c
:
padToFourDim
[
3
]))
}
public
func
initTexture
(
device
:
MTLDevice
,
inTranspose
:
[
Int
]
=
[
0
,
1
,
2
,
3
],
computePrecision
:
Compute
Precision
=
.
Float16
)
{
public
func
initTexture
(
device
:
MTLDevice
,
inTranspose
:
[
Int
]
=
[
0
,
1
,
2
,
3
],
computePrecision
:
Precision
=
.
Float16
)
{
transpose
=
inTranspose
for
i
in
0
..<
(
4
-
tensorDim
.
cout
())
{
if
i
!=
inTranspose
[
i
]
{
...
...
@@ -196,7 +196,7 @@ extension Texture {
public
var
debugDescription
:
String
{
var
str
=
""
str
+=
"Dim:
\(
dim
)
\n
value:[ "
str
+=
"
\(
metalTexture
)
"
str
+=
"
\(
metalTexture
.
description
)
"
str
+=
" ]"
return
str
}
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Base/OpCreator.swift
浏览文件 @
e2e2614d
...
...
@@ -15,7 +15,7 @@
import
Foundation
fileprivate
var
singletons
:
[
String
:
Any
]
=
[:]
class
OpCreator
<
P
:
Precision
Type
>
{
class
OpCreator
<
P
:
Precision
Protocol
>
{
static
var
shared
:
OpCreator
<
P
>
{
let
key
=
String
(
describing
:
P
.
self
)
if
let
singleton
=
singletons
[
key
]
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Base/OpParam.swift
浏览文件 @
e2e2614d
...
...
@@ -26,7 +26,7 @@ protocol OpParam {
var
output
:
OutputType
{
get
set
}
func
outputDesc
()
->
String
//associatedtype ParamPrecisionType: Precision
Type
//associatedtype ParamPrecisionType: Precision
Protocol
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
static
func
getFirstTensor
<
VarType
:
Variant
>
(
key
:
String
,
map
:
[
String
:
[
String
]],
from
:
Scope
)
throws
->
VarType
static
func
inputX
<
VarType
:
Variant
>
(
inputs
:
[
String
:
[
String
]],
from
:
Scope
)
throws
->
VarType
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/BatchNormOp.swift
浏览文件 @
e2e2614d
...
...
@@ -15,7 +15,7 @@
import
Foundation
import
Metal
class
BatchNormParam
<
P
:
Precision
Type
>
:
OpParam
{
class
BatchNormParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -44,7 +44,7 @@ class BatchNormParam<P: PrecisionType>: OpParam {
let
momentum
:
Float
}
class
BatchNormOp
<
P
:
Precision
Type
>
:
Operator
<
BatchNormKernel
<
P
>
,
BatchNormParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
BatchNormOp
<
P
:
Precision
Protocol
>
:
Operator
<
BatchNormKernel
<
P
>
,
BatchNormParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
BatchNormOp
<
P
>
func
inferShape
()
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/BilinearInterpOp.swift
浏览文件 @
e2e2614d
...
...
@@ -15,7 +15,7 @@
import
Foundation
import
Metal
class
BilinearInterpParam
<
P
:
Precision
Type
>
:
OpParam
{
class
BilinearInterpParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -36,7 +36,7 @@ class BilinearInterpParam<P: PrecisionType>: OpParam {
let
out_w
:
Int
}
class
BilinearInterpOp
<
P
:
Precision
Type
>
:
Operator
<
BilinearInterpKernel
<
P
>
,
BilinearInterpParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
BilinearInterpOp
<
P
:
Precision
Protocol
>
:
Operator
<
BilinearInterpKernel
<
P
>
,
BilinearInterpParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
BilinearInterpOp
<
P
>
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/BoxcoderOp.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
BoxcoderParam
<
P
:
Precision
Type
>
:
OpParam
{
class
BoxcoderParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -45,7 +45,7 @@ class BoxcoderParam<P: PrecisionType>: OpParam {
let
boxNormalized
:
Bool
}
class
BoxcoderOp
<
P
:
Precision
Type
>
:
Operator
<
BoxcoderKernel
<
P
>
,
BoxcoderParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
BoxcoderOp
<
P
:
Precision
Protocol
>
:
Operator
<
BoxcoderKernel
<
P
>
,
BoxcoderParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
BoxcoderOp
<
P
>
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/ConcatOp.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
ConcatParam
<
P
:
Precision
Type
>
:
OpParam
{
class
ConcatParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -46,7 +46,7 @@ class ConcatParam<P: PrecisionType>: OpParam {
let
axis
:
Int
}
class
ConcatOp
<
P
:
Precision
Type
>
:
Operator
<
ConcatKernel
<
P
>
,
ConcatParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
ConcatOp
<
P
:
Precision
Protocol
>
:
Operator
<
ConcatKernel
<
P
>
,
ConcatParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
ConcatOp
<
P
>
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddAddPreluOp.swift
浏览文件 @
e2e2614d
...
...
@@ -15,7 +15,7 @@
import
Foundation
import
Metal
class
ConvAddAddPreluParam
<
P
:
Precision
Type
>
:
OpParam
{
class
ConvAddAddPreluParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -46,7 +46,7 @@ class ConvAddAddPreluParam<P: PrecisionType>: OpParam {
let
groups
:
Int
}
class
ConvAddAddPreluOp
<
P
:
Precision
Type
>
:
Operator
<
ConvAddAddPreluKernel
<
P
>
,
ConvAddAddPreluParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
,
Fusion
{
class
ConvAddAddPreluOp
<
P
:
Precision
Protocol
>
:
Operator
<
ConvAddAddPreluKernel
<
P
>
,
ConvAddAddPreluParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
,
Fusion
{
typealias
OpType
=
ConvAddAddPreluOp
<
P
>
static
func
fusionNode
()
->
Node
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddBatchNormReluOp.swift
浏览文件 @
e2e2614d
...
...
@@ -15,7 +15,7 @@
import
Foundation
class
ConvAddBatchNormReluParam
<
P
:
Precision
Type
>
:
OpParam
{
class
ConvAddBatchNormReluParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -59,7 +59,7 @@ class ConvAddBatchNormReluParam<P: PrecisionType>: OpParam {
let
groups
:
Int
}
class
ConvAddBatchNormReluOp
<
P
:
Precision
Type
>
:
Operator
<
ConvAddBatchNormReluKernel
<
P
>
,
ConvAddBatchNormReluParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
,
Fusion
{
class
ConvAddBatchNormReluOp
<
P
:
Precision
Protocol
>
:
Operator
<
ConvAddBatchNormReluKernel
<
P
>
,
ConvAddBatchNormReluParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
,
Fusion
{
typealias
OpType
=
ConvAddBatchNormReluOp
<
P
>
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddOp.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
ConvAddParam
<
P
:
Precision
Type
>
:
OpParam
{
class
ConvAddParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -43,7 +43,7 @@ class ConvAddParam<P: PrecisionType>: OpParam {
let
groups
:
Int
}
class
ConvAddOp
<
P
:
Precision
Type
>
:
Operator
<
ConvAddKernel
<
P
>
,
ConvAddParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
,
Fusion
{
class
ConvAddOp
<
P
:
Precision
Protocol
>
:
Operator
<
ConvAddKernel
<
P
>
,
ConvAddParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
,
Fusion
{
typealias
OpType
=
ConvAddOp
<
P
>
static
func
fusionNode
()
->
Node
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddPreluOp.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
ConvAddPreluParam
<
P
:
Precision
Type
>
:
OpParam
{
class
ConvAddPreluParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -45,7 +45,7 @@ class ConvAddPreluParam<P: PrecisionType>: OpParam {
let
groups
:
Int
}
class
ConvAddPreluOp
<
P
:
Precision
Type
>
:
Operator
<
ConvAddPreluKernel
<
P
>
,
ConvAddPreluParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
,
Fusion
{
class
ConvAddPreluOp
<
P
:
Precision
Protocol
>
:
Operator
<
ConvAddPreluKernel
<
P
>
,
ConvAddPreluParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
,
Fusion
{
typealias
OpType
=
ConvAddPreluOp
<
P
>
static
func
fusionNode
()
->
Node
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/ConvBNReluOp.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
ConvBNReluParam
<
P
:
Precision
Type
>
:
OpParam
{
class
ConvBNReluParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -53,7 +53,7 @@ class ConvBNReluParam<P: PrecisionType>: OpParam {
let
groups
:
Int
}
class
ConvBNReluOp
<
P
:
Precision
Type
>
:
Operator
<
ConvBNReluKernel
<
P
>
,
ConvBNReluParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
,
Fusion
{
class
ConvBNReluOp
<
P
:
Precision
Protocol
>
:
Operator
<
ConvBNReluKernel
<
P
>
,
ConvBNReluParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
,
Fusion
{
typealias
OpType
=
ConvBNReluOp
<
P
>
func
inputs
()
->
[
Variant
]
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/ConvOp.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
ConvParam
<
P
:
Precision
Type
>
:
OpParam
{
class
ConvParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -40,7 +40,7 @@ class ConvParam<P: PrecisionType>: OpParam {
let
groups
:
Int
}
class
ConvOp
<
P
:
Precision
Type
>
:
Operator
<
ConvKernel
<
P
>
,
ConvParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
ConvOp
<
P
:
Precision
Protocol
>
:
Operator
<
ConvKernel
<
P
>
,
ConvParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
ConvOp
<
P
>
func
inferShape
()
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/ConvTransposeOp.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
ConvTransposeParam
<
P
:
Precision
Type
>
:
ConvParam
<
P
>
{
class
ConvTransposeParam
<
P
:
Precision
Protocol
>
:
ConvParam
<
P
>
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -25,7 +25,7 @@ class ConvTransposeParam<P: PrecisionType>: ConvParam<P> {
}
}
class
ConvTransposeOp
<
P
:
Precision
Type
>
:
Operator
<
ConvTransposeKernel
<
P
>
,
ConvTransposeParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
ConvTransposeOp
<
P
:
Precision
Protocol
>
:
Operator
<
ConvTransposeKernel
<
P
>
,
ConvTransposeParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
ConvTransposeOp
<
P
>
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/DepthwiseConvOp.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
DepthConvOp
<
P
:
Precision
Type
>
:
Operator
<
ConvKernel
<
P
>
,
ConvParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
DepthConvOp
<
P
:
Precision
Protocol
>
:
Operator
<
ConvKernel
<
P
>
,
ConvParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
DepthConvOp
<
P
>
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/DwConvBNReluOp.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
DwConvBNReluOp
<
P
:
Precision
Type
>
:
Operator
<
ConvBNReluKernel
<
P
>
,
ConvBNReluParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
,
Fusion
{
class
DwConvBNReluOp
<
P
:
Precision
Protocol
>
:
Operator
<
ConvBNReluKernel
<
P
>
,
ConvBNReluParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
,
Fusion
{
typealias
OpType
=
ConvBNReluOp
<
P
>
func
inferShape
()
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/ElementwiseAddOp.swift
浏览文件 @
e2e2614d
...
...
@@ -15,7 +15,7 @@
import
Foundation
import
Metal
class
ElementwiseAddParam
<
P
:
Precision
Type
>
:
OpParam
{
class
ElementwiseAddParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -61,7 +61,7 @@ class ElementwiseAddParam<P: PrecisionType>: OpParam {
var
axis
:
Int
}
class
ElementwiseAddOp
<
P
:
Precision
Type
>
:
Operator
<
ElementwiseAddKernel
<
P
>
,
ElementwiseAddParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
ElementwiseAddOp
<
P
:
Precision
Protocol
>
:
Operator
<
ElementwiseAddKernel
<
P
>
,
ElementwiseAddParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
ElementwiseAddOp
<
P
>
func
inferShape
()
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/ElementwiseAddPreluOp.swift
浏览文件 @
e2e2614d
...
...
@@ -15,7 +15,7 @@
import
Foundation
import
Metal
class
ElementwiseAddPreluParam
<
P
:
Precision
Type
>
:
OpParam
{
class
ElementwiseAddPreluParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -65,7 +65,7 @@ class ElementwiseAddPreluParam<P: PrecisionType>: OpParam {
var
axis
:
Int
}
class
ElementwiseAddPreluOp
<
P
:
Precision
Type
>
:
Operator
<
ElementwiseAddPreluKernel
<
P
>
,
ElementwiseAddPreluParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
,
Fusion
{
class
ElementwiseAddPreluOp
<
P
:
Precision
Protocol
>
:
Operator
<
ElementwiseAddPreluKernel
<
P
>
,
ElementwiseAddPreluParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
,
Fusion
{
static
func
fusionNode
()
->
Node
{
let
beginNode
=
Node
.
init
(
inType
:
gElementwiseAddType
)
_
=
beginNode
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/FeedOp.swift
浏览文件 @
e2e2614d
...
...
@@ -16,7 +16,7 @@ import Foundation
import
MetalKit
import
CoreMedia
class
FeedParam
<
P
:
Precision
Type
>
:
OpParam
{
class
FeedParam
<
P
:
Precision
Protocol
>
:
OpParam
{
var
output
:
Texture
var
input
:
InputTexture
{
return
scope
.
input
()
as!
InputTexture
...
...
@@ -35,7 +35,7 @@ class FeedParam<P: PrecisionType>: OpParam{
//typealias ParamPrecisionType = P
}
class
FeedOp
<
P
:
Precision
Type
>
:
Operator
<
Texture2DTo2DArrayKernel
<
P
>
,
FeedParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
FeedOp
<
P
:
Precision
Protocol
>
:
Operator
<
Texture2DTo2DArrayKernel
<
P
>
,
FeedParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
FeedOp
<
P
>
func
inferShape
()
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/FetchOp.swift
浏览文件 @
e2e2614d
...
...
@@ -15,7 +15,7 @@
import
Foundation
import
Metal
class
FetchParam
<
P
:
Precision
Type
>
:
OpParam
{
class
FetchParam
<
P
:
Precision
Protocol
>
:
OpParam
{
var
output
:
FetchHolder
let
input
:
Texture
let
scope
:
Scope
...
...
@@ -33,7 +33,7 @@ class FetchParam<P: PrecisionType>: OpParam{
//typealias ParamPrecisionType = P
}
class
FetchOp
<
P
:
Precision
Type
>
:
Operator
<
FetchKernel
<
P
>
,
FetchParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
FetchOp
<
P
:
Precision
Protocol
>
:
Operator
<
FetchKernel
<
P
>
,
FetchParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
FetchOp
<
P
>
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/FlattenOp.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
FlattenParam
<
P
:
Precision
Type
>
:
OpParam
{
class
FlattenParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -31,7 +31,7 @@ class FlattenParam<P: PrecisionType>: OpParam {
}
class
FlattenOp
<
P
:
Precision
Type
>
:
Operator
<
FlattenKernel
<
P
>
,
FlattenParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
FlattenOp
<
P
:
Precision
Protocol
>
:
Operator
<
FlattenKernel
<
P
>
,
FlattenParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
FlattenOp
<
P
>
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/BatchNormKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
BatchNormKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
BatchNormKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
required
init
(
device
:
MTLDevice
,
param
:
BatchNormParam
<
P
>
,
initContext
:
InitContext
)
{
let
count
=
param
.
variance
.
dim
.
numel
()
let
varianceP
=
param
.
variance
.
data
.
pointer
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/BilinearInterpKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -19,7 +19,7 @@ struct BilinearInterpMetalParam {
var
ratio_w
:
Float32
}
class
BilinearInterpKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
BilinearInterpKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
func
compute
(
commandBuffer
:
MTLCommandBuffer
,
param
:
BilinearInterpParam
<
P
>
)
throws
{
guard
let
encoder
=
commandBuffer
.
makeComputeCommandEncoder
()
else
{
throw
PaddleMobileError
.
predictError
(
message
:
" encode is nil"
)
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/BoxcoderKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -17,7 +17,7 @@ import Foundation
struct
BoxcoderMetalParam
{
}
class
BoxcoderKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
BoxcoderKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
func
compute
(
commandBuffer
:
MTLCommandBuffer
,
param
:
BoxcoderParam
<
P
>
)
throws
{
guard
let
encoder
=
commandBuffer
.
makeComputeCommandEncoder
()
else
{
throw
PaddleMobileError
.
predictError
(
message
:
" encode is nil"
)
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConcatKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -31,7 +31,7 @@ struct ConcatMetalParam {
var
vdim
:
(
Int32
,
Int32
,
Int32
,
Int32
,
Int32
,
Int32
)
=
(
0
,
0
,
0
,
0
,
0
,
0
)
}
class
ConcatKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
ConcatKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
var
v
=
"normal"
var
pm
=
ConcatMetalParam
.
init
()
func
compute
(
commandBuffer
:
MTLCommandBuffer
,
param
:
ConcatParam
<
P
>
)
throws
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddAddPreluKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
ConvAddAddPreluKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
ConvAddAddPreluKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
var
metalParam
:
MetalConvParam
!
required
init
(
device
:
MTLDevice
,
param
:
ConvAddAddPreluParam
<
P
>
,
initContext
:
InitContext
)
{
param
.
output
.
initTexture
(
device
:
device
,
inTranspose
:
[
0
,
2
,
3
,
1
],
computePrecision
:
GlobalConfig
.
shared
.
computePrecision
)
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddBatchNormReluKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -36,7 +36,7 @@ struct ConvAddBatchNormReluTestParam: TestParam {
}
}
class
ConvAddBatchNormReluKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
,
Testable
{
class
ConvAddBatchNormReluKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
,
Testable
{
required
init
(
device
:
MTLDevice
,
testParam
:
ConvAddBatchNormReluTestParam
,
initContext
:
InitContext
)
{
if
testParam
.
filterSize
.
width
==
1
&&
testParam
.
filterSize
.
height
==
1
{
super
.
init
(
device
:
device
,
inFunctionName
:
"conv_add_batch_norm_relu_1x1"
,
initContext
:
initContext
)
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -27,7 +27,7 @@ func getUniqueKey() -> String {
return
UUID
.
init
()
.
uuidString
}
class
ConvAddKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
ConvAddKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
var
metalParam
:
MetalConvParam
!
let
identifyingKey
:
String
=
getUniqueKey
()
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddPreluKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
ConvAddPreluKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
ConvAddPreluKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
var
metalParam
:
MetalConvParam
!
required
init
(
device
:
MTLDevice
,
param
:
ConvAddPreluParam
<
P
>
,
initContext
:
InitContext
)
{
param
.
output
.
initTexture
(
device
:
device
,
inTranspose
:
[
0
,
2
,
3
,
1
],
computePrecision
:
GlobalConfig
.
shared
.
computePrecision
)
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvBNReluKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -37,7 +37,7 @@ struct ConvBNReluTestParam: TestParam {
}
}
class
ConvBNReluKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
,
Testable
{
class
ConvBNReluKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
,
Testable
{
required
init
(
device
:
MTLDevice
,
testParam
:
ConvBNReluTestParam
,
initContext
:
InitContext
)
{
if
testParam
.
filterSize
.
width
==
1
&&
testParam
.
filterSize
.
height
==
1
{
super
.
init
(
device
:
device
,
inFunctionName
:
"conv_batch_norm_relu_1x1"
,
initContext
:
initContext
)
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -24,10 +24,10 @@ public struct MetalConvParam {
let
dilationY
:
UInt16
}
class
ConvKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
ConvKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
var
metalParam
:
MetalConvParam
!
required
init
(
device
:
MTLDevice
,
param
:
ConvParam
<
P
>
,
initContext
:
InitContext
)
{
param
.
filter
.
initBuffer
(
device
:
device
,
precision
:
Compute
Precision
.
Float32
)
param
.
filter
.
initBuffer
(
device
:
device
,
precision
:
Precision
.
Float32
)
if
param
.
filter
.
width
==
1
&&
param
.
filter
.
height
==
1
{
super
.
init
(
device
:
device
,
inFunctionName
:
"conv_1x1"
,
initContext
:
initContext
)
}
else
if
param
.
filter
.
channel
==
1
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvTransposeKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -28,7 +28,7 @@ struct MetalConvTransposeParam {
let
dilationY
:
UInt16
;
}
class
ConvTransposeKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
ConvTransposeKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
var
metalParam
:
MetalConvTransposeParam
!
required
init
(
device
:
MTLDevice
,
param
:
ConvTransposeParam
<
P
>
,
initContext
:
InitContext
)
{
param
.
output
.
initTexture
(
device
:
device
,
inTranspose
:
param
.
input
.
transpose
,
computePrecision
:
GlobalConfig
.
shared
.
computePrecision
)
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ElementwiseAddKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -24,7 +24,7 @@ struct ElementwiseAddMetalParam {
var
ytrans
:
(
Int32
,
Int32
,
Int32
,
Int32
)
=
(
0
,
1
,
2
,
3
)
}
class
ElementwiseAddKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
ElementwiseAddKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
var
metalParam
:
ElementwiseAddMetalParam
required
init
(
device
:
MTLDevice
,
param
:
ElementwiseAddParam
<
P
>
,
initContext
:
InitContext
)
{
param
.
output
.
initTexture
(
device
:
device
,
inTranspose
:
param
.
inputX
.
transpose
,
computePrecision
:
GlobalConfig
.
shared
.
computePrecision
)
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ElementwiseAddPreluKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -15,7 +15,7 @@
import
Foundation
class
ElementwiseAddPreluKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
ElementwiseAddPreluKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
var
metalParam
:
ElementwiseAddMetalParam
required
init
(
device
:
MTLDevice
,
param
:
ElementwiseAddPreluParam
<
P
>
,
initContext
:
InitContext
)
{
param
.
output
.
initTexture
(
device
:
device
,
inTranspose
:
param
.
inputX
.
transpose
,
computePrecision
:
GlobalConfig
.
shared
.
computePrecision
)
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/FetchKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
FetchKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
FetchKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
required
init
(
device
:
MTLDevice
,
param
:
FetchParam
<
P
>
,
initContext
:
InitContext
)
{
param
.
output
.
initBuffer
(
device
:
device
)
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/FlattenKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -22,7 +22,7 @@ struct FlattenMetalParam {
}
class
FlattenKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
FlattenKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
var
metalParam
:
FlattenMetalParam
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/MulticlassNMSKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
MulticlassNMSKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
MulticlassNMSKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
let
pipline1
:
MTLComputePipelineState
required
init
(
device
:
MTLDevice
,
param
:
MulticlassNMSParam
<
P
>
,
initContext
:
InitContext
)
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/PoolKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -24,7 +24,7 @@ struct PoolMetalParam {
let
poolType
:
Int32
}
class
PoolKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
PoolKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
var
metalParam
:
PoolMetalParam
required
init
(
device
:
MTLDevice
,
param
:
PoolParam
<
P
>
,
initContext
:
InitContext
)
{
param
.
output
.
initTexture
(
device
:
device
,
inTranspose
:
param
.
input
.
transpose
,
computePrecision
:
GlobalConfig
.
shared
.
computePrecision
)
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/PreluKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
PreluKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
PreluKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
required
init
(
device
:
MTLDevice
,
param
:
PreluParam
<
P
>
,
initContext
:
InitContext
)
{
param
.
alpha
.
initBuffer
(
device
:
device
,
precision
:
GlobalConfig
.
shared
.
computePrecision
)
param
.
output
.
initTexture
(
device
:
device
,
inTranspose
:
param
.
input
.
transpose
,
computePrecision
:
GlobalConfig
.
shared
.
computePrecision
)
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/PriorBoxKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -29,7 +29,7 @@ struct PriorBoxMetalParam {
let
maxSizeSize
:
uint
}
class
PriorBoxKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
PriorBoxKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
var
metalParam
:
PriorBoxMetalParam
!
required
init
(
device
:
MTLDevice
,
param
:
PriorBoxParam
<
P
>
,
initContext
:
InitContext
)
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ReluKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
ReluKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
ReluKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
func
compute
(
commandBuffer
:
MTLCommandBuffer
,
param
:
ReluParam
<
P
>
)
throws
{
guard
let
encoder
=
commandBuffer
.
makeComputeCommandEncoder
()
else
{
throw
PaddleMobileError
.
predictError
(
message
:
" encode is nil"
)
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ReshapeKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -27,7 +27,7 @@ struct ReshapeTestParam: TestParam {
let
param
:
ReshapeMetalParam
}
class
ReshapeKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
ReshapeKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
var
metalParam
:
ReshapeMetalParam
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ResizeBilinearKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -19,7 +19,7 @@ struct ResizeBilinearMetalParam {
var
ratio_w
:
Float32
}
class
ResizeBilinearKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
ResizeBilinearKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
required
init
(
device
:
MTLDevice
,
param
:
ResizeBilinearParam
<
P
>
,
initContext
:
InitContext
)
{
param
.
output
.
initTexture
(
device
:
device
,
inTranspose
:
param
.
input
.
transpose
,
computePrecision
:
GlobalConfig
.
shared
.
computePrecision
)
if
GlobalConfig
.
shared
.
computePrecision
==
.
Float32
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ShapeKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -18,7 +18,7 @@ import Foundation
struct
ShapeMetalParam
{
}
class
ShapeKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
ShapeKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
func
compute
(
commandBuffer
:
MTLCommandBuffer
,
param
:
ShapeParam
<
P
>
)
throws
{
// print("shape compute")
// guard let encoder = commandBuffer.makeComputeCommandEncoder() else {
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/SoftmaxKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -19,7 +19,7 @@ struct SoftmaxMetalParam {
let
K
:
Int32
}
class
SoftmaxKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
SoftmaxKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
var
metalParam
:
SoftmaxMetalParam
required
init
(
device
:
MTLDevice
,
param
:
SoftmaxParam
<
P
>
,
initContext
:
InitContext
)
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/SplitKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -22,7 +22,7 @@ struct SplitMetalParam {
var
vdim
:
(
Int32
,
Int32
,
Int32
,
Int32
)
=
(
0
,
0
,
0
,
0
)
}
class
SplitKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
SplitKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
var
smp
:
SplitMetalParam
func
compute
(
commandBuffer
:
MTLCommandBuffer
,
param
:
SplitParam
<
P
>
)
throws
{
guard
let
encoder
=
commandBuffer
.
makeComputeCommandEncoder
()
else
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/Texture2DTo2DArrayKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -22,7 +22,7 @@ struct Texture2DTo2DArrayParam {
let
expectDim
:
Dim
}
class
Texture2DTo2DArrayKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
Texture2DTo2DArrayKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
func
compute
(
commandBuffer
:
MTLCommandBuffer
,
param
:
FeedParam
<
P
>
)
throws
{
guard
let
encoder
=
commandBuffer
.
makeComputeCommandEncoder
()
else
{
throw
PaddleMobileError
.
predictError
(
message
:
" encode is nil"
)
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/TransposeKernel.swift
浏览文件 @
e2e2614d
...
...
@@ -20,7 +20,7 @@ struct TransposeMetalParam {
var
axis
:
(
Int32
,
Int32
,
Int32
,
Int32
)
=
(
0
,
1
,
2
,
3
)
}
class
TransposeKernel
<
P
:
Precision
Type
>
:
Kernel
,
Computable
{
class
TransposeKernel
<
P
:
Precision
Protocol
>
:
Kernel
,
Computable
{
var
metalParam
:
TransposeMetalParam
=
TransposeMetalParam
.
init
()
required
init
(
device
:
MTLDevice
,
param
:
TransposeParam
<
P
>
,
initContext
:
InitContext
)
{
param
.
output
.
initTexture
(
device
:
device
,
computePrecision
:
GlobalConfig
.
shared
.
computePrecision
)
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/MulticlassNMSOp.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
MulticlassNMSParam
<
P
:
Precision
Type
>
:
OpParam
{
class
MulticlassNMSParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -36,7 +36,7 @@ class MulticlassNMSParam<P: PrecisionType>: OpParam {
var
output
:
Texture
}
class
MulticlassNMSOp
<
P
:
Precision
Type
>
:
Operator
<
MulticlassNMSKernel
<
P
>
,
MulticlassNMSParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
MulticlassNMSOp
<
P
:
Precision
Protocol
>
:
Operator
<
MulticlassNMSKernel
<
P
>
,
MulticlassNMSParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
func
inputVariant
()
->
[
String
:
[
MTLBuffer
]]
{
guard
let
scoreBuffer
=
para
.
middleOutput
.
resultBuffer
,
let
bboxBuffer
=
para
.
middleOutput
.
resultBuffer
else
{
...
...
@@ -48,8 +48,8 @@ class MulticlassNMSOp<P: PrecisionType>: Operator<MulticlassNMSKernel<P>, Multic
func
computeMiddleResult
(
device
:
MTLDevice
,
buffer
:
MTLCommandBuffer
)
{
do
{
try
kernel
.
compute
(
commandBuffer
:
buffer
,
param
:
para
)
}
catch
let
_
{
fatalError
()
}
catch
let
error
{
fatalError
(
"
\(
error
)
"
)
}
}
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/PoolOp.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
PoolParam
<
P
:
Precision
Type
>
:
OpParam
{
class
PoolParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -42,7 +42,7 @@ class PoolParam<P: PrecisionType>: OpParam {
var
globalPooling
:
Bool
}
class
PoolOp
<
P
:
Precision
Type
>
:
Operator
<
PoolKernel
<
P
>
,
PoolParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
PoolOp
<
P
:
Precision
Protocol
>
:
Operator
<
PoolKernel
<
P
>
,
PoolParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
PoolOp
<
P
>
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/PreluOp.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
PreluParam
<
P
:
Precision
Type
>
:
OpParam
{
class
PreluParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -32,7 +32,7 @@ class PreluParam<P: PrecisionType>: OpParam {
var
output
:
Texture
}
class
PreluOp
<
P
:
Precision
Type
>
:
Operator
<
PreluKernel
<
P
>
,
PreluParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
PreluOp
<
P
:
Precision
Protocol
>
:
Operator
<
PreluKernel
<
P
>
,
PreluParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
PreluOp
<
P
>
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/PriorBoxOp.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
PriorBoxParam
<
P
:
Precision
Type
>
:
OpParam
{
class
PriorBoxParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -59,7 +59,7 @@ class PriorBoxParam<P: PrecisionType>: OpParam {
let
outputVariances
:
Texture
}
class
PriorBoxOp
<
P
:
Precision
Type
>
:
Operator
<
PriorBoxKernel
<
P
>
,
PriorBoxParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
PriorBoxOp
<
P
:
Precision
Protocol
>
:
Operator
<
PriorBoxKernel
<
P
>
,
PriorBoxParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
PriorBoxOp
<
P
>
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/ReluOp.swift
浏览文件 @
e2e2614d
...
...
@@ -15,7 +15,7 @@
import
Foundation
class
ReluParam
<
P
:
Precision
Type
>
:
OpParam
{
class
ReluParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -29,7 +29,7 @@ class ReluParam<P: PrecisionType>: OpParam {
var
output
:
Texture
}
class
ReluOp
<
P
:
Precision
Type
>
:
Operator
<
ReluKernel
<
P
>
,
ReluParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
ReluOp
<
P
:
Precision
Protocol
>
:
Operator
<
ReluKernel
<
P
>
,
ReluParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
ReluOp
<
P
>
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/ReshapeOp.swift
浏览文件 @
e2e2614d
...
...
@@ -15,7 +15,7 @@
import
Foundation
import
Metal
class
ReshapeParam
<
P
:
Precision
Type
>
:
OpParam
{
class
ReshapeParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -53,7 +53,7 @@ class ReshapeParam<P: PrecisionType>: OpParam {
var
output
:
Texture
}
class
ReshapeOp
<
P
:
Precision
Type
>
:
Operator
<
ReshapeKernel
<
P
>
,
ReshapeParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
ReshapeOp
<
P
:
Precision
Protocol
>
:
Operator
<
ReshapeKernel
<
P
>
,
ReshapeParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
ReshapeOp
<
P
>
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/ResizeBilinearOp.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
ResizeBilinearParam
<
P
:
Precision
Type
>
:
OpParam
{
class
ResizeBilinearParam
<
P
:
Precision
Protocol
>
:
OpParam
{
typealias
ParamPrecisionType
=
P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -35,7 +35,7 @@ class ResizeBilinearParam<P: PrecisionType>: OpParam {
let
out_w
:
Int32
}
class
ResizeBilinearOp
<
P
:
Precision
Type
>
:
Operator
<
ResizeBilinearKernel
<
P
>
,
ResizeBilinearParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
ResizeBilinearOp
<
P
:
Precision
Protocol
>
:
Operator
<
ResizeBilinearKernel
<
P
>
,
ResizeBilinearParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
ResizeBilinearOp
<
P
>
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/ShapeOp.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
ShapeParam
<
P
:
Precision
Type
>
:
OpParam
{
class
ShapeParam
<
P
:
Precision
Protocol
>
:
OpParam
{
// typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -28,7 +28,7 @@ class ShapeParam<P: PrecisionType>: OpParam {
let
input
:
Texture
}
class
ShapeOp
<
P
:
Precision
Type
>
:
Operator
<
ShapeKernel
<
P
>
,
ShapeParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
ShapeOp
<
P
:
Precision
Protocol
>
:
Operator
<
ShapeKernel
<
P
>
,
ShapeParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
ShapeOp
<
P
>
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/SoftmaxOp.swift
浏览文件 @
e2e2614d
...
...
@@ -15,7 +15,7 @@
import
Foundation
import
Metal
class
SoftmaxParam
<
P
:
Precision
Type
>
:
OpParam
{
class
SoftmaxParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -36,7 +36,7 @@ class SoftmaxParam<P: PrecisionType>: OpParam {
var
output
:
Texture
}
class
SoftmaxOp
<
P
:
Precision
Type
>
:
Operator
<
SoftmaxKernel
<
P
>
,
SoftmaxParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
SoftmaxOp
<
P
:
Precision
Protocol
>
:
Operator
<
SoftmaxKernel
<
P
>
,
SoftmaxParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
SoftmaxOp
<
P
>
func
inferShape
()
{
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/SplitOp.swift
浏览文件 @
e2e2614d
...
...
@@ -14,7 +14,7 @@
import
Foundation
class
SplitParam
<
P
:
Precision
Type
>
:
OpParam
{
class
SplitParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -47,7 +47,7 @@ class SplitParam<P: PrecisionType>: OpParam {
var
sections
:
[
Int32
]
=
[]
}
class
SplitOp
<
P
:
Precision
Type
>
:
Operator
<
SplitKernel
<
P
>
,
SplitParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
SplitOp
<
P
:
Precision
Protocol
>
:
Operator
<
SplitKernel
<
P
>
,
SplitParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
SplitOp
<
P
>
...
...
metal/paddle-mobile/paddle-mobile/Src/Operators/TransposeOp.swift
浏览文件 @
e2e2614d
...
...
@@ -15,7 +15,7 @@
import
Foundation
import
Metal
class
TransposeParam
<
P
:
Precision
Type
>
:
OpParam
{
class
TransposeParam
<
P
:
Precision
Protocol
>
:
OpParam
{
//typealias ParamPrecisionType = P
required
init
(
opDesc
:
PMOpDesc
,
inScope
:
Scope
)
throws
{
do
{
...
...
@@ -31,7 +31,7 @@ class TransposeParam<P: PrecisionType>: OpParam {
let
axis
:
[
Int32
]
}
class
TransposeOp
<
P
:
Precision
Type
>
:
Operator
<
TransposeKernel
<
P
>
,
TransposeParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
class
TransposeOp
<
P
:
Precision
Protocol
>
:
Operator
<
TransposeKernel
<
P
>
,
TransposeParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
typealias
OpType
=
TransposeOp
<
P
>
...
...
metal/paddle-mobile/paddle-mobile/Src/Program/ProgramOptimize.swift
浏览文件 @
e2e2614d
...
...
@@ -181,7 +181,7 @@ extension Node: Equatable {
}
class
ProgramOptimize
<
P
:
Precision
Type
>
{
class
ProgramOptimize
<
P
:
Precision
Protocol
>
{
// register fusion
let
fusionOps
:
[
Fusion
.
Type
]
=
[
ConvAddBatchNormReluOp
<
P
>.
self
,
// ConvAddAddPreluOp<P>.self,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录