Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f5aa88a2
提交
f5aa88a2
authored
1月 26, 2011
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cuda.__init__ 80 char limit
上级
2a37e894
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
31 行增加
和
15 行删除
+31
-15
__init__.py
theano/sandbox/cuda/__init__.py
+31
-15
没有找到文件。
theano/sandbox/cuda/__init__.py
浏览文件 @
f5aa88a2
...
@@ -8,13 +8,17 @@ _logger_name = 'theano.sandbox.cuda'
...
@@ -8,13 +8,17 @@ _logger_name = 'theano.sandbox.cuda'
_logger
=
logging
.
getLogger
(
_logger_name
)
_logger
=
logging
.
getLogger
(
_logger_name
)
_logger
.
setLevel
(
logging
.
WARNING
)
_logger
.
setLevel
(
logging
.
WARNING
)
def
error
(
*
msg
):
def
error
(
*
msg
):
_logger
.
error
(
'ERROR (
%
s):
%
s'
%
(
_logger_name
,
' '
.
join
(
str
(
m
)
for
m
in
msg
)))
_logger
.
error
(
'ERROR (
%
s):
%
s'
%
(
_logger_name
,
' '
.
join
(
str
(
m
)
for
m
in
msg
)))
def
warning
(
*
msg
):
def
warning
(
*
msg
):
_logger
.
warning
(
'WARNING (
%
s):
%
s'
%
(
_logger_name
,
' '
.
join
(
str
(
m
)
for
m
in
msg
)))
_logger
.
warning
(
'WARNING (
%
s):
%
s'
%
(
_logger_name
,
' '
.
join
(
str
(
m
)
for
m
in
msg
)))
def
info
(
*
msg
):
def
info
(
*
msg
):
_logger
.
info
(
'INFO (
%
s):
%
s'
%
(
_logger_name
,
' '
.
join
(
str
(
m
)
for
m
in
msg
)))
_logger
.
info
(
'INFO (
%
s):
%
s'
%
(
_logger_name
,
' '
.
join
(
str
(
m
)
for
m
in
msg
)))
def
debug
(
*
msg
):
def
debug
(
*
msg
):
_logger
.
debug
(
'DEBUG (
%
s):
%
s'
%
(
_logger_name
,
' '
.
join
(
str
(
m
)
for
m
in
msg
)))
_logger
.
debug
(
'DEBUG (
%
s):
%
s'
%
(
_logger_name
,
' '
.
join
(
str
(
m
)
for
m
in
msg
)))
# Compile cuda_ndarray.cu
# Compile cuda_ndarray.cu
...
@@ -29,7 +33,7 @@ cuda_available = True
...
@@ -29,7 +33,7 @@ cuda_available = True
# Global variable to avoid displaying the same warning multiple times.
# Global variable to avoid displaying the same warning multiple times.
cuda_warning_is_displayed
=
False
cuda_warning_is_displayed
=
False
#This variable is set to True when we enable
the
cuda.(i.e. when use() is called)
#This variable is set to True when we enable cuda.(i.e. when use() is called)
cuda_enabled
=
False
cuda_enabled
=
False
# Code factorized within a function so that it may be called from multiple
# Code factorized within a function so that it may be called from multiple
...
@@ -51,8 +55,13 @@ def set_cuda_disabled():
...
@@ -51,8 +55,13 @@ def set_cuda_disabled():
#cuda_ndarray compile and import
#cuda_ndarray compile and import
cuda_path
=
os
.
path
.
abspath
(
os
.
path
.
split
(
__file__
)[
0
])
cuda_path
=
os
.
path
.
abspath
(
os
.
path
.
split
(
__file__
)[
0
])
cuda_files
=
(
'cuda_ndarray.cu'
,
'cuda_ndarray.cuh'
,
'conv_full_kernel.cu'
,
'conv_kernel.cu'
)
cuda_files
=
(
stat_times
=
[
os
.
stat
(
os
.
path
.
join
(
cuda_path
,
cuda_file
))[
stat
.
ST_MTIME
]
for
cuda_file
in
cuda_files
]
'cuda_ndarray.cu'
,
'cuda_ndarray.cuh'
,
'conv_full_kernel.cu'
,
'conv_kernel.cu'
)
stat_times
=
[
os
.
stat
(
os
.
path
.
join
(
cuda_path
,
cuda_file
))[
stat
.
ST_MTIME
]
for
cuda_file
in
cuda_files
]
date
=
max
(
stat_times
)
date
=
max
(
stat_times
)
cuda_ndarray_loc
=
os
.
path
.
join
(
config
.
compiledir
,
'cuda_ndarray'
)
cuda_ndarray_loc
=
os
.
path
.
join
(
config
.
compiledir
,
'cuda_ndarray'
)
...
@@ -113,7 +122,8 @@ from theano.sandbox.cuda.var import (CudaNdarrayVariable,
...
@@ -113,7 +122,8 @@ from theano.sandbox.cuda.var import (CudaNdarrayVariable,
from
theano.sandbox.cuda.type
import
CudaNdarrayType
from
theano.sandbox.cuda.type
import
CudaNdarrayType
if
cuda_available
:
if
cuda_available
:
#check if their is an old cuda_ndarray that was loading instead of the one we compiled!
# check if their is an old cuda_ndarray that was loading instead of the one
# we compiled!
import
cuda_ndarray.cuda_ndarray
import
cuda_ndarray.cuda_ndarray
if
cuda_ndarray_so
!=
cuda_ndarray
.
cuda_ndarray
.
__file__
:
if
cuda_ndarray_so
!=
cuda_ndarray
.
cuda_ndarray
.
__file__
:
warning
(
"WARNING: cuda_ndarray was loaded from"
,
warning
(
"WARNING: cuda_ndarray was loaded from"
,
...
@@ -172,14 +182,17 @@ def use(device, force=False, default_to_move_computation_to_gpu = True,
...
@@ -172,14 +182,17 @@ def use(device, force=False, default_to_move_computation_to_gpu = True,
use
.
device_number
=
device
use
.
device_number
=
device
cuda_enabled
=
True
cuda_enabled
=
True
except
(
EnvironmentError
,
ValueError
),
e
:
except
(
EnvironmentError
,
ValueError
),
e
:
_logger
.
error
(
"ERROR: Not using GPU. Initialisation of device
%
i failed:
\n
%
s"
%
(
device
,
e
))
_logger
.
error
((
"ERROR: Not using GPU."
" Initialisation of device
%
i failed:
\n
%
s"
)
%
(
device
,
e
))
cuda_enabled
=
False
cuda_enabled
=
False
if
force
:
if
force
:
e
.
args
+=
(
"You asked to force this device and it failed. No fallback to the cpu or other gpu device."
,)
e
.
args
+=
((
"You asked to force this device and it failed."
" No fallback to the cpu or other gpu device."
),)
raise
raise
elif
use
.
device_number
!=
device
:
elif
use
.
device_number
!=
device
:
_logger
.
warning
(
"WARNING: ignoring call to use(
%
s), GPU number
%
i is already in use."
%
(
str
(
device
),
use
.
device_number
))
_logger
.
warning
((
"WARNING: ignoring call to use(
%
s), GPU number
%
i "
"is already in use."
)
%
(
str
(
device
),
use
.
device_number
))
if
default_to_move_computation_to_gpu
:
if
default_to_move_computation_to_gpu
:
optdb
.
add_tags
(
'gpu'
,
optdb
.
add_tags
(
'gpu'
,
...
@@ -188,10 +201,12 @@ def use(device, force=False, default_to_move_computation_to_gpu = True,
...
@@ -188,10 +201,12 @@ def use(device, force=False, default_to_move_computation_to_gpu = True,
if
force
:
if
force
:
try
:
try
:
#in case the device if just gpu, we check that the driver init it correctly.
#in case the device if just gpu,
# we check that the driver init it correctly.
cuda_ndarray
.
cuda_ndarray
.
CudaNdarray
.
zeros
((
5
,
5
))
cuda_ndarray
.
cuda_ndarray
.
CudaNdarray
.
zeros
((
5
,
5
))
except
(
Exception
,
NameError
),
e
:
#NameError when no gpu present as cuda_ndarray is not loaded.
except
(
Exception
,
NameError
),
e
:
e
.
args
+=
(
"ERROR: GPU did not work and we told to don't use the cpu. "
,)
# NameError when no gpu present as cuda_ndarray is not loaded.
e
.
args
+=
(
"ERROR: GPU forced but failed. "
,)
raise
raise
...
@@ -212,7 +227,8 @@ def handle_shared_float32(tf):
...
@@ -212,7 +227,8 @@ def handle_shared_float32(tf):
if
config
.
device
.
startswith
(
'gpu'
):
if
config
.
device
.
startswith
(
'gpu'
):
use
(
device
=
config
.
device
,
force
=
config
.
force_device
)
use
(
device
=
config
.
device
,
force
=
config
.
force_device
)
elif
config
.
init_gpu_device
:
elif
config
.
init_gpu_device
:
assert
config
.
device
==
"cpu"
,
"We can use the Theano flag init_gpu_device only when the Theano flag device=='cpu'"
assert
config
.
device
==
"cpu"
,
(
"We can use the Theano flag init_gpu_device"
" only when the Theano flag device=='cpu'"
)
warning
((
"GPU device
%
s will be initialized, and used if a GPU is needed. "
warning
((
"GPU device
%
s will be initialized, and used if a GPU is needed. "
"However, no computation, nor shared variables, will be implicitly "
"However, no computation, nor shared variables, will be implicitly "
"moved to that device. If you want that behavior, use the 'device' "
"moved to that device. If you want that behavior, use the 'device' "
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论