#include #include #include "offloading-cache.hpp" double* GetRandomArray(const size_t size) { double* array = new double[size]; std::uniform_real_distribution unif(std::numeric_limits::min(), std::numeric_limits::max()); std::default_random_engine re; for (size_t i = 0; i < size; i++) { array[i] = unif(re); } return array; } bool IsEqual(const double* a, const double* b, const size_t size) { for (size_t i = 0; i < size; i++) { try { if (a[i] != b[i]) return false; } catch (...) { return false; } } return true; } int main(int argc, char **argv) { offcache::Cache cache; auto cache_policy = [](const int numa_dst_node, const int numa_src_node, const size_t data_size) { return numa_dst_node; }; auto copy_policy = [](const int numa_dst_node, const int numa_src_node) { return std::vector{ numa_src_node, numa_dst_node }; }; cache.Init(cache_policy,copy_policy); static constexpr size_t data_size = 1024 * 1024; double* data = GetRandomArray(data_size); std::unique_ptr data_cache = cache.Access(reinterpret_cast(data), data_size * sizeof(double), offcache::ExecutionPolicy::Relaxed); data_cache->WaitOnCompletion(); double* cached = reinterpret_cast(data_cache->GetDataLocation()); if (data == cached) { std::cout << "Caching did not affect data location." << std::endl; } if (IsEqual(data,cached,data_size)) { std::cout << "Cached data is correct." << std::endl; } else { std::cout << "Cached data is wrong." << std::endl; } }