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

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