MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / rep

Function rep

dnn/src/x86/lrn/opr_impl.cpp:31–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29 type valpha = set1(alpha);
30 type vnbeta = set1(-beta);
31 rep(c, C) {
32 auto sptr = src + c * HW;
33 auto dptr = dst + c * HW;
34 size_t hw = 0u;
35 size_t c_start = (c >= half_n ? c - half_n : 0u);
36 size_t c_end = std::min(c + half_n, C - 1);
37 for (; hw + width <= HW; hw += width, sptr += width, dptr += width) {
38 type suma2 = simd_traits<simd_type>::setzero();
39 for (size_t sc = c_start; sc <= c_end; ++sc) {
40 type sval = loadu(src + (sc * H * W + hw));
41 suma2 = fmadd(sval, sval, suma2);
42 }
43 type a = fmadd(valpha, suma2, vk);
44 type b = vnbeta;
45 type multiplicand = exp(mul(b, log(a)));
46 type multiplier = loadu(sptr);
47 type res = mul(multiplier, multiplicand);
48 storeu(dptr, res);
49 }
50 for (; hw < HW; ++hw, ++sptr, ++dptr) {
51 float suma2 = 0.0f;
52 for (size_t sc = c_start; sc <= c_end; ++sc) {
53 float sval = src[sc * HW + hw];
54 suma2 += sqr(sval);
55 }
56 float_t multiplicand = std::pow(k + alpha * suma2, -beta);
57 float_t multiplier = *sptr;
58 *dptr = multiplicand * multiplier;
59 }
60 }
61}
62
63template MEGDNN_ATTRIBUTE_TARGET("fma") void lrn_single_instance<SIMDType::FMA>(

Callers 4

execMethod · 0.70
warp_affine_cvFunction · 0.50
warp_perspective_cvFunction · 0.50
execMethod · 0.50

Calls 6

sqrFunction · 0.85
minFunction · 0.50
expFunction · 0.50
mulFunction · 0.50
logFunction · 0.50
powFunction · 0.50

Tested by 1

warp_perspective_cvFunction · 0.40