Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
be3cdaaf
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
332
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看板
提交
be3cdaaf
编写于
4月 30, 2019
作者:
N
NazgulLee
提交者:
GitHub
4月 30, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix semaphore crash (#1591)
上级
491737d0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
57 addition
and
25 deletion
+57
-25
metal/paddle-mobile-demo/paddle-mobile-demo/OCInterface/SuperResolutionNet.swift
...o/paddle-mobile-demo/OCInterface/SuperResolutionNet.swift
+15
-8
metal/paddle-mobile/paddle-mobile/API/Runner.swift
metal/paddle-mobile/paddle-mobile/API/Runner.swift
+9
-6
metal/paddle-mobile/paddle-mobile/Src/Framework/Executor.swift
.../paddle-mobile/paddle-mobile/Src/Framework/Executor.swift
+33
-11
未找到文件。
metal/paddle-mobile-demo/paddle-mobile-demo/OCInterface/SuperResolutionNet.swift
浏览文件 @
be3cdaaf
...
...
@@ -43,7 +43,7 @@ import paddle_mobile
metalLibPath
=
Bundle
.
main
.
path
(
forResource
:
"paddle-mobile-metallib"
,
ofType
:
"metallib"
)
}
override
public
func
updateProgram
(
program
:
Program
)
{
override
public
func
updateProgram
(
program
:
Program
)
throws
{
// n h w c
for
block
in
program
.
programDesc
.
blocks
{
for
varDesc
in
block
.
vars
{
...
...
@@ -54,14 +54,21 @@ import paddle_mobile
let
newDim
=
Dim
.
init
(
inDim
:
[
texture
.
dim
[
0
],
inputDim
[
1
],
inputDim
[
2
],
texture
.
tensorDim
[
1
]])
print
(
" var desc name "
+
varDesc
.
name
+
" new dim"
+
"
\(
newDim
)
"
)
texture
.
updateDims
(
inTensorDim
:
Dim
.
init
(
inDim
:
[
texture
.
tensorDim
[
0
],
texture
.
tensorDim
[
1
],
inputDim
[
1
],
inputDim
[
2
]]),
inDim
:
newDim
)
texture
.
initTexture
(
device
:
device
,
inTranspose
:
[
0
,
1
,
2
,
3
],
computePrecision
:
GlobalConfig
.
shared
.
computePrecision
)
do
{
try
texture
.
updateDims
(
inTensorDim
:
Dim
.
init
(
inDim
:
[
texture
.
tensorDim
[
0
],
texture
.
tensorDim
[
1
],
inputDim
[
1
],
inputDim
[
2
]]),
inDim
:
newDim
)
try
texture
.
initTexture
(
device
:
device
,
inTranspose
:
[
0
,
1
,
2
,
3
],
computePrecision
:
GlobalConfig
.
shared
.
computePrecision
)
}
catch
let
error
{
throw
error
}
let
output
:
FetchHolder
=
program
.
scope
.
output
()
as!
FetchHolder
output
.
dim
=
newDim
output
.
capacity
=
newDim
.
numel
()
output
.
paddedCapacity
=
newDim
.
numel
()
*
4
output
.
initBuffer
(
device
:
device
)
if
let
output
:
FetchHolder
=
program
.
scope
.
output
()
as?
FetchHolder
{
output
.
dim
=
newDim
output
.
capacity
=
newDim
.
numel
()
output
.
paddedCapacity
=
newDim
.
numel
()
*
4
output
.
initBuffer
(
device
:
device
)
}
else
{
throw
PaddleMobileError
.
loaderError
(
message
:
"scope output nil"
)
}
}
}
}
...
...
metal/paddle-mobile/paddle-mobile/API/Runner.swift
浏览文件 @
be3cdaaf
...
...
@@ -119,13 +119,16 @@ import Foundation
@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 "
)
try
self
.
executor
?
.
predict
(
input
:
texture
,
dim
:
self
.
net
.
inputDim
,
completionHandle
:
{
[
weak
self
]
(
success
,
res
)
in
if
success
,
let
SSelf
=
self
,
let
res
=
res
{
let
result
=
SSelf
.
net
.
fetchResult
(
paddleMobileRes
:
res
)
if
result
.
count
>
0
{
completion
(
true
,
result
)
return
}
}
let
result
=
SSelf
.
net
.
fetchResult
(
paddleMobileRes
:
res
)
completion
(
true
,
result
)
},
preProcessKernle
:
self
.
net
.
preprocessKernel
,
except
:
self
.
net
.
except
)
completion
(
false
,
nil
)
},
preProcessKernle
:
self
.
net
.
preprocessKernel
,
except
:
self
.
net
.
except
)
}
catch
let
error
{
print
(
error
)
completion
(
false
,
nil
)
...
...
metal/paddle-mobile/paddle-mobile/Src/Framework/Executor.swift
浏览文件 @
be3cdaaf
...
...
@@ -42,7 +42,7 @@ var isTest = false
}
protocol
Executorable
{
func
predict
(
input
:
MTLTexture
,
dim
:
Dim
,
completionHandle
:
@escaping
(
[
GPUResultHolder
]
)
->
Void
,
preProcessKernle
:
CusomKernel
?,
except
:
Int
)
throws
func
predict
(
input
:
MTLTexture
,
dim
:
Dim
,
completionHandle
:
@escaping
(
_
success
:
Bool
,
_
result
:
[
GPUResultHolder
]?
)
->
Void
,
preProcessKernle
:
CusomKernel
?,
except
:
Int
)
throws
func
clear
()
}
...
...
@@ -53,6 +53,8 @@ public class Executor<P: PrecisionProtocol>: Executorable{
let
device
:
MTLDevice
let
inflightSemaphore
:
DispatchSemaphore
let
queue
:
MTLCommandQueue
private
var
isValid
=
true
init
(
inDevice
:
MTLDevice
,
inQueue
:
MTLCommandQueue
,
inProgram
:
Program
,
initContext
:
InitContext
)
throws
{
self
.
inflightSemaphore
=
DispatchSemaphore
(
value
:
1
)
program
=
inProgram
...
...
@@ -73,9 +75,11 @@ public class Executor<P: PrecisionProtocol>: Executorable{
}
}
public
func
predict
(
input
:
MTLTexture
,
dim
:
Dim
,
completionHandle
:
@escaping
(
[
GPUResultHolder
]
)
->
Void
,
preProcessKernle
:
CusomKernel
?
=
nil
,
except
:
Int
=
0
)
throws
{
public
func
predict
(
input
:
MTLTexture
,
dim
:
Dim
,
completionHandle
:
@escaping
(
_
success
:
Bool
,
_
result
:
[
GPUResultHolder
]?
)
->
Void
,
preProcessKernle
:
CusomKernel
?
=
nil
,
except
:
Int
=
0
)
throws
{
inflightSemaphore
.
wait
()
guard
isValid
else
{
throw
PaddleMobileError
.
predictError
(
message
:
"Executor is cleared and invalid"
)
}
guard
let
buffer
=
queue
.
makeCommandBuffer
()
else
{
throw
PaddleMobileError
.
predictError
(
message
:
"CommandBuffer is nil"
)
}
...
...
@@ -110,9 +114,20 @@ public class Executor<P: PrecisionProtocol>: Executorable{
outputTextures
=
ops
[
ops
.
count
-
except
]
.
inputVariant
()
}
let
safeComplete
=
{
[
weak
self
]
(
success
:
Bool
,
result
:
[
GPUResultHolder
]?)
in
completionHandle
(
success
,
result
)
self
?
.
inflightSemaphore
.
signal
()
}
buffer
.
addCompletedHandler
{
[
weak
self
]
(
commandbuffer
)
in
guard
let
SSelf
=
self
else
{
fatalError
()
safeComplete
(
false
,
nil
)
return
}
guard
SSelf
.
isValid
else
{
safeComplete
(
false
,
nil
)
return
}
//将输入写进文件
...
...
@@ -133,24 +148,31 @@ public class Executor<P: PrecisionProtocol>: Executorable{
}
}
var
resultHolder
:
GPUResultHolder
var
resultHolder
:
GPUResultHolder
?
if
except
>
0
{
resultHolder
=
GPUResultHolder
.
init
(
inDim
:
[],
inPointer
:
nil
,
inCapacity
:
0
,
inIntermediateResults
:
outputTextures
)
}
else
{
let
outputVar
:
Variant
=
SSelf
.
program
.
scope
.
output
()
!
let
output
:
FetchHolder
=
outputVar
as!
FetchHolder
}
else
if
let
output
=
SSelf
.
program
.
scope
.
output
()
as?
FetchHolder
{
resultHolder
=
GPUResultHolder
.
init
(
inDim
:
output
.
dim
.
dims
,
inPointer
:
output
.
result
,
inCapacity
:
output
.
capacity
)
}
completionHandle
([
resultHolder
])
SSelf
.
inflightSemaphore
.
signal
()
if
let
resultHolder
=
resultHolder
{
safeComplete
(
true
,
[
resultHolder
])
}
else
{
safeComplete
(
false
,
nil
)
}
}
buffer
.
commit
()
}
public
func
clear
()
{
isValid
=
false
program
.
scope
.
clear
()
}
deinit
{
while
(
inflightSemaphore
.
signal
()
!=
0
)
{
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录