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.

80 lines
2.8 KiB

  1. #pragma once
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <cstdint>
  5. #include <type_traits>
  6. #include <random>
  7. #include <chrono>
  8. #include <immintrin.h>
  9. /// @brief Fills a given array with random generated integers.
  10. /// @tparam base_t Datatype of the array
  11. /// @param dest Pointer to the array
  12. /// @param size Size of the array
  13. /// @param min Minumum value of the generated integers
  14. /// @param max Maximum value of the generated integers
  15. template<typename base_t>
  16. void fill(base_t * dest, uint64_t size, base_t min, base_t max) {
  17. std::srand(std::time(nullptr));
  18. for(uint64_t i = 0; i < size/sizeof(base_t); ++i) {
  19. dest[i] = (std::rand() % (max - min)) + min;
  20. }
  21. }
  22. /// @brief Fills a given array with random generated integers using the mersenne twister engine (type std::mt19937).
  23. /// @tparam base_t Datatype of the array
  24. /// @param dest Pointer to the array
  25. /// @param size Size of the array
  26. /// @param min Minumum value of the generated integers
  27. /// @param max Maximum value of the generated integers
  28. template <typename T>
  29. void fill_mt(T* array, uint64_t size, T min, T max, uint64_t int_seed = 0) {
  30. static_assert(std::is_integral<T>::value, "Data type is not integral.");
  31. size = size / sizeof(T);
  32. std::mt19937::result_type seed;
  33. if (int_seed == 0) {
  34. std::random_device rd;
  35. seed = rd() ^ (
  36. (std::mt19937::result_type) std::chrono::duration_cast<std::chrono::seconds>(
  37. std::chrono::system_clock::now().time_since_epoch()).count() +
  38. (std::mt19937::result_type) std::chrono::duration_cast<std::chrono::microseconds>(
  39. std::chrono::high_resolution_clock::now().time_since_epoch()).count());
  40. } else seed = int_seed;
  41. std::mt19937 gen(seed);
  42. std::uniform_int_distribution<T> distrib(min, max);
  43. for (uint64_t j = 0; j < size; ++j) {
  44. array[j] = distrib(gen);
  45. }
  46. }
  47. /**
  48. * @brief Checks if two arrays of the integral type *T* contain the same values
  49. *
  50. * @tparam T Integral type of *array0* and *array1*
  51. * @param array0 Array 0 to check
  52. * @param array1 Array 1 to check
  53. * @param size_b Size of the two arrays in byte
  54. * @param verbose Decides if outputs are verbose of not (print every not matching numbers with their index)
  55. * @return bool Weathor or not the content is equal or not
  56. */
  57. template <typename T>
  58. typename std::enable_if<std::is_integral<T>::value, bool>::type
  59. check_same(T* array0, T* array1, size_t size_b, bool verbose) {
  60. for(uint64_t i = 0; i <= size_b / sizeof(T); i += 64 / sizeof(T)) {
  61. __m512i vec0 = _mm512_stream_load_si512(array0 + i);
  62. __m512i vec1 = _mm512_stream_load_si512(array1 + i);
  63. __mmask8 res = _mm512_cmpeq_epi64_mask(vec0, vec1);
  64. }
  65. //TODO complete function
  66. return false;
  67. }