Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f6050ea8
提交
f6050ea8
authored
11月 29, 2010
作者:
Josh Bleecher Snyder
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
backout ab866c953440
上级
7b011a76
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
17 行增加
和
41 行删除
+17
-41
__init__.py
theano/sandbox/cuda/__init__.py
+4
-1
cuda_ndarray.cu
theano/sandbox/cuda/cuda_ndarray.cu
+13
-40
没有找到文件。
theano/sandbox/cuda/__init__.py
浏览文件 @
f6050ea8
import
atexit
,
os
,
stat
import
atexit
,
gc
,
os
,
stat
from
theano.compile
import
optdb
from
theano.compile
import
optdb
from
theano
import
config
from
theano
import
config
...
@@ -96,6 +96,9 @@ if cuda_available:
...
@@ -96,6 +96,9 @@ if cuda_available:
cuda_initialization_error_message
=
""
cuda_initialization_error_message
=
""
# actively closing our gpu session presents segfault-on-exit on some systems
# actively closing our gpu session presents segfault-on-exit on some systems
atexit
.
register
(
gpu_shutdown
)
atexit
.
register
(
gpu_shutdown
)
# do garbage collection before releasing the gpu to avoid releasing invalid pointers later
# note that atexit-registered calls are called in LIFO order
atexit
.
register
(
gc
.
collect
)
except
EnvironmentError
,
e
:
except
EnvironmentError
,
e
:
cuda_available
=
False
cuda_available
=
False
cuda_initialization_error_message
=
e
.
message
cuda_initialization_error_message
=
e
.
message
...
...
theano/sandbox/cuda/cuda_ndarray.cu
浏览文件 @
f6050ea8
...
@@ -12,43 +12,12 @@
...
@@ -12,43 +12,12 @@
//If true, we fill with NAN allocated device memory.
//If true, we fill with NAN allocated device memory.
#define ALLOC_MEMSET 0
#define ALLOC_MEMSET 0
#define DEBUG_GPU_CONTEXT_REFCOUNT 0
// g_gpu_context_refcount starts at one b/c the gpu context will be implicitly created
// on the first successful cuda call. the matching decref is in CudaNdarray_gpu_shutdown.
static int g_gpu_context_refcount = 1;
///////////////////////////
// cuda context management
///////////////////////////
void gpu_context_incref() {
g_gpu_context_refcount++;
#if DEBUG_GPU_CONTEXT_REFCOUNT
fprintf(stderr, "gpu_context_incref, to %d\n", g_gpu_context_refcount);
#endif
}
void gpu_context_decref() {
g_gpu_context_refcount--;
#if DEBUG_GPU_CONTEXT_REFCOUNT
fprintf(stderr, "gpu_context_decref, to %d\n", g_gpu_context_refcount);
#endif
if(g_gpu_context_refcount == 0) {
// we're now free to close the cuda context; if we don't explicitly
// exit our cuda context, some systems segfault on process exit
// for as-yet unknown reasons; see
// http://groups.google.com/group/theano-users/browse_thread/thread/c351846e5cebe35f
cudaThreadExit();
#if DEBUG_GPU_CONTEXT_REFCOUNT
fprintf(stderr, "gpu_context_decref at 0, calling cudaThreadExit\n");
#endif
}
}
/////////////////////////
/////////////////////////
// Alloc and Free
// Alloc and Free
/////////////////////////
/////////////////////////
static int g_gpu_shutdown = 0;
/**
/**
*
*
* In the test program I'm using, the _outstanding_mallocs decreases with every call.
* In the test program I'm using, the _outstanding_mallocs decreases with every call.
...
@@ -80,9 +49,6 @@ void * device_malloc(size_t size)
...
@@ -80,9 +49,6 @@ void * device_malloc(size_t size)
return NULL;
return NULL;
}
}
_outstanding_mallocs[0] += (rval != NULL);
_outstanding_mallocs[0] += (rval != NULL);
if(rval != NULL) {
gpu_context_incref(); // keep the gpu context around until we've free this memory
}
#if COMPUTE_GPU_MEM_USED
#if COMPUTE_GPU_MEM_USED
for(int i=0;i<TABLE_SIZE;i++){
for(int i=0;i<TABLE_SIZE;i++){
if(NULL==_alloc_size_table[i].ptr){
if(NULL==_alloc_size_table[i].ptr){
...
@@ -116,9 +82,6 @@ int device_free(void *ptr)
...
@@ -116,9 +82,6 @@ int device_free(void *ptr)
return -1;
return -1;
}
}
_outstanding_mallocs[0] -= (ptr != NULL);
_outstanding_mallocs[0] -= (ptr != NULL);
if(ptr != NULL) {
gpu_context_decref();
}
#if COMPUTE_GPU_MEM_USED
#if COMPUTE_GPU_MEM_USED
int i=0;
int i=0;
for(;i<TABLE_SIZE;i++)
for(;i<TABLE_SIZE;i++)
...
@@ -132,6 +95,16 @@ int device_free(void *ptr)
...
@@ -132,6 +95,16 @@ int device_free(void *ptr)
if(i==TABLE_SIZE)
if(i==TABLE_SIZE)
printf("Unallocated unknow size!\n");
printf("Unallocated unknow size!\n");
#endif
#endif
if(g_gpu_shutdown && (0 == _outstanding_mallocs[0])) {
// we're done with the gpu, and all relevant memory has been freed
// we're now free to close the cuda context; if we don't explicitly
// exit our cuda context, some systems segfault on process exit
// for as-yet unknown reasons; see
// http://groups.google.com/group/theano-users/browse_thread/thread/c351846e5cebe35f
cudaThreadExit();
}
return 0;
return 0;
}
}
static PyObject *
static PyObject *
...
@@ -1926,7 +1899,7 @@ CudaNdarray_gpu_init(PyObject* _unused, PyObject* args)
...
@@ -1926,7 +1899,7 @@ CudaNdarray_gpu_init(PyObject* _unused, PyObject* args)
PyObject *
PyObject *
CudaNdarray_gpu_shutdown(PyObject* _unused, PyObject* _unused_args) {
CudaNdarray_gpu_shutdown(PyObject* _unused, PyObject* _unused_args) {
g
pu_context_decref()
;
g
_gpu_shutdown = 1
;
Py_INCREF(Py_None);
Py_INCREF(Py_None);
return Py_None;
return Py_None;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论