Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3e3b384b
提交
3e3b384b
authored
6月 22, 2017
作者:
João Victor Tozatti Risso
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use theano_prep_output to allocate output in spatialtf_grid C implementation
Signed-off-by:
João Victor Tozatti Risso
<
joaovictor.risso@gmail.com
>
上级
dedc5aef
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
20 行增加
和
26 行删除
+20
-26
spatialtf_grid.c
theano/gpuarray/c_code/spatialtf_grid.c
+20
-26
没有找到文件。
theano/gpuarray/c_code/spatialtf_grid.c
浏览文件 @
3e3b384b
#section support_code
#section support_code
int
spatialtf_grid
(
cudnnSpatialTransformerDescriptor_t
desc
,
int
spatialtf_grid
(
cudnnSpatialTransformerDescriptor_t
desc
,
PyGpuArrayObject
*
theta
,
PyGpuArrayObject
*
theta
,
PyArrayObject
*
dimensions
,
PyArrayObject
*
grid_
dimensions
,
PyGpuArrayObject
**
grid
,
PyGpuArrayObject
**
grid
,
cudnnHandle_t
_handle
)
cudnnHandle_t
_handle
)
{
{
PyGpuContextObject
*
gpu_ctx
=
theta
->
context
;
PyGpuContextObject
*
gpu_ctx
=
theta
->
context
;
cudnnDataType_t
dt
;
cudnnStatus_t
err
;
cudnnStatus_t
err
;
// Obtain GPU datatype from theta
if
(
theta
->
ga
.
typecode
!=
GA_FLOAT
&&
switch
(
theta
->
ga
.
typecode
)
theta
->
ga
.
typecode
!=
GA_DOUBLE
&&
theta
->
ga
.
typecode
!=
GA_HALF
)
{
{
case
GA_FLOAT
:
dt
=
CUDNN_DATA_FLOAT
;
break
;
case
GA_DOUBLE
:
dt
=
CUDNN_DATA_DOUBLE
;
break
;
case
GA_HALF
:
dt
=
CUDNN_DATA_HALF
;
break
;
default:
PyErr_SetString
(
PyExc_TypeError
,
"Unsupported data type for theta"
);
PyErr_SetString
(
PyExc_TypeError
,
"Unsupported data type for theta"
);
return
-
1
;
return
-
1
;
}
}
if
(
NULL
==
*
grid
)
if
(
PyArray_NDIM
(
grid_dimensions
)
<
4
)
{
{
PyErr_Format
(
PyExc_RuntimeError
,
"Grid dimensions array must have at least 4 dimensions!"
);
return
-
1
;
}
// Obtain grid dimensions
// Obtain grid dimensions
npy_int
*
dimensions_data
=
(
npy_int
*
)
PyArray_DATA
(
dimensions
);
npy_int
*
dimensions_data
=
(
npy_int
*
)
PyArray_DATA
(
grid_dimensions
);
const
size_t
width
=
dimensions_data
[
0
];
const
size_t
width
=
dimensions_data
[
0
];
const
size_t
height
=
dimensions_data
[
1
];
const
size_t
height
=
dimensions_data
[
1
];
const
size_t
num_images
=
dimensions_data
[
3
];
const
size_t
num_images
=
dimensions_data
[
3
];
// Grid of coordinates is of size num_images * height * width * 2 for a 2D transformation
// Grid of coordinates is of size num_images * height * width * 2 for a 2D transformation
const
size_t
grid_dims
[
4
]
=
{
width
,
height
,
2
,
num_images
};
const
size_t
grid_dims
[
4
]
=
{
width
,
height
,
2
,
num_images
};
*
grid
=
pygpu_empty
(
4
,
&
(
grid_dims
[
0
]),
theta
->
ga
.
typecode
,
GA_C_ORDER
,
if
(
theano_prep_output
(
grid
,
4
,
&
(
grid_dims
[
0
]),
theta
->
ga
.
typecode
,
gpu_ctx
,
Py_None
);
GA_C_ORDER
,
gpu_ctx
)
!=
0
)
if
(
NULL
==
*
grid
)
{
{
PyErr_Format
(
PyExc_MemoryError
,
PyErr_SetString
(
PyExc_MemoryError
,
"Could not allocate memory for grid coordinates"
);
"Could not allocate memory for the grid of coordinates"
);
return
1
;
return
-
1
;
}
}
}
const
void
*
theta_data
=
PyGpuArray_DEV_DATA
(
theta
);
const
void
*
theta_data
=
PyGpuArray_DEV_DATA
(
theta
);
...
@@ -58,7 +52,7 @@ int spatialtf_grid(cudnnSpatialTransformerDescriptor_t desc,
...
@@ -58,7 +52,7 @@ int spatialtf_grid(cudnnSpatialTransformerDescriptor_t desc,
PyErr_Format
(
PyExc_RuntimeError
,
PyErr_Format
(
PyExc_RuntimeError
,
"Failed to create grid of coordinates: %s"
,
"Failed to create grid of coordinates: %s"
,
cudnnGetErrorString
(
err
)
);
cudnnGetErrorString
(
err
)
);
return
1
;
return
-
1
;
}
}
return
0
;
return
0
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论