Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
dca4bc5b
提交
dca4bc5b
authored
4月 23, 2013
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add CudaFromGpu and use it for the grad and R_op of GpuFromCuda
上级
01b993dd
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
98 行增加
和
4 行删除
+98
-4
basic_ops.py
theano/sandbox/gpuarray/basic_ops.py
+98
-4
没有找到文件。
theano/sandbox/gpuarray/basic_ops.py
浏览文件 @
dca4bc5b
...
...
@@ -207,12 +207,12 @@ class GpuFromCuda(Op):
def
grad
(
self
,
inputs
,
grads
):
gz
,
=
grads
return
[
host
_from_gpu
(
gz
)]
return
[
cuda
_from_gpu
(
gz
)]
def
R_op
(
self
,
inputs
,
eval_points
):
ev
,
=
eval_points
if
isintance
(
ev
,
GpuArrayType
):
return
[
host
_from_gpu
(
ev
)]
return
[
cuda
_from_gpu
(
ev
)]
else
:
return
ev
...
...
@@ -247,8 +247,8 @@ class GpuFromCuda(Op):
def
c_support_code
(
self
):
return
"""
void
(*cuda_get_ctx)(void *ctx) = compyte_get_extension('cuda_get_ctx');
void
(*cuda_make_buf)(void *c, CUdeviceptr p, size_t sz) = compyte_get_extension('cuda_make_buf');
CUcontext
(*cuda_get_ctx)(void *ctx) = compyte_get_extension('cuda_get_ctx');
gpudata *
(*cuda_make_buf)(void *c, CUdeviceptr p, size_t sz) = compyte_get_extension('cuda_make_buf');
"""
def
c_code
(
self
,
node
,
name
,
input
,
output
,
sub
):
...
...
@@ -281,6 +281,7 @@ class GpuFromCuda(Op):
%(name)
sstr[i] = (ssize_t)CudaNdArray_HOST_STRIDES(
%(in)
s)[i];
}
Py_XDECREF(
%(out)
s);
%(out)
s = new_GpuArray((PyObject *)&GpuArrayType);
if (
%(out)
s == NULL) {
free(
%(name)
sdims);
...
...
@@ -318,3 +319,96 @@ class GpuFromCuda(Op):
return
(
0
,)
gpu_from_cuda
=
GpuFromCuda
()
class
CudaFromGpu
(
Op
):
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
def
__hash__
(
self
):
return
hash
(
type
(
self
))
def
make_node
(
self
,
x
):
from
theano.sandbox.cuda
import
CudaNdArrayType
if
not
isinstance
(
x
.
type
,
GpuArrayType
):
raise
TypeError
(
x
)
return
Apply
(
self
,
[
x
],
[
CudaNdarrayType
(
broadcastable
=
x
.
broadcastable
,
dtype
=
x
.
dtype
)()])
def
perform
(
self
,
node
,
inp
,
out
):
from
theano.sandbox.cuda
import
filter
as
cuda_filter
x
,
=
inp
z
,
=
out
z
[
0
]
=
cuda_filter
(
theano
.
_asarray
(
x
,
dtype
=
'float32'
),
tuple
([
0
]
*
x
.
ndim
),
0
,
z
[
0
])
def
grad
(
self
,
inputs
,
grads
):
gz
,
=
grads
return
[
gpu_from_cuda
(
gz
)]
def
R_op
(
self
,
inputs
,
eval_points
):
from
theano.sandbox.cuda
import
CudaNdArrayType
ev
,
=
eval_points
if
(
isinstance
(
ev
,
CudaNdarrayType
)):
return
[
gpu_from_cuda
(
ev
)]
else
:
return
[
ev
]
def
infer_shape
(
self
,
node
,
shp
):
return
shp
def
c_headers
(
self
):
return
[
'cuda_ndarray.cuh'
,
'compyte/extension.h'
,
'cuda.h'
]
def
c_header_dirs
(
self
):
import
cuda_ndarray
ret
=
[
os
.
path
.
dirname
(
cuda_ndarray
.
__file__
)]
cuda_root
=
config
.
cuda
.
root
if
cuda_root
:
ret
.
append
(
os
.
path
.
join
(
cuda_root
,
'include'
))
return
ret
def
c_lib_dirs
(
self
):
import
cuda_ndarray
ret
=
[
os
.
path
.
dirname
(
cuda_ndarray
.
__file__
)]
cuda_root
=
config
.
cuda
.
root
if
cuda_root
:
ret
.
append
(
os
.
path
.
join
(
cuda_root
,
'lib'
))
return
ret
def
c_libraries
(
self
):
return
[
'cudart'
,
'cublas'
,
'cuda'
]
def
c_conpiler
(
self
):
from
theano.sandbox.cuda.nvcc_compiler
import
NVCC_compiler
return
NVCC_compiler
def
c_support_code
(
self
):
return
"""
CUcontext (*cuda_get_ctx)(void *ctx) = compyte_get_extension('cuda_get_ctx');
CUdeviceptr (*cuda_get_ptr)(gpudata *g) = compyte_get_extension('cuda_get_ptr');
size_t (*cuda_get_sz)(gpudata *g) = compyte_get_extension('cuda_get_sz');
"""
def
c_code
(
self
,
node
,
name
,
input
,
output
,
sub
):
return
"""
int err = 0, i;
Py_XDECREF(
%(out)
s);
%(out)
s = (CudaNdarray *)CudaNdarray_new_nd(
%(inp)
s->nd);
if (!
%(out)
s) {
%(fail)
s
}
for (i = 0; i <
%(inp)
s->nd; i++) {
CudaNdarray_set_dim(
%(out)
s, i,
%(inp)
s->dimensions[i]);
CudaNdarray_set_stride(
%(out)
s, i,
%(inp)
s->strides[i]);
}
err = CudaNdarray_set_device_data(
%(out)
,
(float *)(((char *)cuda_get_ptr(
%(inp)
s.ga->data))+
%(inp)
.ga.offset),
(PyObject *)
%(inp)
s);
if (err) {
%(fail)
s
}
"""
%
{
'inp'
:
inputs
[
0
],
'out'
:
output
[
0
],
'fail'
:
sub
[
'fail'
]}
cuda_from_gpu
=
CudaFromGpu
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论