Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
aec5e37f
提交
aec5e37f
authored
12月 21, 2010
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Split Josh's documentation between aliasing.txt and…
Split Josh's documentation between aliasing.txt and CudaNdarraySharedVariable.set_value docstring note.
上级
375e144b
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
51 行增加
和
23 行删除
+51
-23
aliasing.txt
doc/tutorial/aliasing.txt
+23
-23
var.py
theano/sandbox/cuda/var.py
+28
-0
没有找到文件。
doc/tutorial/aliasing.txt
浏览文件 @
aec5e37f
...
...
@@ -182,29 +182,29 @@ This pattern works regardless of the compute device, and when the compute device
makes it possible to expose Theano's internal variables without a copy, then it
goes as fast as an in-place update.
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
are met:
* The destination on the GPU must be c_contiguous
.
* The old value must have the same dtype as the new value (which is a given for now,
since only float32 is supported).
* The old and new value must have the same shape.
* The old value is being completely replaced by the new value (not 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
accessors. You should not use the .value accessors anyway, since they will soon be
deprecated and removed
.
Fortunately, these conditions are usually straightforwardly met without any additional effort.
If you are going to swap several chunks of data in and out of a shared variable repeatedly,
it is worth padding your source data to make sure that every chunk is the same size.
It is also worth mentioning that, for efficient transfer to the GPU, theano will make the new data
c_contiguous. This could mean making a copy of the data on the host.
When shared variables are allocated on the GPU, the transfers to and from GPU device memory can
be costly. Here are a few tips to ensure fast and efficient use of GPU memory and bandwidth:
* 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
unnecessarily. *Solution*: update to a newer version of Theano
.
* If you are going to swap several chunks of data in and out of a shared variable repeatedly,
you will want to reuse the memory that you allocated the first time if possible - it is both
faster and more memory efficient.
*Solution*: upgrade to a recent version of Theano (>0.3.0) and consider padding your source
data to make sure that every chunk is the same size.
* It is also worth mentioning that, current GPU copying routines support only contiguous memory
.
So Theano must make the ``value`` you provide ``c_contiguous`` prior to copying it.
This can require an extra copy of the data on the host. *Solution*: make sure that the value
you assign to a CudaNdarraySharedVariable is *already* ``c_contiguous``.
(Further remarks on the current implementation of the GPU version of set_value() can be found
here: :ref:`libdoc_cuda_var`)
Retrieving and assigning via the .value property
------------------------------------------------
...
...
theano/sandbox/cuda/var.py
浏览文件 @
aec5e37f
...
...
@@ -82,6 +82,34 @@ class CudaNdarraySharedVariable(SharedVariable, _operators):
return
numpy
.
asarray
(
self
.
container
.
value
)
def
set_value
(
self
,
value
,
borrow
=
False
):
"""
Assign `value` to the GPU-allocated array.
:param borrow: ``True`` permits reusing `value` itself, ``False`` requires that this function
copies `value` into internal storage.
:note:
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
are met:
* The destination on the GPU must be c_contiguous.
* The old value must have the same dtype as the new value (which is a given for now,
since only float32 is supported).
* The old and new value must have the same shape.
* The old value is being completely replaced by the new value (not 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
accessors. You should not use the .value accessors 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.
"""
if
not
borrow
:
#TODO: check for cuda_ndarray type
if
not
isinstance
(
value
,
numpy
.
ndarray
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论