Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b834babe
提交
b834babe
authored
6月 17, 2016
作者:
Ciyong Chen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
forcing gemm to use 1 thread in corrOP, and change PyArray_EMPTY to PyArray_ZEROS
上级
192a59d1
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
31 行增加
和
4 行删除
+31
-4
corr.py
theano/tensor/nnet/corr.py
+24
-3
corr_gemm.c
theano/tensor/nnet/corr_gemm.c
+7
-1
没有找到文件。
theano/tensor/nnet/corr.py
浏览文件 @
b834babe
...
...
@@ -62,6 +62,16 @@ class BaseCorrMM(gof.OpenMPOp):
self
.
subsample
=
tuple
(
subsample
)
self
.
filter_dilation
=
tuple
(
filter_dilation
)
if
not
theano
.
config
.
blas
.
ldflags
:
raise
NotImplementedError
(
"C code for corrMM* classes need a blas library."
)
else
:
if
'openblas'
in
theano
.
config
.
blas
.
ldflags
:
self
.
blas_type
=
'openblas'
elif
'mkl'
in
theano
.
config
.
blas
.
ldflags
:
self
.
blas_type
=
'mkl'
else
:
self
.
blas_type
=
''
@property
def
pad
(
self
):
if
self
.
border_mode
!=
'valid'
:
...
...
@@ -95,6 +105,10 @@ class BaseCorrMM(gof.OpenMPOp):
def
c_headers
(
self
):
headers
=
[
'<stdio.h>'
]
headers
+=
super
(
BaseCorrMM
,
self
)
.
c_headers
()
if
self
.
blas_type
==
'openblas'
:
headers
+=
[
'cblas.h'
]
if
self
.
blas_type
==
'mkl'
:
headers
+=
[
'mkl.h'
]
return
headers
def
c_code_cache_version
(
self
):
...
...
@@ -119,6 +133,7 @@ class BaseCorrMM(gof.OpenMPOp):
sub
[
'float_typenum'
]
=
'NPY_DOUBLE'
sub
[
'n_bytes'
]
=
8
sub
[
'c_float_type'
]
=
'double'
if
self
.
openmp
:
sub
[
'omp_flags'
]
=
'#pragma omp parallel for schedule(static)'
sub
[
'omp_max_threads'
]
=
'omp_get_max_threads()'
...
...
@@ -130,6 +145,13 @@ class BaseCorrMM(gof.OpenMPOp):
sub
[
'omp_set_threads'
]
=
''
sub
[
'omp_get_threads'
]
=
0
if
self
.
blas_type
==
'openblas'
:
sub
[
'blas_flags'
]
=
'openblas_set_num_threads(1)'
elif
self
.
blas_type
==
'mkl'
:
sub
[
'blas_flags'
]
=
'mkl_set_num_threads(1)'
else
:
sub
[
'blas_flags'
]
=
''
files
=
[
'corr_gemm.c'
]
codes
=
[
open
(
os
.
path
.
join
(
os
.
path
.
split
(
__file__
)[
0
],
f
))
.
read
()
for
f
in
files
]
...
...
@@ -173,8 +195,6 @@ class BaseCorrMM(gof.OpenMPOp):
If self.border_mode == 'half', a variable giving the width of the
filters for direction="backprop weights". Ignored otherwise.
"""
if
not
theano
.
config
.
blas
.
ldflags
:
raise
NotImplementedError
(
"C code for CorrMM* classes need a blas library."
)
dH
,
dW
=
self
.
subsample
dilH
,
dilW
=
self
.
filter_dilation
if
self
.
border_mode
==
"half"
:
...
...
@@ -340,7 +360,8 @@ class BaseCorrMM(gof.OpenMPOp):
else {
typenum = PyArray_TYPE(bottom);
}
%(out)
s = (PyArrayObject*)PyArray_EMPTY(4,
//Change to PyArray_ZEROS which is faster than PyArray_EMPTY.
%(out)
s = (PyArrayObject*)PyArray_ZEROS(4,
out_dim,
typenum,
0);
...
...
theano/tensor/nnet/corr_gemm.c
浏览文件 @
b834babe
...
...
@@ -189,7 +189,7 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
col_dim
[
0
]
=
(
npy_intp
)
max_threads
;
col_dim
[
1
]
=
(
npy_intp
)(
nChannels
*
kW
*
kH
);
col_dim
[
2
]
=
(
npy_intp
)(
topHeight
*
topWidth
);
//Change to PyArray_ZEROS which is faster than PyArray_EMPTY.
PyArrayObject
*
col
=
(
PyArrayObject
*
)
PyArray_ZEROS
(
3
,
col_dim
,
...
...
@@ -230,6 +230,8 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
bottomWidth
,
kH
,
kW
,
dilH
,
dilW
,
padH
,
padW
,
dH
,
dW
,
(
%
(
float_type
)
s
*
)
PyArray_DATA
(
col
)
+
tid
*
col_stride
);
// Second, gemm
// Always forcing gemm to one thread here for best and stable performance.
%
(
blas_flags
)
s
;
%
(
gemm
)
s
(
&
NTrans
,
&
NTrans
,
&
N_
,
&
M_
,
&
K_
,
&
one
,
...
...
@@ -301,6 +303,8 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
// Note that we accumulate into weight. We do so by setting beta = 0
// for the first iteration and beta = 1 for subsequent ones. (This
// is faster than setting weight to all zeros before the loop.)
// Always forcing gemm to one thread here for best and stable performance.
%
(
blas_flags
)
s
;
%
(
gemm
)
s
(
&
Trans
,
&
NTrans
,
&
K_
,
&
M_
,
&
N_
,
&
one
,
...
...
@@ -365,6 +369,8 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
for
(
int
n
=
0
;
n
<
batchSize
;
++
n
)
{
// gemm into columns
int
tid
=
%
(
omp_get_threads
)
s
;
// Always forcing gemm to one thread here for best and stable performance.
%
(
blas_flags
)
s
;
%
(
gemm
)
s
(
&
NTrans
,
&
Trans
,
&
N_
,
&
K_
,
&
M_
,
&
one
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论