Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cb20f65e
提交
cb20f65e
authored
6月 24, 2017
作者:
João Victor Tozatti Risso
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tensor descriptor initialization and fix memory alloc for output in spatialtf_sampler
Signed-off-by:
João Victor Tozatti Risso
<
joaovictor.risso@gmail.com
>
上级
7bc63958
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
62 行增加
和
17 行删除
+62
-17
spatialtf_sampler.c
theano/gpuarray/c_code/spatialtf_sampler.c
+62
-17
没有找到文件。
theano/gpuarray/c_code/spatialtf_sampler.c
浏览文件 @
cb20f65e
...
@@ -23,12 +23,13 @@ void spatialtf_context_destroy( spatialtf_context_t * ctx )
...
@@ -23,12 +23,13 @@ void spatialtf_context_destroy( spatialtf_context_t * ctx )
#section support_code_struct
#section support_code_struct
int
int
spatialtf_sampler
(
PyGpuArrayObject
*
input
,
spatialtf_sampler
(
PyGpuArrayObject
*
input
,
PyGpuArrayObject
*
om
,
PyGpuArrayObject
*
om
,
PyGpuArrayObject
*
grid
,
PyGpuArrayObject
*
grid
,
PyArrayObject
*
grid_dimensions
,
cudnnSpatialTransformerDescriptor_t
desc
,
cudnnSpatialTransformerDescriptor_t
desc
,
double
alpha
,
double
beta
,
double
alpha
,
double
beta
,
PyGpuArrayObject
**
output
,
PyGpuArrayObject
**
output
,
cudnnHandle_t
_handle
)
cudnnHandle_t
_handle
)
{
{
PyGpuContextObject
*
gpu_ctx
=
input
->
context
;
PyGpuContextObject
*
gpu_ctx
=
input
->
context
;
...
@@ -36,18 +37,32 @@ spatialtf_sampler(PyGpuArrayObject *input,
...
@@ -36,18 +37,32 @@ spatialtf_sampler(PyGpuArrayObject *input,
void
*
beta_p
;
void
*
beta_p
;
float
af
=
alpha
,
bf
=
beta
;
float
af
=
alpha
,
bf
=
beta
;
spatialtf_context_t
spatialtf_ctx
;
spatialtf_context_t
spatialtf_ctx
;
cudnnDataType_t
dt
;
cudnnStatus_t
err
=
CUDNN_STATUS_SUCCESS
;
cudnnStatus_t
err
=
CUDNN_STATUS_SUCCESS
;
switch
(
input
->
ga
.
typecode
)
// Obtain grid dimensions
npy_int
*
dimensions_data
=
(
npy_int
*
)
PyArray_DATA
(
grid_dimensions
);
const
int
width
=
dimensions_data
[
0
];
const
int
height
=
dimensions_data
[
1
];
const
int
num_channels
=
dimensions_data
[
2
];
const
int
num_images
=
dimensions_data
[
3
];
switch
(
grid
->
ga
.
typecode
)
{
{
case
GA_DOUBLE
:
case
GA_DOUBLE
:
alpha_p
=
(
void
*
)
&
alpha
;
alpha_p
=
(
void
*
)
&
alpha
;
beta_p
=
(
void
*
)
&
beta
;
beta_p
=
(
void
*
)
&
beta
;
dt
=
CUDNN_DATA_DOUBLE
;
break
;
break
;
case
GA_FLOAT
:
case
GA_FLOAT
:
alpha_p
=
(
void
*
)
&
af
;
beta_p
=
(
void
*
)
&
bf
;
dt
=
CUDNN_DATA_FLOAT
;
break
;
case
GA_HALF
:
case
GA_HALF
:
alpha_p
=
(
void
*
)
&
af
;
alpha_p
=
(
void
*
)
&
af
;
beta_p
=
(
void
*
)
&
bf
;
beta_p
=
(
void
*
)
&
bf
;
dt
=
CUDNN_DATA_HALF
;
break
;
break
;
default:
default:
PyErr_SetString
(
PyExc_TypeError
,
PyErr_SetString
(
PyExc_TypeError
,
...
@@ -55,14 +70,6 @@ spatialtf_sampler(PyGpuArrayObject *input,
...
@@ -55,14 +70,6 @@ spatialtf_sampler(PyGpuArrayObject *input,
return
-
1
;
return
-
1
;
}
}
if
(
grid
->
ga
.
typecode
!=
GA_FLOAT
&&
grid
->
ga
.
typecode
!=
GA_DOUBLE
&&
grid
->
ga
.
typecode
!=
GA_HALF
)
{
PyErr_SetString
(
PyExc_TypeError
,
"Unsupported data type for grid"
);
return
-
1
;
}
spatialtf_context_init
(
&
spatialtf_ctx
);
spatialtf_context_init
(
&
spatialtf_ctx
);
cuda_enter
(
gpu_ctx
->
ctx
);
cuda_enter
(
gpu_ctx
->
ctx
);
...
@@ -80,12 +87,17 @@ spatialtf_sampler(PyGpuArrayObject *input,
...
@@ -80,12 +87,17 @@ spatialtf_sampler(PyGpuArrayObject *input,
return
-
1
;
return
-
1
;
}
}
if
(
theano_prep_output
(
output
,
PyGpuArray_NDIM
(
om
),
PyGpuArray_DIMS
(
om
),
grid
->
ga
.
typecode
,
err
=
cudnnSetTensor4dDescriptor
(
spatialtf_ctx
.
xdesc
,
CUDNN_TENSOR_NCHW
,
dt
,
GA_C_ORDER
,
gpu_ctx
)
!=
0
)
num_images
,
num_channels
,
height
,
width
);
if
(
err
!=
CUDNN_STATUS_SUCCESS
)
{
{
spatialtf_context_destroy
(
&
spatialtf_ctx
);
spatialtf_context_destroy
(
&
spatialtf_ctx
);
cuda_exit
(
gpu_ctx
->
ctx
);
cuda_exit
(
gpu_ctx
->
ctx
);
PyErr_Format
(
PyExc_RuntimeError
,
"Could not initialize xdesc: %s"
,
cudnnGetErrorString
(
err
)
);
return
-
1
;
return
-
1
;
}
}
...
@@ -102,9 +114,42 @@ spatialtf_sampler(PyGpuArrayObject *input,
...
@@ -102,9 +114,42 @@ spatialtf_sampler(PyGpuArrayObject *input,
return
-
1
;
return
-
1
;
}
}
err
=
cudnnSetTensor4dDescriptor
(
spatialtf_ctx
.
ydesc
,
CUDNN_TENSOR_NCHW
,
dt
,
num_images
,
num_channels
,
height
,
width
);
if
(
err
!=
CUDNN_STATUS_SUCCESS
)
{
spatialtf_context_destroy
(
&
spatialtf_ctx
);
cuda_exit
(
gpu_ctx
->
ctx
);
PyErr_Format
(
PyExc_RuntimeError
,
"Could not initialize ydesc: %s"
,
cudnnGetErrorString
(
err
)
);
return
-
1
;
}
if
(
NULL
==
*
output
)
{
*
output
=
pygpu_zeros
(
PyGpuArray_NDIM
(
om
),
PyGpuArray_DIMS
(
om
),
input
->
ga
.
typecode
,
GA_C_ORDER
,
gpu_ctx
,
Py_None
);
if
(
NULL
==
*
output
)
{
spatialtf_context_destroy
(
&
spatialtf_ctx
);
cuda_exit
(
gpu_ctx
->
ctx
);
PyErr_SetString
(
PyExc_MemoryError
,
"Could allocate memory for spatial transformer's grid sampler"
);
return
-
1
;
}
}
const
void
*
input_data
=
PyGpuArray_DEV_DATA
(
input
);
const
void
*
grid_data
=
PyGpuArray_DEV_DATA
(
grid
);
void
*
out_data
=
PyGpuArray_DEV_DATA
(
*
output
);
err
=
cudnnSpatialTfSamplerForward
(
_handle
,
desc
,
alpha_p
,
spatialtf_ctx
.
xdesc
,
err
=
cudnnSpatialTfSamplerForward
(
_handle
,
desc
,
alpha_p
,
spatialtf_ctx
.
xdesc
,
PyGpuArray_DEV_DATA
(
input
),
PyGpuArray_DEV_DATA
(
grid
),
beta_p
,
input_data
,
grid_data
,
beta_p
,
spatialtf_ctx
.
ydesc
,
out_data
);
spatialtf_ctx
.
ydesc
,
PyGpuArray_DEV_DATA
(
*
output
)
);
if
(
CUDNN_STATUS_SUCCESS
!=
err
)
if
(
CUDNN_STATUS_SUCCESS
!=
err
)
{
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论