Skip to content

Commit

Permalink
fix msvc-v141-toolkits mm512_maskz_load bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoh-Z committed Aug 13, 2023
1 parent 6a773c5 commit d5575f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 46 deletions.
18 changes: 4 additions & 14 deletions src/layer/x86/gridsample_bicubic_apply_interpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ static void cubic_interp1d_p16(__m512& coeffs0, __m512& coeffs1, __m512& coeffs2
coeffs3 = _mm512_sub_ps(_mm512_sub_ps(_mm512_sub_ps(_mm512_set1_ps(1.0f), coeffs0), coeffs1), coeffs2);
}

#if _MSC_VER >= 1910 && _MSC_VER < 1920
#pragma optimize("", off)
#endif // _MSC_VER >= 1910 && _MSC_VER < 1920
static void gridsample_2d_bicubic_apply_interpolation_p16(const Mat& src, Mat& dst, Mat& offset_value, const Option& opt)
{
const int channels = dst.c;
Expand Down Expand Up @@ -59,14 +56,10 @@ static void gridsample_2d_bicubic_apply_interpolation_p16(const Mat& src, Mat& d

for (int ii = 0; ii < 4; ii++)
{
__mmask16 in_bound = offset_ptr[0] >= 0 ? 0xFFFF : 0;
__m512 x0_val = _mm512_maskz_load_ps(in_bound, srcptr + offset_ptr[0]);
in_bound = offset_ptr[1] >= 0 ? 0xFFFF : 0;
__m512 x1_val = _mm512_maskz_load_ps(in_bound, srcptr + offset_ptr[1]);
in_bound = offset_ptr[2] >= 0 ? 0xFFFF : 0;
__m512 x2_val = _mm512_maskz_load_ps(in_bound, srcptr + offset_ptr[2]);
in_bound = offset_ptr[3] >= 0 ? 0xFFFF : 0;
__m512 x3_val = _mm512_maskz_load_ps(in_bound, srcptr + offset_ptr[3]);
__m512 x0_val = offset_ptr[0] >= 0 ? _mm512_load_ps(srcptr + offset_ptr[0]) : _mm512_set1_ps(0);
__m512 x1_val = offset_ptr[1] >= 0 ? _mm512_load_ps(srcptr + offset_ptr[1]) : _mm512_set1_ps(0);
__m512 x2_val = offset_ptr[2] >= 0 ? _mm512_load_ps(srcptr + offset_ptr[2]) : _mm512_set1_ps(0);
__m512 x3_val = offset_ptr[3] >= 0 ? _mm512_load_ps(srcptr + offset_ptr[3]) : _mm512_set1_ps(0);

value_f[ii] = _mm512_mul_ps(x_coeffs0, x0_val);
value_f[ii] = _mm512_fmadd_ps(x_coeffs1, x1_val, value_f[ii]);
Expand All @@ -87,9 +80,6 @@ static void gridsample_2d_bicubic_apply_interpolation_p16(const Mat& src, Mat& d
}
}
}
#if _MSC_VER >= 1910 && _MSC_VER < 1920
#pragma optimize("", on)
#endif // _MSC_VER >= 1910 && _MSC_VER < 1920

#endif // __AVX512F__
static void cubic_interp1d_p8(__m256& coeffs0, __m256& coeffs1, __m256& coeffs2, __m256& coeffs3, const __m256& tx)
Expand Down
47 changes: 15 additions & 32 deletions src/layer/x86/gridsample_bilinear_apply_interpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
#if __SSE2__
#if __AVX__
#if __AVX512F__
#if _MSC_VER >= 1910 && _MSC_VER < 1920
#pragma optimize("", off)
#endif // _MSC_VER >= 1910 && _MSC_VER < 1920
static void gridsample_2d_bilinear_apply_interpolation_p16(const Mat& src, Mat& dst, const Mat& offset_value, const Option& opt)
{
const int channels = dst.c;
Expand All @@ -38,14 +35,10 @@ static void gridsample_2d_bilinear_apply_interpolation_p16(const Mat& src, Mat&
const int* offset_ptr = (int*)offset_value_ptr;
const float* value_ptr = offset_value_ptr + 4;

__mmask16 in_bound = offset_ptr[0] >= 0 ? 0xFFFF : 0;
__m512 v00_val = _mm512_maskz_load_ps(in_bound, srcptr + offset_ptr[0]);
in_bound = offset_ptr[1] >= 0 ? 0xFFFF : 0;
__m512 v01_val = _mm512_maskz_load_ps(in_bound, srcptr + offset_ptr[1]);
in_bound = offset_ptr[2] >= 0 ? 0xFFFF : 0;
__m512 v10_val = _mm512_maskz_load_ps(in_bound, srcptr + offset_ptr[2]);
in_bound = offset_ptr[3] >= 0 ? 0xFFFF : 0;
__m512 v11_val = _mm512_maskz_load_ps(in_bound, srcptr + offset_ptr[3]);
__m512 v00_val = offset_ptr[0] >= 0 ? _mm512_load_ps(srcptr + offset_ptr[0]) : _mm512_set1_ps(0);
__m512 v01_val = offset_ptr[1] >= 0 ? _mm512_load_ps(srcptr + offset_ptr[1]) : _mm512_set1_ps(0);
__m512 v10_val = offset_ptr[2] >= 0 ? _mm512_load_ps(srcptr + offset_ptr[2]) : _mm512_set1_ps(0);
__m512 v11_val = offset_ptr[3] >= 0 ? _mm512_load_ps(srcptr + offset_ptr[3]) : _mm512_set1_ps(0);

__m512 value1 = _mm512_set1_ps(value_ptr[0]);
__m512 v0 = _mm512_fmadd_ps(v01_val, value1, _mm512_fnmadd_ps(v00_val, value1, v00_val));
Expand Down Expand Up @@ -82,23 +75,16 @@ static void gridsample_3d_bilinear_apply_interpolation_p16(const Mat& src, Mat&
const int* offset_ptr = (int*)offset_value_ptr;
const float* value_ptr = offset_value_ptr + 8;

__mmask16 in_bound = offset_ptr[0] >= 0 ? 0xFFFF : 0;
__m512 v000_val = _mm512_maskz_load_ps(in_bound, srcptr + offset_ptr[0]);
in_bound = offset_ptr[1] >= 0 ? 0xFFFF : 0;
__m512 v001_val = _mm512_maskz_load_ps(in_bound, srcptr + offset_ptr[1]);
in_bound = offset_ptr[2] >= 0 ? 0xFFFF : 0;
__m512 v010_val = _mm512_maskz_load_ps(in_bound, srcptr + offset_ptr[2]);
in_bound = offset_ptr[3] >= 0 ? 0xFFFF : 0;
__m512 v011_val = _mm512_maskz_load_ps(in_bound, srcptr + offset_ptr[3]);

in_bound = offset_ptr[4] >= 0 ? 0xFFFF : 0;
__m512 v100_val = _mm512_maskz_load_ps(in_bound, srcptr + offset_ptr[4]);
in_bound = offset_ptr[5] >= 0 ? 0xFFFF : 0;
__m512 v101_val = _mm512_maskz_load_ps(in_bound, srcptr + offset_ptr[5]);
in_bound = offset_ptr[6] >= 0 ? 0xFFFF : 0;
__m512 v110_val = _mm512_maskz_load_ps(in_bound, srcptr + offset_ptr[6]);
in_bound = offset_ptr[7] >= 0 ? 0xFFFF : 0;
__m512 v111_val = _mm512_maskz_load_ps(in_bound, srcptr + offset_ptr[7]);
__m512 v000_val = offset_ptr[0] >= 0 ? _mm512_load_ps(srcptr + offset_ptr[0]) : _mm512_set1_ps(0);
__m512 v001_val = offset_ptr[1] >= 0 ? _mm512_load_ps(srcptr + offset_ptr[1]) : _mm512_set1_ps(0);
__m512 v010_val = offset_ptr[2] >= 0 ? _mm512_load_ps(srcptr + offset_ptr[2]) : _mm512_set1_ps(0);
__m512 v011_val = offset_ptr[3] >= 0 ? _mm512_load_ps(srcptr + offset_ptr[3]) : _mm512_set1_ps(0);

__m512 v100_val = offset_ptr[4] >= 0 ? _mm512_load_ps(srcptr + offset_ptr[4]) : _mm512_set1_ps(0);
__m512 v101_val = offset_ptr[5] >= 0 ? _mm512_load_ps(srcptr + offset_ptr[5]) : _mm512_set1_ps(0);
__m512 v110_val = offset_ptr[6] >= 0 ? _mm512_load_ps(srcptr + offset_ptr[6]) : _mm512_set1_ps(0);
__m512 v111_val = offset_ptr[7] >= 0 ? _mm512_load_ps(srcptr + offset_ptr[7]) : _mm512_set1_ps(0);


__m512 value = _mm512_set1_ps(value_ptr[0]);
__m512 v00 = _mm512_fmadd_ps(v001_val, value, _mm512_fnmadd_ps(v000_val, value, v000_val));
Expand All @@ -119,9 +105,6 @@ static void gridsample_3d_bilinear_apply_interpolation_p16(const Mat& src, Mat&
}
}
}
#if _MSC_VER >= 1910 && _MSC_VER < 1920
#pragma optimize("", on)
#endif // _MSC_VER >= 1910 && _MSC_VER < 1920

#endif // __AVX512F__

Expand Down Expand Up @@ -284,7 +267,7 @@ static void gridsample_3d_bilinear_apply_interpolation_p4(const Mat& src, Mat& d
{
const int* offset_ptr = (int*)offset_value_ptr;
const float* value_ptr = offset_value_ptr + 8;

__m128 v000_val = offset_ptr[0] >= 0 ? _mm_load_ps(srcptr + offset_ptr[0]) : _mm_set1_ps(0);
__m128 v001_val = offset_ptr[1] >= 0 ? _mm_load_ps(srcptr + offset_ptr[1]) : _mm_set1_ps(0);
__m128 v010_val = offset_ptr[2] >= 0 ? _mm_load_ps(srcptr + offset_ptr[2]) : _mm_set1_ps(0);
Expand Down

0 comments on commit d5575f7

Please sign in to comment.