Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d08a40fa
提交
d08a40fa
authored
7月 20, 2015
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactore the new code
上级
574e7965
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
74 行增加
和
116 行删除
+74
-116
basic_ops.py
theano/sandbox/cuda/basic_ops.py
+7
-55
cuda_ndarray.cu
theano/sandbox/cuda/cuda_ndarray.cu
+4
-60
cuda_ndarray.cuh
theano/sandbox/cuda/cuda_ndarray.cuh
+63
-1
没有找到文件。
theano/sandbox/cuda/basic_ops.py
浏览文件 @
d08a40fa
...
@@ -2974,7 +2974,7 @@ class GpuAdvancedIncSubtensor1_dev20(GpuAdvancedIncSubtensor1):
...
@@ -2974,7 +2974,7 @@ class GpuAdvancedIncSubtensor1_dev20(GpuAdvancedIncSubtensor1):
return
Apply
(
self
,
[
x_
,
y_
,
ilist_
],
[
x_
.
type
()])
return
Apply
(
self
,
[
x_
,
y_
,
ilist_
],
[
x_
.
type
()])
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
5
,)
return
(
6
,)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
active_device_no
=
theano
.
sandbox
.
cuda
.
active_device_number
()
active_device_no
=
theano
.
sandbox
.
cuda
.
active_device_number
()
...
@@ -3048,23 +3048,8 @@ class GpuAdvancedIncSubtensor1_dev20(GpuAdvancedIncSubtensor1):
...
@@ -3048,23 +3048,8 @@ class GpuAdvancedIncSubtensor1_dev20(GpuAdvancedIncSubtensor1):
int CudaNdarray_vector_add_fast(CudaNdarray* py_self,
int CudaNdarray_vector_add_fast(CudaNdarray* py_self,
CudaNdarray* py_other, PyArrayObject *indices_arr)
CudaNdarray* py_other, PyArrayObject *indices_arr)
{
{
if (err_var == NULL) {
if(init_err_var()!= 0) return -1;
err_var = (int*)device_malloc(sizeof(int));
if (!err_var) { // PyErr set by device_malloc
return -1;
}
cudaError_t err = cudaMemset((void*)err_var, 0,
sizeof(int));
if (cudaSuccess != err) {
// Clear the error flag, cudaMemset doesn't do it.
cudaGetLastError();
PyErr_Format(
PyExc_RuntimeError,
"Error setting device error code to 0.
%%
s",
cudaGetErrorString(err));
return -1;
}
}
const int *shapeX = CudaNdarray_HOST_DIMS(py_self);
const int *shapeX = CudaNdarray_HOST_DIMS(py_self);
const int *shapeY = CudaNdarray_HOST_DIMS(py_other);
const int *shapeY = CudaNdarray_HOST_DIMS(py_other);
const int *strX = CudaNdarray_HOST_STRIDES(py_self);
const int *strX = CudaNdarray_HOST_STRIDES(py_self);
...
@@ -3112,46 +3097,13 @@ class GpuAdvancedIncSubtensor1_dev20(GpuAdvancedIncSubtensor1):
...
@@ -3112,46 +3097,13 @@ class GpuAdvancedIncSubtensor1_dev20(GpuAdvancedIncSubtensor1):
PyArray_SIZE(indices_arr),
PyArray_SIZE(indices_arr),
err_var
err_var
);
);
int index_err = check_err_var();
//-10 could be any value different then 0.
int cpu_err_var=-10;
CNDA_BEGIN_ALLOW_THREADS
// As we execute cudaMemcpy on the default stream, it waits
// for all kernels (on all streams) to be finished before
// starting to copy
err = cudaMemcpy(&cpu_err_var, err_var, sizeof(int),
cudaMemcpyDeviceToHost);
CNDA_END_ALLOW_THREADS
if (cudaSuccess != err) {
PyErr_Format(
PyExc_RuntimeError,
"Cuda error:
%%
s:
%%
s when trying to get the error"
" value.
\\
n",
"GpuAdvancedIncSubtensor1_dev20",
cudaGetErrorString(err));
return NULL;
}
if (cpu_err_var != 0) {
PyErr_Format(
PyExc_IndexError,
"GpuAdvancedIncSubtensor1_dev20: One of the index"
" value is out of bound. Error code:
%%
i.
\\
n",
cpu_err_var);
// Must reset it to 0 to don't reset it before each use.
err = cudaMemset((void*)err_var, 0, sizeof(int));
if (cudaSuccess != err) {
PyErr_Format(PyExc_MemoryError,
"Error setting device error code to 0 after having"
" an index error.
%%
s", cudaGetErrorString(err));
return -1;
}
return -1;
}
device_free(d_indices_arr);
device_free(d_indices_arr);
Py_XDECREF(cpu_indices_arr);
Py_XDECREF(cpu_indices_arr);
if(index_err != 0) return -1;
err = cudaGetLastError();
err = cudaGetLastError();
if(err != cudaSuccess){
if(err != cudaSuccess){
PyErr_Format(
PyErr_Format(
...
...
theano/sandbox/cuda/cuda_ndarray.cu
浏览文件 @
d08a40fa
...
@@ -1141,30 +1141,7 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){
...
@@ -1141,30 +1141,7 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){
k3
=
k_take_3
<
CPY
>
;
k3
=
k_take_3
<
CPY
>
;
// Create the memory place that will store the error information.
// Create the memory place that will store the error information.
if
(
err_var
==
NULL
)
{
if
(
init_err_var
()
!=
0
)
return
NULL
;
err_var
=
(
int
*
)
device_malloc
(
sizeof
(
int
));
if
(
!
err_var
)
{
// PyErr set by device_malloc
Py_DECREF
(
indices
);
Py_DECREF
(
out
);
free
(
dims
);
return
NULL
;
}
cudaError_t
err
=
cudaMemset
((
void
*
)
err_var
,
0
,
sizeof
(
int
));
if
(
cudaSuccess
!=
err
)
{
// Clear the error flag, cudaMemset doesn't do it.
// Currently this returns the same thing as err, but if in future
// it returns something else I still don't see why we should ignore
// it. All we want to do here is reset the flag.
cudaGetLastError
();
PyErr_Format
(
PyExc_RuntimeError
,
"Error setting device error code to 0. %s"
,
cudaGetErrorString
(
err
));
Py_DECREF
(
indices
);
Py_DECREF
(
out
);
free
(
dims
);
return
NULL
;
}
}
dim3
n_blocks
(
std
::
min
(
CudaNdarray_HOST_DIMS
(
out
)[
0
],
65535
),
1
,
1
);
dim3
n_blocks
(
std
::
min
(
CudaNdarray_HOST_DIMS
(
out
)[
0
],
65535
),
1
,
1
);
if
(
CudaNdarray_HOST_DIMS
(
out
)[
0
]
==
0
){
if
(
CudaNdarray_HOST_DIMS
(
out
)[
0
]
==
0
){
...
@@ -1276,47 +1253,14 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){
...
@@ -1276,47 +1253,14 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){
Py_DECREF
(
out
);
Py_DECREF
(
out
);
return
NULL
;
return
NULL
;
}
}
//-10 could be any value different then 0.
int
cpu_err_var
=-
10
;
CNDA_BEGIN_ALLOW_THREADS
// As we execute cudaMemcpy on the default stream, it waits for all
// kernels (on all streams) to be finished before starting to copy
err
=
cudaMemcpy
(
&
cpu_err_var
,
err_var
,
sizeof
(
int
),
cudaMemcpyDeviceToHost
);
CNDA_END_ALLOW_THREADS
if
(
cudaSuccess
!=
err
)
{
PyErr_Format
(
PyExc_RuntimeError
,
"Cuda error: %s: %s when trying to get the error value.
\n
"
,
"CudaNdarray_TakeFrom"
,
cudaGetErrorString
(
err
));
Py_DECREF
(
indices
);
Py_DECREF
(
out
);
return
NULL
;
}
if
(
cpu_err_var
!=
0
)
{
int
index_err
=
check_err_var
();
PyErr_Format
(
Py_DECREF
(
indices
);
PyExc_IndexError
,
if
(
index_err
!=
0
)
{
"CudaNdarray_TakeFrom: One of the index value is out of bound. Error code: %i.
\n
"
,
cpu_err_var
);
// Must reset it to 0 to don't reset it before each use.
err
=
cudaMemset
((
void
*
)
err_var
,
0
,
sizeof
(
int
));
if
(
cudaSuccess
!=
err
)
{
PyErr_Format
(
PyExc_MemoryError
,
"Error setting device error code to 0 after having an index error. %s"
,
cudaGetErrorString
(
err
));
Py_DECREF
(
indices
);
Py_DECREF
(
out
);
return
NULL
;
}
Py_DECREF
(
indices
);
Py_DECREF
(
out
);
Py_DECREF
(
out
);
return
NULL
;
return
NULL
;
}
}
Py_DECREF
(
indices
);
if
(
verbose
)
printf
(
"TAKE SUCCEDED
\n
"
);
if
(
verbose
)
printf
(
"TAKE SUCCEDED
\n
"
);
return
(
PyObject
*
)
out
;
return
(
PyObject
*
)
out
;
}
}
...
...
theano/sandbox/cuda/cuda_ndarray.cuh
浏览文件 @
d08a40fa
...
@@ -122,7 +122,69 @@ DllExport void *get_work_mem(size_t sz);
...
@@ -122,7 +122,69 @@ DllExport void *get_work_mem(size_t sz);
// When it is allocated, it should always be 0
// When it is allocated, it should always be 0
// So if there is an error, we must reset it to 0 BEFORE we raise the error
// So if there is an error, we must reset it to 0 BEFORE we raise the error
// This prevent us from setting it to 0 before each use
// This prevent us from setting it to 0 before each use
static
int
*
err_var
=
NULL
;
extern
DllExport
int
*
err_var
=
NULL
;
DllExport
inline
int
init_err_var
(){
if
(
err_var
==
NULL
)
{
err_var
=
(
int
*
)
device_malloc
(
sizeof
(
int
));
if
(
!
err_var
)
{
// PyErr set by device_malloc
return
-
1
;
}
cudaError_t
err
=
cudaMemset
((
void
*
)
err_var
,
0
,
sizeof
(
int
));
if
(
cudaSuccess
!=
err
)
{
// Clear the error flag, cudaMemset doesn't do it.
cudaGetLastError
();
PyErr_Format
(
PyExc_RuntimeError
,
"Error setting device error code to 0. %s"
,
cudaGetErrorString
(
err
));
return
-
1
;
}
}
return
0
;
}
DllExport
inline
int
check_err_var
(){
//-10 could be any value different then 0.
int
cpu_err_var
=-
10
;
cudaError_t
err
;
CNDA_BEGIN_ALLOW_THREADS
// As we execute cudaMemcpy on the default stream, it waits
// for all kernels (on all streams) to be finished before
// starting to copy
err
=
cudaMemcpy
(
&
cpu_err_var
,
err_var
,
sizeof
(
int
),
cudaMemcpyDeviceToHost
);
CNDA_END_ALLOW_THREADS
if
(
cudaSuccess
!=
err
)
{
PyErr_Format
(
PyExc_RuntimeError
,
"Cuda error: %s when trying to get the error"
" value.
\\
n"
,
cudaGetErrorString
(
err
));
return
-
1
;
}
if
(
cpu_err_var
!=
0
)
{
PyErr_Format
(
PyExc_IndexError
,
"One of the index value is out of bound. Error code: %i.
\\
n"
,
cpu_err_var
);
// Must reset it to 0 to don't reset it before each use.
err
=
cudaMemset
((
void
*
)
err_var
,
0
,
sizeof
(
int
));
if
(
cudaSuccess
!=
err
)
{
PyErr_Format
(
PyExc_MemoryError
,
"Error setting device error code to 0 after having"
" an index error. %s"
,
cudaGetErrorString
(
err
));
return
-
1
;
}
return
-
1
;
}
return
0
;
}
template
<
typename
T
>
template
<
typename
T
>
static
T
ceil_intdiv
(
T
a
,
T
b
)
static
T
ceil_intdiv
(
T
a
,
T
b
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论