Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5c373d90
提交
5c373d90
authored
4月 15, 2016
作者:
kelvinxu
提交者:
Kelvin Xu
4月 20, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Initial Op
上级
9b1c1a5d
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
69 行增加
和
0 行删除
+69
-0
extra_ops.py
theano/sandbox/gpuarray/extra_ops.py
+69
-0
没有找到文件。
theano/sandbox/gpuarray/extra_ops.py
浏览文件 @
5c373d90
...
...
@@ -292,3 +292,72 @@ class GpuCumsum(CumsumOp, Op):
return
kernels
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
if
node
.
inputs
[
0
]
.
type
.
context
.
kind
!=
'cuda'
:
raise
NotImplementedError
(
"cuda only"
)
x
,
=
inp
z
,
=
out
axis
=
self
.
axis
if
self
.
axis
is
not
None
else
0
fail
=
sub
[
'fail'
]
max_threads_dim0
=
self
.
max_threads_dim0
max_grid_size1
=
self
.
max_grid_size1
max_grid_size2
=
self
.
max_grid_size2
if
max_threads_dim0
is
None
or
max_grid_size1
is
None
or
max_grid_size2
is
None
:
raise
NotImplementedError
(
"GpuCumsum.c_code should not be called "
"directly. It should be called by "
"make_thunk() that add some information "
"related to the selected GPU."
)
code
=
"""
const int* shape = PyGpuArray_DIMS(
%(x)
s);
bool needAllocation = !
%(z)
s || PyGpuArray_NDIM(
%(x)
s) != PyGpuArray_NDIM(
%(z)
s);
int axis =
%(axis)
s;
if (axis < 0) {
// Convert negative axis to positive axis.
axis += PyGpuArray_NDIM(
%(x)
s);
}
// If output is already allocated, check if its shape matches the input's one.
if (!needAllocation) {
for (int i= 0; i < PyGpuArray_NDIM(
%(x)
s); ++i) {
if (PyGpuArray_DIMS(
%(x)
s)[i] != PyGpuArray_DIMS(
%(z)
s)[i]) {
needAllocation = true;
}
}
}
if (needAllocation){
Py_XDECREF(
%(z)
s);
%(z)
s = (CudaNdarray*) CudaNdarray_NewDims(PyGpuArray_NDIM(
%(x)
s), shape);
}
if (!
%(z)
s) {
%(fail)
s;
}
{ // Namespace for kernel calls //
if (cumSum_
%(nodename)
s(
%(x)
s,
%(z)
s, axis,
%(max_threads_dim0)
s,
%(max_grid_size1)
s,
%(max_grid_size2)
s) == -1){
%(fail)
s;
}
cudaError_t sts = cudaGetLastError();
if (cudaSuccess != sts)
{
PyErr_Format(PyExc_RuntimeError,
"Cuda error:
%%
s:
%%
s.
\\
n",
"cumSum_
%(nodename)
s",
cudaGetErrorString(sts));
%(fail)
s;
}
}
"""
%
locals
()
return
code
@op_lifter
([
CumsumOp
])
def
use_gpu_cumsumop
(
node
,
axis
):
return
GpuCumsum
(
axis
)
register_gpu_opt
()(
use_gpu_cumsumop
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论