E.V.E
v2023.02.15
Loading...
Searching...
No Matches
Frequency Scaling.

In SIMD programming there is a known issue of processor frequency scaling: when working with wider registers, in order to avoid overheating, some processors limit their CPU frequency. There are a lot of situations where this can happen but it is a noticeable problem mostly for 64 byte registers on intel avx512 cpus.

This is why, for example, if you look at libc, it at most uses 32 byte registers: sure you might speed up the strlen somewhat but then all the code after will be slower.

For big datasets the price of lower frequency is often outweighed by processing more numbers in one operation, and speed-ups of 15% are not unheard of.

This was a sticking point in the API design, but we decided to go with 32 byte registers by default on AVX512. You can override that default with the EVE_AVX512_DEFAULT_64_BYTES define. The wider registers are always available through the eve::max_native_wide and eve::max_native_logical typedefs. For algorithms, there is the eve::algo::allow_frequency_scaling trait.

Note
Other than on intel avx512 we always use the maximum register width, since we expect the compiler to do so anyway and it is generally accepted. If you want to set a specific width for an algorithm, you can always use eve::algo::force_width.
#include <eve/module/core.hpp>
#include <eve/module/algo.hpp>
#include <span>
#ifndef EVE_AVX512_DEFAULT_64_BYTES
static_assert(eve::current_api != eve::avx512 || eve::expected_width_v<std::int8_t> == 32);
static_assert(eve::current_api != eve::avx512 || eve::max_native_width_v<std::int8_t> == 64);
#endif // EVE_AVX512_DEFAULT_64_BYTES
auto find_small_array(std::span<const int> a)
-> std::span<const int>::iterator
{
return eve::algo::find_if(a, [](eve::wide<int> x) { return x < 0; });
}
auto find_large_array(std::span<const int> a)
-> std::span<const int>::iterator
{
[](eve::max_native_wide<int> x) { return x < 0; });
}
auto find_use_4_ints(std::span<const int> a)
-> std::span<const int>::iterator
{
[](eve::wide<int, 4> x) { return x < 0; });
}