Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cc3deb5e
提交
cc3deb5e
authored
6月 21, 2016
作者:
Ciyong Chen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename omp and blas key name
上级
8850e88d
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
26 行增加
和
27 行删除
+26
-27
corr.py
theano/tensor/nnet/corr.py
+13
-12
corr_gemm.c
theano/tensor/nnet/corr_gemm.c
+13
-15
没有找到文件。
theano/tensor/nnet/corr.py
浏览文件 @
cc3deb5e
...
@@ -137,23 +137,24 @@ class BaseCorrMM(gof.OpenMPOp):
...
@@ -137,23 +137,24 @@ class BaseCorrMM(gof.OpenMPOp):
if
self
.
openmp
:
if
self
.
openmp
:
sub
[
'omp_flags'
]
=
'#pragma omp parallel for schedule(static)'
sub
[
'omp_flags'
]
=
'#pragma omp parallel for schedule(static)'
sub
[
'omp_max_threads'
]
=
'omp_get_max_threads()'
sub
[
'omp_get_max_threads'
]
=
'omp_get_max_threads()'
sub
[
'set_omp_threads'
]
=
'omp_set_num_threads'
sub
[
'omp_get_thread_num'
]
=
'omp_get_thread_num()'
sub
[
'get_omp_threads'
]
=
'omp_get_thread_num()'
if
self
.
blas_type
==
'openblas'
:
if
self
.
blas_type
==
'openblas'
:
sub
[
'
set_blas
_threads'
]
=
'openblas_set_num_threads'
sub
[
'
blas_set_num
_threads'
]
=
'openblas_set_num_threads'
sub
[
'
get_blas
_threads'
]
=
'openblas_get_num_threads()'
sub
[
'
blas_get_num
_threads'
]
=
'openblas_get_num_threads()'
elif
self
.
blas_type
==
'mkl'
:
elif
self
.
blas_type
==
'mkl'
:
sub
[
'set_blas_threads'
]
=
'mkl_set_num_threads'
sub
[
'blas_set_num_threads'
]
=
'mkl_set_num_threads'
sub
[
'get_blas_threads'
]
=
'mkl_get_max_threads()'
sub
[
'blas_get_num_threads'
]
=
'mkl_get_max_threads()'
else
:
sub
[
'blas_set_num_threads'
]
=
''
sub
[
'blas_get_num_threads'
]
=
'0'
else
:
else
:
sub
[
'omp_flags'
]
=
''
sub
[
'omp_flags'
]
=
''
sub
[
'omp_max_threads'
]
=
'1'
sub
[
'omp_get_max_threads'
]
=
'1'
sub
[
'set_omp_threads'
]
=
''
sub
[
'omp_get_thread_num'
]
=
'0'
sub
[
'get_omp_threads'
]
=
'0'
sub
[
'blas_set_num_threads'
]
=
''
sub
[
'set_blas_threads'
]
=
''
sub
[
'blas_get_num_threads'
]
=
'0'
sub
[
'get_blas_threads'
]
=
'0'
files
=
[
'corr_gemm.c'
]
files
=
[
'corr_gemm.c'
]
codes
=
[
open
(
os
.
path
.
join
(
os
.
path
.
split
(
__file__
)[
0
],
f
))
.
read
()
codes
=
[
open
(
os
.
path
.
join
(
os
.
path
.
split
(
__file__
)[
0
],
f
))
.
read
()
...
...
theano/tensor/nnet/corr_gemm.c
浏览文件 @
cc3deb5e
...
@@ -184,7 +184,7 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
...
@@ -184,7 +184,7 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
}
}
// Create temporary columns
// Create temporary columns
int
max_threads
=
%
(
omp_max_threads
)
s
;
int
max_threads
=
%
(
omp_
get_
max_threads
)
s
;
if
(
batchSize
<
max_threads
)
{
if
(
batchSize
<
max_threads
)
{
max_threads
=
batchSize
;
max_threads
=
batchSize
;
}
}
...
@@ -219,18 +219,16 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
...
@@ -219,18 +219,16 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
char
Trans
=
'T'
;
char
Trans
=
'T'
;
PyArrayObject
*
output
;
PyArrayObject
*
output
;
%
(
set_omp_threads
)
s
(
max_threads
);
if
(
direction
==
0
)
{
// forward pass
if
(
direction
==
0
)
{
// forward pass
output
=
top
;
output
=
top
;
// valid correlation: im2col, then gemm
// valid correlation: im2col, then gemm
// Iterate over batch
// Iterate over batch
int
blas_threads_saved
=
%
(
get_blas
_threads
)
s
;
int
blas_threads_saved
=
%
(
blas_get_num
_threads
)
s
;
// Always forcing gemm to one thread when OpenMP is enalbed for best and stable performance.
// Always forcing gemm to one thread when OpenMP is enalbed for best and stable performance.
%
(
set_blas
_threads
)
s
(
1
);
%
(
blas_set_num
_threads
)
s
(
1
);
%
(
omp_flags
)
s
%
(
omp_flags
)
s
for
(
int
n
=
0
;
n
<
batchSize
;
++
n
)
{
for
(
int
n
=
0
;
n
<
batchSize
;
++
n
)
{
int
tid
=
%
(
get_omp_threads
)
s
;
int
tid
=
%
(
omp_get_thread_num
)
s
;
// First, im2col
// First, im2col
im2col
((
%
(
float_type
)
s
*
)
PyArray_DATA
(
bottom
)
+
n
*
bottom_stride
,
nChannels
,
bottomHeight
,
im2col
((
%
(
float_type
)
s
*
)
PyArray_DATA
(
bottom
)
+
n
*
bottom_stride
,
nChannels
,
bottomHeight
,
bottomWidth
,
kH
,
kW
,
dilH
,
dilW
,
padH
,
padW
,
dH
,
dW
,
bottomWidth
,
kH
,
kW
,
dilH
,
dilW
,
padH
,
padW
,
dH
,
dW
,
...
@@ -245,7 +243,7 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
...
@@ -245,7 +243,7 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
(
%
(
float_type
)
s
*
)
PyArray_DATA
(
top
)
+
n
*
top_stride
,
&
N_
);
(
%
(
float_type
)
s
*
)
PyArray_DATA
(
top
)
+
n
*
top_stride
,
&
N_
);
}
}
// Restore to previous blas threads
// Restore to previous blas threads
%
(
set_blas
_threads
)
s
(
blas_threads_saved
);
%
(
blas_set_num
_threads
)
s
(
blas_threads_saved
);
/*
/*
// Original caffe code for comparison
// Original caffe code for comparison
...
@@ -297,13 +295,13 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
...
@@ -297,13 +295,13 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
// valid convolution: im2col, then gemm
// valid convolution: im2col, then gemm
// Iterate over batch
// Iterate over batch
int
blas_threads_saved
=
%
(
get_blas
_threads
)
s
;
int
blas_threads_saved
=
%
(
blas_get_num
_threads
)
s
;
// Always forcing gemm to one thread when OpenMP is enalbed for best and stable performance.
// Always forcing gemm to one thread when OpenMP is enalbed for best and stable performance.
%
(
set_blas
_threads
)
s
(
1
);
%
(
blas_set_num
_threads
)
s
(
1
);
// OMP for batch-level paralization
// OMP for batch-level paralization
%
(
omp_flags
)
s
%
(
omp_flags
)
s
for
(
int
n
=
0
;
n
<
batchSize
;
++
n
)
{
for
(
int
n
=
0
;
n
<
batchSize
;
++
n
)
{
int
tid
=
%
(
get_omp_threads
)
s
;
int
tid
=
%
(
omp_get_thread_num
)
s
;
// First, im2col
// First, im2col
im2col
((
%
(
float_type
)
s
*
)
PyArray_DATA
(
bottom
)
+
n
*
bottom_stride
,
nChannels
,
bottomHeight
,
im2col
((
%
(
float_type
)
s
*
)
PyArray_DATA
(
bottom
)
+
n
*
bottom_stride
,
nChannels
,
bottomHeight
,
bottomWidth
,
kH
,
kW
,
dilH
,
dilW
,
padH
,
padW
,
dH
,
dW
,
bottomWidth
,
kH
,
kW
,
dilH
,
dilW
,
padH
,
padW
,
dH
,
dW
,
...
@@ -322,7 +320,7 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
...
@@ -322,7 +320,7 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
tid
*
weight_dim
[
1
],
&
K_
);
tid
*
weight_dim
[
1
],
&
K_
);
}
}
// Restore to previous blas threads
// Restore to previous blas threads
%
(
set_blas
_threads
)
s
(
blas_threads_saved
);
%
(
blas_set_num
_threads
)
s
(
blas_threads_saved
);
//aggregate weights
//aggregate weights
memset
((
%
(
float_type
)
s
*
)
PyArray_DATA
(
weight
),
0
,
M_
*
K_
*
sizeof
(
%
(
float_type
)
s
));
memset
((
%
(
float_type
)
s
*
)
PyArray_DATA
(
weight
),
0
,
M_
*
K_
*
sizeof
(
%
(
float_type
)
s
));
...
@@ -375,13 +373,13 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
...
@@ -375,13 +373,13 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
// full convolution: gemm, then col2im
// full convolution: gemm, then col2im
// Iterate over batch
// Iterate over batch
int
blas_threads_saved
=
%
(
get_blas
_threads
)
s
;
int
blas_threads_saved
=
%
(
blas_get_num
_threads
)
s
;
// Always forcing gemm to one thread when OpenMP is enalbed for best and stable performance.
// Always forcing gemm to one thread when OpenMP is enalbed for best and stable performance.
%
(
set_blas
_threads
)
s
(
1
);
%
(
blas_set_num
_threads
)
s
(
1
);
%
(
omp_flags
)
s
%
(
omp_flags
)
s
for
(
int
n
=
0
;
n
<
batchSize
;
++
n
)
{
for
(
int
n
=
0
;
n
<
batchSize
;
++
n
)
{
// gemm into columns
// gemm into columns
int
tid
=
%
(
get_omp_threads
)
s
;
int
tid
=
%
(
omp_get_thread_num
)
s
;
%
(
gemm
)
s
(
&
NTrans
,
&
Trans
,
%
(
gemm
)
s
(
&
NTrans
,
&
Trans
,
&
N_
,
&
K_
,
&
M_
,
&
N_
,
&
K_
,
&
M_
,
&
one
,
&
one
,
...
@@ -395,7 +393,7 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
...
@@ -395,7 +393,7 @@ PyArrayObject* corrMM(PyArrayObject* bottom,
dH
,
dW
,
(
%
(
float_type
)
s
*
)
PyArray_DATA
(
bottom
)
+
n
*
bottom_stride
);
dH
,
dW
,
(
%
(
float_type
)
s
*
)
PyArray_DATA
(
bottom
)
+
n
*
bottom_stride
);
}
}
// Restore to previous blas threads
// Restore to previous blas threads
%
(
set_blas
_threads
)
s
(
blas_threads_saved
);
%
(
blas_set_num
_threads
)
s
(
blas_threads_saved
);
/*
/*
// Original caffe code for comparison
// Original caffe code for comparison
// Note that this code was translated from the Theano GPU code,
// Note that this code was translated from the Theano GPU code,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论