C++ AVX2 Function Pointers/std::function не работает в Windows (но работает в Linux)< /p>
С тех пор, благодаря полезным комментариям, я решил эту проблему; с помощью:
Код: Выделить всё
// Simple test function that just multiplies vector by 2
__m256d test_simple_AVX2(const __m256d x) {
ALIGN32 const __m256d two = _mm256_set1_pd(2.0);
ALIGN32 const __m256d res = _mm256_mul_pd(x, two);
return res;
}
Код: Выделить всё
// Simple test function that just multiplies vector by 2
__m256d test_simple_AVX2(const __m256d x) {
const __m256d two = _mm256_set1_pd(2.0);
const __m256d res = _mm256_mul_pd(x, two);
return res;
}
Код: Выделить всё
#ifdef _MSC_VER
#define ALIGN32 __declspec(align(32))
#else
#define ALIGN32 alignas(32)
#endif
Например, вот моя функция exp:
Код: Выделить всё
// Adapted from: https://stackoverflow.com/questions/48863719/fastest-implementation-of-exponential-function-using-avx
// added (optional) extra degree(s) for poly approx (oroginal float fn had 4 degrees) - using "minimaxApprox" R package to find coefficient terms
// R code: minimaxApprox::minimaxApprox(fn = exp, lower = -0.346573590279972643113, upper = 0.346573590279972643113, degree = 5, basis ="Chebyshev")
inline __m256d fast_exp_1_wo_checks_AVX2 VECTORCALL(const __m256d x) {
_mm256_zeroupper(); // Reset AVX state
ALIGN32 __m256d const x_aligned = x;
ALIGN32 __m256d const exp_l2e = _mm256_set1_pd (1.442695040888963387); /* log2(e) */
ALIGN32 __m256d const exp_l2h = _mm256_set1_pd (-0.693145751999999948367); /* -log(2)_hi */
ALIGN32 __m256d const exp_l2l = _mm256_set1_pd (-0.00000142860676999999996193); /* -log(2)_lo */
// /* coefficients for core approximation to exp() in [-log(2)/2, log(2)/2] */
ALIGN32 __m256d const exp_c0 = _mm256_set1_pd(0.00000276479776161191821278);
ALIGN32 __m256d const exp_c1 = _mm256_set1_pd(0.0000248844480527491290235);
ALIGN32 __m256d const exp_c2 = _mm256_set1_pd(0.000198411488032534342194);
ALIGN32 __m256d const exp_c3 = _mm256_set1_pd(0.00138888017711994078175);
ALIGN32 __m256d const exp_c4 = _mm256_set1_pd(0.00833333340524595143906);
ALIGN32 __m256d const exp_c5 = _mm256_set1_pd(0.0416666670404215802592);
ALIGN32 __m256d const exp_c6 = _mm256_set1_pd(0.166666666664891632843);
ALIGN32 __m256d const exp_c7 = _mm256_set1_pd(0.499999999994389376923);
ALIGN32 __m256d const exp_c8 = _mm256_set1_pd(1.00000000000001221245);
ALIGN32 __m256d const exp_c9 = _mm256_set1_pd(1.00000000000001332268);
ALIGN32 __m256d const input = x_aligned;
/* exp(x) = 2^i * e^f; i = rint (log2(e) * a), f = a - log(2) * i */
ALIGN32 __m256d const t = _mm256_mul_pd(x_aligned, exp_l2e); /* t = log2(e) * a */
/// const __m256i i = _mm256_cvttpd_epi32(t); /* i = (int)rint(t) */
ALIGN32 __m256i const i = avx2_cvtpd_epi64(t);
// const __m256d x_2 = _mm256_round_pd(t, _MM_FROUND_TO_NEAREST_INT) ; // ((0
Подробнее здесь: [url]https://stackoverflow.com/questions/79328976/c-avx2-custom-functions-e-g-exp-not-working-on-windows-but-work-on-linu[/url]