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.

64 lines
1.7 KiB

  1. #include <iostream>
  2. #include <random>
  3. #include "offloading-cache.hpp"
  4. double* GetRandomArray(const size_t size) {
  5. double* array = new double[size];
  6. std::uniform_real_distribution<double> unif(std::numeric_limits<double>::min(), std::numeric_limits<double>::max());
  7. std::default_random_engine re;
  8. for (size_t i = 0; i < size; i++) {
  9. array[i] = unif(re);
  10. }
  11. return array;
  12. }
  13. bool IsEqual(const double* a, const double* b, const size_t size) {
  14. for (size_t i = 0; i < size; i++) {
  15. try {
  16. if (a[i] != b[i]) return false;
  17. }
  18. catch (...) {
  19. return false;
  20. }
  21. }
  22. return true;
  23. }
  24. int main(int argc, char **argv) {
  25. offcache::Cache cache;
  26. auto cache_policy = [](const int numa_dst_node, const int numa_src_node, const size_t data_size) {
  27. return numa_dst_node;
  28. };
  29. auto copy_policy = [](const int numa_dst_node, const int numa_src_node) {
  30. return std::vector{ numa_src_node, numa_dst_node };
  31. };
  32. cache.Init(cache_policy,copy_policy);
  33. static constexpr size_t data_size = 1024 * 1024;
  34. double* data = GetRandomArray(data_size);
  35. std::unique_ptr<offcache::CacheData> data_cache = cache.Access(reinterpret_cast<uint8_t *>(data), data_size * sizeof(double), offcache::ExecutionPolicy::Relaxed);
  36. data_cache->WaitOnCompletion();
  37. double* cached = reinterpret_cast<double *>(data_cache->GetDataLocation());
  38. if (data == cached) {
  39. std::cout << "Caching did not affect data location." << std::endl;
  40. }
  41. if (IsEqual(data,cached,data_size)) {
  42. std::cout << "Cached data is correct." << std::endl;
  43. }
  44. else {
  45. std::cout << "Cached data is wrong." << std::endl;
  46. }
  47. }