Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
cb9db5f5
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看板
提交
cb9db5f5
编写于
7月 20, 2018
作者:
R
Ruilong Liu
提交者:
GitHub
7月 20, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #613 from dolphin8/metal
add kernel (pool & reshape & softmax)
上级
e1692681
57cc72a9
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
70 addition
and
0 deletion
+70
-0
metal/paddle-mobile/paddle-mobile/Operators/Kernels/Kernels.metal
...ddle-mobile/paddle-mobile/Operators/Kernels/Kernels.metal
+70
-0
未找到文件。
metal/paddle-mobile/paddle-mobile/Operators/Kernels/Kernels.metal
浏览文件 @
cb9db5f5
...
@@ -95,3 +95,73 @@ kernel void texture2d_to_2d_array(texture2d<float, access::read> inTexture [[tex
...
@@ -95,3 +95,73 @@ kernel void texture2d_to_2d_array(texture2d<float, access::read> inTexture [[tex
outTexture.write(input, gid.xy, 0);
outTexture.write(input, gid.xy, 0);
}
}
kernel void pool(texture2d_array<half, access::read> inTexture [[texture(0)]],
texture2d_array<half, access::write> outTexture [[texture(1)]],
const device int * ksize [[buffer(0)]],
const device int * stride [[buffer(1)]],
const device int * padding [[buffer(2)]],
const device int * poolType [[buffer(3)]],
uint3 gid [[thread_position_in_grid]]) {
if (gid.x >= outTexture.get_width() ||
gid.y >= outTexture.get_height() ||
gid.z >= outTexture.get_array_size()) return;
int xmin = gid.x * stride[0] - padding[0];
int xmax = min(xmin + ksize[0], int(inTexture.get_width()));
xmin = max(xmin, 0);
int ymin = gid.y * stride[1] - padding[1];
int ymax = min(ymin + ksize[1], int(inTexture.get_width()));
ymin = max(ymin, 0);
half4 r = 0;
if (*poolType == 0) {
r = inTexture.read(uint2(xmin, ymin), gid.z);
for (int32_t x = xmin; x < xmax; x++) {
for (int y = ymin; y < ymax; y++) {
r = fmax(r, inTexture.read(uint2(x, y), gid.z));
}
}
} else if (*poolType == 1) {
for (int32_t x = xmin; x < xmax; x++) {
for (int y = ymin; y < ymax; y++) {
r += inTexture.read(uint2(x, y), gid.z);
}
}
r /= ksize[0] * ksize[1];
}
outTexture.write(r, gid.xy, gid.z);
}
kernel void reshape(texture2d_array<half, access::read> inTexture [[texture(0)]],
texture2d<half, access::write> outTexture [[texture(1)]],
uint3 gid [[thread_position_in_grid]]) {
if (gid.x >= outTexture.get_width() ||
gid.y >= outTexture.get_height()) return;
int zz = gid.y / 4;
int cc = gid.y % 4;
half4 r = inTexture.read(uint2(0, 0), zz);
r[0] = r[cc];
outTexture.write(r, gid.xy, gid.z);
}
kernel void softmax(texture2d<half, access::read> inTexture [[texture(1)]],
texture2d<half, access::write> outTexture [[texture(2)]],
uint3 gid [[thread_position_in_grid]]) {
if (gid.x >= outTexture.get_width() ||
gid.y >= outTexture.get_height()) return;
// int xsize = inTexture.get_width();
int ysize = inTexture.get_height();
half maxv = inTexture.read(uint2(0, 0), gid.z)[0];
for (int y = 0; y < ysize; y++) {
half r = inTexture.read(uint2(0, y), gid.z)[0];
maxv = max(maxv, r);
}
half sum = 0;
for (int y = 0; y < ysize; y++) {
half r = inTexture.read(uint2(0, y), gid.z)[0];
sum += exp(r - maxv);
}
half4 rr = inTexture.read(gid.xy, gid.z);
rr[0] = exp(rr[0] - maxv) / sum;
outTexture.write(rr, gid.xy, gid.z);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录