在 std::enable_if 中添加等价检查时的模板推导问题
发布时间:2022-08-19 17:36:20 258
相关标签: # golang
我正在尝试对不同的求和方法进行基准测试。我想使用如下界面
avx2_sum(container.begin(), container.end());
然而,我的尝试
enum class sum_algorithm: char{
normal,
kahan,
twofold_fast //https://arxiv.org/pdf/1401.0248.pdf
};
template::value_type,
std::enable_if_t<std::is_same<sum_t, double>::value && (algorithm_t == sum_algorithm::normal)> = true>
sum_t avx2_sum(const iterator_t begin, const iterator_t end) noexcept {
// SIMD-parallel summation stage
auto running_sums = _mm256_set1_pd(0);
auto iterator_skip = 256/sizeof(sum_t);
for (iterator_t it = begin; it + iterator_skip < end; it += iterator_skip){
//TODO: flip to double load reduction
running_sums = _mm256_add_pd(_mm256_load_pd(it), running_sums);
}
// Serial summation
running_sums = _mm256_hadd_pd(running_sums, running_sums);
running_sums = _mm256_hadd_pd(running_sums, running_sums);
return _mm256_cvtsd_f64(running_sums);
}
产生以下结果:
error: no matching function for call to 'avx2_sum'
std::cout << "avx2<float, normal>: " << accumulators::avx2_sum(float_arr.begin(), float_arr.end()) <<"\n";
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/rlfactory/dev/thommmj1/cppbenchmarks/cpp_utils/algorithms/cpu_accumulators.hpp:55:11: note: candidate template ignored: requirement 'std::is_same<float, double>::value' was not satisfied [with algorithm_t = accumulators::sum_algorithm::normal, iterator_t = __gnu_cxx::__normal_iterator > >, sum_t = float]
sum_t avx2_sum(const iterator_t begin, const iterator_t end) noexcept {
^
/home/rlfactory/dev/thommmj1/cppbenchmarks/cpp_utils/algorithms/cpu_accumulators.hpp:71:11: note: candidate template ignored: substitution failure [with algorithm_t = accumulators::sum_algorithm::normal, iterator_t = __gnu_cxx::__normal_iterator > >, sum_t = float]: a non-type template parameter cannot have type 'std::enable_if_t<std::is_same<float, float>::value && ((sum_algorithm)'\x00' == sum_algorithm::normal)>' (aka 'void')
sum_t avx2_sum(const iterator_t begin, const iterator_t end) noexcept {
^
/home/rlfactory/dev/thommmj1/cppbenchmarks/cpp_utils/algorithms/cpu_accumulators.hpp:87:11: note: candidate template ignored: requirement 'std::is_same<float, double>::value' was not satisfied [with algorithm_t = accumulators::sum_algorithm::normal, iterator_t = __gnu_cxx::__normal_iterator > >, sum_t = float]
sum_t avx2_sum(const iterator_t begin, const iterator_t end) noexcept {
^
/home/rlfactory/dev/thommmj1/cppbenchmarks/cpp_utils/algorithms/cpu_accumulators.hpp:109:11: note: candidate template ignored: requirement 'std::is_same<float, float>::value && ((accumulators::sum_algorithm)'\x00' == sum_algorithm::kahan)' was not satisfied [with algorithm_t = accumulators::sum_algorithm::normal, iterator_t = __gnu_cxx::__normal_iterator > >, sum_t = float]
sum_t avx2_sum(const iterator_t begin, const iterator_t end) noexcept {
我不明白如何扣除在这里不起作用。如果没有 algorithm_t 模板部分和检查,它工作得很好。也许是由于我的 using 声明?using algo = accumulators::sum_algorithm;
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报