Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
603383d3
提交
603383d3
authored
6月 18, 2014
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add GPUContiguous to the new back-end
上级
3ee7720a
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
80 行增加
和
1 行删除
+80
-1
basic_ops.py
theano/sandbox/gpuarray/basic_ops.py
+68
-0
test_basic_ops.py
theano/sandbox/gpuarray/tests/test_basic_ops.py
+12
-1
没有找到文件。
theano/sandbox/gpuarray/basic_ops.py
浏览文件 @
603383d3
...
@@ -750,6 +750,74 @@ class GpuAlloc(HideC, Alloc):
...
@@ -750,6 +750,74 @@ class GpuAlloc(HideC, Alloc):
gpu_alloc
=
GpuAlloc
()
gpu_alloc
=
GpuAlloc
()
class
GpuContiguous
(
Op
):
"""
Always return a c contiguous output. Copy the input only if it is
not already c contiguous.
"""
view_map
=
{
0
:
[
0
]}
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
def
__hash__
(
self
):
return
hash
(
type
(
self
))
def
grad
(
self
,
inputs
,
dout
):
x
,
=
inputs
dout
,
=
dout
dout
=
as_gpuarray_variable
(
dout
)
return
[
dout
]
def
__str__
(
self
):
return
self
.
__class__
.
__name__
def
make_node
(
self
,
input
):
input
=
as_gpuarray_variable
(
input
)
return
Apply
(
self
,
[
input
],
[
input
.
type
()])
def
c_headers
(
self
):
return
[
'<numpy_compat.h>'
]
def
c_code_cache_version
(
self
):
return
(
1
,)
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
input
,
=
inp
z
,
=
out
fail
=
sub
[
'fail'
]
str
=
"""
{
if (
%(input)
s->ga.flags & (GA_C_CONTIGUOUS)){
Py_XDECREF(
%(z)
s);
%(z)
s =
%(input)
s;
Py_INCREF(
%(z)
s);
} else if ((NULL ==
%(z)
s)"""
%
locals
()
for
i
in
xrange
(
len
(
node
.
inputs
[
0
]
.
type
.
broadcastable
)):
str
+=
"
\n
|| (PyGpuArray_DIMS(
%(input)
s)[
%(i)
s] != PyGpuArray_DIMS(
%(z)
s)[
%(i)
s])"
%
locals
()
str
+=
"""
|| !(
%(z)
s->ga.flags & GA_C_CONTIGUOUS))
{
Py_XDECREF(
%(z)
s);
%(z)
s = pygpu_copy(
%(input)
s, GA_C_ORDER);
if (!
%(z)
s)
{
%(fail)
s;
}
}else if(GpuArray_copy(&(
%(z)
s->ga), &(
%(input)
s->ga),
GA_C_ORDER) != GA_NO_ERROR){
%(fail)
s;
}
}
"""
%
locals
()
return
str
gpu_contiguous
=
GpuContiguous
()
class
GpuReshape
(
HideC
,
tensor
.
Reshape
):
class
GpuReshape
(
HideC
,
tensor
.
Reshape
):
"""
"""
Implement Reshape on the gpu.
Implement Reshape on the gpu.
...
...
theano/sandbox/gpuarray/tests/test_basic_ops.py
浏览文件 @
603383d3
...
@@ -42,7 +42,7 @@ from theano.sandbox.gpuarray.basic_ops import (
...
@@ -42,7 +42,7 @@ from theano.sandbox.gpuarray.basic_ops import (
gpu_from_cuda
,
gpu_from_cuda
,
cuda_from_gpu
,
HostFromGpu
,
cuda_from_gpu
,
HostFromGpu
,
GpuFromHost
,
GpuReshape
,
GpuFromHost
,
GpuReshape
,
gpu_join
,
GpuJoin
,
GpuSplit
,
GpuEye
)
gpu_join
,
GpuJoin
,
GpuSplit
,
GpuEye
,
gpu_contiguous
)
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
utt
.
seed_rng
()
utt
.
seed_rng
()
...
@@ -326,6 +326,17 @@ def test_shape():
...
@@ -326,6 +326,17 @@ def test_shape():
assert
isinstance
(
topo
[
0
]
.
op
,
T
.
Shape
)
assert
isinstance
(
topo
[
0
]
.
op
,
T
.
Shape
)
def
test_gpu_contiguous
():
a
=
T
.
fmatrix
(
'a'
)
i
=
T
.
iscalar
(
'i'
)
a_val
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
4
,
5
),
dtype
=
'float32'
)
f
=
theano
.
function
([
a
,
i
],
gpu_contiguous
(
a
[::
i
]),
mode
=
mode_without_gpu
)
f
(
a_val
,
1
)
f
(
a_val
,
2
)
theano
.
printing
.
debugprint
(
f
)
class
G_reshape
(
T_reshape
):
class
G_reshape
(
T_reshape
):
def
shortDescription
(
self
):
def
shortDescription
(
self
):
return
None
return
None
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论