Skip to content

Commit

Permalink
Enable wasm32 as a target architecture for the SIMD feature (#324)
Browse files Browse the repository at this point in the history
* Add wasm32 as target_arch for simd

Signed-off-by: roee88 <[email protected]>

* Allow wasm32 as a target arch for SIMD

Signed-off-by: roee88 <[email protected]>
  • Loading branch information
roee88 authored May 23, 2021
1 parent b88ef80 commit 91ef8e9
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 104 deletions.
1 change: 0 additions & 1 deletion arrow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ flate2 = "1"
tempfile = "3"

[build-dependencies]
cfg_aliases = "0.1"

[[bench]]
name = "aggregate_kernels"
Expand Down
26 changes: 0 additions & 26 deletions arrow/build.rs

This file was deleted.

6 changes: 3 additions & 3 deletions arrow/src/buffer/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use super::{Buffer, MutableBuffer};
/// and the `scalar_op` gets applied to remaining bytes.
/// Contrary to the non-simd version `bitwise_bin_op_helper`, the offset and length is specified in bytes
/// and this version does not support operations starting at arbitrary bit offsets.
#[cfg(simd)]
#[cfg(feature = "simd")]
pub fn bitwise_bin_op_simd_helper<F_SIMD, F_SCALAR>(
left: &Buffer,
left_offset: usize,
Expand Down Expand Up @@ -82,7 +82,7 @@ where
/// and the `scalar_op` gets applied to remaining bytes.
/// Contrary to the non-simd version `bitwise_unary_op_helper`, the offset and length is specified in bytes
/// and this version does not support operations starting at arbitrary bit offsets.
#[cfg(simd)]
#[cfg(feature = "simd")]
pub fn bitwise_unary_op_simd_helper<F_SIMD, F_SCALAR>(
left: &Buffer,
left_offset: usize,
Expand Down Expand Up @@ -411,7 +411,7 @@ pub fn buffer_unary_not(
len_in_bits: usize,
) -> Buffer {
// SIMD implementation if available and byte-aligned
#[cfg(simd)]
#[cfg(feature = "simd")]
if offset_in_bits % 8 == 0 && len_in_bits % 8 == 0 {
return bitwise_unary_op_simd_helper(
&left,
Expand Down
14 changes: 7 additions & 7 deletions arrow/src/compute/kernels/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn min_max_string<T: StringOffsetSizeTrait, F: Fn(&str, &str) -> bool>(

/// Returns the minimum value in the array, according to the natural order.
/// For floating point arrays any NaN values are considered to be greater than any other non-null value
#[cfg(not(simd))]
#[cfg(not(feature = "simd"))]
pub fn min<T>(array: &PrimitiveArray<T>) -> Option<T::Native>
where
T: ArrowNumericType,
Expand All @@ -80,7 +80,7 @@ where

/// Returns the maximum value in the array, according to the natural order.
/// For floating point arrays any NaN values are considered to be greater than any other non-null value
#[cfg(not(simd))]
#[cfg(not(feature = "simd"))]
pub fn max<T>(array: &PrimitiveArray<T>) -> Option<T::Native>
where
T: ArrowNumericType,
Expand Down Expand Up @@ -193,7 +193,7 @@ pub fn max_boolean(array: &BooleanArray) -> Option<bool> {
/// Returns the sum of values in the array.
///
/// Returns `None` if the array is empty or only contains null values.
#[cfg(not(simd))]
#[cfg(not(feature = "simd"))]
pub fn sum<T>(array: &PrimitiveArray<T>) -> Option<T::Native>
where
T: ArrowNumericType,
Expand Down Expand Up @@ -247,7 +247,7 @@ where
}
}

#[cfg(simd)]
#[cfg(feature = "simd")]
mod simd {
use super::is_nan;
use crate::array::{Array, PrimitiveArray};
Expand Down Expand Up @@ -592,7 +592,7 @@ mod simd {
/// Returns the sum of values in the array.
///
/// Returns `None` if the array is empty or only contains null values.
#[cfg(simd)]
#[cfg(feature = "simd")]
pub fn sum<T: ArrowNumericType>(array: &PrimitiveArray<T>) -> Option<T::Native>
where
T::Native: Add<Output = T::Native>,
Expand All @@ -602,7 +602,7 @@ where
simd::simd_aggregation::<T, SumAggregate<T>>(&array)
}

#[cfg(simd)]
#[cfg(feature = "simd")]
/// Returns the minimum value in the array, according to the natural order.
/// For floating point arrays any NaN values are considered to be greater than any other non-null value
pub fn min<T: ArrowNumericType>(array: &PrimitiveArray<T>) -> Option<T::Native>
Expand All @@ -614,7 +614,7 @@ where
simd::simd_aggregation::<T, MinAggregate<T>>(&array)
}

#[cfg(simd)]
#[cfg(feature = "simd")]
/// Returns the maximum value in the array, according to the natural order.
/// For floating point arrays any NaN values are considered to be greater than any other non-null value
pub fn max<T: ArrowNumericType>(array: &PrimitiveArray<T>) -> Option<T::Native>
Expand Down
52 changes: 26 additions & 26 deletions arrow/src/compute/kernels/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ use std::ops::{Add, Div, Mul, Neg, Sub};
use num::{One, Zero};

use crate::buffer::Buffer;
#[cfg(simd)]
#[cfg(feature = "simd")]
use crate::buffer::MutableBuffer;
#[cfg(not(simd))]
#[cfg(not(feature = "simd"))]
use crate::compute::kernels::arity::unary;
use crate::compute::util::combine_option_bitmap;
use crate::datatypes;
use crate::datatypes::ArrowNumericType;
use crate::error::{ArrowError, Result};
use crate::{array::*, util::bit_util};
use num::traits::Pow;
#[cfg(simd)]
#[cfg(feature = "simd")]
use std::borrow::BorrowMut;
#[cfg(simd)]
#[cfg(feature = "simd")]
use std::slice::{ChunksExact, ChunksExactMut};

/// SIMD vectorized version of `unary_math_op` above specialized for signed numerical values.
#[cfg(simd)]
#[cfg(feature = "simd")]
fn simd_signed_unary_math_op<T, SIMD_OP, SCALAR_OP>(
array: &PrimitiveArray<T>,
simd_op: SIMD_OP,
Expand Down Expand Up @@ -91,7 +91,7 @@ where
Ok(PrimitiveArray::<T>::from(data))
}

#[cfg(simd)]
#[cfg(feature = "simd")]
fn simd_float_unary_math_op<T, SIMD_OP, SCALAR_OP>(
array: &PrimitiveArray<T>,
simd_op: SIMD_OP,
Expand Down Expand Up @@ -286,7 +286,7 @@ where
}

/// SIMD vectorized version of `math_op` above.
#[cfg(simd)]
#[cfg(feature = "simd")]
fn simd_math_op<T, SIMD_OP, SCALAR_OP>(
left: &PrimitiveArray<T>,
right: &PrimitiveArray<T>,
Expand Down Expand Up @@ -351,7 +351,7 @@ where
/// SIMD vectorized implementation of `left / right`.
/// If any of the lanes marked as valid in `valid_mask` are `0` then an `ArrowError::DivideByZero`
/// is returned. The contents of no-valid lanes are undefined.
#[cfg(simd)]
#[cfg(feature = "simd")]
#[inline]
fn simd_checked_divide<T: ArrowNumericType>(
valid_mask: Option<u64>,
Expand Down Expand Up @@ -384,7 +384,7 @@ where

/// Scalar implementation of `left / right` for the remainder elements after complete chunks have been processed using SIMD.
/// If any of the values marked as valid in `valid_mask` are `0` then an `ArrowError::DivideByZero` is returned.
#[cfg(simd)]
#[cfg(feature = "simd")]
#[inline]
fn simd_checked_divide_remainder<T: ArrowNumericType>(
valid_mask: Option<u64>,
Expand Down Expand Up @@ -417,7 +417,7 @@ where
}

/// Scalar-divisor version of `simd_checked_divide_remainder`.
#[cfg(simd)]
#[cfg(feature = "simd")]
#[inline]
fn simd_checked_divide_scalar_remainder<T: ArrowNumericType>(
array_chunks: ChunksExact<T::Native>,
Expand Down Expand Up @@ -448,7 +448,7 @@ where
///
/// The divide kernels need their own implementation as there is a need to handle situations
/// where a divide by `0` occurs. This is complicated by `NULL` slots and padding.
#[cfg(simd)]
#[cfg(feature = "simd")]
fn simd_divide<T>(
left: &PrimitiveArray<T>,
right: &PrimitiveArray<T>,
Expand Down Expand Up @@ -565,7 +565,7 @@ where
}

/// SIMD vectorized version of `divide_scalar`.
#[cfg(simd)]
#[cfg(feature = "simd")]
fn simd_divide_scalar<T>(
array: &PrimitiveArray<T>,
divisor: T::Native,
Expand Down Expand Up @@ -624,9 +624,9 @@ where
+ Div<Output = T::Native>
+ Zero,
{
#[cfg(simd)]
#[cfg(feature = "simd")]
return simd_math_op(&left, &right, |a, b| a + b, |a, b| a + b);
#[cfg(not(simd))]
#[cfg(not(feature = "simd"))]
return math_op(left, right, |a, b| a + b);
}

Expand All @@ -644,9 +644,9 @@ where
+ Div<Output = T::Native>
+ Zero,
{
#[cfg(simd)]
#[cfg(feature = "simd")]
return simd_math_op(&left, &right, |a, b| a - b, |a, b| a - b);
#[cfg(not(simd))]
#[cfg(not(feature = "simd"))]
return math_op(left, right, |a, b| a - b);
}

Expand All @@ -656,9 +656,9 @@ where
T: datatypes::ArrowSignedNumericType,
T::Native: Neg<Output = T::Native>,
{
#[cfg(simd)]
#[cfg(feature = "simd")]
return simd_signed_unary_math_op(array, |x| -x, |x| -x);
#[cfg(not(simd))]
#[cfg(not(feature = "simd"))]
return Ok(unary(array, |x| -x));
}

Expand All @@ -671,7 +671,7 @@ where
T: datatypes::ArrowFloatNumericType,
T::Native: Pow<T::Native, Output = T::Native>,
{
#[cfg(simd)]
#[cfg(feature = "simd")]
{
let raise_vector = T::init(raise);
return simd_float_unary_math_op(
Expand All @@ -680,7 +680,7 @@ where
|x| x.pow(raise),
);
}
#[cfg(not(simd))]
#[cfg(not(feature = "simd"))]
return Ok(unary(array, |x| x.pow(raise)));
}

Expand All @@ -698,9 +698,9 @@ where
+ Div<Output = T::Native>
+ Zero,
{
#[cfg(simd)]
#[cfg(feature = "simd")]
return simd_math_op(&left, &right, |a, b| a * b, |a, b| a * b);
#[cfg(not(simd))]
#[cfg(not(feature = "simd"))]
return math_op(left, right, |a, b| a * b);
}

Expand All @@ -720,9 +720,9 @@ where
+ Zero
+ One,
{
#[cfg(simd)]
#[cfg(feature = "simd")]
return simd_divide(&left, &right);
#[cfg(not(simd))]
#[cfg(not(feature = "simd"))]
return math_divide(&left, &right);
}

Expand All @@ -742,9 +742,9 @@ where
+ Zero
+ One,
{
#[cfg(simd)]
#[cfg(feature = "simd")]
return simd_divide_scalar(&array, divisor);
#[cfg(not(simd))]
#[cfg(not(feature = "simd"))]
return math_divide_scalar(&array, divisor);
}

Expand Down
Loading

0 comments on commit 91ef8e9

Please sign in to comment.