Skip to content

Commit

Permalink
*refactoring of SynetConvolution32fNhwcDepthwise class.
Browse files Browse the repository at this point in the history
  • Loading branch information
ermig1979 committed Oct 1, 2024
1 parent 12333d2 commit f78c4bf
Show file tree
Hide file tree
Showing 13 changed files with 460 additions and 2,192 deletions.
2 changes: 1 addition & 1 deletion docs/2024.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h3 id="R143">November X, 2024 (version X.X.143)</h3>
<h4>Algorithms</h4>
<h5>Improving</h5>
<ul>
<li>AVX-512BW optimizations of function ConvolutionDirectNhwcConvolutionBiasActivationDepthwise.</li>
<li>AVX-512BW optimizations of function Convolution32fNhwcDepthwiseDefault.</li>
</ul>

<a href="#HOME">Home</a>
Expand Down
4 changes: 2 additions & 2 deletions src/Simd/SimdAvx2SynetConvolution32f.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ namespace Simd
return new Avx2::SynetConvolution32fDirectNchw(param);
else if (SynetConvolution32fNhwcDirect::Preferable(param))
return new SynetConvolution32fNhwcDirect(param);
else if (SynetConvolution32fDirectNhwc::Preferable(param))
return new SynetConvolution32fDirectNhwc(param);
else if (SynetConvolution32fNhwcDepthwise::Preferable(param))
return new SynetConvolution32fNhwcDepthwise(param);
else if (SynetConvolution32fNhwcGroupedBlock1x2::Preferable(param))
return new SynetConvolution32fNhwcGroupedBlock1x2(param);
else
Expand Down
804 changes: 214 additions & 590 deletions src/Simd/SimdAvx2SynetConvolution32fNhwcDepthwise.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Simd/SimdAvx512bwSynetConvolution32f.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ namespace Simd
return new SynetConvolution32fDirectNchw(param);
else if (SynetConvolution32fNhwcDirect::Preferable(param))
return new SynetConvolution32fNhwcDirect(param);
else if (SynetConvolution32fDirectNhwc::Preferable(param))
return new SynetConvolution32fDirectNhwc(param);
else if (SynetConvolution32fNhwcDepthwise::Preferable(param))
return new SynetConvolution32fNhwcDepthwise(param);
else if (SynetConvolution32fNhwcGroupedBlock1x2::Preferable(param))
return new SynetConvolution32fNhwcGroupedBlock1x2(param);
else
Expand Down
730 changes: 49 additions & 681 deletions src/Simd/SimdAvx512bwSynetConvolution32fNhwcDepthwise.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Simd/SimdBaseSynetConvolution32f.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ namespace Simd
return new SynetConvolution32fDirectNchw(param);
else if (SynetConvolution32fNhwcDirect::Preferable(param))
return new SynetConvolution32fNhwcDirect(param);
else if (SynetConvolution32fDirectNhwc::Preferable(param))
return new SynetConvolution32fDirectNhwc(param);
else if (SynetConvolution32fNhwcDepthwise::Preferable(param))
return new SynetConvolution32fNhwcDepthwise(param);
else if (SynetConvolution32fNhwcGroupedBlock1x2::Preferable(param))
return new SynetConvolution32fNhwcGroupedBlock1x2(param);
#endif
Expand Down
58 changes: 24 additions & 34 deletions src/Simd/SimdBaseSynetConvolution32fNhwcDepthwise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,7 @@ namespace Simd
#if defined(SIMD_SYNET_ENABLE)
namespace Base
{
SynetConvolution32fDirectNhwc::SynetConvolution32fDirectNhwc(const ConvParam & p)
: SynetConvolution32f(p)
{
_batch = p.batch;
_sizeS = p.srcC*p.srcH*p.srcW;
_sizeD = p.dstC*p.dstH*p.dstW;
_convolutionBiasActivation = SetConvolutionBiasActivation();
}

void SynetConvolution32fDirectNhwc::Forward(const float * src, float * buf, float * dst)
{
for (size_t b = 0; b < _batch; ++b)
{
_convolutionBiasActivation(src, _param, _weight, _bias, _params, dst);
src += _sizeS;
dst += _sizeD;
}
}

bool SynetConvolution32fDirectNhwc::Preferable(const ConvParam & p)
{
if (p.trans == 0)
return false;
if (p.group == 1)
{
double k = double(p.srcC) / p.group * p.strideX * p.strideY / p.kernelX / p.kernelY;
return k < 2.0;
}
return p.IsDepthwise();
}

static void ConvolutionDirectNhwcConvolutionBiasActivationDefault(const float * src, const ConvParam & p, const float * weight, const float * bias, const float * params, float * dst)
static void ConvolutionNhwcDepthwiseDefault(const float * src, const ConvParam & p, const float * weight, const float * bias, const float * params, float * dst)
{
size_t group = p.group;
size_t srcC = p.srcC / group;
Expand Down Expand Up @@ -111,10 +80,31 @@ namespace Simd
}
}

SynetConvolution32fDirectNhwc::ConvolutionBiasActivationPtr SynetConvolution32fDirectNhwc::SetConvolutionBiasActivation()
//-------------------------------------------------------------------------------------------------

SynetConvolution32fNhwcDepthwise::SynetConvolution32fNhwcDepthwise(const ConvParam & p)
: SynetConvolution32f(p)
{
return ConvolutionDirectNhwcConvolutionBiasActivationDefault;
_batch = p.batch;
_sizeS = p.srcC*p.srcH*p.srcW;
_sizeD = p.dstC*p.dstH*p.dstW;
_convolution = ConvolutionNhwcDepthwiseDefault;
}

void SynetConvolution32fNhwcDepthwise::Forward(const float * src, float * buf, float * dst)
{
for (size_t b = 0; b < _batch; ++b)
{
_convolution(src, _param, _weight, _bias, _params, dst);
src += _sizeS;
dst += _sizeD;
}
}

bool SynetConvolution32fNhwcDepthwise::Preferable(const ConvParam & p)
{
return p.trans && p.IsDepthwise();
}
}
#endif
}
4 changes: 2 additions & 2 deletions src/Simd/SimdNeonSynetConvolution32f.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ namespace Simd
return new SynetConvolution32fGemmNT(param);
else if (SynetConvolution32fNhwcDirect::Preferable(param))
return new SynetConvolution32fNhwcDirect(param);
else if (SynetConvolution32fDirectNhwc::Preferable(param))
return new SynetConvolution32fDirectNhwc(param);
else if (SynetConvolution32fNhwcDepthwise::Preferable(param))
return new SynetConvolution32fNhwcDepthwise(param);
else if (Base::SynetConvolution32fNhwcGroupedBlock1x2::Preferable(param))
return new Base::SynetConvolution32fNhwcGroupedBlock1x2(param);
else
Expand Down
Loading

0 comments on commit f78c4bf

Please sign in to comment.