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
64 lines
1.7 KiB
#include <iostream>
|
|
#include <random>
|
|
|
|
#include "offloading-cache.hpp"
|
|
|
|
double* GetRandomArray(const size_t size) {
|
|
double* array = new double[size];
|
|
|
|
std::uniform_real_distribution<double> unif(std::numeric_limits<double>::min(), std::numeric_limits<double>::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<offcache::CacheData> data_cache = cache.Access(reinterpret_cast<uint8_t *>(data), data_size * sizeof(double), offcache::ExecutionPolicy::Relaxed);
|
|
|
|
data_cache->WaitOnCompletion();
|
|
|
|
double* cached = reinterpret_cast<double *>(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;
|
|
}
|
|
}
|