Skip to content

Commit 8f81e4f

Browse files
authored
[SYCL] Test for set_final_data(..) method (intel/llvm-test-suite#122)
Signed-off-by: mdimakov <[email protected]>
1 parent a5c29bb commit 8f81e4f

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

SYCL/Basic/buffer/buffer.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,76 @@ int main() {
502502
}
503503
}
504504

505+
// Check that data is copied back after forcing write-back using
506+
// set_write_back
507+
{
508+
size_t size = 32;
509+
const size_t dims = 1;
510+
cl::sycl::range<dims> r(size);
511+
512+
std::shared_ptr<bool> bool_shrd(new bool[size],
513+
[](bool *data) { delete[] data; });
514+
std::shared_ptr<int> int_shrd(new int[size],
515+
[](int *data) { delete[] data; });
516+
std::shared_ptr<double> double_shrd(new double[size],
517+
[](double *data) { delete[] data; });
518+
519+
std::vector<bool> bool_vector;
520+
std::vector<int> int_vector;
521+
std::vector<double> double_vector;
522+
bool_vector.reserve(size);
523+
int_vector.reserve(size);
524+
double_vector.reserve(size);
525+
526+
cl::sycl::queue Queue;
527+
cl::sycl::mutex_class m;
528+
{
529+
cl::sycl::buffer<bool, dims> buf_bool_shrd(
530+
bool_shrd, r,
531+
cl::sycl::property_list{cl::sycl::property::buffer::use_mutex(m)});
532+
cl::sycl::buffer<int, dims> buf_int_shrd(
533+
int_shrd, r,
534+
cl::sycl::property_list{cl::sycl::property::buffer::use_mutex(m)});
535+
cl::sycl::buffer<double, dims> buf_double_shrd(
536+
double_shrd, r,
537+
cl::sycl::property_list{cl::sycl::property::buffer::use_mutex(m)});
538+
m.lock();
539+
std::fill(bool_shrd.get(), (bool_shrd.get() + size), bool());
540+
std::fill(int_shrd.get(), (int_shrd.get() + size), int());
541+
std::fill(double_shrd.get(), (double_shrd.get() + size), double());
542+
m.unlock();
543+
544+
buf_bool_shrd.set_final_data(bool_vector.begin());
545+
buf_int_shrd.set_final_data(int_vector.begin());
546+
buf_double_shrd.set_final_data(double_vector.begin());
547+
buf_bool_shrd.set_write_back(true);
548+
buf_int_shrd.set_write_back(true);
549+
buf_double_shrd.set_write_back(true);
550+
551+
Queue.submit([&](cl::sycl::handler &cgh) {
552+
auto Accessor_bool =
553+
buf_bool_shrd.get_access<cl::sycl::access::mode::write>(cgh);
554+
auto Accessor_int =
555+
buf_int_shrd.get_access<cl::sycl::access::mode::write>(cgh);
556+
auto Accessor_double =
557+
buf_double_shrd.get_access<cl::sycl::access::mode::write>(cgh);
558+
cgh.parallel_for<class FillBuffer>(r, [=](cl::sycl::id<1> WIid) {
559+
Accessor_bool[WIid] = true;
560+
Accessor_int[WIid] = 3;
561+
Accessor_double[WIid] = 7.5;
562+
});
563+
});
564+
} // Data is copied back
565+
566+
for (size_t i = 0; i < size; i++) {
567+
if (bool_vector[i] != true || int_vector[i] != 3 ||
568+
double_vector[i] != 7.5) {
569+
assert(false && "Data was not copied back");
570+
return 1;
571+
}
572+
}
573+
}
574+
505575
// Check that data is not copied back after canceling write-back using
506576
// set_write_back
507577
{

0 commit comments

Comments
 (0)