This contains my bachelors thesis and associated tex files, code snippets and maybe more. Topic: Data Movement in Heterogeneous Memories with Intel Data Streaming Accelerator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

83 lines
2.9 KiB

// source: https://os.inf.tu-dresden.de/repo/gitbox/andre.berthold/Query-driven_Prefetching/src/branch/intel_xeon_max/code/src/utils/array_utils.h
// author: Andre Berthold
#pragma once
#include <cstdlib>
#include <ctime>
#include <cstdint>
#include <type_traits>
#include <random>
#include <chrono>
#include <immintrin.h>
/// @brief Fills a given array with random generated integers.
/// @tparam base_t Datatype of the array
/// @param dest Pointer to the array
/// @param size Size of the array
/// @param min Minumum value of the generated integers
/// @param max Maximum value of the generated integers
template<typename base_t>
void fill(base_t * dest, uint64_t size, base_t min, base_t max) {
std::srand(std::time(nullptr));
for(uint64_t i = 0; i < size/sizeof(base_t); ++i) {
dest[i] = (std::rand() % (max - min)) + min;
}
}
/// @brief Fills a given array with random generated integers using the mersenne twister engine (type std::mt19937).
/// @tparam base_t Datatype of the array
/// @param dest Pointer to the array
/// @param size Size of the array
/// @param min Minumum value of the generated integers
/// @param max Maximum value of the generated integers
template <typename T>
void fill_mt(T* array, uint64_t size, T min, T max, uint64_t int_seed = 0) {
static_assert(std::is_integral<T>::value, "Data type is not integral.");
size = size / sizeof(T);
std::mt19937::result_type seed;
if (int_seed == 0) {
std::random_device rd;
seed = rd() ^ (
(std::mt19937::result_type) std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch()).count() +
(std::mt19937::result_type) std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch()).count());
} else seed = int_seed;
std::mt19937 gen(seed);
std::uniform_int_distribution<T> distrib(min, max);
for (uint64_t j = 0; j < size; ++j) {
array[j] = distrib(gen);
}
}
/**
* @brief Checks if two arrays of the integral type *T* contain the same values
*
* @tparam T Integral type of *array0* and *array1*
* @param array0 Array 0 to check
* @param array1 Array 1 to check
* @param size_b Size of the two arrays in byte
* @param verbose Decides if outputs are verbose of not (print every not matching numbers with their index)
* @return bool Weathor or not the content is equal or not
*/
template <typename T>
typename std::enable_if<std::is_integral<T>::value, bool>::type
check_same(T* array0, T* array1, size_t size_b, bool verbose) {
for(uint64_t i = 0; i <= size_b / sizeof(T); i += 64 / sizeof(T)) {
__m512i vec0 = _mm512_stream_load_si512(array0 + i);
__m512i vec1 = _mm512_stream_load_si512(array1 + i);
__mmask8 res = _mm512_cmpeq_epi64_mask(vec0, vec1);
}
//TODO complete function
return false;
}