Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
58c804e4
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看板
未验证
提交
58c804e4
编写于
7月 19, 2018
作者:
D
dolphin8
提交者:
GitHub
7月 19, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #608 from dolphin8/metal
reshape & softmax
上级
b53529c1
f88a8e2f
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
65 addition
and
11 deletion
+65
-11
metal/paddle-mobile/paddle-mobile/Operators/Kernels/Kernels.metal
...ddle-mobile/paddle-mobile/Operators/Kernels/Kernels.metal
+1
-1
metal/paddle-mobile/paddle-mobile/Operators/Kernels/PoolKernel.swift
...e-mobile/paddle-mobile/Operators/Kernels/PoolKernel.swift
+21
-2
metal/paddle-mobile/paddle-mobile/Operators/Kernels/ReshapeKernel.swift
...obile/paddle-mobile/Operators/Kernels/ReshapeKernel.swift
+8
-3
metal/paddle-mobile/paddle-mobile/Operators/Kernels/SoftmaxKernel.swift
...obile/paddle-mobile/Operators/Kernels/SoftmaxKernel.swift
+8
-1
metal/paddle-mobile/paddle-mobile/Operators/PoolOp.swift
metal/paddle-mobile/paddle-mobile/Operators/PoolOp.swift
+24
-1
metal/paddle-mobile/paddle-mobile/Operators/ReshapeOp.swift
metal/paddle-mobile/paddle-mobile/Operators/ReshapeOp.swift
+1
-1
test/net/test_mobilenet.cpp
test/net/test_mobilenet.cpp
+2
-2
未找到文件。
metal/paddle-mobile/paddle-mobile/Operators/Kernels/Kernels.metal
浏览文件 @
58c804e4
...
...
@@ -70,7 +70,7 @@ kernel void batchnorm(texture2d_array<half, access::read> inTexture [[texture(0)
gid.z >= outTexture.get_array_size()) return;
const half4 input = inTexture.read(gid.xy, gid.z);
half4 output = input * newScale[gid.z] + newBias[gid.z];
outTexture.write(
in
put, gid.xy, gid.z);
outTexture.write(
out
put, gid.xy, gid.z);
}
//kernel void texture2d_to_2d_array(texture2d<half, access::read> inTexture [[texture(0)]],
...
...
metal/paddle-mobile/paddle-mobile/Operators/Kernels/PoolKernel.swift
浏览文件 @
58c804e4
...
...
@@ -15,11 +15,30 @@
import
Foundation
class
PoolKernel
<
P
:
PrecisionType
>
:
Kernel
,
Computable
{
func
compute
(
commandBuffer
:
MTLCommandBuffer
,
param
:
PoolParam
<
P
>
)
throws
{
guard
let
encoder
=
commandBuffer
.
makeComputeCommandEncoder
()
else
{
throw
PaddleMobileError
.
predictError
(
message
:
" encoder is nil"
)
}
print
(
"Pool compute"
)
encoder
.
setTexture
(
param
.
input
.
metalTexture
,
index
:
0
)
encoder
.
setTexture
(
param
.
output
.
metalTexture
,
index
:
1
)
encoder
.
setBytes
(
UnsafeRawPointer
(
param
.
ksize
),
length
:
param
.
ksize
.
count
*
4
,
index
:
0
)
encoder
.
setBytes
(
UnsafeRawPointer
(
param
.
stride
),
length
:
param
.
stride
.
count
*
4
,
index
:
1
)
encoder
.
setBytes
(
UnsafeRawPointer
(
param
.
padding
),
length
:
param
.
padding
.
count
*
4
,
index
:
2
)
var
poolType
:
Int32
switch
param
.
poolType
{
case
"max"
:
poolType
=
0
case
"avg"
:
poolType
=
1
default
:
throw
PaddleMobileError
.
predictError
(
message
:
" unknown pooltype "
+
param
.
poolType
)
}
encoder
.
setBytes
(
&
poolType
,
length
:
4
,
index
:
3
)
encoder
.
endEncoding
()
}
required
init
(
device
:
MTLDevice
,
param
:
PoolParam
<
P
>
)
{
super
.
init
(
device
:
device
,
inFunctionName
:
"
relu
"
)
super
.
init
(
device
:
device
,
inFunctionName
:
"
pool
"
)
}
}
metal/paddle-mobile/paddle-mobile/Operators/Kernels/ReshapeKernel.swift
浏览文件 @
58c804e4
...
...
@@ -16,11 +16,16 @@ import Foundation
class
ReshapeKernel
<
P
:
PrecisionType
>
:
Kernel
,
Computable
{
required
init
(
device
:
MTLDevice
,
param
:
ReshapeParam
<
P
>
)
{
super
.
init
(
device
:
device
,
inFunctionName
:
"re
lu
"
)
super
.
init
(
device
:
device
,
inFunctionName
:
"re
shape
"
)
}
func
compute
(
commandBuffer
:
MTLCommandBuffer
,
param
:
ReshapeParam
<
P
>
)
throws
{
guard
let
encoder
=
commandBuffer
.
makeComputeCommandEncoder
()
else
{
throw
PaddleMobileError
.
predictError
(
message
:
" encoder is nil"
)
}
print
(
"Reshape compute"
)
encoder
.
setTexture
(
param
.
input
.
metalTexture
,
index
:
0
)
encoder
.
setTexture
(
param
.
output
.
metalTexture
,
index
:
1
)
encoder
.
endEncoding
()
}
}
metal/paddle-mobile/paddle-mobile/Operators/Kernels/SoftmaxKernel.swift
浏览文件 @
58c804e4
...
...
@@ -17,9 +17,16 @@ import Foundation
class
SoftmaxKernel
<
P
:
PrecisionType
>
:
Kernel
,
Computable
{
func
compute
(
commandBuffer
:
MTLCommandBuffer
,
param
:
SoftmaxParam
<
P
>
)
throws
{
guard
let
encoder
=
commandBuffer
.
makeComputeCommandEncoder
()
else
{
throw
PaddleMobileError
.
predictError
(
message
:
" encoder is nil"
)
}
print
(
"softmax compute"
)
encoder
.
setTexture
(
param
.
input
.
metalTexture
,
index
:
0
)
encoder
.
setTexture
(
param
.
output
.
metalTexture
,
index
:
1
)
encoder
.
endEncoding
()
}
required
init
(
device
:
MTLDevice
,
param
:
SoftmaxParam
<
P
>
)
{
super
.
init
(
device
:
device
,
inFunctionName
:
"
relu
"
)
super
.
init
(
device
:
device
,
inFunctionName
:
"
softmax
"
)
}
}
metal/paddle-mobile/paddle-mobile/Operators/PoolOp.swift
浏览文件 @
58c804e4
...
...
@@ -20,18 +20,31 @@ class PoolParam<P: PrecisionType>: OpParam {
do
{
input
=
try
PoolParam
.
inputX
(
inputs
:
opDesc
.
inputs
,
from
:
inScope
)
output
=
try
PoolParam
.
outputOut
(
outputs
:
opDesc
.
outputs
,
from
:
inScope
)
poolType
=
try
PoolParam
.
getAttr
(
key
:
"pooling_type"
,
attrs
:
opDesc
.
attrs
)
ksize
=
try
PoolParam
.
getAttr
(
key
:
"ksize"
,
attrs
:
opDesc
.
attrs
)
stride
=
try
PoolParam
.
getAttr
(
key
:
"strides"
,
attrs
:
opDesc
.
attrs
)
padding
=
try
PoolParam
.
getAttr
(
key
:
"paddings"
,
attrs
:
opDesc
.
attrs
)
ceilMode
=
try
PoolParam
.
getAttr
(
key
:
"ceil_mode"
,
attrs
:
opDesc
.
attrs
)
globalPooling
=
try
PoolParam
.
getAttr
(
key
:
"global_pooling"
,
attrs
:
opDesc
.
attrs
)
}
catch
let
error
{
throw
error
}
// let buffer = input.metalTexture.buffer.contents().assumingMemoryBound(to: P.self)
}
let
input
:
Texture
<
P
>
var
output
:
Texture
<
P
>
var
ksize
:
[
Int32
]
var
stride
:
[
Int32
]
var
padding
:
[
Int32
]
var
poolType
:
String
var
ceilMode
:
Bool
var
globalPooling
:
Bool
}
class
PoolOp
<
P
:
PrecisionType
>
:
Operator
<
PoolKernel
<
P
>
,
PoolParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
func
inferShape
()
{
para
.
output
.
dim
=
para
.
input
.
dim
//
para.output.dim = para.input.dim
}
typealias
OpType
=
PoolOp
<
P
>
...
...
@@ -42,4 +55,14 @@ class PoolOp<P: PrecisionType>: Operator<PoolKernel<P>, PoolParam<P>>, Runable,
throw
error
}
}
func
delogOutput
()
{
print
(
"pool2d delog"
)
let
_
:
P
?
=
para
.
input
.
metalTexture
.
logDesc
(
header
:
"pool2d input: "
,
stridable
:
false
)
print
(
para
.
ksize
)
print
(
para
.
stride
)
print
(
para
.
padding
)
print
(
para
.
poolType
)
let
_
:
P
?
=
para
.
output
.
metalTexture
.
logDesc
(
header
:
"pool2d output: "
,
stridable
:
false
)
}
}
metal/paddle-mobile/paddle-mobile/Operators/ReshapeOp.swift
浏览文件 @
58c804e4
...
...
@@ -31,7 +31,7 @@ class ReshapeParam<P: PrecisionType>: OpParam {
class
ReshapeOp
<
P
:
PrecisionType
>
:
Operator
<
ReshapeKernel
<
P
>
,
ReshapeParam
<
P
>>
,
Runable
,
Creator
,
InferShaperable
{
func
inferShape
()
{
para
.
output
.
dim
=
para
.
input
.
dim
//
para.output.dim = para.input.dim
}
typealias
OpType
=
ReshapeOp
<
P
>
...
...
test/net/test_mobilenet.cpp
浏览文件 @
58c804e4
...
...
@@ -19,9 +19,9 @@ limitations under the License. */
int
main
()
{
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
auto
time1
=
time
();
// auto program = loader.Load(g_mobilenet_combine, true);
// auto program = loader.Load(g_mobilenet_combine, true);
auto
program
=
loader
.
Load
(
g_mobilenet_combine
+
"/model"
,
g_mobilenet_combine
+
"/params"
,
true
);
g_mobilenet_combine
+
"/params"
,
true
);
auto
time2
=
time
();
DLOG
<<
"load cost :"
<<
time_diff
(
time1
,
time1
)
<<
"ms"
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录