Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1e7b212f
提交
1e7b212f
authored
8月 11, 2015
作者:
Iban Harlouchet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
numpydoc for theano/sandbox/cuda/var.py
上级
a5eb2288
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
57 行增加
和
38 行删除
+57
-38
var.py
theano/sandbox/cuda/var.py
+57
-38
没有找到文件。
theano/sandbox/cuda/var.py
浏览文件 @
1e7b212f
...
@@ -19,15 +19,18 @@ except ImportError:
...
@@ -19,15 +19,18 @@ except ImportError:
class
_operators
(
tensor
.
basic
.
_tensor_py_operators
):
class
_operators
(
tensor
.
basic
.
_tensor_py_operators
):
"""Define a few properties and conversion methods for CudaNdarray Variables.
"""
Define a few properties and conversion methods for CudaNdarray Variables.
The default implementation of arithemetic operators is to build graphs of
TensorType
The default implementation of arithemetic operators is to build graphs of
variables.
TensorType
variables.
The optimization pass (specialization) will insert pure GPU implementations.
The optimization pass (specialization) will insert pure GPU implementations.
This approach relieves the Cuda-Ops of having to deal with input argument checking and
This approach relieves the Cuda-Ops of having to deal with input argument
gradients.
checking and gradients.
"""
"""
def
_as_TensorVariable
(
self
):
def
_as_TensorVariable
(
self
):
return
HostFromGpu
()(
self
)
return
HostFromGpu
()(
self
)
def
_as_CudaNdarrayVariable
(
self
):
def
_as_CudaNdarrayVariable
(
self
):
...
@@ -63,7 +66,8 @@ CudaNdarrayType.Constant = CudaNdarrayConstant
...
@@ -63,7 +66,8 @@ CudaNdarrayType.Constant = CudaNdarrayConstant
class
CudaNdarraySharedVariable
(
_operators
,
SharedVariable
):
class
CudaNdarraySharedVariable
(
_operators
,
SharedVariable
):
"""
"""
Shared Variable interface to CUDA-allocated arrays
Shared Variable interface to CUDA-allocated arrays.
"""
"""
get_value_return_ndarray
=
True
get_value_return_ndarray
=
True
...
@@ -72,20 +76,23 @@ class CudaNdarraySharedVariable(_operators, SharedVariable):
...
@@ -72,20 +76,23 @@ class CudaNdarraySharedVariable(_operators, SharedVariable):
"""
"""
Return the value of this SharedVariable's internal array.
Return the value of this SharedVariable's internal array.
:param borrow:
Parameters
permit the return of internal storage, when used in conjunction with
----------
``return_internal_type=True``
borrow
:param return_internal_type:
Permit the return of internal storage, when used in conjunction with
True to return the internal ``cuda_ndarray`` instance rather than a ``numpy.ndarray``
``return_internal_type=True``.
(Default False)
return_internal_type
True to return the internal ``cuda_ndarray`` instance rather than a
``numpy.ndarray`` (Default False).
By default ``get_value()`` copies from the GPU to a ``numpy.ndarray``
and returns that
By default ``get_value()`` copies from the GPU to a ``numpy.ndarray``
host-allocated array.
and returns that
host-allocated array.
``get_value(False,True)`` will return a GPU-allocated copy of the original GPU array.
``get_value(False,True)`` will return a GPU-allocated copy of the
original GPU array.
``get_value(True,True)`` will return the original GPU-allocated array
without any
``get_value(True,True)`` will return the original GPU-allocated array
copying.
without any
copying.
"""
"""
if
return_internal_type
or
not
self
.
get_value_return_ndarray
:
if
return_internal_type
or
not
self
.
get_value_return_ndarray
:
...
@@ -101,33 +108,39 @@ class CudaNdarraySharedVariable(_operators, SharedVariable):
...
@@ -101,33 +108,39 @@ class CudaNdarraySharedVariable(_operators, SharedVariable):
"""
"""
Assign `value` to the GPU-allocated array.
Assign `value` to the GPU-allocated array.
:param borrow: ``True`` permits reusing `value` itself, ``False`` requires that this function
Parameters
copies `value` into internal storage.
----------
borrow : bool
:note:
``True`` permits reusing `value` itself, ``False`` requires that
this function copies `value` into internal storage.
Prior to Theano 0.3.1, set_value did not work in-place on the GPU. This meant that sometimes,
Notes
GPU memory for the new value would be allocated before the old memory was released. If you're
-----
running near the limits of GPU memory, this could cause you to run out of GPU memory.
Prior to Theano 0.3.1, set_value did not work in-place on the GPU. This
meant that sometimes, GPU memory for the new value would be allocated
before the old memory was released. If you're running near the limits of
GPU memory, this could cause you to run out of GPU memory.
Beginning with Theano 0.3.1, set_value will work in-place on the GPU, if the following conditions
Beginning with Theano 0.3.1, set_value will work in-place on the GPU, if
are met:
the following conditions
are met:
* The destination on the GPU must be c_contiguous.
* The destination on the GPU must be c_contiguous.
* The source is on the CPU.
* The source is on the CPU.
* The old value must have the same dtype as the new value (which is
a given for now,
* The old value must have the same dtype as the new value (which is
since only float32 is supported).
a given for now,
since only float32 is supported).
* The old and new value must have the same shape.
* The old and new value must have the same shape.
* The old value is being completely replaced by the new value (not partially modified,
* The old value is being completely replaced by the new value (not
e.g. by replacing some subtensor of it).
partially modified, e.g. by replacing some subtensor of it).
* You change the value of the shared variable via set_value, not via the .value
* You change the value of the shared variable via set_value, not via
accessors. You should not use the .value accessors anyway, since they will soon be
the .value accessors. You should not use the .value accessors
deprecated and removed.
anyway, since they will soon be deprecated and removed.
It is also worth mentioning that, for efficient transfer to the GPU,
Theano will make the new data ``c_contiguous``. This can require an
extra copy of the data on the host.
It is also worth mentioning that, for efficient transfer to the GPU, Theano will make the new data
The inplace on gpu memory work when borrow is either True or False.
``c_contiguous``. This can require an extra copy of the data on the host.
The inplace on gpu memory work when borrow is either True or False.
"""
"""
if
not
borrow
:
if
not
borrow
:
# TODO: check for cuda_ndarray type
# TODO: check for cuda_ndarray type
...
@@ -147,8 +160,10 @@ CudaNdarrayType.SharedVariable = CudaNdarraySharedVariable
...
@@ -147,8 +160,10 @@ CudaNdarrayType.SharedVariable = CudaNdarraySharedVariable
def
cuda_shared_constructor
(
value
,
name
=
None
,
strict
=
False
,
def
cuda_shared_constructor
(
value
,
name
=
None
,
strict
=
False
,
allow_downcast
=
None
,
borrow
=
False
,
broadcastable
=
None
):
allow_downcast
=
None
,
borrow
=
False
,
broadcastable
=
None
):
"""SharedVariable Constructor for CudaNdarrayType"""
"""
SharedVariable Constructor for CudaNdarrayType.
"""
# THIS CONSTRUCTOR TRIES TO CAST VALUE TO A FLOAT32, WHICH THEN GOES ONTO THE CARD
# THIS CONSTRUCTOR TRIES TO CAST VALUE TO A FLOAT32, WHICH THEN GOES ONTO THE CARD
# SO INT shared vars, float64 shared vars, etc. all end up on the card.
# SO INT shared vars, float64 shared vars, etc. all end up on the card.
# THIS IS NOT THE DEFAULT BEHAVIOUR THAT WE WANT.
# THIS IS NOT THE DEFAULT BEHAVIOUR THAT WE WANT.
...
@@ -179,7 +194,11 @@ def cuda_shared_constructor(value, name=None, strict=False,
...
@@ -179,7 +194,11 @@ def cuda_shared_constructor(value, name=None, strict=False,
def
float32_shared_constructor
(
value
,
name
=
None
,
strict
=
False
,
def
float32_shared_constructor
(
value
,
name
=
None
,
strict
=
False
,
allow_downcast
=
None
,
borrow
=
False
,
broadcastable
=
None
):
allow_downcast
=
None
,
borrow
=
False
,
broadcastable
=
None
):
"""SharedVariable Constructor for CudaNdarrayType from numpy.ndarray or CudaNdarray"""
"""
SharedVariable Constructor for CudaNdarrayType from numpy.ndarray or
CudaNdarray.
"""
if
theano
.
sandbox
.
cuda
.
use
.
device_number
is
None
:
if
theano
.
sandbox
.
cuda
.
use
.
device_number
is
None
:
theano
.
sandbox
.
cuda
.
use
(
"gpu"
,
theano
.
sandbox
.
cuda
.
use
(
"gpu"
,
force
=
True
,
force
=
True
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论