summaryrefslogtreecommitdiff
path: root/modules/remote-sycl/tests/data_ref.cpp
blob: 7f5bb1b7bcc184e7f553064ee298f6da9e0786b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <forstio/test/suite.hpp>

#include "../c++/data.hpp"

namespace {
namespace sch {
using namespace saw::schema;
}

SAW_TEST("Data Ref Basics"){
	using namespace saw;

  device<rmt::Sycl> dev;
	acpp::sycl::queue& sycl_q = dev.get_handle();

	constexpr uint64_t dat_size = 1000u;

  data<sch::Array<sch::UInt64>, encode::Native> dat{{{dat_size}}};
  auto eo_syc_dat = dev.template allocate_on_device<sch::Array<sch::UInt64>,encode::Native>({{dat_size}});
  SAW_EXPECT(eo_syc_dat.is_value(), "Couldn't allocate on device");
  auto& sycl_dat = eo_syc_dat.get_value();

	{
  	auto eov = dev.copy_to_device(dat,sycl_dat);
  	SAW_EXPECT_EOV(eov);
  }

	data<sch::Ref<sch::Array<sch::UInt64>>, encode::Sycl<encode::Native>> sdat_ref{sycl_dat};
	auto dat_ptr = sdat_ref.get_internal_data();

	sycl_q.parallel_for(dat_size, [=](acpp::sycl::id<1> idx){
		size_t i = idx[0];

		dat_ptr[i] = {i};
	}).wait();

	{
		auto eov = dev.copy_to_host(sycl_dat,dat);
		SAW_EXPECT_EOV(eov);
	}
	for(saw::data<sch::UInt64> i = 0u; i < saw::data<sch::UInt64>{dat_size}; ++i){
		SAW_EXPECT(dat.at({i}) == i, std::string{"Unexpected value: "} + std::to_string(i.get()));
	}
}
}