Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
bf9e145a
提交
bf9e145a
authored
9月 17, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
renamed mysum to myresult
上级
ac1555c0
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
41 行增加
和
41 行删除
+41
-41
basic_ops.py
theano/sandbox/cuda/basic_ops.py
+41
-41
没有找到文件。
theano/sandbox/cuda/basic_ops.py
浏览文件 @
bf9e145a
...
@@ -825,7 +825,7 @@ class GpuCAReduce(GpuOp):
...
@@ -825,7 +825,7 @@ class GpuCAReduce(GpuOp):
const int threadCount = blockDim.x * blockDim.y * blockDim.z;
const int threadCount = blockDim.x * blockDim.y * blockDim.z;
const int threadNum = threadIdx.z * blockDim.x * blockDim.y + threadIdx.y * blockDim.x + threadIdx.x;
const int threadNum = threadIdx.z * blockDim.x * blockDim.y + threadIdx.y * blockDim.x + threadIdx.x;
extern __shared__ float buf[];
extern __shared__ float buf[];
float my
sum
= 0.0f;
float my
result
= 0.0f;
if (warpSize != 32)
if (warpSize != 32)
{
{
...
@@ -842,7 +842,7 @@ class GpuCAReduce(GpuOp):
...
@@ -842,7 +842,7 @@ class GpuCAReduce(GpuOp):
# But only for power or multiple of 2!
# But only for power or multiple of 2!
new_version
=
"""
new_version
=
"""
__syncthreads(); // some kernel do multiple reduction.
__syncthreads(); // some kernel do multiple reduction.
buf[threadNum] = my
sum
;
buf[threadNum] = my
result
;
__syncthreads();
__syncthreads();
...
@@ -885,7 +885,7 @@ class GpuCAReduce(GpuOp):
...
@@ -885,7 +885,7 @@ class GpuCAReduce(GpuOp):
"""
%
locals
()
"""
%
locals
()
return
"""
return
"""
__syncthreads(); // some kernel do multiple reduction.
__syncthreads(); // some kernel do multiple reduction.
buf[threadNum] = my
sum
;
buf[threadNum] = my
result
;
__syncthreads();
__syncthreads();
// rest of function is handled by one warp
// rest of function is handled by one warp
...
@@ -894,9 +894,9 @@ class GpuCAReduce(GpuOp):
...
@@ -894,9 +894,9 @@ class GpuCAReduce(GpuOp):
//round up all the partial sums into the first `warpSize` elements
//round up all the partial sums into the first `warpSize` elements
for (int i = threadNum + warpSize; i < threadCount; i += warpSize)
for (int i = threadNum + warpSize; i < threadCount; i += warpSize)
{
{
my
sum
+= buf[i];
my
result
+= buf[i];
}
}
buf[threadNum] = my
sum
;
buf[threadNum] = my
result
;
/*Comment this optimization as it don't work on Fermi GPU.
/*Comment this optimization as it don't work on Fermi GPU.
TODO: find why it don't work or put the GPU compute capability into the version
TODO: find why it don't work or put the GPU compute capability into the version
// no sync because only one warp is running
// no sync because only one warp is running
...
@@ -936,7 +936,7 @@ class GpuCAReduce(GpuOp):
...
@@ -936,7 +936,7 @@ class GpuCAReduce(GpuOp):
self
.
_op_guard
()
self
.
_op_guard
()
return
"""
return
"""
__syncthreads(); // some kernel do multiple reduction.
__syncthreads(); // some kernel do multiple reduction.
buf[threadNum] = my
sum
;
buf[threadNum] = my
result
;
__syncthreads();
__syncthreads();
// rest of function is handled by one warp
// rest of function is handled by one warp
...
@@ -945,9 +945,9 @@ class GpuCAReduce(GpuOp):
...
@@ -945,9 +945,9 @@ class GpuCAReduce(GpuOp):
//round up all the partial sums into the first `nb_reduce` elements
//round up all the partial sums into the first `nb_reduce` elements
for (int i = threadNum +
%(nb_reduce)
s; i < threadCount; i +=
%(nb_reduce)
s)
for (int i = threadNum +
%(nb_reduce)
s; i < threadCount; i +=
%(nb_reduce)
s)
{
{
my
sum
+= buf[i];
my
result
+= buf[i];
}
}
%(z_pos)
s = my
sum
;
%(z_pos)
s = my
result
;
}
}
"""
%
locals
()
"""
%
locals
()
...
@@ -1502,7 +1502,7 @@ class GpuCAReduce(GpuOp):
...
@@ -1502,7 +1502,7 @@ class GpuCAReduce(GpuOp):
const int threadCount = blockDim.x;
const int threadCount = blockDim.x;
const int threadNum = threadIdx.x;
const int threadNum = threadIdx.x;
extern __shared__ float buf[];
extern __shared__ float buf[];
float my
sum
= 0.0f;
float my
result
= 0.0f;
if (warpSize != 32)
if (warpSize != 32)
{
{
...
@@ -1511,7 +1511,7 @@ class GpuCAReduce(GpuOp):
...
@@ -1511,7 +1511,7 @@ class GpuCAReduce(GpuOp):
for (int i0 = threadIdx.x; i0 < d0; i0 += blockDim.x)
for (int i0 = threadIdx.x; i0 < d0; i0 += blockDim.x)
{
{
my
sum
+= A[i0];
my
result
+= A[i0];
}
}
%(reducebuf)
s
%(reducebuf)
s
}
}
...
@@ -1530,7 +1530,7 @@ class GpuCAReduce(GpuOp):
...
@@ -1530,7 +1530,7 @@ class GpuCAReduce(GpuOp):
const int threadCount = blockDim.x;
const int threadCount = blockDim.x;
const int threadNum = threadIdx.x;
const int threadNum = threadIdx.x;
extern __shared__ float buf[];
extern __shared__ float buf[];
float my
sum
= 0.0f;
float my
result
= 0.0f;
if (warpSize != 32)
if (warpSize != 32)
{
{
...
@@ -1540,7 +1540,7 @@ class GpuCAReduce(GpuOp):
...
@@ -1540,7 +1540,7 @@ class GpuCAReduce(GpuOp):
for (int i0 = threadIdx.x; i0 < d0; i0 += blockDim.x)
for (int i0 = threadIdx.x; i0 < d0; i0 += blockDim.x)
{
{
float Ai = A[i0 * sA0];
float Ai = A[i0 * sA0];
my
sum
+= Ai;
my
result
+= Ai;
}
}
%(reducebuf)
s
%(reducebuf)
s
}
}
...
@@ -1560,7 +1560,7 @@ class GpuCAReduce(GpuOp):
...
@@ -1560,7 +1560,7 @@ class GpuCAReduce(GpuOp):
const int threadCount = blockDim.x * blockDim.y;
const int threadCount = blockDim.x * blockDim.y;
const int threadNum = threadIdx.y*blockDim.x + threadIdx.x;
const int threadNum = threadIdx.y*blockDim.x + threadIdx.x;
extern __shared__ float buf[];
extern __shared__ float buf[];
float my
sum
= 0.0f;
float my
result
= 0.0f;
if (warpSize != 32)
if (warpSize != 32)
{
{
...
@@ -1572,7 +1572,7 @@ class GpuCAReduce(GpuOp):
...
@@ -1572,7 +1572,7 @@ class GpuCAReduce(GpuOp):
for (int i1 = threadIdx.x; i1 < d1; i1 += blockDim.x)
for (int i1 = threadIdx.x; i1 < d1; i1 += blockDim.x)
{
{
float Ai = A[i0 * sA0 + i1 * sA1];
float Ai = A[i0 * sA0 + i1 * sA1];
my
sum
+= Ai;
my
result
+= Ai;
}
}
}
}
%(reducebuf)
s
%(reducebuf)
s
...
@@ -1619,12 +1619,12 @@ class GpuCAReduce(GpuOp):
...
@@ -1619,12 +1619,12 @@ class GpuCAReduce(GpuOp):
%(decl)
s{
%(decl)
s{
%(init)
s
%(init)
s
for (int i0 = blockIdx.x; i0 < d0; i0 += gridDim.x){
for (int i0 = blockIdx.x; i0 < d0; i0 += gridDim.x){
my
sum
= 0;
my
result
= 0;
%(for_i1)
s{
%(for_i1)
s{
%(for_i2)
s{
%(for_i2)
s{
%(for_i3)
s{
%(for_i3)
s{
float Ai = A[i3 * sA3 + i2 * sA2 + i1 * sA1 + i0 * sA0];
float Ai = A[i3 * sA3 + i2 * sA2 + i1 * sA1 + i0 * sA0];
my
sum
+= Ai;
my
result
+= Ai;
}
}
}
}
}
}
...
@@ -1638,12 +1638,12 @@ class GpuCAReduce(GpuOp):
...
@@ -1638,12 +1638,12 @@ class GpuCAReduce(GpuOp):
%(decl)
s{
%(decl)
s{
%(init)
s
%(init)
s
for (int i0 = blockIdx.x; i0 < d0; i0 += gridDim.x){
for (int i0 = blockIdx.x; i0 < d0; i0 += gridDim.x){
my
sum
= 0;
my
result
= 0;
%(for_i1)
s{
%(for_i1)
s{
%(for_i2)
s{
%(for_i2)
s{
%(for_i3)
s{
%(for_i3)
s{
float Ai = A[i3 * sA3 + i2 * sA2 + i1 * sA1 + i0 * sA0];
float Ai = A[i3 * sA3 + i2 * sA2 + i1 * sA1 + i0 * sA0];
my
sum
+= Ai;
my
result
+= Ai;
}
}
}
}
}
}
...
@@ -1685,10 +1685,10 @@ class GpuCAReduce(GpuOp):
...
@@ -1685,10 +1685,10 @@ class GpuCAReduce(GpuOp):
{
{
for (int i2 = blockIdx.y; i2 < d2; i2 += gridDim.y)
for (int i2 = blockIdx.y; i2 < d2; i2 += gridDim.y)
{
{
float my
sum
= 0.0f;
float my
result
= 0.0f;
for (int i1 = threadIdx.x; i1 < d1; i1 += blockDim.x)
for (int i1 = threadIdx.x; i1 < d1; i1 += blockDim.x)
{
{
my
sum
+= A[i0 * sA0 + i1 * sA1 + i2 * sA2];
my
result
+= A[i0 * sA0 + i1 * sA1 + i2 * sA2];
}
}
%(reducebuf)
s
%(reducebuf)
s
}
}
...
@@ -1711,7 +1711,7 @@ class GpuCAReduce(GpuOp):
...
@@ -1711,7 +1711,7 @@ class GpuCAReduce(GpuOp):
{
{
const int threadCount = blockDim.x;
const int threadCount = blockDim.x;
const int threadNum = threadIdx.x;
const int threadNum = threadIdx.x;
float my
sum
= 0.0f;
float my
result
= 0.0f;
if (warpSize != 32)
if (warpSize != 32)
{
{
...
@@ -1725,12 +1725,12 @@ class GpuCAReduce(GpuOp):
...
@@ -1725,12 +1725,12 @@ class GpuCAReduce(GpuOp):
int c = i2_D * 32 + threadIdx.x;
int c = i2_D * 32 + threadIdx.x;
if (c < C)
if (c < C)
{
{
my
sum
= 0;
my
result
= 0;
for (int b = 0; b < B; ++b)
for (int b = 0; b < B; ++b)
{
{
my
sum
+= X[a * sX0 + b * sX1 + c * sX2];
my
result
+= X[a * sX0 + b * sX1 + c * sX2];
}
}
Z[a * sZ0 + c * sZ1] = my
sum
;
Z[a * sZ0 + c * sZ1] = my
result
;
}
}
}
}
}
}
...
@@ -1772,7 +1772,7 @@ class GpuCAReduce(GpuOp):
...
@@ -1772,7 +1772,7 @@ class GpuCAReduce(GpuOp):
{
{
for (int i1 = threadIdx.y; i1 < d1; i1 += blockDim.y)
for (int i1 = threadIdx.y; i1 < d1; i1 += blockDim.y)
{
{
my
sum
+= A[i0 * sA0 + i1 * sA1 + i2 * sA2];
my
result
+= A[i0 * sA0 + i1 * sA1 + i2 * sA2];
}
}
%(reducebuf)
s
%(reducebuf)
s
}
}
...
@@ -1800,7 +1800,7 @@ class GpuCAReduce(GpuOp):
...
@@ -1800,7 +1800,7 @@ class GpuCAReduce(GpuOp):
const int threadCount = blockDim.x * blockDim.y;
const int threadCount = blockDim.x * blockDim.y;
const int threadNum = threadIdx.y * blockDim.x + threadIdx.x;
const int threadNum = threadIdx.y * blockDim.x + threadIdx.x;
extern __shared__ float buf[];
extern __shared__ float buf[];
float my
sum
= 0.0f;
float my
result
= 0.0f;
if (warpSize != 32)
if (warpSize != 32)
{
{
...
@@ -1814,7 +1814,7 @@ class GpuCAReduce(GpuOp):
...
@@ -1814,7 +1814,7 @@ class GpuCAReduce(GpuOp):
for (int i1 = threadIdx.x; i1 < d1; i1 += blockDim.x)
for (int i1 = threadIdx.x; i1 < d1; i1 += blockDim.x)
{
{
float Ai = A[i0 * sA0 + i1 * sA1 + blockIdx.x * sA2];
float Ai = A[i0 * sA0 + i1 * sA1 + blockIdx.x * sA2];
my
sum
+= Ai;
my
result
+= Ai;
}
}
}
}
...
@@ -1834,10 +1834,10 @@ class GpuCAReduce(GpuOp):
...
@@ -1834,10 +1834,10 @@ class GpuCAReduce(GpuOp):
{
{
for (int i1 = blockIdx.x; i1 < d1; i1 += gridDim.x)
for (int i1 = blockIdx.x; i1 < d1; i1 += gridDim.x)
{
{
my
sum
= 0;
my
result
= 0;
for (int i0 = threadIdx.x; i0 < d0; i0 += blockDim.x)
for (int i0 = threadIdx.x; i0 < d0; i0 += blockDim.x)
{
{
my
sum
+= A[i0 * sA0 + i1 * sA1 + i2 * sA2];
my
result
+= A[i0 * sA0 + i1 * sA1 + i2 * sA2];
}
}
%(reducebuf)
s
%(reducebuf)
s
}
}
...
@@ -1853,14 +1853,14 @@ class GpuCAReduce(GpuOp):
...
@@ -1853,14 +1853,14 @@ class GpuCAReduce(GpuOp):
%(decl)
s
%(decl)
s
{
{
%(init)
s
%(init)
s
my
sum
= 0;
my
result
= 0;
for (int i0 = threadIdx.z; i0 < d0; i0 += blockDim.z)
for (int i0 = threadIdx.z; i0 < d0; i0 += blockDim.z)
{
{
for (int i1 = threadIdx.y; i1 < d1; i1 += blockDim.y)
for (int i1 = threadIdx.y; i1 < d1; i1 += blockDim.y)
{
{
for (int i2 = threadIdx.x; i2 < d2; i2 += blockDim.x)
for (int i2 = threadIdx.x; i2 < d2; i2 += blockDim.x)
{
{
my
sum
+= A[i0 * sA0 + i1 * sA1 + i2 * sA2];
my
result
+= A[i0 * sA0 + i1 * sA1 + i2 * sA2];
}
}
}
}
}
}
...
@@ -1894,10 +1894,10 @@ class GpuCAReduce(GpuOp):
...
@@ -1894,10 +1894,10 @@ class GpuCAReduce(GpuOp):
{
{
for (int i1 = blockIdx.y; i1 < d1; i1 += gridDim.y)
for (int i1 = blockIdx.y; i1 < d1; i1 += gridDim.y)
{
{
float my
sum
= 0.0f;
float my
result
= 0.0f;
for (int i2 = threadIdx.x; i2 < d2; i2 += blockDim.x)
for (int i2 = threadIdx.x; i2 < d2; i2 += blockDim.x)
{
{
my
sum
+= A[i0 * sA0 + i1 * sA1 + i2 * sA2];
my
result
+= A[i0 * sA0 + i1 * sA1 + i2 * sA2];
}
}
%(reducebuf)
s
%(reducebuf)
s
}
}
...
@@ -1920,12 +1920,12 @@ class GpuCAReduce(GpuOp):
...
@@ -1920,12 +1920,12 @@ class GpuCAReduce(GpuOp):
{
{
for (int i1 = blockIdx.y; i1 < d1; i1 += gridDim.y)
for (int i1 = blockIdx.y; i1 < d1; i1 += gridDim.y)
{
{
float my
sum
= 0.0f;
float my
result
= 0.0f;
for (int i2 = threadIdx.y; i2 < d2; i2 += blockDim.y)
for (int i2 = threadIdx.y; i2 < d2; i2 += blockDim.y)
{
{
for (int i3 = threadIdx.x; i3 < d3; i3 += blockDim.x)
for (int i3 = threadIdx.x; i3 < d3; i3 += blockDim.x)
{
{
my
sum
+= A[i0 * sA0 + i1 * sA1 + i2 * sA2 + i3 * sA3];
my
result
+= A[i0 * sA0 + i1 * sA1 + i2 * sA2 + i3 * sA3];
}
}
}
}
%(reducebuf)
s
%(reducebuf)
s
...
@@ -1949,12 +1949,12 @@ class GpuCAReduce(GpuOp):
...
@@ -1949,12 +1949,12 @@ class GpuCAReduce(GpuOp):
{
{
for (int i2 = blockIdx.y; i2 < d2; i2 += gridDim.y)
for (int i2 = blockIdx.y; i2 < d2; i2 += gridDim.y)
{
{
float my
sum
= 0.0f;
float my
result
= 0.0f;
for (int i1 = threadIdx.y; i1 < d1; i1 += blockDim.y)
for (int i1 = threadIdx.y; i1 < d1; i1 += blockDim.y)
{
{
for (int i3 = threadIdx.x; i3 < d3; i3 += blockDim.x)
for (int i3 = threadIdx.x; i3 < d3; i3 += blockDim.x)
{
{
my
sum
+= A[i0 * sA0 + i1 * sA1 + i2 * sA2 + i3 * sA3];
my
result
+= A[i0 * sA0 + i1 * sA1 + i2 * sA2 + i3 * sA3];
}
}
}
}
%(reducebuf)
s
%(reducebuf)
s
...
@@ -1971,7 +1971,7 @@ class GpuCAReduce(GpuOp):
...
@@ -1971,7 +1971,7 @@ class GpuCAReduce(GpuOp):
%(decl)
s
%(decl)
s
{
{
%(init)
s
%(init)
s
my
sum
= 0;
my
result
= 0;
for (int i0 = 0; i0 < d0; i0++)
for (int i0 = 0; i0 < d0; i0++)
for (int i1 = threadIdx.z; i1 < d1; i1 += blockDim.z)
for (int i1 = threadIdx.z; i1 < d1; i1 += blockDim.z)
{
{
...
@@ -1979,7 +1979,7 @@ class GpuCAReduce(GpuOp):
...
@@ -1979,7 +1979,7 @@ class GpuCAReduce(GpuOp):
{
{
for (int i3 = threadIdx.x; i3 < d3; i3 += blockDim.x)
for (int i3 = threadIdx.x; i3 < d3; i3 += blockDim.x)
{
{
my
sum
+= A[i0 * sA0 + i1 * sA1 + i2 * sA2 + i3 * sA3];
my
result
+= A[i0 * sA0 + i1 * sA1 + i2 * sA2 + i3 * sA3];
}
}
}
}
}
}
...
@@ -2002,7 +2002,7 @@ class GpuCAReduce(GpuOp):
...
@@ -2002,7 +2002,7 @@ class GpuCAReduce(GpuOp):
const int threadCount = blockDim.x * blockDim.y * blockDim.z;
const int threadCount = blockDim.x * blockDim.y * blockDim.z;
const int threadNum = threadIdx.z * blockDim.x * blockDim.y + threadIdx.y * blockDim.x + threadIdx.x;
const int threadNum = threadIdx.z * blockDim.x * blockDim.y + threadIdx.y * blockDim.x + threadIdx.x;
extern __shared__ float buf[];
extern __shared__ float buf[];
float my
sum
= 0.0f;
float my
result
= 0.0f;
if (warpSize != 32)
if (warpSize != 32)
{
{
...
@@ -2016,7 +2016,7 @@ class GpuCAReduce(GpuOp):
...
@@ -2016,7 +2016,7 @@ class GpuCAReduce(GpuOp):
for (int i3 = threadIdx.x; i3 < d3; i3 += blockDim.x)
for (int i3 = threadIdx.x; i3 < d3; i3 += blockDim.x)
{
{
float Ai = A[i0 * sA0 + blockIdx.x * sA1 + i2 * sA2 + i3 * sA3];
float Ai = A[i0 * sA0 + blockIdx.x * sA1 + i2 * sA2 + i3 * sA3];
my
sum
+= Ai;
my
result
+= Ai;
}
}
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论