SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches

The simd module contains a unified interface to provide simd types and functions used in seqan3. More...

+ Collaboration diagram for SIMD:

Modules

 Views
 SIMD related views.
 

Classes

struct  seqan3::detail::builtin_simd< scalar_t, length >
 A class that holds the type of a simd implementation called [vector extension] (https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html) (formerly known as "seqan simd" in seqan2). More...
 
struct  seqan3::detail::builtin_simd< scalar_t, length >
 A class that holds the type of a simd implementation called [vector extension] (https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html) (formerly known as "seqan simd" in seqan2). More...
 
struct  seqan3::detail::builtin_simd_traits_helper< builtin_simd_t >
 Helper struct for seqan3::detail::is_builtin_simd. More...
 
struct  seqan3::detail::builtin_simd_traits_helper< builtin_simd_t >
 Helper struct for seqan3::detail::is_builtin_simd. More...
 
struct  seqan3::detail::is_builtin_simd< builtin_simd_t >
 This class inherits from std::true_type, iff seqan3::detail::builtin_simd<scalar_t, length>::type is a builtin simd type. More...
 
struct  seqan3::detail::is_native_builtin_simd< builtin_simd_t >
 This class inherits from std::true_type, iff the builtin simd type is supported by the current architecture. More...
 
interface  simd_concept
 The generic simd concept. More...
 
interface  simd_index
 Refines the seqan3::simd::simd_concept requiring the underlying scalar type to model std::integral. More...
 
struct  seqan3::simd::simd_traits< simd_t >
 seqan3::simd::simd_traits is the trait class that provides uniform interface to the properties of simd_t types. More...
 
struct  seqan3::simd::simd_traits< builtin_simd_t >
 This class specializes seqan3::simd::simd_traits for seqan3::detail::builtin_simd types. More...
 
struct  seqan3::simd::simd_type< scalar_t, length, simd_backend >
 seqan3::simd::simd_type encapsulates simd vector types, which can be manipulated by simd operations. More...
 

Typedefs

template<typename scalar_t , size_t length>
using seqan3::detail::default_simd_backend = builtin_simd< scalar_t, length >
 seqan3::detail::default_simd_backend is the default used implementation of seqan3::simd::simd_type.
 
template<typename scalar_t , size_t length = detail::default_simd_length<scalar_t, detail::default_simd_backend>, template< typename scalar_t_, size_t length_ > typename simd_backend = detail::default_simd_backend>
using seqan3::simd::simd_type_t = typename simd_type< scalar_t, length, simd_backend >::type
 Helper type of seqan3::simd::simd_type.
 

Functions

template<uint8_t index, simd::simd_concept simd_t>
constexpr simd_t seqan3::detail::extract_eighth (simd_t const &src)
 Extracts one eighth of the given simd vector and stores it in the lower eighth of the target vector.
 
template<uint8_t index, simd::simd_concept simd_t>
constexpr simd_t seqan3::detail::extract_half (simd_t const &src)
 Extracts one half of the given simd vector and stores the result in the lower half of the target vector.
 
template<size_t divisor, simd_concept simd_t>
constexpr simd_t seqan3::detail::extract_impl (simd_t const &src, uint8_t const mask)
 Helper function to extract a part of the given simd vector.
 
template<uint8_t index, simd::simd_concept simd_t>
constexpr simd_t seqan3::detail::extract_quarter (simd_t const &src)
 Extracts one quarter of the given simd vector and stores it in the lower quarter of the target vector.
 
template<simd::simd_concept simd_t>
constexpr simd_t seqan3::simd::fill (typename simd_traits< simd_t >::scalar_type const scalar) noexcept
 Fills a seqan3::simd::simd_type vector with a scalar value.
 
template<simd::simd_concept simd_t, size_t... I>
constexpr simd_t seqan3::detail::fill_impl (typename simd_traits< simd_t >::scalar_type const scalar, std::index_sequence< I... >) noexcept
 Helper function for seqan3::simd::fill.
 
template<simd::simd_concept simd_t>
constexpr simd_t seqan3::simd::iota (typename simd_traits< simd_t >::scalar_type const offset)
 Fills a seqan3::simd::simd_type vector with the scalar values offset, offset+1, offset+2, ...
 
template<simd::simd_concept simd_t, typename scalar_t , scalar_t... I>
constexpr simd_t seqan3::detail::iota_impl (scalar_t const offset, std::integer_sequence< scalar_t, I... >)
 Helper function for seqan3::simd::iota.
 
template<simd::simd_concept simd_t>
constexpr simd_t seqan3::simd::load (void const *mem_addr)
 Load simd_t size bits of integral data from memory.
 
template<typename char_t , typename simd_t >
requires simd::simd_concept<std::remove_cvref_t<simd_t>>
debug_stream_type< char_t > & seqan3::operator<< (debug_stream_type< char_t > &s, simd_t &&simd)
 Overload for debug_stream for simd types.
 
template<simd::simd_concept simd_t>
constexpr void seqan3::simd::store (void *mem_addr, simd_t const &simd_vec)
 Store simd_t size bits of integral data into memory.
 
template<simd::simd_concept simd_t>
constexpr void seqan3::simd::transpose (std::array< simd_t, simd_traits< simd_t >::length > &matrix)
 Transposes the given simd vector matrix.
 
template<simd::simd_concept target_simd_t, simd::simd_concept source_simd_t>
constexpr target_simd_t seqan3::simd::upcast (source_simd_t const &src)
 Upcasts the given vector into the target vector using sign extension of packed values.
 
template<simd::simd_concept target_simd_t, simd::simd_concept source_simd_t>
constexpr target_simd_t seqan3::detail::upcast_signed (source_simd_t const &src)
 Upcasts the given vector into the target vector using signed extension of packed values.
 
template<simd::simd_concept target_simd_t, simd::simd_concept source_simd_t>
constexpr target_simd_t seqan3::detail::upcast_unsigned (source_simd_t const &src)
 Upcasts the given vector into the target vector using unsigned extension of packed values.
 

Variables

template<typename scalar_t , template< typename, size_t > typename simd_backend_t>
constexpr auto seqan3::detail::default_simd_length
 seqan3::detail::default_simd_length returns the default length depending on the given scalar_t type, which is used in seqan3::simd::simd_type.
 
template<template< typename, size_t > typename simd_backend_t>
constexpr auto seqan3::detail::default_simd_max_length = 0u
 seqan3 auto-detects the maximum number of packable [u]int8_t types.
 
template<>
constexpr auto seqan3::detail::default_simd_max_length< builtin_simd >
 This function specializes seqan3::detail::default_simd_max_length for seqan3::detail::builtin_simd.
 
template<typename builtin_simd_t >
constexpr bool seqan3::detail::is_builtin_simd_v = is_builtin_simd<builtin_simd_t>::value
 Helper variable to test whether a type is a simd builtin type.
 
template<typename builtin_simd_t >
constexpr bool seqan3::detail::is_native_builtin_simd_v = is_native_builtin_simd<builtin_simd_t>::value
 Helper variable to test whether a type is a native simd builtin type.
 

Detailed Description

The simd module contains a unified interface to provide simd types and functions used in seqan3.

See also
Utility
https://en.wikipedia.org/wiki/SIMD

There are different simd implementations (backends), which are auto-selected by seqan3::simd::simd_type_t. Namely seqan3::detail::builtin_simd.

Todo:
Make this public again. We made this documentation internal-documentation only for the 3.0.0 release, because the API was not in shape yet. Remove /utility/simd/ exclusion from EXCLUDE_PATTERNS.
Todo:
Describe more what SIMD is and how to use it.

Typedef Documentation

◆ default_simd_backend

template<typename scalar_t , size_t length>
using seqan3::detail::default_simd_backend = typedef builtin_simd<scalar_t, length>

seqan3::detail::default_simd_backend is the default used implementation of seqan3::simd::simd_type.

Template Parameters
scalar_tThe underlying type of a simd vector
lengthThe number of packed values in a simd vector

Function Documentation

◆ extract_eighth()

template<uint8_t index, simd::simd_concept simd_t>
constexpr simd_t seqan3::detail::extract_eighth ( simd_t const &  src)
constexpr

Extracts one eighth of the given simd vector and stores it in the lower eighth of the target vector.

Template Parameters
indexAn index value in the range of [0, 1, 2, 3, 4, 5, 6, 7].
simd_tThe simd type.
Parameters
srcThe source to extract the eighth from.
Returns
A simd vector with the lower bits set with the respective eighth from src If the simd vector contains less than 8 elements, the unchanged source will be returned.

Only the first simd length / 8 elements are defined. The value of the remaining elements is implementation defined.

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
int main()
{
int16x8_t a{0, -1, 2, -3, 4, -5, 6, -7};
int16x8_t b = seqan3::detail::extract_half<1>(a);
int16x8_t c = seqan3::detail::extract_quarter<1>(a);
int16x8_t d = seqan3::detail::extract_eighth<7>(a);
seqan3::debug_stream << b << '\n'; // [4,-5,6,-7,0,0,0,0]
seqan3::debug_stream << c << '\n'; // [2,-3,0,0,0,0,0,0]
seqan3::debug_stream << d << '\n'; // [-7,0,0,0,0,0,0,0]
return 0;
}
Provides seqan3::debug_stream and related types.
Provides seqan3::debug_stream overload for seqan3::simd::simd_type.
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition debug_stream.hpp:37
typename simd_type< scalar_t, length, simd_backend >::type simd_type_t
Helper type of seqan3::simd::simd_type.
Definition simd.hpp:56
Meta-header for the Utility / SIMD submodule .

Example operation for SSE4:

i := index * 16
dst[15:0] := src[i+15:i]

◆ extract_half()

template<uint8_t index, simd::simd_concept simd_t>
constexpr simd_t seqan3::detail::extract_half ( simd_t const &  src)
constexpr

Extracts one half of the given simd vector and stores the result in the lower half of the target vector.

Template Parameters
indexAn index value in the range of [0, 1].
simd_tThe simd type.
Parameters
srcThe source to extract the half from.
Returns
A simd vector with the lower bits set with the respective half from src If the simd vector contains less than 2 elements, the unchanged source will be returned.

Only the first simd length / 2 elements are defined. The value of the remaining elements is implementation defined.

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
int main()
{
int16x8_t a{0, -1, 2, -3, 4, -5, 6, -7};
int16x8_t b = seqan3::detail::extract_half<1>(a);
int16x8_t c = seqan3::detail::extract_quarter<1>(a);
int16x8_t d = seqan3::detail::extract_eighth<7>(a);
seqan3::debug_stream << b << '\n'; // [4,-5,6,-7,0,0,0,0]
seqan3::debug_stream << c << '\n'; // [2,-3,0,0,0,0,0,0]
seqan3::debug_stream << d << '\n'; // [-7,0,0,0,0,0,0,0]
return 0;
}

Example operation for SSE4:

i := index * 64
dst[63:0] := src[i+63:i]

◆ extract_impl()

template<size_t divisor, simd_concept simd_t>
constexpr simd_t seqan3::detail::extract_impl ( simd_t const &  src,
uint8_t const  mask 
)
constexpr

Helper function to extract a part of the given simd vector.

Template Parameters
divisorThe divisor to select the chunk size.
simd_tThe simd type; must model seqan3::simd::simd_concept.
Parameters
[in]srcThe source vector to extract from.
[in]maskThe control mask to select which chunk is extracted.
Returns
The destination vector containing the extracted part.

Extracts the specified part of the source simd vector and stores it in the first chunk starting at offset 0 in the destination vector.

◆ extract_quarter()

template<uint8_t index, simd::simd_concept simd_t>
constexpr simd_t seqan3::detail::extract_quarter ( simd_t const &  src)
constexpr

Extracts one quarter of the given simd vector and stores it in the lower quarter of the target vector.

Template Parameters
indexAn index value in the range of [0, 1, 2, 3].
simd_tThe simd type.
Parameters
srcThe source to extract the quarter from.
Returns
A simd vector with the lower bits set with the respective quarter from src. If the simd vector contains less than 4 elements, the unchanged source will be returned.

Only the first simd length / 4 elements are defined. The value of the remaining elements is implementation defined.

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
int main()
{
int16x8_t a{0, -1, 2, -3, 4, -5, 6, -7};
int16x8_t b = seqan3::detail::extract_half<1>(a);
int16x8_t c = seqan3::detail::extract_quarter<1>(a);
int16x8_t d = seqan3::detail::extract_eighth<7>(a);
seqan3::debug_stream << b << '\n'; // [4,-5,6,-7,0,0,0,0]
seqan3::debug_stream << c << '\n'; // [2,-3,0,0,0,0,0,0]
seqan3::debug_stream << d << '\n'; // [-7,0,0,0,0,0,0,0]
return 0;
}

Example operation for SSE4:

i := index * 32
dst[31:0] := src[i+31:i]

◆ fill()

template<simd::simd_concept simd_t>
constexpr simd_t seqan3::simd::fill ( typename simd_traits< simd_t >::scalar_type const  scalar)
constexprnoexcept

Fills a seqan3::simd::simd_type vector with a scalar value.

Template Parameters
simd_tThe simd type which satisfies seqan3::simd::simd_concept.
Parameters
[in]scalarThe scalar value to fill the seqan3::simd::simd_type vector.
// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
int main()
{
uint16x8_t a = seqan3::fill<uint16x8_t>(4);
seqan3::debug_stream << a << "\n"; // [4,4,4,4,4,4,4,4]
// or:
uint16x8_t b = seqan3::simd::fill<uint16x8_t>(4);
seqan3::debug_stream << b << "\n"; // [4,4,4,4,4,4,4,4]
return 0;
}

◆ iota()

template<simd::simd_concept simd_t>
constexpr simd_t seqan3::simd::iota ( typename simd_traits< simd_t >::scalar_type const  offset)
constexpr

Fills a seqan3::simd::simd_type vector with the scalar values offset, offset+1, offset+2, ...

Template Parameters
simd_tThe simd type which satisfies seqan3::simd::simd_concept.
Parameters
[in]offsetThe scalar offset to fill the seqan3::simd::simd_type vector
// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
int main()
{
uint16x8_t a = seqan3::iota<uint16x8_t>(1);
seqan3::debug_stream << a << "\n"; // [1,2,3,4,5,6,7,8]
// or:
uint16x8_t b = seqan3::simd::iota<uint16x8_t>(1);
seqan3::debug_stream << b << "\n"; // [1,2,3,4,5,6,7,8]
return 0;
}

◆ load()

template<simd::simd_concept simd_t>
constexpr simd_t seqan3::simd::load ( void const *  mem_addr)
constexpr

Load simd_t size bits of integral data from memory.

Template Parameters
simd_tThe simd type; must model seqan3::simd::simd_concept.
Parameters
[in]mem_addrThe memory address to load from. Does not need to be aligned on any particular boundary.
// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
int main()
{
std::vector<uint16_t> memory{0, 1, 2, 3, 4, 5, 6, 7};
uint16x8_t a = seqan3::simd::load<uint16x8_t>(memory.data());
seqan3::debug_stream << a << '\n'; // [0,1,2,3,4,5,6,7]
return 0;
}

◆ store()

template<simd::simd_concept simd_t>
constexpr void seqan3::simd::store ( void *  mem_addr,
simd_t const &  simd_vec 
)
constexpr

Store simd_t size bits of integral data into memory.

Template Parameters
simd_tThe simd type; must model seqan3::simd::simd_concept.
Parameters
[in]mem_addrThe memory address to write to. Does not need to be aligned on any particular boundary.
[in]simd_vecThe simd vector to read the data from.
// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
int main()
{
uint16x8_t a = seqan3::simd::iota<uint16x8_t>(0);
seqan3::simd::store(memory.data(), a);
seqan3::debug_stream << memory << '\n'; // [0,1,2,3,4,5,6,7]
return 0;
}
constexpr void store(void *mem_addr, simd_t const &simd_vec)
Store simd_t size bits of integral data into memory.
Definition algorithm.hpp:374
seqan3::simd::simd_traits is the trait class that provides uniform interface to the properties of sim...
Definition simd_traits.hpp:38

◆ transpose()

template<simd::simd_concept simd_t>
constexpr void seqan3::simd::transpose ( std::array< simd_t, simd_traits< simd_t >::length > &  matrix)
constexpr

Transposes the given simd vector matrix.

Template Parameters
simd_tThe simd vector type; must model seqan3::simd::simd_concept and must be a simd built-in type.
Parameters
[in,out]matrixThe matrix that is transposed in place.
// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <array>
int main()
{
{uint8x4_t{0, 1, 2, 3}, uint8x4_t{0, 1, 2, 3}, uint8x4_t{0, 1, 2, 3}, uint8x4_t{0, 1, 2, 3}}};
seqan3::debug_stream << matrix[0] << '\n'; // [0,0,0,0]
seqan3::debug_stream << matrix[1] << '\n'; // [1,1,1,1]
seqan3::debug_stream << matrix[2] << '\n'; // [2,2,2,2]
seqan3::debug_stream << matrix[3] << '\n'; // [3,3,3,3]
return 0;
}
constexpr void transpose(std::array< simd_t, simd_traits< simd_t >::length > &matrix)
Transposes the given simd vector matrix.
Definition algorithm.hpp:420

Exception

Strong exception guarantee.

Complexity

Quadratic.

◆ upcast()

template<simd::simd_concept target_simd_t, simd::simd_concept source_simd_t>
constexpr target_simd_t seqan3::simd::upcast ( source_simd_t const &  src)
constexpr

Upcasts the given vector into the target vector using sign extension of packed values.

Template Parameters
simd_tThe simd type; must model seqan3::simd::simd_concept and must be a builtin simd type.
// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
int main()
{
int16x8_t a{0, -1, 2, -3, 4, -5, 6, -7};
int32x4_t b = seqan3::simd::upcast<int32x4_t>(a);
seqan3::debug_stream << b << '\n'; // [0,-1,2,-3]
return 0;
}

◆ upcast_signed()

template<simd::simd_concept target_simd_t, simd::simd_concept source_simd_t>
constexpr target_simd_t seqan3::detail::upcast_signed ( source_simd_t const &  src)
constexpr

Upcasts the given vector into the target vector using signed extension of packed values.

Template Parameters
target_simd_tThe target simd type; must model seqan3::simd::simd_concept and must be a native builtin simd type.
source_simd_tThe source simd type; must model seqan3::simd::simd_concept and must be a native builtin simd type.
Parameters
[in]srcThe source to upcast into target_simd_t.

◆ upcast_unsigned()

template<simd::simd_concept target_simd_t, simd::simd_concept source_simd_t>
constexpr target_simd_t seqan3::detail::upcast_unsigned ( source_simd_t const &  src)
constexpr

Upcasts the given vector into the target vector using unsigned extension of packed values.

Template Parameters
target_simd_tThe target simd type; must model seqan3::simd::simd_concept and must be a native builtin simd type.
source_simd_tThe source simd type; must model seqan3::simd::simd_concept and must be a native builtin simd type.
Parameters
[in]srcThe source to upcast into target_simd_t.

Variable Documentation

◆ default_simd_length

template<typename scalar_t , template< typename, size_t > typename simd_backend_t>
constexpr auto seqan3::detail::default_simd_length
constexpr
Initial value:
= []
{
constexpr auto max_length = default_simd_max_length<simd_backend_t>;
if constexpr (max_length == 0)
return min_viable_uint_v<1u>;
else
return min_viable_uint_v<max_length / sizeof(scalar_t)>;
}()
constexpr auto min_viable_uint_v
Given a value, cast the value as the smallest unsigned integer that can hold it.
Definition integer_traits.hpp:40

seqan3::detail::default_simd_length returns the default length depending on the given scalar_t type, which is used in seqan3::simd::simd_type.

Template Parameters
scalar_tThe underlying type of a simd vector
simd_backend_tThe name of the simd backend.

◆ default_simd_max_length

template<template< typename, size_t > typename simd_backend_t>
constexpr auto seqan3::detail::default_simd_max_length = 0u
constexpr

seqan3 auto-detects the maximum number of packable [u]int8_t types.

Template Parameters
simd_backend_tThe name of the simd backend.
// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
int main()
{
constexpr auto max_length = seqan3::detail::default_simd_max_length<seqan3::detail::default_simd_backend>;
uint8_simd_t a = seqan3::fill<uint8_simd_t>(4);
uint8_simd_t b = seqan3::fill<uint8_simd_t>(5);
uint8_simd_t c = a + b;
seqan3::debug_stream << c << "\n"; // [9,9,9,9,9,9,9,9]
return 0;
}

This value is influenced by compiler flags like -march=native, -msse4, -mavx2, etc and sets this value accordingly.

See also
https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html#x86-Options for simd instruction sets and their flags.

◆ default_simd_max_length< builtin_simd >

template<>
constexpr auto seqan3::detail::default_simd_max_length< builtin_simd >
inlineconstexpr
Initial value:
= []()
{
return min_viable_uint_v<0u>;
}()

This function specializes seqan3::detail::default_simd_max_length for seqan3::detail::builtin_simd.

The redefinition of default_simd_max_length influences the default length (i.e., seqan3::detail::default_simd_length) of seqan3::simd::simd_type for seqan3::detail::builtin_simd types.

◆ is_builtin_simd_v

template<typename builtin_simd_t >
constexpr bool seqan3::detail::is_builtin_simd_v = is_builtin_simd<builtin_simd_t>::value
constexpr

Helper variable to test whether a type is a simd builtin type.

Template Parameters
builtin_simd_tThe type to check.
See also
seqan3::detail::is_builtin_simd

◆ is_native_builtin_simd_v

template<typename builtin_simd_t >
constexpr bool seqan3::detail::is_native_builtin_simd_v = is_native_builtin_simd<builtin_simd_t>::value
constexpr

Helper variable to test whether a type is a native simd builtin type.

Template Parameters
builtin_simd_tThe type to check.
See also
seqan3::detail::is_native_builtin_simd_v
Hide me