Experimental::simd_mask#
Header File: Kokkos_SIMD.hpp
Usage:
Kokkos::Experimental::simd_mask is an abstraction over platform-specific vector masks and calls platform-specific vector intrinsics.
It is based on the simd_mask type proposed for ISO C++ in this document
Interface#
namespace Experimental {
template <class T, class Abi>
class simd_mask;
}
Template Parameters#
The first template parameter T should be a C++ fundamental type for which the current platform supports vector intrinsics. Kokkos supports the following types for T:
doublestd::int32_tstd::int64_tstd::uint32_tstd::uint64_t
The second template parameter Abi is one of the pre-defined ABI types in the namespace Kokkos::Experimental::simd_abi. This type determines the size of the vector and what architecture-specific intrinsics will be used. The following types are always available in that namespace:
scalar: a fallback ABI which always has vector size of 1 and uses no special intrinsics.native: the “best” ABI for the architecture for which Kokkos was compiled.
Typedefs#
value_type: Equal toboolreference: This type should be convertible toboolandboolshould be assignable toreference. It may be a plain reference or it may be a special class that calls vector intrinsics to extract or fill in one mask bit.simd_type: Equal tosimd<T, Abi>abi_type: Equal toAbi
Width#
static constexpr std::size_t size():simd_mask<T, Abi>::size()is a compile-time constant of the width of the vector, i.e. the number of values of typeTin the vector.
Constructors#
simd_mask(): Default Constructor. The vector values are not initialized by this constructor.simd_mask(bool): Single-value constructor. All values in the mask will be set to the value of the argument.template <class G> simd_mask(G&& gen): Generator constructor. The generatorgenshould be a callable type (e.g. functor) that can acceptstd::integral_constant<std::size_t, i>()as an argument and return something convertible tobool. Vector mask valueiwill be initialized to the value ofgen(std::integral_constant<std::size_t, i>()).
Value Access Methods#
reference operator[](std::size_t): returns a reference to mask valueithat can be modified.bool operator[](std::size_t) const: returns the mask valuei.
Boolean Operators#
simd_mask simd_mask::operator!() constsimd_mask operator&&(const simd_mask& lhs, const simd_mask& rhs)simd_mask operator||(const simd_mask& lhs, const simd_mask& rhs)
Comparison Operators#
simd_mask operator==(const simd_mask& lhs, const simd_mask& rhs)simd_mask operator!=(const simd_mask& lhs, const simd_mask& rhs)
Reductions#
bool all_of(const simd_mask&): returns true iff all of the vector values in the mask are truebool any_of(const simd_mask&): returns true iff any of the vector values in the mask are truebool none_of(const simd_mask&): returns true iff none of the vector values in the mask are true
Global Typedefs#
template <class T> Kokkos::Experimental::native_simd_mask: Alias forKokkos::Experimental::simd_mask<T, Kokkos::Experimental::simd_abi::native<T>>.
Examples#
#include <Kokkos_SIMD.hpp>
#include <cstdio>
int main(int argc, char* argv[]) {
Kokkos::initialize(argc,argv);
{
using mask_type = Kokkos::Experimental::native_simd_mask<double>;
mask_type a([] (std::size_t i) { return i == 0; });
mask_type b([] (std::size_t i) { return i == 1; });
mask_type c([] (std::size_t i) { return i == 0 || i == 1; });
if (all_of(c == (a || b))) {
printf("Kokkos simd_mask works as expected!");
}
}
Kokkos::finalize();
}