Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c5f98527
提交
c5f98527
authored
6月 04, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implemented GpuGemm not inplace version
上级
6658cf32
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
76 行增加
和
9 行删除
+76
-9
blas.py
theano/sandbox/cuda/blas.py
+60
-5
opt.py
theano/sandbox/cuda/opt.py
+16
-4
没有找到文件。
theano/sandbox/cuda/blas.py
浏览文件 @
c5f98527
...
@@ -153,14 +153,29 @@ class GpuGemm(Op):
...
@@ -153,14 +153,29 @@ class GpuGemm(Op):
Need to check al least refcount.
Need to check al least refcount.
"""
"""
destroy_map
=
{
0
:[
0
]}
def
__init__
(
self
,
inplace
):
self
.
__setstate__
({
'inplace'
:
inplace
})
def
__str__
(
self
):
def
__str__
(
self
):
return
'GpuGemm'
if
self
.
inplace
:
inplace_str
=
'inplace'
else
:
inplace_str
=
'no_inplace'
return
'
%
s{
%
s}'
%
(
self
.
__class__
.
__name__
,
inplace_str
)
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
return
(
type
(
self
)
==
type
(
other
)
\
and
self
.
inplace
==
other
.
inplace
)
def
__hash__
(
self
):
def
__hash__
(
self
):
return
hash
(
type
(
self
))
return
hash
(
type
(
self
))
^
hash
(
self
.
inplace
)
def
__setstate__
(
self
,
dct
):
inplace
=
dct
.
get
(
'inplace'
,
True
)
if
inplace
:
self
.
destroy_map
=
{
0
:
[
0
]}
self
.
inplace
=
inplace
def
__getstate__
(
self
):
return
dict
(
inplace
=
self
.
inplace
)
def
make_node
(
self
,
z
,
a
,
x
,
y
,
b
):
def
make_node
(
self
,
z
,
a
,
x
,
y
,
b
):
# the more complicated error checking performed by tensor.gemm is assumed to already
# the more complicated error checking performed by tensor.gemm is assumed to already
...
@@ -171,9 +186,13 @@ class GpuGemm(Op):
...
@@ -171,9 +186,13 @@ class GpuGemm(Op):
return
(
2
,)
return
(
2
,)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
#z_out = alpha * dot(x,y) + beta * z_in
#inplace version, set set z_out = z_in
#not inplace version, we copy z_in to z_out.
z_in
,
a
,
x
,
y
,
b
=
inputs
z_in
,
a
,
x
,
y
,
b
=
inputs
z_out
,
=
outputs
z_out
,
=
outputs
fail
=
sub
[
'fail'
]
fail
=
sub
[
'fail'
]
if
self
.
inplace
:
return
"""
return
"""
#define REAL float
#define REAL float
...
@@ -194,7 +213,43 @@ class GpuGemm(Op):
...
@@ -194,7 +213,43 @@ class GpuGemm(Op):
%(z_out)
s =
%(z_in)
s;
%(z_out)
s =
%(z_in)
s;
Py_INCREF(
%(z_out)
s);
Py_INCREF(
%(z_out)
s);
"""
%
locals
()
"""
%
locals
()
gpu_gemm
=
GpuGemm
()
else
:
return
"""
#define REAL float
float
%(name)
s_a = (
%(a)
s->descr->type_num == PyArray_FLOAT)
? (REAL)(((float*)
%(a)
s->data)[0])
: (REAL)(((double*)
%(a)
s->data)[0]);
float
%(name)
s_b = (
%(b)
s->descr->type_num == PyArray_FLOAT) ?
(REAL)(((float*)
%(b)
s->data)[0])
: (REAL)(((double*)
%(b)
s->data)[0]);
#undef REAL
if ((NULL ==
%(z_out)
s)
|| (CudaNdarray_HOST_DIMS(
%(z_out)
s)[0] != CudaNdarray_HOST_DIMS(
%(z_in)
s)[0])
|| (CudaNdarray_HOST_DIMS(
%(z_out)
s)[1] != CudaNdarray_HOST_DIMS(
%(z_in)
s)[1]))
{
Py_XDECREF(
%(z_out)
s);
%(z_out)
s = (CudaNdarray*)CudaNdarray_Copy(
%(z_in)
s);
if(!
%(z_out)
s) {
PyErr_SetString(PyExc_MemoryError, "failed to alloc GpuGemm{no_inplace} output");
%(fail)
s
}
}else{
if(CudaNdarray_CopyFromCudaNdarray(
%(z_out)
s,
%(z_in)
s)){
PyErr_SetString(PyExc_MemoryError, "failed to copy input in GpuGemm{no_inplace}");
%(fail)
s
}
}
if (CudaNdarray_gemm(
%(name)
s_a,
%(x)
s,
%(y)
s,
%(name)
s_b,
%(z_out)
s))
{
%(fail)
s;
}
"""
%
locals
()
gpu_gemm_inplace
=
GpuGemm
(
True
)
gpu_gemm_no_inplace
=
GpuGemm
(
False
)
##
##
# Not really a BLAS operation, but whatever.
# Not really a BLAS operation, but whatever.
...
...
theano/sandbox/cuda/opt.py
浏览文件 @
c5f98527
...
@@ -7,7 +7,7 @@ from theano.gof import local_optimizer, EquilibriumDB, SequenceDB, Optimizer, to
...
@@ -7,7 +7,7 @@ from theano.gof import local_optimizer, EquilibriumDB, SequenceDB, Optimizer, to
from
theano.sandbox.cuda.basic_ops
import
*
from
theano.sandbox.cuda.basic_ops
import
*
from
theano.sandbox.cuda.type
import
CudaNdarrayType
from
theano.sandbox.cuda.type
import
CudaNdarrayType
from
theano.sandbox.cuda.blas
import
gpu_dot22
,
gpu_dot22scalar
,
gpu_gemm
,
GpuConv
from
theano.sandbox.cuda.blas
import
gpu_dot22
,
gpu_dot22scalar
,
gpu_gemm
_inplace
,
gpu_gemm_no_inplace
,
GpuConv
from
theano.sandbox.cuda.blas
import
GpuDownsampleFactorMax
,
GpuDownsampleFactorMaxGrad
from
theano.sandbox.cuda.blas
import
GpuDownsampleFactorMax
,
GpuDownsampleFactorMaxGrad
from
theano.sandbox.cuda.nnet
import
(
from
theano.sandbox.cuda.nnet
import
(
GpuCrossentropySoftmaxArgmax1HotWithBias
,
GpuCrossentropySoftmaxArgmax1HotWithBias
,
...
@@ -187,6 +187,8 @@ def local_gpu_dot22scalar(node):
...
@@ -187,6 +187,8 @@ def local_gpu_dot22scalar(node):
@local_optimizer
([])
@local_optimizer
([])
def
local_gpu_gemm
(
node
):
def
local_gpu_gemm
(
node
):
"""
"""
work for inplace and not inplace gemm
gpu_from_host(gemm) -> gpu_gemm(gpu_from_host)
gpu_from_host(gemm) -> gpu_gemm(gpu_from_host)
gemm(host_from_gpu) -> host_from_gpu(gpu_gemm)
gemm(host_from_gpu) -> host_from_gpu(gpu_gemm)
...
@@ -195,14 +197,24 @@ def local_gpu_gemm(node):
...
@@ -195,14 +197,24 @@ def local_gpu_gemm(node):
host_input
=
node
.
inputs
[
0
]
host_input
=
node
.
inputs
[
0
]
if
host_input
.
owner
and
host_input
.
owner
.
op
==
tensor
.
blas
.
gemm_inplace
:
if
host_input
.
owner
and
host_input
.
owner
.
op
==
tensor
.
blas
.
gemm_inplace
:
z
,
a
,
x
,
y
,
b
=
host_input
.
owner
.
inputs
z
,
a
,
x
,
y
,
b
=
host_input
.
owner
.
inputs
return
[
gpu_gemm
(
gpu_from_host
(
z
),
a
,
gpu_from_host
(
x
),
gpu_from_host
(
y
),
b
)]
return
[
gpu_gemm_inplace
(
gpu_from_host
(
z
),
a
,
gpu_from_host
(
x
),
gpu_from_host
(
y
),
b
)]
if
node
.
op
==
tensor
.
blas
.
gemm_inplace
:
elif
host_input
.
owner
and
host_input
.
owner
.
op
==
tensor
.
blas
.
gemm_no_inplace
:
z
,
a
,
x
,
y
,
b
=
host_input
.
owner
.
inputs
return
[
gpu_gemm_no_inplace
(
gpu_from_host
(
z
),
a
,
gpu_from_host
(
x
),
gpu_from_host
(
y
),
b
)]
elif
node
.
op
==
tensor
.
blas
.
gemm_inplace
:
z
,
a
,
x
,
y
,
b
=
node
.
inputs
x_on_gpu
=
(
x
.
owner
and
x
.
owner
.
op
==
host_from_gpu
)
y_on_gpu
=
(
y
.
owner
and
y
.
owner
.
op
==
host_from_gpu
)
z_on_gpu
=
(
z
.
owner
and
z
.
owner
.
op
==
host_from_gpu
)
if
x_on_gpu
or
y_on_gpu
or
z_on_gpu
:
return
[
host_from_gpu
(
gpu_gemm_inplace
(
gpu_from_host
(
z
),
a
,
gpu_from_host
(
x
),
gpu_from_host
(
y
),
b
))]
elif
node
.
op
==
tensor
.
blas
.
gemm_no_inplace
:
z
,
a
,
x
,
y
,
b
=
node
.
inputs
z
,
a
,
x
,
y
,
b
=
node
.
inputs
x_on_gpu
=
(
x
.
owner
and
x
.
owner
.
op
==
host_from_gpu
)
x_on_gpu
=
(
x
.
owner
and
x
.
owner
.
op
==
host_from_gpu
)
y_on_gpu
=
(
y
.
owner
and
y
.
owner
.
op
==
host_from_gpu
)
y_on_gpu
=
(
y
.
owner
and
y
.
owner
.
op
==
host_from_gpu
)
z_on_gpu
=
(
z
.
owner
and
z
.
owner
.
op
==
host_from_gpu
)
z_on_gpu
=
(
z
.
owner
and
z
.
owner
.
op
==
host_from_gpu
)
if
x_on_gpu
or
y_on_gpu
or
z_on_gpu
:
if
x_on_gpu
or
y_on_gpu
or
z_on_gpu
:
return
[
host_from_gpu
(
gpu_gemm
(
gpu_from_host
(
z
),
a
,
gpu_from_host
(
x
),
gpu_from_host
(
y
),
b
))]
return
[
host_from_gpu
(
gpu_gemm
_no_inplace
(
gpu_from_host
(
z
),
a
,
gpu_from_host
(
x
),
gpu_from_host
(
y
),
b
))]
return
False
return
False
@register_opt
()
@register_opt
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论