Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
73b55c61
提交
73b55c61
authored
10月 07, 2014
作者:
carriepl
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2114 from ballasn/Corr3DMM
Add 3d correlation based on blas matrix multiplication
上级
31a6c527
5f50150f
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
91 行增加
和
1 行删除
+91
-1
conv.txt
doc/library/tensor/nnet/conv.txt
+15
-0
blas.py
theano/sandbox/cuda/blas.py
+0
-0
corr3d_gemm.cu
theano/sandbox/cuda/corr3d_gemm.cu
+0
-0
corr_gemm.cu
theano/sandbox/cuda/corr_gemm.cu
+6
-0
opt.py
theano/sandbox/cuda/opt.py
+70
-1
test_gemmcorr3d.py
theano/sandbox/cuda/tests/test_gemmcorr3d.py
+0
-0
没有找到文件。
doc/library/tensor/nnet/conv.txt
浏览文件 @
73b55c61
...
...
@@ -123,6 +123,21 @@ TODO: Give examples on how to use these things! They are pretty complicated.
f = theano.function(..., mode=mode)
- :func:`GpuCorr3dMM <theano.sandbox.cuda.blas.GpuCorr3dMM>`
This is a GPU-only 3d correlation relying on a Toeplitz matrix
and gemm implementation (see :func:`GpuCorrMM <theano.sandbox.cuda.blas.GpuCorrMM>`)
It needs extra memory for the Toeplitz matrix, which is a 2D matrix of shape
``(no of channels * filter width * filter height * filter depth, output width * output height * output depth)``.
As it provides a gradient, you can use it as a replacement for nnet.conv3d.
Alternatively, you can use nnet.conv3d and allow Theano's graph optimizer
to replace it by the GEMM version by setting
``THEANO_FLAGS=optimizer_including=conv3d_gemm:convgrad3d_gemm:convtransp3d_gemm`` in your environment.
This is not enabled by default because it uses some extra memory, but the
overhead is small compared to conv3d_fft, there are no restrictions on
input or kernel shapes and strides are supported. If using it,
please see the warning about a bug in CUDA 5.0 to 6.0
in :func:`GpuCorrMM <theano.sandbox.cuda.blas.GpuCorrMM>`.
- :func:`conv3d2d <theano.tensor.nnet.conv3d2d.conv3d>`
Another conv3d implementation that uses the conv2d with data reshaping.
It is faster in some cases than conv3d, and work on the GPU.
...
...
theano/sandbox/cuda/blas.py
浏览文件 @
73b55c61
差异被折叠。
点击展开。
theano/sandbox/cuda/corr3d_gemm.cu
0 → 100644
浏览文件 @
73b55c61
差异被折叠。
点击展开。
theano/sandbox/cuda/co
nv
_gemm.cu
→
theano/sandbox/cuda/co
rr
_gemm.cu
浏览文件 @
73b55c61
...
...
@@ -294,6 +294,7 @@ CudaNdarray* corrMM(CudaNdarray *const bottom,
"This could be a known bug in CUDA, please see the "
"GpuCorrMM() documentation.\n",
cudaGetErrorString(err));
Py_DECREF(col);
return NULL;
}
// Second, gemm
...
...
@@ -311,6 +312,7 @@ CudaNdarray* corrMM(CudaNdarray *const bottom,
"This could be a known bug in CUDA, please see the "
"GpuCorrMM() documentation.\n",
cublasGetErrorString(status));
Py_DECREF(col);
return NULL;
}
}
...
...
@@ -359,6 +361,7 @@ CudaNdarray* corrMM(CudaNdarray *const bottom,
"This could be a known bug in CUDA, please see the "
"GpuCorrMM() documentation.\n",
cudaGetErrorString(err));
Py_DECREF(col);
return NULL;
}
// Second, gemm
...
...
@@ -379,6 +382,7 @@ CudaNdarray* corrMM(CudaNdarray *const bottom,
"This could be a known bug in CUDA, please see the "
"GpuCorrMM() documentation.\n",
cublasGetErrorString(status));
Py_DECREF(col);
return NULL;
}
}
...
...
@@ -429,6 +433,7 @@ CudaNdarray* corrMM(CudaNdarray *const bottom,
"This could be a known bug in CUDA, please see the "
"GpuCorrMM() documentation.\n",
cublasGetErrorString(status));
Py_DECREF(col);
return NULL;
}
// col2im back to the data
...
...
@@ -441,6 +446,7 @@ CudaNdarray* corrMM(CudaNdarray *const bottom,
"This could be a known bug in CUDA, please see the "
"GpuCorrMM() documentation.\n",
cudaGetErrorString(err));
Py_DECREF(col);
return NULL;
}
}
...
...
theano/sandbox/cuda/opt.py
浏览文件 @
73b55c61
...
...
@@ -26,7 +26,8 @@ from theano.sandbox.cuda.basic_ops import (
from
theano.sandbox.cuda.type
import
CudaNdarrayType
from
theano.sandbox.cuda.blas
import
(
gpu_dot22
,
gpu_dot22scalar
,
gpu_gemm_inplace
,
gpu_gemm_no_inplace
,
GpuConv
,
GpuCorrMM
,
GpuCorrMM_gradInputs
,
GpuCorrMM_gradWeights
)
GpuCorrMM
,
GpuCorrMM_gradInputs
,
GpuCorrMM_gradWeights
,
GpuCorr3dMM
,
GpuCorr3dMM_gradInputs
,
GpuCorr3dMM_gradWeights
)
from
theano.sandbox.cuda.blas
import
gpu_gemv_inplace
from
theano.sandbox.cuda.blas
import
gpu_gemv_no_inplace
from
theano.sandbox.cuda.blas
import
gpu_ger_inplace
...
...
@@ -1338,6 +1339,74 @@ def local_convtransp3d_fft(node):
gpu_optimizer
.
register
(
"convtransp3d_fft"
,
local_convtransp3d_fft
)
@local_optimizer
([
Conv3D
])
def
local_conv3d_gemm
(
node
):
if
not
isinstance
(
node
.
op
,
Conv3D
):
return
try
:
sx
=
tensor
.
get_scalar_constant_value
(
node
.
inputs
[
3
][
0
])
sy
=
tensor
.
get_scalar_constant_value
(
node
.
inputs
[
3
][
1
])
sz
=
tensor
.
get_scalar_constant_value
(
node
.
inputs
[
3
][
2
])
except
tensor
.
NotScalarConstantError
:
return
False
if
isinstance
(
node
.
op
,
Conv3D
):
# Shuffle inputs signal from (b, 0, 1, t, c) to (b, c, 0, 1, t)
x
=
node
.
inputs
[
0
]
x
=
x
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
)
# Shuffle filters from (oc, 0, 1, t, ic) to (oc, ic, 0, 1, t)
f
=
node
.
inputs
[
1
]
f
=
f
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
)
rval
=
GpuCorr3dMM
(
border_mode
=
'valid'
,
subsample
=
(
sx
,
sy
,
sz
))(
x
,
f
)
# Shuffle from (oc, c, 0, 1, t) to (oc, 0, 1, t, c)
return
[
rval
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)
+
node
.
inputs
[
2
]]
gpu_optimizer
.
register
(
"conv3d_gemm"
,
local_conv3d_gemm
)
@local_optimizer
([
ConvGrad3D
])
def
local_convgrad3d_gemm
(
node
):
try
:
sx
=
tensor
.
get_scalar_constant_value
(
node
.
inputs
[
1
][
0
])
sy
=
tensor
.
get_scalar_constant_value
(
node
.
inputs
[
1
][
1
])
sz
=
tensor
.
get_scalar_constant_value
(
node
.
inputs
[
1
][
2
])
except
tensor
.
NotScalarConstantError
:
return
False
if
isinstance
(
node
.
op
,
ConvGrad3D
):
# Shuffle inputs signal from (b, 0, 1, t, c) to (b, c, 0, 1, t)
x
=
node
.
inputs
[
0
]
x
=
gpu_contiguous
(
x
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
# Shuffle dCdH from (b, 0, 1, t, oc) to (oc, b, 0, 1, t)
f
=
node
.
inputs
[
3
]
f
=
gpu_contiguous
(
f
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
rval
=
GpuCorr3dMM_gradWeights
(
subsample
=
(
sx
,
sy
,
sz
))(
x
,
f
,
shape
=
node
.
inputs
[
2
][
1
:
4
])
# Shuffle from (ic, oc, 0, 1, t) to (oc, 0, 1, t, ic)
return
[
rval
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)]
gpu_optimizer
.
register
(
"convgrad3d_gemm"
,
local_convgrad3d_gemm
)
@local_optimizer
([
ConvTransp3D
])
def
local_convtransp3d_gemm
(
node
):
try
:
sx
=
tensor
.
get_scalar_constant_value
(
node
.
inputs
[
2
][
0
])
sy
=
tensor
.
get_scalar_constant_value
(
node
.
inputs
[
2
][
1
])
sz
=
tensor
.
get_scalar_constant_value
(
node
.
inputs
[
2
][
2
])
except
tensor
.
NotScalarConstantError
:
return
False
if
isinstance
(
node
.
op
,
ConvTransp3D
)
and
(
sx
,
sy
,
sz
)
==
(
1
,
1
,
1
):
# Shuffle filters from (oc, 0, 1, t, ic) to (ic, oc, 0, 1, t)
x
=
node
.
inputs
[
0
]
x
=
gpu_contiguous
(
x
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
# Shuffle dCdH from (b, 0, 1, t, oc) to (b, oc, 0, 1, t)
f
=
node
.
inputs
[
3
]
f
=
gpu_contiguous
(
f
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
rval
=
GpuCorr3dMM_gradInputs
(
subsample
=
(
sx
,
sy
,
sz
))(
kern
=
x
,
topgrad
=
f
)
# Shuffle from (ic, b, 0, 1, t) to (b, 0, 1, t, ic)
return
[
rval
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)
+
node
.
inputs
[
1
]]
gpu_optimizer
.
register
(
"convtransp3d_gemm"
,
local_convtransp3d_gemm
)
import
theano.tensor.signal.downsample
as
downsample
...
...
theano/sandbox/cuda/tests/test_gemmcorr3d.py
0 → 100644
浏览文件 @
73b55c61
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论