Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e1c07d5b
提交
e1c07d5b
authored
6月 18, 2012
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #643 from nouiz/pycuda
fix context problem with pycuda by checking it is imported before.
上级
a05a98e0
183ec937
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
69 行增加
和
18 行删除
+69
-18
config.txt
doc/library/config.txt
+14
-0
pycuda_init.py
theano/misc/pycuda_init.py
+36
-14
__init__.py
theano/sandbox/cuda/__init__.py
+19
-4
没有找到文件。
doc/library/config.txt
浏览文件 @
e1c07d5b
...
...
@@ -145,6 +145,20 @@ import theano and print the config variable, as in:
This flag's value cannot be modified during the program execution.
.. attribute:: config.pycuda.init
Bool value: either ``True`` or ``False``
Default: ``False``
If True, always initialize PyCUDA when Theano want to initialize
the GPU. With PyCUDA version 2011.2.2 or earlier, PyCUDA must
initialize the GPU before Theano does it. Setting
this flag to True, ensure that, but always import PyCUDA. It can
be done manually by importing theano.misc.pycuda_init before
Theano initialize the GPU device. Newer version of PyCUDA
(currently only in the trunk) don't have this restriction.
.. attribute:: floatX
String value: either 'float64' or 'float32'
...
...
theano/misc/pycuda_init.py
浏览文件 @
e1c07d5b
...
...
@@ -2,29 +2,28 @@ import os
import
warnings
import
theano
import
theano.sandbox.cuda
as
cuda
cuda_ndarray
=
cuda
.
cuda_ndarray
.
cuda_ndarray
import
theano.sandbox.cuda
from
theano
import
config
def
set_gpu_from_theano
():
"""
This set the GPU used by PyCUDA to the same as the one used by Theano.
"""
#import pdb;pdb.set_trace()
if
cuda
.
use
.
device_number
is
None
:
cuda
.
use
(
"gpu"
,
force
=
False
,
default_to_move_computation_to_gpu
=
False
,
move_shared_float32_to_gpu
=
False
,
enable_cuda
=
True
,
test_driver
=
True
)
assert
cuda
.
use
.
device_number
==
cuda_ndarray
.
active_device_number
()
# Transfer the theano gpu binding to pycuda, for consistency
if
config
.
device
.
startswith
(
"gpu"
)
and
len
(
config
.
device
)
>
3
:
os
.
environ
[
"CUDA_DEVICE"
]
=
theano
.
config
.
device
[
3
:]
elif
(
config
.
init_gpu_device
.
startswith
(
"gpu"
)
and
len
(
config
.
init_gpu_device
)
>
3
):
os
.
environ
[
"CUDA_DEVICE"
]
=
theano
.
config
.
init_gpu_device
[
3
:]
# os.environ["CUDA_DEVICE"] = str(cuda.use.device_number)
set_gpu_from_theano
()
pycuda_available
=
False
if
False
:
# If theano.sandbox.cuda don't exist, it is because we are importing
# it and it try to import this file! This mean we must init the device.
if
(
not
hasattr
(
theano
.
sandbox
,
'cuda'
)
or
theano
.
sandbox
.
cuda
.
use
.
device_number
is
None
):
try
:
import
pycuda
import
pycuda.autoinit
...
...
@@ -33,3 +32,26 @@ if False:
# presumably, the user wanted to use pycuda, else they wouldn't have
# imported this module, so issue a warning that the import failed.
warnings
.
warn
(
"PyCUDA import failed in theano.misc.pycuda_init"
)
except
pycuda
.
_driver
.
LogicError
:
if
theano
.
config
.
force_device
:
raise
else
:
if
"CUDA_DEVICE"
in
os
.
environ
:
del
os
.
environ
[
"CUDA_DEVICE"
]
import
pycuda.autoinit
pycuda_available
=
True
else
:
import
pycuda.driver
if
hasattr
(
pycuda
.
driver
.
Context
,
"attach"
):
pycuda
.
driver
.
Context
.
attach
()
else
:
# Now we always import this file when we call theano.sandbox.cuda.use
# So this should not happen normally.
# TODO: make this an error.
warnings
.
warn
(
"For some unknow reason, theano.misc.pycuda_init was not"
" imported before Theano initialized the GPU and"
" your PyCUDA version is 2011.2.2 or earlier."
" To fix the problem, import theano.misc.pycuda_init"
" manually before using/initializing the GPU, use the"
" Theano flag pycuda.init=True or use a"
" more recent version of PyCUDA."
)
theano/sandbox/cuda/__init__.py
浏览文件 @
e1c07d5b
...
...
@@ -11,7 +11,7 @@ import theano
from
theano.compile
import
optdb
from
theano.gof.cmodule
import
get_lib_extension
from
theano.gof.compilelock
import
get_lock
,
release_lock
from
theano.configparser
import
config
,
AddConfigVar
,
StrParam
from
theano.configparser
import
config
,
AddConfigVar
,
StrParam
,
BoolParam
import
nvcc_compiler
_logger_name
=
'theano.sandbox.cuda'
...
...
@@ -29,6 +29,16 @@ AddConfigVar('cuda.root',
"""
,
StrParam
(
os
.
getenv
(
'CUDA_ROOT'
,
"AUTO"
)))
AddConfigVar
(
'pycuda.init'
,
"""If True, always initialize PyCUDA when Theano want to
initilize the GPU. Currently, we must always initialize
PyCUDA before Theano do it. Setting this flag to True,
ensure that, but always import PyCUDA. It can be done
manually by importing theano.misc.pycuda_init before theano
initialize the GPU device.
"""
,
BoolParam
(
False
))
if
config
.
cuda
.
root
==
"AUTO"
:
# set nvcc_path correctly and get the version
nvcc_compiler
.
set_cuda_root
()
...
...
@@ -328,10 +338,15 @@ def use(device,
# No successful call to use() has been made yet
if
device
!=
'gpu'
and
device
<
0
:
return
if
device
in
[
None
,
""
]:
device
=
0
# Has PyCUDA already initialized the GPU context
pycuda_init_dev
=
False
if
config
.
pycuda
.
init
:
import
theano.misc.pycuda_init
pycuda_init_dev
=
theano
.
misc
.
pycuda_init
.
pycuda_available
try
:
if
device
!=
'gpu'
:
if
(
device
!=
'gpu'
)
and
not
pycuda_init_dev
:
assert
isinstance
(
device
,
int
)
gpu_init
(
device
)
use
.
device_number
=
device
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论