Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d467adf9
提交
d467adf9
authored
11月 28, 2014
作者:
Caglar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added the new cula op.
上级
63b7b834
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
107 行增加
和
0 行删除
+107
-0
cula.py
theano/sandbox/cuda/cula.py
+107
-0
没有找到文件。
theano/sandbox/cuda/cula.py
0 → 100644
浏览文件 @
d467adf9
import
theano
from
theano.sandbox.cuda.type
import
CudaNdarrayType
from
theano.sandbox.cuda
import
GpuOp
from
theano.sandbox.cuda.basic_ops
import
(
as_cuda_ndarray_variable
,
gpu_contiguous
)
from
theano.tensor
import
as_tensor_variable
from
scikits.cuda
import
cula
def
gpu_solve
(
A
,
b
,
trans
=
'N'
):
cula
.
culaInitialize
()
A_shape
=
A
.
shape
b_shape
=
b
.
shape
assert
(
len
(
A_shape
)
==
2
)
assert
(
len
(
b_shape
)
==
2
)
import
string
if
trans
in
[
'T'
,
'C'
]:
l
,
n
=
A_shape
m
,
k
=
b_shape
elif
trans
in
[
'N'
]:
n
,
l
=
A_shape
k
,
m
=
b_shape
else
:
raise
ValueError
(
'Invalid value for trans'
)
if
n
!=
k
:
raise
ValueError
(
'A and b must be aligned.'
)
if
trans
==
'n'
:
lda
=
max
(
1
,
n
)
else
:
lda
=
max
(
1
,
l
)
ldb
=
max
(
1
,
k
)
# construct pointer arrays needed for culaDeviceSgels
# Cula requires you to pass a pointer for A and b.
A_ptr
=
A
.
gpudata
b_ptr
=
b
.
gpudata
cula
.
culaDeviceSgels
(
trans
,
n
,
l
,
m
,
A_ptr
,
lda
,
b_ptr
,
ldb
)
return
A
,
b
class
GpuSolve
(
GpuOp
):
"""
Cula Gpu solver OP.
"""
def
__init__
(
self
,
trans
=
'N'
):
self
.
trans
=
trans
super
(
GpuSolve
,
self
)
.
__init__
()
def
__eq__
(
self
,
other
):
return
(
type
(
other
)
==
type
(
self
))
def
__hash__
(
self
):
return
hash
(
type
(
self
))
def
output_type
(
self
,
inp
):
return
cuda
.
CudaNdarrayType
(
broadcastable
=
[
False
]
*
inp
.
type
.
ndim
)
def
make_node
(
self
,
inp1
,
inp2
):
inp1
=
gpu_contiguous
(
as_cuda_ndarray_variable
(
inp1
))
inp2
=
gpu_contiguous
(
as_cuda_ndarray_variable
(
inp2
))
assert
inp1
.
dtype
==
"float32"
assert
inp2
.
dtype
==
"float32"
assert
inp1
.
ndim
==
2
assert
inp2
.
ndim
==
2
return
theano
.
Apply
(
self
,
[
inp1
,
inp2
],
[
self
.
output_type
(
inp1
)()])
def
make_thunk
(
self
,
node
,
storage_map
,
_
,
_2
):
from
theano.misc.pycuda_utils
import
to_gpuarray
inputs
=
[
storage_map
[
v
]
for
v
in
node
.
inputs
]
outputs
=
[
storage_map
[
v
]
for
v
in
node
.
outputs
]
def
thunk
():
input_shape
=
inputs
[
0
][
0
]
.
shape
#size of the matrices to invert
size
=
input_shape
[
1
]
z
=
outputs
[
0
]
if
z
[
0
]
is
None
or
z
[
0
]
.
shape
!=
input_shape
:
z
[
0
]
=
cuda
.
CudaNdarray
.
zeros
(
input_shape
)
#Matrix
A
=
inputs
[
0
][
0
]
#Solution vectors
b
=
inputs
[
0
][
1
]
A_pycuda
=
to_gpuarray
(
A
)
b_pycuda
=
to_gpuarray
(
b
)
gpu_solve
(
A_pycuda
,
b_pycuda
,
self
.
trans
)
thunk
.
inputs
=
inputs
thunk
.
outputs
=
outputs
thunk
.
lazy
=
False
return
thunk
#gpu_solve = GpuSolve()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论