Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ff120e15
提交
ff120e15
authored
12月 01, 2016
作者:
Arnaud Bergeron
提交者:
Frederic Bastien
12月 22, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Now that we have dicts on GpuContext get rid of the horrible prop hack.
上级
f7596c63
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
46 行增加
和
71 行删除
+46
-71
__init__.py
theano/gpuarray/__init__.py
+39
-42
dnn.py
theano/gpuarray/dnn.py
+7
-9
type.py
theano/gpuarray/type.py
+0
-20
没有找到文件。
theano/gpuarray/__init__.py
浏览文件 @
ff120e15
...
@@ -27,7 +27,7 @@ except ImportError:
...
@@ -27,7 +27,7 @@ except ImportError:
# This is for documentation not to depend on the availability of pygpu
# This is for documentation not to depend on the availability of pygpu
from
.type
import
(
GpuArrayType
,
GpuArrayVariable
,
GpuArrayConstant
,
from
.type
import
(
GpuArrayType
,
GpuArrayVariable
,
GpuArrayConstant
,
GpuArraySharedVariable
,
gpuarray_shared_constructor
,
GpuArraySharedVariable
,
gpuarray_shared_constructor
,
reg_context
,
get_context
,
ContextNotDefined
,
_get_props
)
reg_context
,
get_context
,
ContextNotDefined
)
from
.basic_ops
import
as_gpuarray_variable
from
.basic_ops
import
as_gpuarray_variable
from
.
import
fft
,
dnn
,
opt
,
nerv
,
extra_ops
,
multinomial
,
reduction
from
.
import
fft
,
dnn
,
opt
,
nerv
,
extra_ops
,
multinomial
,
reduction
...
@@ -50,68 +50,65 @@ def init_dev(dev, name=None):
...
@@ -50,68 +50,65 @@ def init_dev(dev, name=None):
# This is for the C headers API
# This is for the C headers API
if
pygpu
.
gpuarray
.
api_version
()[
0
]
<
0
:
if
pygpu
.
gpuarray
.
api_version
()[
0
]
<
0
:
raise
ValueError
(
"Your installed libgpuarray is too old, please update"
)
raise
ValueError
(
"Your installed libgpuarray is too old, please update"
)
need_preallocate
=
False
if
init_dev
.
dnn_version
is
None
and
dev
.
startswith
(
'cuda'
):
try
:
init_dev
.
dnn_version
=
dnn
.
version
()
# 5200 should not print warning with cudnn 5.1 final.
if
init_dev
.
dnn_version
>=
5200
:
warnings
.
warn
(
"Your cuDNN version is more recent than "
"Theano. If you encounter problems, try "
"updating Theano or downgrading cuDNN to "
"version 5.1."
)
if
config
.
print_active_device
:
print
(
"Using cuDNN version
%
d"
%
(
init_dev
.
dnn_version
,
name
),
file
=
sys
.
stderr
)
except
Exception
:
pass
if
dev
not
in
init_dev
.
devmap
:
if
dev
not
in
init_dev
.
devmap
:
ctx
=
pygpu
.
init
(
dev
,
ctx
=
pygpu
.
init
(
dev
,
disable_alloc_cache
=
config
.
gpuarray
.
preallocate
<
0
,
disable_alloc_cache
=
config
.
gpuarray
.
preallocate
<
0
,
single_stream
=
config
.
gpuarray
.
single_stream
,
single_stream
=
config
.
gpuarray
.
single_stream
,
sched
=
config
.
gpuarray
.
sched
)
sched
=
config
.
gpuarray
.
sched
)
ctx
.
dev
=
dev
init_dev
.
devmap
[
dev
]
=
ctx
init_dev
.
devmap
[
dev
]
=
ctx
if
dev
.
startswith
(
'cuda'
):
ctx
.
cudnn_handle
=
dnn
.
_make_handle
(
ctx
)
if
config
.
gpuarray
.
preallocate
<
0
:
if
config
.
gpuarray
.
preallocate
<
0
:
print
(
"Disabling allocation cache on
%
s"
%
(
dev
,))
print
(
"Disabling allocation cache on
%
s"
%
(
dev
,))
elif
config
.
gpuarray
.
preallocate
>
0
:
elif
config
.
gpuarray
.
preallocate
>
0
:
need_preallocate
=
True
MB
=
(
1024
*
1024
)
if
config
.
gpuarray
.
preallocate
<=
1
:
gmem
=
min
(
config
.
gpuarray
.
preallocate
,
0.95
)
*
context
.
total_gmem
else
:
gmem
=
config
.
gpuarray
.
preallocate
*
MB
if
gmem
>
context
.
free_gmem
-
50
*
MB
:
print
(
"WARNING: Preallocating too much memory can prevent cudnn and cublas from working properly"
)
# This will allocate and immediatly free an object of size gmem
# which will reserve that amount of memory on the GPU.
pygpu
.
empty
((
gmem
,),
dtype
=
'int8'
,
context
=
ctx
)
if
config
.
print_active_device
:
print
(
"Preallocating
%
d/
%
d Mb (
%
f) on
%
s"
%
(
gmem
//
MB
,
ctx
.
total_gmem
//
MB
,
gmem
/
ctx
.
total_gmem
,
dev
),
file
=
sys
.
stderr
)
context
=
init_dev
.
devmap
[
dev
]
context
=
init_dev
.
devmap
[
dev
]
# This will map the context name to the real context object.
# This will map the context name to the real context object.
reg_context
(
name
,
context
)
reg_context
(
name
,
context
)
if
config
.
print_active_device
:
if
config
.
print_active_device
:
try
:
try
:
pcibusid
=
context
.
pcibusid
pcibusid
=
'('
+
context
.
pcibusid
+
')'
except
pygpu
.
gpuarray
.
UnsupportedException
:
except
pygpu
.
gpuarray
.
UnsupportedException
:
pcibusid
=
'
(unsupported for device
%
s)'
%
dev
pcibusid
=
'
'
print
(
"Mapped name
%
s to device
%
s:
%
s"
%
print
(
"Mapped name
%
s to device
%
s:
%
s
%
s
"
%
(
name
,
dev
,
context
.
devname
),
(
name
,
dev
,
context
.
devname
,
pcibusid
),
file
=
sys
.
stderr
)
file
=
sys
.
stderr
)
print
(
"PCI Bus ID:"
,
pcibusid
,
file
=
sys
.
stderr
)
pygpu_activated
=
True
pygpu_activated
=
True
ctx_props
=
_get_props
(
name
)
ctx_props
[
'dev'
]
=
dev
if
dev
.
startswith
(
'cuda'
):
if
'cudnn_version'
not
in
ctx_props
:
try
:
ctx_props
[
'cudnn_version'
]
=
dnn
.
version
()
# 5200 should not print warning with cudnn 5.1 final.
if
ctx_props
[
'cudnn_version'
]
>=
5200
:
warnings
.
warn
(
"Your cuDNN version is more recent than "
"Theano. If you encounter problems, try "
"updating Theano or downgrading cuDNN to "
"version 5.1."
)
if
config
.
print_active_device
:
print
(
"Using cuDNN version
%
d on context
%
s"
%
(
ctx_props
[
'cudnn_version'
],
name
),
file
=
sys
.
stderr
)
ctx_props
[
'cudnn_handle'
]
=
dnn
.
_make_handle
(
context
)
except
Exception
:
pass
if
need_preallocate
:
MB
=
(
1024
*
1024
)
if
config
.
gpuarray
.
preallocate
<=
1
:
gmem
=
min
(
config
.
gpuarray
.
preallocate
,
0.95
)
*
context
.
total_gmem
else
:
gmem
=
config
.
gpuarray
.
preallocate
*
MB
if
gmem
>
context
.
free_gmem
-
50
*
MB
:
print
(
"WARNING: Preallocating too much memory can prevent cudnn and cublas from working properly"
)
# This will allocate and immediatly free an object of size gmem
# which will reserve that amount of memory on the GPU.
pygpu
.
empty
((
gmem
,),
dtype
=
'int8'
,
context
=
ctx
)
if
config
.
print_active_device
:
print
(
"Preallocating
%
d/
%
d Mb (
%
f) on
%
s"
%
(
gmem
//
MB
,
ctx
.
total_gmem
//
MB
,
gmem
/
ctx
.
total_gmem
,
dev
),
file
=
sys
.
stderr
)
# This maps things like 'cuda0' to the context object on that device.
# This maps things like 'cuda0' to the context object on that device.
init_dev
.
devmap
=
{}
init_dev
.
devmap
=
{}
init_dev
.
dnn_version
=
None
if
pygpu
:
if
pygpu
:
try
:
try
:
...
...
theano/gpuarray/dnn.py
浏览文件 @
ff120e15
...
@@ -30,7 +30,7 @@ from theano.tensor.signal.pool import (
...
@@ -30,7 +30,7 @@ from theano.tensor.signal.pool import (
Pool
,
MaxPoolGrad
,
AveragePoolGrad
)
Pool
,
MaxPoolGrad
,
AveragePoolGrad
)
from
.
import
pygpu
from
.
import
pygpu
from
.type
import
(
get_context
,
gpu_context_type
,
list_contexts
,
from
.type
import
(
get_context
,
gpu_context_type
,
list_contexts
,
get_prop
,
set_prop
,
GpuArraySharedVariable
)
GpuArraySharedVariable
)
from
.basic_ops
import
(
as_gpuarray_variable
,
infer_context_name
,
from
.basic_ops
import
(
as_gpuarray_variable
,
infer_context_name
,
gpu_contiguous
,
gpu_alloc_empty
,
gpu_contiguous
,
gpu_alloc_empty
,
empty_like
,
GpuArrayType
)
empty_like
,
GpuArrayType
)
...
@@ -209,14 +209,12 @@ class DnnBase(COp):
...
@@ -209,14 +209,12 @@ class DnnBase(COp):
return
node
.
outputs
[
0
]
.
type
.
context_name
return
node
.
outputs
[
0
]
.
type
.
context_name
def
get_params
(
self
,
node
):
def
get_params
(
self
,
node
):
try
:
ctx
=
self
.
dnn_context
(
node
)
return
get_prop
(
self
.
dnn_context
(
node
),
'cudnn_handle_param'
)
if
not
hasattr
(
ctx
,
'cudnn_handle_param'
):
except
KeyError
:
ptr
=
ctx
.
cudnn_handle
.
value
pass
res
=
handle_type
.
make_value
(
ptr
)
ptr
=
get_prop
(
self
.
dnn_context
(
node
),
'cudnn_handle'
)
.
value
ctx
.
cudnn_handle_param
=
res
res
=
handle_type
.
make_value
(
ptr
)
return
ctx
.
cudnn_handle_param
set_prop
(
self
.
dnn_context
(
node
),
'cudnn_handle_param'
,
res
)
return
res
def
__init__
(
self
,
files
=
None
,
c_func
=
None
):
def
__init__
(
self
,
files
=
None
,
c_func
=
None
):
if
files
is
None
:
if
files
is
None
:
...
...
theano/gpuarray/type.py
浏览文件 @
ff120e15
...
@@ -97,26 +97,6 @@ def list_contexts():
...
@@ -97,26 +97,6 @@ def list_contexts():
"""
"""
return
_context_reg
.
keys
()
return
_context_reg
.
keys
()
# Mappings of properties to contexts. Please never use this if you
# can avoid it.
# This is basically a way to store "global" variables that depend on
# the context.
_props_map
=
{}
def
_get_props
(
name
):
ctx
=
get_context
(
name
)
return
_props_map
[
ctx
]
def
get_prop
(
name
,
k
):
return
_get_props
(
name
)[
k
]
def
set_prop
(
name
,
k
,
v
):
_get_props
(
name
)[
k
]
=
v
# Private method
# Private method
def
_name_for_ctx
(
ctx
):
def
_name_for_ctx
(
ctx
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论