Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8e23c533
提交
8e23c533
authored
7月 30, 2014
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove the python version of these ops as it laughably slow and forces
a dependecy on scikits.cuda and pycuda.
上级
d3088260
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
3 行增加
和
140 行删除
+3
-140
blocksparse.py
theano/sandbox/cuda/blocksparse.py
+3
-140
没有找到文件。
theano/sandbox/cuda/blocksparse.py
浏览文件 @
8e23c533
...
...
@@ -13,66 +13,6 @@ if cuda_available:
HostFromGpu
,
host_from_gpu
,
GpuDimShuffle
)
import
theano.misc.pycuda_init
from
theano.misc.pycuda_init
import
pycuda_available
if
pycuda_available
:
import
pycuda.gpuarray
from
theano.misc.pycuda_utils
import
to_cudandarray
try
:
import
scikits.cuda
from
scikits.cuda
import
cublas
import
scikits.cuda.misc
scikits
.
cuda
.
misc
.
init
()
scikits_cuda_available
=
True
except
ImportError
:
scikits_cuda_available
=
False
def
gemm_batched
(
tA
,
tB
,
m
,
n
,
k
,
Al
,
lda
,
Bl
,
ldb
,
Cl
,
ldc
,
alpha
=
numpy
.
float32
(
1.0
),
beta
=
numpy
.
float32
(
0.0
)):
assert
Al
.
shape
[
0
]
==
Bl
.
shape
[
0
]
assert
Al
.
shape
[
0
]
==
Cl
.
shape
[
0
]
handle
=
scikits
.
cuda
.
misc
.
_global_cublas_handle
cublas
.
cublasSgemmBatched
(
handle
,
tA
,
tB
,
m
,
n
,
k
,
alpha
,
Al
.
ptr
,
lda
,
Bl
.
ptr
,
ldb
,
beta
,
Cl
.
ptr
,
ldc
,
Cl
.
shape
[
0
])
def
gemv
(
alpha
,
A
,
x
,
beta
,
y
):
assert
A
.
shape
[
0
]
==
x
.
shape
[
0
]
assert
A
.
shape
[
1
]
==
y
.
shape
[
0
]
if
A
.
strides
[
0
]
==
1
:
n
,
m
=
0
,
1
trans
=
't'
else
:
n
,
m
=
1
,
0
trans
=
'n'
handle
=
scikits
.
cuda
.
misc
.
_global_cublas_handle
cublas
.
cublasSgemv
(
handle
,
trans
,
A
.
shape
[
n
],
A
.
shape
[
m
],
alpha
,
A
.
gpudata
,
A
.
strides
[
m
],
x
.
gpudata
,
x
.
strides
[
0
],
beta
,
y
.
gpudata
,
y
.
strides
[
0
])
def
ger
(
alpha
,
x
,
y
,
A
):
assert
A
.
shape
[
1
]
==
x
.
shape
[
0
]
assert
A
.
shape
[
0
]
==
y
.
shape
[
0
]
handle
=
scikits
.
cuda
.
misc
.
_global_cublas_handle
cublas
.
cublasSger
(
handle
,
A
.
shape
[
1
],
A
.
shape
[
0
],
alpha
,
x
.
gpudata
,
x
.
strides
[
0
],
y
.
gpudata
,
y
.
strides
[
0
],
A
.
gpudata
,
A
.
strides
[
0
])
class
SparseBlockGemvSS
(
GpuOp
):
def
__init__
(
self
,
inplace
=
False
):
self
.
inplace
=
inplace
...
...
@@ -104,6 +44,9 @@ class SparseBlockGemvSS(GpuOp):
return
Apply
(
self
,
[
o
,
W
,
h
,
inputIdx
,
outputIdx
],
[
o
.
type
()])
def
infer_shape
(
self
,
node
,
input_shapes
):
return
[
input_shapes
[
0
]]
def
c_support_code
(
self
):
return
"""
__global__ void
...
...
@@ -206,52 +149,6 @@ float *out, int o_str_0, int o_str_1, int o_str_2
}
"""
%
dict
(
n
=
nodename
)
def
perform
(
self
,
node
,
inputs
,
outputs
):
o
,
W
,
h
,
inputIdx
,
outputIdx
=
inputs
out
=
outputs
[
0
]
dd
=
(
o
.
shape
[
0
]
*
o
.
shape
[
1
]
*
h
.
shape
[
1
],)
weightHostB
=
numpy
.
empty
(
dd
,
dtype
=
'intp'
)
outputHostB
=
numpy
.
empty
(
dd
,
dtype
=
'intp'
)
inputHostB
=
numpy
.
empty
(
dd
,
dtype
=
'intp'
)
outputBatched
=
pycuda
.
gpuarray
.
GPUArray
((
h
.
shape
[
0
],
h
.
shape
[
1
],
o
.
shape
[
1
],
o
.
shape
[
2
]),
dtype
=
'float32'
)
k
=
0
for
b
in
range
(
o
.
shape
[
0
]):
for
j
in
range
(
o
.
shape
[
1
]):
out_id
=
outputIdx
[
b
,
j
]
for
i
in
range
(
h
.
shape
[
1
]):
inp_id
=
inputIdx
[
b
,
i
]
weightHostB
[
k
]
=
W
[
inp_id
,
out_id
]
.
gpudata
outputHostB
[
k
]
=
outputBatched
[
b
,
i
,
j
]
.
ptr
inputHostB
[
k
]
=
h
[
b
,
i
]
.
gpudata
k
+=
1
weightB
=
pycuda
.
gpuarray
.
to_gpu
(
weightHostB
)
inputB
=
pycuda
.
gpuarray
.
to_gpu
(
inputHostB
)
outputB
=
pycuda
.
gpuarray
.
to_gpu
(
outputHostB
)
tA
=
'n'
lda
=
W
.
strides
[
2
]
if
lda
==
1
:
tA
=
't'
lda
=
W
.
strides
[
3
]
gemm_batched
(
tA
,
'n'
,
o
.
shape
[
2
],
1
,
h
.
shape
[
2
],
weightB
,
lda
,
inputB
,
h
.
strides
[
1
],
outputB
,
o
.
strides
[
1
],
beta
=
numpy
.
asarray
(
0.0
,
dtype
=
'float32'
))
outputBatchedG
=
to_cudandarray
(
outputBatched
)
out
[
0
]
=
o
+
outputBatchedG
.
reduce_sum
([
0
,
1
,
0
,
0
])
def
infer_shape
(
self
,
node
,
input_shapes
):
return
[
input_shapes
[
0
]]
def
c_code
(
self
,
node
,
nodename
,
inputs
,
outputs
,
sub
):
o
,
W
,
h
,
inputIdx
,
outputIdx
=
inputs
out
=
outputs
[
0
]
...
...
@@ -410,40 +307,6 @@ class SparseBlockOuterSS(GpuOp):
return
Apply
(
self
,
[
o
,
x
,
y
,
xIdx
,
yIdx
,
alpha
,
beta
],
[
o
.
type
()])
def
perform
(
self
,
node
,
inputs
,
outputs
):
o
,
x
,
y
,
xIdx
,
yIdx
,
alpha
,
beta
=
inputs
out
=
outputs
[
0
]
if
not
self
.
inplace
:
o
=
o
.
copy
()
dd
=
(
x
.
shape
[
0
]
*
x
.
shape
[
1
]
*
y
.
shape
[
1
],)
xHostB
=
numpy
.
empty
(
dd
,
dtype
=
'intp'
)
yHostB
=
numpy
.
empty
(
dd
,
dtype
=
'intp'
)
outHostB
=
numpy
.
empty
(
dd
,
dtype
=
'intp'
)
k
=
0
for
b
in
range
(
x
.
shape
[
0
]):
for
j
in
range
(
y
.
shape
[
1
]):
out_id
=
yIdx
[
b
,
j
]
for
i
in
range
(
x
.
shape
[
1
]):
inp_id
=
xIdx
[
b
,
i
]
outHostB
[
k
]
=
o
[
inp_id
,
out_id
]
.
gpudata
xHostB
[
k
]
=
x
[
b
,
i
]
.
gpudata
yHostB
[
k
]
=
y
[
b
,
j
]
.
gpudata
k
+=
1
xB
=
pycuda
.
gpuarray
.
to_gpu
(
xHostB
)
yB
=
pycuda
.
gpuarray
.
to_gpu
(
yHostB
)
outB
=
pycuda
.
gpuarray
.
to_gpu
(
outHostB
)
gemm_batched
(
'n'
,
't'
,
y
.
shape
[
2
],
x
.
shape
[
2
],
1
,
yB
,
y
.
strides
[
1
],
xB
,
x
.
strides
[
1
],
outB
,
o
.
strides
[
2
],
alpha
=
alpha
,
beta
=
beta
)
out
[
0
]
=
o
def
infer_shape
(
self
,
node
,
input_shapes
):
return
[
input_shapes
[
0
]]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论