Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
ed956410
Commit
ed956410
authored
Jul 06, 2017
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reuse AVX2-optimized kernels for AVX1 CPUs (like IvyBridge)
parent
f670a992
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
91 additions
and
2 deletions
+91
-2
convolution_layer.cpp
modules/dnn/src/layers/convolution_layer.cpp
+16
-1
fully_connected_layer.cpp
modules/dnn/src/layers/fully_connected_layer.cpp
+8
-1
layers_common.avx.cpp
modules/dnn/src/layers/layers_common.avx.cpp
+54
-0
layers_common.avx2.cpp
modules/dnn/src/layers/layers_common.avx2.cpp
+0
-0
layers_common.hpp
modules/dnn/src/layers/layers_common.hpp
+13
-0
layers_common.simd.hpp
modules/dnn/src/layers/layers_common.simd.hpp
+0
-0
No files found.
modules/dnn/src/layers/convolution_layer.cpp
View file @
ed956410
...
...
@@ -285,11 +285,12 @@ public:
const
std
::
vector
<
float
>*
reluslope_
;
const
ActivationLayer
*
activ_
;
bool
is1x1_
;
bool
useAVX
;
bool
useAVX2
;
ParallelConv
()
:
input_
(
0
),
weights_
(
0
),
output_
(
0
),
ngroups_
(
0
),
nstripes_
(
0
),
biasvec_
(
0
),
reluslope_
(
0
),
activ_
(
0
),
is1x1_
(
false
),
useAVX2
(
false
)
biasvec_
(
0
),
reluslope_
(
0
),
activ_
(
0
),
is1x1_
(
false
),
useAVX
(
false
),
useAVX
2
(
false
)
{}
static
void
run
(
const
Mat
&
input
,
Mat
&
output
,
const
Mat
&
weights
,
...
...
@@ -322,6 +323,7 @@ public:
int
inpCnAll
=
input
.
size
[
1
],
width
=
input
.
size
[
3
],
height
=
input
.
size
[
2
];
int
inpCn
=
inpCnAll
/
ngroups
;
p
.
is1x1_
=
kernel
==
Size
(
0
,
0
)
&&
pad
==
Size
(
0
,
0
);
p
.
useAVX
=
checkHardwareSupport
(
CPU_AVX
);
p
.
useAVX2
=
checkHardwareSupport
(
CPU_AVX2
);
int
ncn
=
std
::
min
(
inpCn
,
(
int
)
BLK_SIZE_CN
);
...
...
@@ -507,6 +509,12 @@ public:
fastConv_avx2
(
wptr
,
wstep
,
biasptr
,
rowbuf0
,
data_out0
+
ofs0
,
outShape
,
bsz
,
vsz
,
vsz_a
,
relu
,
cn0
==
0
);
else
#endif
#if CV_TRY_AVX
if
(
useAVX
)
fastConv_avx
(
wptr
,
wstep
,
biasptr
,
rowbuf0
,
data_out0
+
ofs0
,
outShape
,
bsz
,
vsz
,
vsz_a
,
relu
,
cn0
==
0
);
else
#endif
for
(
int
i
=
0
;
i
<
outCn
;
i
+=
2
)
{
...
...
@@ -795,6 +803,7 @@ public:
b_
=
&
b
;
c_
=
&
c
;
nstripes_
=
nstripes
;
useAVX
=
checkHardwareSupport
(
CPU_AVX
);
useAVX2
=
checkHardwareSupport
(
CPU_AVX2
);
}
...
...
@@ -817,6 +826,11 @@ public:
if
(
useAVX2
)
fastGEMM_avx2
(
aptr
,
astep
,
bptr
,
bstep
,
cptr
,
cstep
,
mmax
,
kmax
,
nmax
);
else
#endif
#if CV_TRY_AVX
if
(
useAVX
)
fastGEMM_avx
(
aptr
,
astep
,
bptr
,
bstep
,
cptr
,
cstep
,
mmax
,
kmax
,
nmax
);
else
#endif
for
(
m
=
0
;
m
<
mmax
;
m
+=
2
)
{
...
...
@@ -910,6 +924,7 @@ public:
const
Mat
*
a_
,
*
b_
;
Mat
*
c_
;
int
nstripes_
;
bool
useAVX
;
bool
useAVX2
;
};
...
...
modules/dnn/src/layers/fully_connected_layer.cpp
View file @
ed956410
...
...
@@ -119,7 +119,7 @@ public:
class
FullyConnected
:
public
ParallelLoopBody
{
public
:
FullyConnected
()
:
srcMat
(
0
),
weights
(
0
),
biasMat
(
0
),
activ
(
0
),
dstMat
(
0
),
nstripes
(
0
),
useAVX2
(
false
)
{}
FullyConnected
()
:
srcMat
(
0
),
weights
(
0
),
biasMat
(
0
),
activ
(
0
),
dstMat
(
0
),
nstripes
(
0
),
useAVX
(
false
),
useAVX
2
(
false
)
{}
static
void
run
(
const
Mat
&
srcMat
,
const
Mat
&
weights
,
const
Mat
&
biasMat
,
Mat
&
dstMat
,
const
ActivationLayer
*
activ
,
int
nstripes
)
...
...
@@ -139,6 +139,7 @@ public:
p
.
dstMat
=
&
dstMat
;
p
.
nstripes
=
nstripes
;
p
.
activ
=
activ
;
p
.
useAVX
=
checkHardwareSupport
(
CPU_AVX
);
p
.
useAVX2
=
checkHardwareSupport
(
CPU_AVX2
);
parallel_for_
(
Range
(
0
,
nstripes
),
p
,
nstripes
);
...
...
@@ -178,6 +179,11 @@ public:
if
(
useAVX2
)
fastGEMM1T_avx2
(
sptr
,
wptr
,
wstep
,
biasptr
,
dptr
,
nw
,
vecsize
);
else
#endif
#if CV_TRY_AVX
if
(
useAVX
)
fastGEMM1T_avx
(
sptr
,
wptr
,
wstep
,
biasptr
,
dptr
,
nw
,
vecsize
);
else
#endif
{
int
i
=
0
;
...
...
@@ -228,6 +234,7 @@ public:
const
ActivationLayer
*
activ
;
Mat
*
dstMat
;
int
nstripes
;
bool
useAVX
;
bool
useAVX2
;
};
...
...
modules/dnn/src/layers/layers_common.avx.cpp
0 → 100644
View file @
ed956410
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Copyright (C) 2017, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "precomp.hpp"
#include "layers_common.hpp"
#include "opencv2/core/hal/intrin.hpp"
#define fastConv_some_avx fastConv_avx
#define fastGEMM1T_some_avx fastGEMM1T_avx
#define fastGEMM_some_avx fastGEMM_avx
#undef _mm256_fmadd_ps
#define _mm256_fmadd_ps(a, b, c) _mm256_add_ps(c, _mm256_mul_ps(a, b))
#include "layers_common.simd.hpp"
modules/dnn/src/layers/layers_common.avx2.cpp
View file @
ed956410
This diff is collapsed.
Click to expand it.
modules/dnn/src/layers/layers_common.hpp
View file @
ed956410
...
...
@@ -64,6 +64,19 @@ void getConvPoolPaddings(const Size& inp, const Size& out,
const
Size
&
kernel
,
const
Size
&
stride
,
const
String
&
padMode
,
Size
&
pad
);
#if CV_TRY_AVX
void
fastConv_avx
(
const
float
*
weights
,
size_t
wstep
,
const
float
*
bias
,
const
float
*
rowbuf
,
float
*
output
,
const
int
*
outShape
,
int
blockSize
,
int
vecsize
,
int
vecsize_aligned
,
const
float
*
relu
,
bool
initOutput
);
void
fastGEMM1T_avx
(
const
float
*
vec
,
const
float
*
weights
,
size_t
wstep
,
const
float
*
bias
,
float
*
dst
,
int
nvecs
,
int
vecsize
);
void
fastGEMM_avx
(
const
float
*
aptr
,
size_t
astep
,
const
float
*
bptr0
,
size_t
bstep
,
float
*
cptr
,
size_t
cstep
,
int
ma
,
int
na
,
int
nb
);
#endif
#if CV_TRY_AVX2
void
fastConv_avx2
(
const
float
*
weights
,
size_t
wstep
,
const
float
*
bias
,
const
float
*
rowbuf
,
float
*
output
,
const
int
*
outShape
,
...
...
modules/dnn/src/layers/layers_common.simd.hpp
0 → 100644
View file @
ed956410
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment