|
14 | 14 | //
|
15 | 15 | //===----------------------------------------------------------------------===//
|
16 | 16 |
|
| 17 | +#include <sycl/sycl.hpp> |
| 18 | + |
17 | 19 | #include <cassert>
|
18 |
| -#include <iostream> |
19 | 20 | #include <memory>
|
20 |
| -#include <sycl/sycl.hpp> |
21 | 21 |
|
22 | 22 | using namespace sycl;
|
23 | 23 |
|
24 | 24 | int main() {
|
25 | 25 | int data = 5;
|
26 | 26 | bool failed = false;
|
27 | 27 | buffer<int, 1> buf(&data, range<1>(1));
|
28 |
| - |
29 | 28 | {
|
30 | 29 | int data1[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
|
31 | 30 | {
|
@@ -509,6 +508,7 @@ int main() {
|
509 | 508 | size_t size = 32;
|
510 | 509 | const size_t dims = 1;
|
511 | 510 | sycl::range<dims> r(size);
|
| 511 | + |
512 | 512 | std::shared_ptr<bool> bool_shrd(new bool[size],
|
513 | 513 | [](bool *data) { delete[] data; });
|
514 | 514 | std::shared_ptr<int> int_shrd(new int[size],
|
@@ -551,6 +551,7 @@ int main() {
|
551 | 551 | std::fill(double_shrd.get(), (double_shrd.get() + size), double());
|
552 | 552 | #endif
|
553 | 553 | m.unlock();
|
| 554 | + |
554 | 555 | buf_bool_shrd.set_final_data(bool_vector.begin());
|
555 | 556 | buf_int_shrd.set_final_data(int_vector.begin());
|
556 | 557 | #ifdef ENABLE_FP64
|
@@ -591,137 +592,136 @@ int main() {
|
591 | 592 | #endif
|
592 | 593 | assert(Passed && "Data was not copied back");
|
593 | 594 | }
|
| 595 | + } |
594 | 596 |
|
595 |
| - // Check that data is not copied back after canceling write-back using |
596 |
| - // set_write_back |
597 |
| - { |
598 |
| - std::vector<int> data1(10, -1); |
599 |
| - { |
600 |
| - buffer<int, 1> b(range<1>(10)); |
601 |
| - b.set_final_data(data1.data()); |
602 |
| - b.set_write_back(false); |
603 |
| - queue myQueue; |
604 |
| - myQueue.submit([&](handler &cgh) { |
605 |
| - auto B = b.get_access<access::mode::read_write>(cgh); |
606 |
| - cgh.parallel_for<class notwb>(range<1>{10}, |
607 |
| - [=](id<1> index) { B[index] = 0; }); |
608 |
| - }); |
609 |
| - } |
610 |
| - // Data is not copied back because write-back is canceled |
611 |
| - for (int i = 0; i < 10; i++) |
612 |
| - if (data1[i] != -1) { |
613 |
| - assert(false); |
614 |
| - failed = true; |
615 |
| - } |
616 |
| - } |
617 |
| - |
| 597 | + // Check that data is not copied back after canceling write-back using |
| 598 | + // set_write_back |
| 599 | + { |
| 600 | + std::vector<int> data1(10, -1); |
618 | 601 | {
|
619 |
| - std::vector<int> data1(10, -1); |
620 |
| - std::vector<int> data2(10, -2); |
621 |
| - { |
622 |
| - buffer<int, 1> a(data1.data(), range<1>(10)); |
623 |
| - buffer<int, 1> b(data2.data(), range<1>(10)); |
624 |
| - queue myQueue; |
625 |
| - myQueue.submit([&](handler &cgh) { |
626 |
| - auto A = a.get_access<access::mode::read_write>(cgh); |
627 |
| - auto B = b.get_access<access::mode::read_write>(cgh); |
628 |
| - cgh.parallel_for<class override_lambda>( |
629 |
| - range<1>{10}, [=](id<1> index) { A[index] = 0; }); |
630 |
| - }); |
631 |
| - } // Data is copied back |
632 |
| - for (int i = 0; i < 10; i++) |
633 |
| - assert(data2[i] == -2); |
634 |
| - for (int i = 0; i < 10; i++) |
635 |
| - assert(data1[i] == 0); |
| 602 | + buffer<int, 1> b(range<1>(10)); |
| 603 | + b.set_final_data(data1.data()); |
| 604 | + b.set_write_back(false); |
| 605 | + queue myQueue; |
| 606 | + myQueue.submit([&](handler &cgh) { |
| 607 | + auto B = b.get_access<access::mode::read_write>(cgh); |
| 608 | + cgh.parallel_for<class notwb>(range<1>{10}, |
| 609 | + [=](id<1> index) { B[index] = 0; }); |
| 610 | + }); |
636 | 611 | }
|
| 612 | + // Data is not copied back because write-back is canceled |
| 613 | + for (int i = 0; i < 10; i++) |
| 614 | + if (data1[i] != -1) { |
| 615 | + assert(false); |
| 616 | + failed = true; |
| 617 | + } |
| 618 | + } |
637 | 619 |
|
| 620 | + { |
| 621 | + std::vector<int> data1(10, -1); |
| 622 | + std::vector<int> data2(10, -2); |
638 | 623 | {
|
639 |
| - std::vector<int> data1(10, -1); |
640 |
| - std::vector<int> data2(10, -2); |
641 |
| - { |
642 |
| - buffer<int, 1> a(data1.data(), range<1>(10)); |
643 |
| - buffer<int, 1> b(data2); |
644 |
| - accessor<int, 1, access::mode::read_write, access::target::device, |
645 |
| - access::placeholder::true_t> |
646 |
| - A(a); |
647 |
| - accessor<int, 1, access::mode::read_write, access::target::device, |
648 |
| - access::placeholder::true_t> |
649 |
| - B(b); |
650 |
| - queue myQueue; |
651 |
| - myQueue.submit([&](handler &cgh) { |
652 |
| - cgh.require(A); |
653 |
| - cgh.require(B); |
654 |
| - cgh.parallel_for<class override_lambda_placeholder>( |
655 |
| - range<1>{10}, [=](id<1> index) { A[index] = 0; }); |
656 |
| - }); |
657 |
| - } // Data is copied back |
658 |
| - for (int i = 0; i < 10; i++) |
659 |
| - assert(data2[i] == -2); |
660 |
| - for (int i = 0; i < 10; i++) |
661 |
| - assert(data1[i] == 0); |
662 |
| - } |
| 624 | + buffer<int, 1> a(data1.data(), range<1>(10)); |
| 625 | + buffer<int, 1> b(data2.data(), range<1>(10)); |
| 626 | + queue myQueue; |
| 627 | + myQueue.submit([&](handler &cgh) { |
| 628 | + auto A = a.get_access<access::mode::read_write>(cgh); |
| 629 | + auto B = b.get_access<access::mode::read_write>(cgh); |
| 630 | + cgh.parallel_for<class override_lambda>( |
| 631 | + range<1>{10}, [=](id<1> index) { A[index] = 0; }); |
| 632 | + }); |
| 633 | + } // Data is copied back |
| 634 | + for (int i = 0; i < 10; i++) |
| 635 | + assert(data2[i] == -2); |
| 636 | + for (int i = 0; i < 10; i++) |
| 637 | + assert(data1[i] == 0); |
| 638 | + } |
663 | 639 |
|
| 640 | + { |
| 641 | + std::vector<int> data1(10, -1); |
| 642 | + std::vector<int> data2(10, -2); |
664 | 643 | {
|
665 |
| - int data[10]; |
666 |
| - void *voidPtr = (void *)data; |
667 |
| - buffer<int, 1> b(range<1>(10)); |
668 |
| - b.set_final_data(voidPtr); |
669 |
| - } |
| 644 | + buffer<int, 1> a(data1.data(), range<1>(10)); |
| 645 | + buffer<int, 1> b(data2); |
| 646 | + accessor<int, 1, access::mode::read_write, access::target::device, |
| 647 | + access::placeholder::true_t> |
| 648 | + A(a); |
| 649 | + accessor<int, 1, access::mode::read_write, access::target::device, |
| 650 | + access::placeholder::true_t> |
| 651 | + B(b); |
| 652 | + queue myQueue; |
| 653 | + myQueue.submit([&](handler &cgh) { |
| 654 | + cgh.require(A); |
| 655 | + cgh.require(B); |
| 656 | + cgh.parallel_for<class override_lambda_placeholder>( |
| 657 | + range<1>{10}, [=](id<1> index) { A[index] = 0; }); |
| 658 | + }); |
| 659 | + } // Data is copied back |
| 660 | + for (int i = 0; i < 10; i++) |
| 661 | + assert(data2[i] == -2); |
| 662 | + for (int i = 0; i < 10; i++) |
| 663 | + assert(data1[i] == 0); |
| 664 | + } |
670 | 665 |
|
671 |
| - { |
672 |
| - std::allocator<float8> buf_alloc; |
673 |
| - std::shared_ptr<float8> data(new float8[8], |
674 |
| - [](float8 *p) { delete[] p; }); |
675 |
| - sycl::buffer<float8, 1, std::allocator<float8>> b(data, sycl::range<1>(8), |
676 |
| - buf_alloc); |
677 |
| - } |
| 666 | + { |
| 667 | + int data[10]; |
| 668 | + void *voidPtr = (void *)data; |
| 669 | + buffer<int, 1> b(range<1>(10)); |
| 670 | + b.set_final_data(voidPtr); |
| 671 | + } |
678 | 672 |
|
679 |
| - { |
680 |
| - constexpr int Size = 6; |
681 |
| - sycl::buffer<char, 1> Buf_1(Size); |
682 |
| - sycl::buffer<char, 1> Buf_2(Size / 2); |
683 |
| - |
684 |
| - { |
685 |
| - auto AccA = Buf_1.get_access<sycl::access::mode::read_write>(Size / 2); |
686 |
| - auto AccB = Buf_2.get_access<sycl::access::mode::read_write>(Size / 2); |
687 |
| - assert(AccA.get_size() == AccB.get_size()); |
688 |
| - assert(AccA.get_range() == AccB.get_range()); |
689 |
| - assert(AccA.get_count() == AccB.get_count()); |
690 |
| - } |
| 673 | + { |
| 674 | + std::allocator<float8> buf_alloc; |
| 675 | + std::shared_ptr<float8> data(new float8[8], [](float8 *p) { delete[] p; }); |
| 676 | + sycl::buffer<float8, 1, std::allocator<float8>> b(data, sycl::range<1>(8), |
| 677 | + buf_alloc); |
| 678 | + } |
691 | 679 |
|
692 |
| - auto AH0 = accessor<char, 0, access::mode::read_write, |
693 |
| - access::target::host_buffer>(Buf_1); |
694 |
| - auto BH0 = accessor<char, 0, access::mode::read_write, |
695 |
| - access::target::host_buffer>(Buf_2); |
696 |
| - assert(AH0.get_size() == sizeof(char)); |
697 |
| - assert(BH0.get_size() == sizeof(char)); |
698 |
| - assert(AH0.get_count() == 1); |
699 |
| - assert(BH0.get_count() == 1); |
700 |
| - |
701 |
| - queue Queue; |
702 |
| - Queue.submit([&](handler &CGH) { |
703 |
| - auto AK0 = |
704 |
| - accessor<char, 0, access::mode::read_write, access::target::device>( |
705 |
| - Buf_1, CGH); |
706 |
| - auto BK0 = |
707 |
| - accessor<char, 0, access::mode::read_write, access::target::device>( |
708 |
| - Buf_2, CGH); |
709 |
| - assert(AK0.get_size() == sizeof(char)); |
710 |
| - assert(BK0.get_size() == sizeof(char)); |
711 |
| - assert(AK0.get_count() == 1); |
712 |
| - assert(BK0.get_count() == 1); |
713 |
| - CGH.single_task<class DummyKernel>([]() {}); |
714 |
| - }); |
715 |
| - } |
| 680 | + { |
| 681 | + constexpr int Size = 6; |
| 682 | + sycl::buffer<char, 1> Buf_1(Size); |
| 683 | + sycl::buffer<char, 1> Buf_2(Size / 2); |
716 | 684 |
|
717 | 685 | {
|
718 |
| - int data = 5; |
719 |
| - buffer<int, 1> Buffer(&data, range<1>(1)); |
720 |
| - assert(Buffer.size() == 1); |
721 |
| - assert(Buffer.byte_size() == 1 * sizeof(int)); |
| 686 | + auto AccA = Buf_1.get_access<sycl::access::mode::read_write>(Size / 2); |
| 687 | + auto AccB = Buf_2.get_access<sycl::access::mode::read_write>(Size / 2); |
| 688 | + assert(AccA.get_size() == AccB.get_size()); |
| 689 | + assert(AccA.get_range() == AccB.get_range()); |
| 690 | + assert(AccA.get_count() == AccB.get_count()); |
722 | 691 | }
|
723 | 692 |
|
724 |
| - // TODO tests with mutex property |
725 |
| - return failed; |
| 693 | + auto AH0 = accessor<char, 0, access::mode::read_write, |
| 694 | + access::target::host_buffer>(Buf_1); |
| 695 | + auto BH0 = accessor<char, 0, access::mode::read_write, |
| 696 | + access::target::host_buffer>(Buf_2); |
| 697 | + assert(AH0.get_size() == sizeof(char)); |
| 698 | + assert(BH0.get_size() == sizeof(char)); |
| 699 | + assert(AH0.get_count() == 1); |
| 700 | + assert(BH0.get_count() == 1); |
| 701 | + |
| 702 | + queue Queue; |
| 703 | + Queue.submit([&](handler &CGH) { |
| 704 | + auto AK0 = |
| 705 | + accessor<char, 0, access::mode::read_write, access::target::device>( |
| 706 | + Buf_1, CGH); |
| 707 | + auto BK0 = |
| 708 | + accessor<char, 0, access::mode::read_write, access::target::device>( |
| 709 | + Buf_2, CGH); |
| 710 | + assert(AK0.get_size() == sizeof(char)); |
| 711 | + assert(BK0.get_size() == sizeof(char)); |
| 712 | + assert(AK0.get_count() == 1); |
| 713 | + assert(BK0.get_count() == 1); |
| 714 | + CGH.single_task<class DummyKernel>([]() {}); |
| 715 | + }); |
| 716 | + } |
| 717 | + |
| 718 | + { |
| 719 | + int data = 5; |
| 720 | + buffer<int, 1> Buffer(&data, range<1>(1)); |
| 721 | + assert(Buffer.size() == 1); |
| 722 | + assert(Buffer.byte_size() == 1 * sizeof(int)); |
726 | 723 | }
|
| 724 | + |
| 725 | + // TODO tests with mutex property |
| 726 | + return failed; |
727 | 727 | }
|
0 commit comments