Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
270bcaca
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看板
未验证
提交
270bcaca
编写于
9月 12, 2018
作者:
R
Ruilong Liu
提交者:
GitHub
9月 12, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #953 from codeWorm2015/metal
update
上级
94fdc4ef
aef276e0
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
29 addition
and
19 deletion
+29
-19
metal/paddle-mobile-demo/paddle-mobile-demo/ViewController.swift
...addle-mobile-demo/paddle-mobile-demo/ViewController.swift
+3
-2
metal/paddle-mobile/paddle-mobile.xcodeproj/project.pbxproj
metal/paddle-mobile/paddle-mobile.xcodeproj/project.pbxproj
+4
-0
metal/paddle-mobile/paddle-mobile/MobileNet.swift
metal/paddle-mobile/paddle-mobile/MobileNet.swift
+8
-13
metal/paddle-mobile/paddle-mobile/PaddleMobile.swift
metal/paddle-mobile/paddle-mobile/PaddleMobile.swift
+1
-1
metal/paddle-mobile/paddle-mobile/framework/Executor.swift
metal/paddle-mobile/paddle-mobile/framework/Executor.swift
+13
-3
未找到文件。
metal/paddle-mobile-demo/paddle-mobile-demo/ViewController.swift
浏览文件 @
270bcaca
...
@@ -102,9 +102,10 @@ class ViewController: UIViewController {
...
@@ -102,9 +102,10 @@ class ViewController: UIViewController {
}
}
}
}
}
}
print
(
"sleep before "
)
usleep
(
33000
)
print
(
"sleep after "
)
}
}
case
.
CPU
:
case
.
CPU
:
guard
let
inInputPointer
=
inputPointer
else
{
guard
let
inInputPointer
=
inputPointer
else
{
fatalError
(
" need input pointer "
)
fatalError
(
" need input pointer "
)
...
...
metal/paddle-mobile/paddle-mobile.xcodeproj/project.pbxproj
浏览文件 @
270bcaca
...
@@ -57,6 +57,7 @@
...
@@ -57,6 +57,7 @@
FC292C82214255BD00CF622F
/* MobileNetSSD.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC292C7E214255BC00CF622F
/* MobileNetSSD.swift */
;
};
FC292C82214255BD00CF622F
/* MobileNetSSD.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC292C7E214255BC00CF622F
/* MobileNetSSD.swift */
;
};
FC292C85214257CB00CF622F
/* CPUCompute.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC292C7D214255BC00CF622F
/* CPUCompute.h */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
FC292C85214257CB00CF622F
/* CPUCompute.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC292C7D214255BC00CF622F
/* CPUCompute.h */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
FC292C872142624800CF622F
/* Genet.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC292C862142624800CF622F
/* Genet.swift */
;
};
FC292C872142624800CF622F
/* Genet.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC292C862142624800CF622F
/* Genet.swift */
;
};
FC33B0F02147659000714A93
/* MobileNet.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC33B0EF2147659000714A93
/* MobileNet.swift */
;
};
FC3602CC2108819F00FACB58
/* PaddleMobileUnitTest.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC3602CB2108819F00FACB58
/* PaddleMobileUnitTest.swift */
;
};
FC3602CC2108819F00FACB58
/* PaddleMobileUnitTest.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC3602CB2108819F00FACB58
/* PaddleMobileUnitTest.swift */
;
};
FC4CB74920F0B954007C0C6D
/* ConvKernel.metal in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC4CB74820F0B954007C0C6D
/* ConvKernel.metal */
;
};
FC4CB74920F0B954007C0C6D
/* ConvKernel.metal in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC4CB74820F0B954007C0C6D
/* ConvKernel.metal */
;
};
FC4CB74B20F12C30007C0C6D
/* ProgramOptimize.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC4CB74A20F12C30007C0C6D
/* ProgramOptimize.swift */
;
};
FC4CB74B20F12C30007C0C6D
/* ProgramOptimize.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC4CB74A20F12C30007C0C6D
/* ProgramOptimize.swift */
;
};
...
@@ -169,6 +170,7 @@
...
@@ -169,6 +170,7 @@
FC292C7D214255BC00CF622F
/* CPUCompute.h */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
CPUCompute.h
;
sourceTree
=
"<group>"
;
};
FC292C7D214255BC00CF622F
/* CPUCompute.h */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
CPUCompute.h
;
sourceTree
=
"<group>"
;
};
FC292C7E214255BC00CF622F
/* MobileNetSSD.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MobileNetSSD.swift
;
sourceTree
=
"<group>"
;
};
FC292C7E214255BC00CF622F
/* MobileNetSSD.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MobileNetSSD.swift
;
sourceTree
=
"<group>"
;
};
FC292C862142624800CF622F
/* Genet.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Genet.swift
;
sourceTree
=
"<group>"
;
};
FC292C862142624800CF622F
/* Genet.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Genet.swift
;
sourceTree
=
"<group>"
;
};
FC33B0EF2147659000714A93
/* MobileNet.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MobileNet.swift
;
sourceTree
=
"<group>"
;
};
FC3602CB2108819F00FACB58
/* PaddleMobileUnitTest.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
PaddleMobileUnitTest.swift
;
sourceTree
=
"<group>"
;
};
FC3602CB2108819F00FACB58
/* PaddleMobileUnitTest.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
PaddleMobileUnitTest.swift
;
sourceTree
=
"<group>"
;
};
FC4CB74820F0B954007C0C6D
/* ConvKernel.metal */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.metal
;
path
=
ConvKernel.metal
;
sourceTree
=
"<group>"
;
};
FC4CB74820F0B954007C0C6D
/* ConvKernel.metal */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.metal
;
path
=
ConvKernel.metal
;
sourceTree
=
"<group>"
;
};
FC4CB74A20F12C30007C0C6D
/* ProgramOptimize.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ProgramOptimize.swift
;
sourceTree
=
"<group>"
;
};
FC4CB74A20F12C30007C0C6D
/* ProgramOptimize.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ProgramOptimize.swift
;
sourceTree
=
"<group>"
;
};
...
@@ -278,6 +280,7 @@
...
@@ -278,6 +280,7 @@
FC039B6C20E11C3C0081E9F8
/* paddle-mobile */
=
{
FC039B6C20E11C3C0081E9F8
/* paddle-mobile */
=
{
isa
=
PBXGroup
;
isa
=
PBXGroup
;
children
=
(
children
=
(
FC33B0EF2147659000714A93
/* MobileNet.swift */
,
FC292C862142624800CF622F
/* Genet.swift */
,
FC292C862142624800CF622F
/* Genet.swift */
,
FC292C7E214255BC00CF622F
/* MobileNetSSD.swift */
,
FC292C7E214255BC00CF622F
/* MobileNetSSD.swift */
,
FC292C7C214255BC00CF622F
/* CPUCompute.mm */
,
FC292C7C214255BC00CF622F
/* CPUCompute.mm */
,
...
@@ -589,6 +592,7 @@
...
@@ -589,6 +592,7 @@
FCEBC0F420F1FDD90099DBAF
/* ConvAddBatchNormReluOp.swift in Sources */
,
FCEBC0F420F1FDD90099DBAF
/* ConvAddBatchNormReluOp.swift in Sources */
,
FC0E2DC020EE461F009C1FAC
/* ElementwiseAddKernel.swift in Sources */
,
FC0E2DC020EE461F009C1FAC
/* ElementwiseAddKernel.swift in Sources */
,
4AF928772133F1DB005B6C3A
/* BoxCoder.metal in Sources */
,
4AF928772133F1DB005B6C3A
/* BoxCoder.metal in Sources */
,
FC33B0F02147659000714A93
/* MobileNet.swift in Sources */
,
FCEB684C212F093800D2448E
/* PreluOp.swift in Sources */
,
FCEB684C212F093800D2448E
/* PreluOp.swift in Sources */
,
FCA67CD92138287B00BD58AA
/* ConvBNReluKernel.metal in Sources */
,
FCA67CD92138287B00BD58AA
/* ConvBNReluKernel.metal in Sources */
,
FC60DB8920E9AAA500FF203F
/* MetalExtension.swift in Sources */
,
FC60DB8920E9AAA500FF203F
/* MetalExtension.swift in Sources */
,
...
...
metal/paddle-mobile/paddle-mobile/MobileNet.swift
浏览文件 @
270bcaca
...
@@ -17,12 +17,6 @@ import paddle_mobile
...
@@ -17,12 +17,6 @@ import paddle_mobile
class
MobileNet
:
Net
{
class
MobileNet
:
Net
{
var
means
:
[
Float
]
=
[
123.68
,
116.78
,
103.94
]
var
scale
:
Float
=
0.017
let
except
:
Int
=
0
class
MobilenetPreProccess
:
CusomKernel
{
class
MobilenetPreProccess
:
CusomKernel
{
init
(
device
:
MTLDevice
)
{
init
(
device
:
MTLDevice
)
{
let
s
=
CusomKernel
.
Shape
.
init
(
inWidth
:
224
,
inHeight
:
224
,
inChannel
:
3
)
let
s
=
CusomKernel
.
Shape
.
init
(
inWidth
:
224
,
inHeight
:
224
,
inChannel
:
3
)
...
@@ -49,7 +43,7 @@ class MobileNet: Net{
...
@@ -49,7 +43,7 @@ class MobileNet: Net{
let
labels
=
PreWords
.
init
(
fileName
:
"synset"
)
let
labels
=
PreWords
.
init
(
fileName
:
"synset"
)
func
resultStr
(
res
:
[
Float
])
->
String
{
override
public
func
resultStr
(
res
:
[
Float
])
->
String
{
var
s
:
[
String
]
=
[]
var
s
:
[
String
]
=
[]
res
.
top
(
r
:
5
)
.
enumerated
()
.
forEach
{
res
.
top
(
r
:
5
)
.
enumerated
()
.
forEach
{
s
.
append
(
String
(
format
:
"%d: %@ (%3.2f%%)"
,
$0
+
1
,
labels
[
$1
.
0
],
$1
.
1
*
100
))
s
.
append
(
String
(
format
:
"%d: %@ (%3.2f%%)"
,
$0
+
1
,
labels
[
$1
.
0
],
$1
.
1
*
100
))
...
@@ -57,17 +51,18 @@ class MobileNet: Net{
...
@@ -57,17 +51,18 @@ class MobileNet: Net{
return
s
.
joined
(
separator
:
"
\n
"
)
return
s
.
joined
(
separator
:
"
\n
"
)
}
}
var
preprocessKernel
:
CusomKernel
let
dim
=
(
n
:
1
,
h
:
224
,
w
:
224
,
c
:
3
)
let
modelPath
:
String
let
paramPath
:
String
let
modelDir
:
String
init
(
device
:
MTLDevice
)
{
override
init
(
device
:
MTLDevice
)
{
super
.
init
(
device
:
device
)
means
=
[
123.68
,
116.78
,
103.94
]
scale
=
0.017
except
=
0
modelPath
=
Bundle
.
main
.
path
(
forResource
:
"model"
,
ofType
:
nil
)
?
!
"model null"
modelPath
=
Bundle
.
main
.
path
(
forResource
:
"model"
,
ofType
:
nil
)
?
!
"model null"
paramPath
=
Bundle
.
main
.
path
(
forResource
:
"params"
,
ofType
:
nil
)
?
!
"para null"
paramPath
=
Bundle
.
main
.
path
(
forResource
:
"params"
,
ofType
:
nil
)
?
!
"para null"
modelDir
=
""
modelDir
=
""
preprocessKernel
=
MobilenetPreProccess
.
init
(
device
:
device
)
preprocessKernel
=
MobilenetPreProccess
.
init
(
device
:
device
)
dim
=
(
n
:
1
,
h
:
224
,
w
:
224
,
c
:
3
)
}
}
}
}
metal/paddle-mobile/paddle-mobile/PaddleMobile.swift
浏览文件 @
270bcaca
...
@@ -37,7 +37,7 @@ public class Net: NSObject {
...
@@ -37,7 +37,7 @@ public class Net: NSObject {
fatalError
()
fatalError
()
}
}
func
fetchResult
(
paddleMobileRes
:
ResultHolder
)
->
[
Float32
]
{
func
fetchResult
(
paddleMobileRes
:
ResultHolder
)
->
[
Float32
]
{
fatalError
()
return
paddleMobileRes
.
resultArr
}
}
@objc
public
init
(
device
:
MTLDevice
)
{
@objc
public
init
(
device
:
MTLDevice
)
{
super
.
init
()
super
.
init
()
...
...
metal/paddle-mobile/paddle-mobile/framework/Executor.swift
浏览文件 @
270bcaca
...
@@ -59,8 +59,10 @@ public class Executor<P: PrecisionType> {
...
@@ -59,8 +59,10 @@ public class Executor<P: PrecisionType> {
var
ops
:
[
Runable
&
InferShaperable
]
=
[]
var
ops
:
[
Runable
&
InferShaperable
]
=
[]
let
program
:
Program
let
program
:
Program
let
device
:
MTLDevice
let
device
:
MTLDevice
let
inflightSemaphore
:
DispatchSemaphore
let
queue
:
MTLCommandQueue
let
queue
:
MTLCommandQueue
public
init
(
inDevice
:
MTLDevice
,
inQueue
:
MTLCommandQueue
,
inProgram
:
Program
)
throws
{
public
init
(
inDevice
:
MTLDevice
,
inQueue
:
MTLCommandQueue
,
inProgram
:
Program
)
throws
{
self
.
inflightSemaphore
=
DispatchSemaphore
(
value
:
3
)
program
=
inProgram
program
=
inProgram
device
=
inDevice
device
=
inDevice
queue
=
inQueue
queue
=
inQueue
...
@@ -82,6 +84,9 @@ public class Executor<P: PrecisionType> {
...
@@ -82,6 +84,9 @@ public class Executor<P: PrecisionType> {
guard
let
buffer
=
queue
.
makeCommandBuffer
()
else
{
guard
let
buffer
=
queue
.
makeCommandBuffer
()
else
{
throw
PaddleMobileError
.
predictError
(
message
:
"CommandBuffer is nil"
)
throw
PaddleMobileError
.
predictError
(
message
:
"CommandBuffer is nil"
)
}
}
inflightSemaphore
.
wait
()
let
resInput
:
MTLTexture
let
resInput
:
MTLTexture
if
let
inPre
=
preProcessKernle
{
if
let
inPre
=
preProcessKernle
{
do
{
do
{
...
@@ -112,8 +117,8 @@ public class Executor<P: PrecisionType> {
...
@@ -112,8 +117,8 @@ public class Executor<P: PrecisionType> {
outputTextures
=
ops
[
ops
.
count
-
except
]
.
inputVariant
()
outputTextures
=
ops
[
ops
.
count
-
except
]
.
inputVariant
()
}
}
buffer
.
addCompletedHandler
{
(
commandbuffer
)
in
buffer
.
addCompletedHandler
{
[
weak
self
]
(
commandbuffer
)
in
// return
// let inputArr = resInput.toTensor(dim: (n: dim[0], c: dim[3], h: dim[1], w: dim[2]))
// let inputArr = resInput.toTensor(dim: (n: dim[0], c: dim[3], h: dim[1], w: dim[2]))
//// print(inputArr.strideArray())
//// print(inputArr.strideArray())
//
//
...
@@ -139,18 +144,23 @@ public class Executor<P: PrecisionType> {
...
@@ -139,18 +144,23 @@ public class Executor<P: PrecisionType> {
// return
// return
guard
let
SSelf
=
self
else
{
fatalError
()
}
let
afterDate
=
Date
.
init
()
let
afterDate
=
Date
.
init
()
var
resultHolder
:
ResultHolder
var
resultHolder
:
ResultHolder
if
except
>
0
{
if
except
>
0
{
resultHolder
=
ResultHolder
.
init
(
inDim
:
[],
inResult
:
[],
inElapsedTime
:
afterDate
.
timeIntervalSince
(
beforeDate
),
inIntermediateResults
:
outputTextures
)
resultHolder
=
ResultHolder
.
init
(
inDim
:
[],
inResult
:
[],
inElapsedTime
:
afterDate
.
timeIntervalSince
(
beforeDate
),
inIntermediateResults
:
outputTextures
)
}
else
{
}
else
{
let
outputVar
:
Variant
=
s
elf
.
program
.
scope
.
output
()
!
let
outputVar
:
Variant
=
SS
elf
.
program
.
scope
.
output
()
!
let
output
:
Texture
<
P
>
=
outputVar
as!
Texture
<
P
>
let
output
:
Texture
<
P
>
=
outputVar
as!
Texture
<
P
>
resultHolder
=
ResultHolder
.
init
(
inDim
:
output
.
dim
.
dims
,
inResult
:
output
.
toTensor
(),
inElapsedTime
:
afterDate
.
timeIntervalSince
(
beforeDate
))
resultHolder
=
ResultHolder
.
init
(
inDim
:
output
.
dim
.
dims
,
inResult
:
output
.
toTensor
(),
inElapsedTime
:
afterDate
.
timeIntervalSince
(
beforeDate
))
}
}
completionHandle
(
resultHolder
)
completionHandle
(
resultHolder
)
SSelf
.
inflightSemaphore
.
signal
()
}
}
buffer
.
commit
()
buffer
.
commit
()
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录