Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
130d2ce9
提交
130d2ce9
authored
7月 21, 2015
作者:
Julien Demouth
提交者:
Frederic
7月 23, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for CNMeM library.
Update the code to support CNMeM (formerly known as Cumem).
上级
389c4aba
全部展开
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
51 行增加
和
48 行删除
+51
-48
MANIFEST.in
MANIFEST.in
+1
-0
setup.py
setup.py
+1
-1
__init__.py
theano/sandbox/cuda/__init__.py
+7
-6
cnmem.cpp
theano/sandbox/cuda/cnmem.cpp
+0
-0
cnmem.h
theano/sandbox/cuda/cnmem.h
+0
-0
cuda_ndarray.cu
theano/sandbox/cuda/cuda_ndarray.cu
+42
-41
cumem.cpp
theano/sandbox/cuda/cumem.cpp
+0
-0
没有找到文件。
MANIFEST.in
浏览文件 @
130d2ce9
...
...
@@ -2,6 +2,7 @@ global-include *.txt
global-include *.c
global-include *.cu
global-include *.cuh
global-include *.cpp
global-include *.h
global-include *.sh
global-include *.pkl
...
...
setup.py
浏览文件 @
130d2ce9
...
...
@@ -164,7 +164,7 @@ def do_setup():
install_requires
=
[
'numpy>=1.6.2'
,
'scipy>=0.11'
,
'six>=1.9.0'
],
package_data
=
{
''
:
[
'*.txt'
,
'*.rst'
,
'*.cu'
,
'*.cuh'
,
'*.c'
,
'*.sh'
,
'*.pkl'
,
'*.h'
,
'ChangeLog'
],
'*.h'
,
'
*.cpp'
,
'
ChangeLog'
],
'theano.misc'
:
[
'*.sh'
]
},
scripts
=
[
'bin/theano-cache'
,
'bin/theano-nose'
,
'bin/theano-test'
],
...
...
theano/sandbox/cuda/__init__.py
浏览文件 @
130d2ce9
...
...
@@ -54,8 +54,8 @@ AddConfigVar('cublas.lib',
"""Name of the cuda blas library for the linker."""
,
StrParam
(
'cublas'
))
AddConfigVar
(
'lib.c
u
mem'
,
"""Do we enable c
u
mem or not."""
,
AddConfigVar
(
'lib.c
n
mem'
,
"""Do we enable c
n
mem or not."""
,
# We should not mix both allocator, so we can't override
BoolParam
(
False
,
allow_override
=
False
),
in_c_key
=
False
)
...
...
@@ -385,7 +385,7 @@ def use(device,
try
:
if
(
device
!=
'gpu'
)
and
not
pycuda_init_dev
:
assert
isinstance
(
device
,
int
)
gpu_init
(
device
,
config
.
lib
.
c
u
mem
)
gpu_init
(
device
,
config
.
lib
.
c
n
mem
)
use
.
device_number
=
device
assert
active_device_number
()
==
device
else
:
...
...
@@ -398,7 +398,7 @@ def use(device,
cuda_ndarray
.
cuda_ndarray
.
select_a_gpu
()
use
.
device_number
=
active_device_number
()
# This is needed to initialize the cublas handle.
gpu_init
(
use
.
device_number
,
config
.
lib
.
c
u
mem
)
gpu_init
(
use
.
device_number
,
config
.
lib
.
c
n
mem
)
if
test_driver
:
import
theano.sandbox.cuda.tests.test_driver
...
...
@@ -411,8 +411,9 @@ def use(device,
" this property"
)
if
config
.
print_active_device
:
print
(
"Using gpu device
%
d:
%
s"
%
(
active_device_number
(),
active_device_name
()),
file
=
sys
.
stderr
)
cnmem_enabled
=
"enabled"
if
config
.
lib
.
cnmem
else
"disabled"
print
(
"Using gpu device
%
d:
%
s (cnmem is
%
s)"
%
(
active_device_number
(),
active_device_name
(),
cnmem_enabled
),
file
=
sys
.
stderr
)
if
device_properties
(
use
.
device_number
)[
'regsPerBlock'
]
<
16384
:
# We will try to use too much register per bloc at many places
# when there is only 8k register per multi-processor.
...
...
theano/sandbox/cuda/cnmem.cpp
0 → 100644
浏览文件 @
130d2ce9
差异被折叠。
点击展开。
theano/sandbox/cuda/c
u
mem.h
→
theano/sandbox/cuda/c
n
mem.h
浏览文件 @
130d2ce9
差异被折叠。
点击展开。
theano/sandbox/cuda/cuda_ndarray.cu
浏览文件 @
130d2ce9
...
...
@@ -9,8 +9,8 @@
#include "cuda_ndarray.cuh"
#include "c
u
mem.h"
#include "c
u
mem.cpp"
#include "c
n
mem.h"
#include "c
n
mem.cpp"
//If true, when there is a gpu malloc or free error, we print the size of allocated memory on the device.
#define COMPUTE_GPU_MEM_USED 0
...
...
@@ -71,20 +71,20 @@ void * device_malloc(size_t size)
}
///@TODO: thejaswi: link this option to a theano config variable?
static
bool
g_use_c
u
mem
=
false
;
static
bool
g_use_c
n
mem
=
false
;
static
const
int
g_max_devices
=
8
;
int
initC
u
mem
(
int
card_number_provided
,
int
card_nb
)
{
static
bool
c
u
memInitialized
=
false
;
if
(
c
u
memInitialized
)
{
int
initC
n
mem
(
int
card_number_provided
,
int
card_nb
)
{
static
bool
c
n
memInitialized
=
false
;
if
(
c
n
memInitialized
)
{
return
0
;
}
// On stderr to be at the same place as "Using gpu device..."
fprintf
(
stderr
,
"Initializing c
u
mem...
\n
"
);
fprintf
(
stderr
,
"Initializing c
n
mem...
\n
"
);
int
numDevices
=
0
;
c
u
memDevice_t
devices
[
g_max_devices
];
c
n
memDevice_t
devices
[
g_max_devices
];
if
(
cudaGetDeviceCount
(
&
numDevices
)
!=
cudaSuccess
)
{
PyErr_Format
(
PyExc_RuntimeError
,
"initC
u
mem: 'cudaGetDeviceCount' failed! Reason=%s
\n
"
,
"initC
n
mem: 'cudaGetDeviceCount' failed! Reason=%s
\n
"
,
cudaGetErrorString
(
cudaGetLastError
()));
return
-
1
;
}
...
...
@@ -97,7 +97,6 @@ int initCumem(int card_number_provided, int card_nb) {
///@TODO: thejaswi: add support for multiple streams
devices
[
i
].
numStreams
=
0
;
devices
[
i
].
streams
=
NULL
;
devices
[
i
].
granularity
=
0
;
}
else
{
for
(
int
i
=
0
;
i
<
numDevices
;
++
i
)
{
...
...
@@ -107,19 +106,18 @@ int initCumem(int card_number_provided, int card_nb) {
///@TODO: thejaswi: add support for multiple streams
devices
[
i
].
numStreams
=
0
;
devices
[
i
].
streams
=
NULL
;
devices
[
i
].
granularity
=
0
;
}
}
///@TODO: thejaswi: passing custom c
u
mem flags?
c
umemStatus_t
status
=
cumemInit
(
numDevices
,
devices
,
CU
MEM_FLAGS_DEFAULT
);
if
(
status
!=
C
U
MEM_STATUS_SUCCESS
)
{
///@TODO: thejaswi: passing custom c
n
mem flags?
c
nmemStatus_t
status
=
cnmemInit
(
numDevices
,
devices
,
CN
MEM_FLAGS_DEFAULT
);
if
(
status
!=
C
N
MEM_STATUS_SUCCESS
)
{
PyErr_Format
(
PyExc_RuntimeError
,
"initC
umem: cu
memInit call failed! Reason=%s. numdev=%d
\n
"
,
c
u
memGetErrorString
(
status
),
numDevices
);
"initC
nmem: cn
memInit call failed! Reason=%s. numdev=%d
\n
"
,
c
n
memGetErrorString
(
status
),
numDevices
);
return
-
1
;
}
c
u
memInitialized
=
true
;
c
n
memInitialized
=
true
;
return
0
;
}
...
...
@@ -138,12 +136,15 @@ void * device_malloc(size_t size, int verbose)
#endif
void
*
rval
=
NULL
;
///@TODO: thejaswi: support for multiple-streams?
if
(
g_use_cumem
)
{
cumemStatus_t
status
=
cumemMalloc
(
&
rval
,
size
,
NULL
);
if
(
status
!=
CUMEM_STATUS_SUCCESS
)
{
if
(
g_use_cnmem
)
{
cnmemStatus_t
status
=
CNMEM_STATUS_SUCCESS
;
if
(
size
!=
0
)
{
status
=
cnmemMalloc
(
&
rval
,
size
,
NULL
);
}
if
(
status
!=
CNMEM_STATUS_SUCCESS
)
{
PyErr_Format
(
PyExc_MemoryError
,
"Error allocating %zd bytes of device memory (%s)."
,
size
,
c
u
memGetErrorString
(
status
));
size
,
c
n
memGetErrorString
(
status
));
return
NULL
;
}
}
...
...
@@ -271,11 +272,11 @@ int device_free(void *ptr)
}
///@TODO: thejaswi: multi-stream support
if
(
g_use_c
u
mem
)
{
c
umemStatus_t
status
=
cu
memFree
(
ptr
,
NULL
);
if
(
status
!=
C
U
MEM_STATUS_SUCCESS
)
{
fprintf
(
stderr
,
"device_free: c
u
memFree call failed! Reason=%s
\n
"
,
c
u
memGetErrorString
(
status
));
if
(
g_use_c
n
mem
)
{
c
nmemStatus_t
status
=
cn
memFree
(
ptr
,
NULL
);
if
(
status
!=
C
N
MEM_STATUS_SUCCESS
)
{
fprintf
(
stderr
,
"device_free: c
n
memFree call failed! Reason=%s
\n
"
,
c
n
memGetErrorString
(
status
));
}
}
else
{
...
...
@@ -3134,22 +3135,22 @@ CudaNdarray_ptr_int_size(PyObject* _unused, PyObject* args)
static
int
cublas_init
();
static
void
cublas_shutdown
();
// Initialize the gpu.
// Takes two optional parameters, the device number and if we should use c
u
mem.
// Takes two optional parameters, the device number and if we should use c
n
mem.
// If the device number is provided, it sets that device to be the active device.
// If not provided (usually just to test whether the gpu is available at all),
// it does not set an active device.
// Raises EnvironmentError or ValueError (as appropriate) if the initialization failed.
// c
umem is threaded like a bool. If converted to 0, don't use cu
mem. Otherwise, use it.
// c
nmem is threaded like a bool. If converted to 0, don't use cn
mem. Otherwise, use it.
PyObject
*
CudaNdarray_gpu_init
(
PyObject
*
_unused
,
PyObject
*
args
)
{
int
card_nb
=
0
;
int
card_number_provided
=
1
;
int
c
u
mem
=
0
;
// 0 False, 1 True
int
c
n
mem
=
0
;
// 0 False, 1 True
// if we're given something wildly invalid, this will throw a TypeError
PyArg_ParseTuple
(
args
,
"|ii"
,
&
card_nb
,
&
c
u
mem
);
if
(
c
u
mem
)
g_use_c
u
mem
=
true
;
PyArg_ParseTuple
(
args
,
"|ii"
,
&
card_nb
,
&
c
n
mem
);
if
(
c
n
mem
)
g_use_c
n
mem
=
true
;
if
(
PyTuple_Size
(
args
)
==
0
)
{
card_number_provided
=
0
;
...
...
@@ -3204,8 +3205,8 @@ CudaNdarray_gpu_init(PyObject* _unused, PyObject* args)
if
(
cublas_init
()
==
-
1
)
return
NULL
;
}
if
(
card_number_provided
&&
g_use_c
u
mem
)
{
if
(
initC
u
mem
(
card_number_provided
,
card_nb
)
==
-
1
){
if
(
card_number_provided
&&
g_use_c
n
mem
)
{
if
(
initC
n
mem
(
card_number_provided
,
card_nb
)
==
-
1
){
return
NULL
;
}
}
...
...
@@ -3240,13 +3241,13 @@ CudaNdarray_gpu_shutdown(PyObject* _unused, PyObject* _unused_args) {
// Don't handle errors here
cublas_shutdown
();
g_gpu_context_active
=
0
;
// context has now been closed down
if
(
g_use_c
u
mem
)
{
fprintf
(
stderr
,
"Shutting down c
u
mem...
\n
"
);
c
umemStatus_t
status
=
cu
memFinalize
();
if
(
status
!=
C
UMEM_STATUS_SUCCESS
)
{
fprintf
(
stderr
,
"CudaNdarray_gpu_shutdown: c
u
memFinalize failed! Reason=%s
\n
"
,
c
u
memGetErrorString
(
status
));
if
(
status
==
C
U
MEM_STATUS_CUDA_ERROR
)
{
if
(
g_use_c
n
mem
)
{
fprintf
(
stderr
,
"Shutting down c
n
mem...
\n
"
);
c
nmemStatus_t
status
=
cn
memFinalize
();
if
(
status
!=
C
NMEM_STATUS_SUCCESS
&&
status
!=
CNMEM_STATUS_MEMORY_LEAK
)
{
fprintf
(
stderr
,
"CudaNdarray_gpu_shutdown: c
n
memFinalize failed! Reason=%s
\n
"
,
c
n
memGetErrorString
(
status
));
if
(
status
==
C
N
MEM_STATUS_CUDA_ERROR
)
{
fprintf
(
stderr
,
" Cuda-Reason=%s
\n
"
,
cudaGetErrorString
(
cudaGetLastError
()));
}
...
...
theano/sandbox/cuda/cumem.cpp
deleted
100644 → 0
浏览文件 @
389c4aba
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论