Skip to content

Commit

Permalink
ARROW-9643: [C++] Only register the SIMD variants when it's supported.
Browse files Browse the repository at this point in the history
Fix illegal instruction on GCC 7.5 build, compiler may use advanced instruction just for a register routine.

Signed-off-by: Frank Du <frank.du@intel.com>

Closes apache#7903 from jianxind/ARROW-9643

Authored-by: Frank Du <frank.du@intel.com>
Signed-off-by: Wes McKinney <wesm@apache.org>
  • Loading branch information
frankdjx authored and kszucs committed Aug 11, 2020
1 parent 51d0c45 commit abf6b07
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cpp/src/arrow/compute/kernels/aggregate_basic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "arrow/compute/kernels/aggregate_basic_internal.h"
#include "arrow/compute/kernels/aggregate_internal.h"
#include "arrow/compute/kernels/common.h"
#include "arrow/util/cpu_info.h"
#include "arrow/util/make_unique.h"

namespace arrow {
Expand Down Expand Up @@ -389,12 +390,35 @@ void RegisterScalarAggregateBasic(FunctionRegistry* registry) {
func.get());
aggregate::AddBasicAggKernels(aggregate::SumInit, FloatingPointTypes(), float64(),
func.get());
// Add the SIMD variants for sum
auto cpu_info = arrow::internal::CpuInfo::GetInstance();
#if defined(ARROW_HAVE_RUNTIME_AVX2)
if (cpu_info->IsSupported(arrow::internal::CpuInfo::AVX2)) {
aggregate::AddSumAvx2AggKernels(func.get());
}
#endif
#if defined(ARROW_HAVE_RUNTIME_AVX512)
if (cpu_info->IsSupported(arrow::internal::CpuInfo::AVX512)) {
aggregate::AddSumAvx512AggKernels(func.get());
}
#endif
DCHECK_OK(registry->AddFunction(std::move(func)));

func = std::make_shared<ScalarAggregateFunction>("mean", Arity::Unary());
aggregate::AddBasicAggKernels(aggregate::MeanInit, {boolean()}, float64(), func.get());
aggregate::AddBasicAggKernels(aggregate::MeanInit, NumericTypes(), float64(),
func.get());
// Add the SIMD variants for mean
#if defined(ARROW_HAVE_RUNTIME_AVX2)
if (cpu_info->IsSupported(arrow::internal::CpuInfo::AVX2)) {
aggregate::AddMeanAvx2AggKernels(func.get());
}
#endif
#if defined(ARROW_HAVE_RUNTIME_AVX512)
if (cpu_info->IsSupported(arrow::internal::CpuInfo::AVX512)) {
aggregate::AddMeanAvx512AggKernels(func.get());
}
#endif
DCHECK_OK(registry->AddFunction(std::move(func)));

static auto default_minmax_options = MinMaxOptions::Defaults();
Expand Down

0 comments on commit abf6b07

Please sign in to comment.