@@ -650,16 +650,20 @@ namespace detail {
650
650
template <int >
651
651
class acc_out_of_bounds_kernel {};
652
652
653
- TEMPLATE_TEST_CASE_METHOD_SIG (oob_fixture, " accessor reports out-of-bounds accesses" , " [accessor][oob]" , ((int Dims), Dims), 1 , 2 , 3 ) {
653
+ TEMPLATE_TEST_CASE_METHOD_SIG (oob_fixture, " device accessor reports out-of-bounds accesses" , " [accessor][oob]" , ((int Dims), Dims), 1 , 2 , 3 ) {
654
654
#if !CELERITY_ACCESSOR_BOUNDARY_CHECK
655
655
SKIP (" CELERITY_ACCESSOR_BOUNDARY_CHECK=0" );
656
656
#endif
657
- buffer<int , Dims> buff (range_cast<Dims>(range<3 >{10 , 20 , 30 }));
657
+ buffer<int , Dims> buff_nl (range_cast<Dims>(range<3 >{10 , 20 , 30 }));
658
+ buffer<int , Dims> buff_nf (range_cast<Dims>(range<3 >{10 , 20 , 30 }));
658
659
const auto accessible_sr = subrange_cast<Dims>(subrange<3 >{{5 , 10 , 15 }, {1 , 2 , 3 }});
659
660
const auto oob_idx_lo = id_cast<Dims>(id<3 >{1 , 2 , 3 });
660
661
const auto oob_idx_hi = id_cast<Dims>(id<3 >{7 , 13 , 25 });
662
+ const auto buffer_name = " oob" ;
663
+
664
+ celerity::debug::set_buffer_name (buff_nf, buffer_name);
661
665
662
- // we need to be careful about the orderign of the construction and destruction
666
+ // we need to be careful about the ordering of the construction and destruction
663
667
// of the Celerity queue and the log capturing utility here
664
668
std::unique_ptr<celerity::test_utils::log_capture> lc;
665
669
{
@@ -668,21 +672,75 @@ namespace detail {
668
672
lc = std::make_unique<celerity::test_utils::log_capture>();
669
673
670
674
q.submit ([&](handler& cgh) {
671
- accessor acc (buff, cgh, celerity::access::fixed (accessible_sr), celerity::write_only, celerity::no_init);
675
+ accessor acc_nl (buff_nl, cgh, celerity::access::fixed (accessible_sr), celerity::write_only, celerity::no_init);
676
+ accessor acc_nf (buff_nf, cgh, celerity::access::fixed (accessible_sr), celerity::write_only, celerity::no_init);
677
+
672
678
cgh.parallel_for <acc_out_of_bounds_kernel<Dims>>(range<Dims>(unit_range), [=](item<Dims>) {
673
- acc[oob_idx_lo] = 0 ;
674
- acc[oob_idx_hi] = 0 ;
679
+ acc_nl[oob_idx_lo] = 0 ;
680
+ acc_nl[oob_idx_hi] = 0 ;
681
+
682
+ acc_nf[oob_idx_lo] = 0 ;
683
+ acc_nf[oob_idx_hi] = 0 ;
675
684
});
676
685
});
677
686
q.slow_full_sync ();
678
687
}
679
688
680
689
const auto attempted_sr = subrange<3 >{id_cast<3 >(oob_idx_lo), range_cast<3 >(oob_idx_hi - oob_idx_lo + id_cast<Dims>(range<Dims>(unit_range)))};
681
- const auto error_message = fmt::format (" Out-of-bounds access in kernel 'acc_out_of_bounds_kernel<{}>' detected: Accessor 0 for buffer 0 attempted to "
682
- " access indices between {} which are outside of mapped subrange {}" ,
683
- Dims, attempted_sr, subrange_cast<3 >(accessible_sr));
684
- CHECK_THAT (lc->get_log (), Catch::Matchers::ContainsSubstring (error_message));
690
+ const auto error_message_nl = fmt::format (" Out-of-bounds access in kernel 'acc_out_of_bounds_kernel<{}>' detected: Accessor 0 for buffer 0 attempted to "
691
+ " access indices between {} which are outside of mapped subrange {}" , Dims, attempted_sr, subrange_cast<3 >(accessible_sr));
692
+ CHECK_THAT (lc->get_log (), Catch::Matchers::ContainsSubstring (error_message_nl));
693
+
694
+ const auto error_message_nf = fmt::format (" Out-of-bounds access in kernel 'acc_out_of_bounds_kernel<{}>' detected: Accessor 1 for buffer {} attempted to "
695
+ " access indices between {} which are outside of mapped subrange {}" , Dims, buffer_name, attempted_sr, subrange_cast<3 >(accessible_sr));
696
+ CHECK_THAT (lc->get_log (), Catch::Matchers::ContainsSubstring (error_message_nf));
685
697
}
686
698
699
+ TEMPLATE_TEST_CASE_METHOD_SIG (oob_fixture, " host accessor reports out-of-bounds accesses" , " [accessor][oob]" , ((int Dims), Dims), 1 , 2 , 3 ) {
700
+ #if !CELERITY_ACCESSOR_BOUNDARY_CHECK
701
+ SKIP (" CELERITY_ACCESSOR_BOUNDARY_CHECK=0" );
702
+ #endif
703
+ buffer<int , Dims> buff_nl (range_cast<Dims>(range<3 >{10 , 20 , 30 }));
704
+ buffer<int , Dims> buff_nf (range_cast<Dims>(range<3 >{10 , 20 , 30 }));
705
+ const auto accessible_sr = subrange_cast<Dims>(subrange<3 >{{5 , 10 , 15 }, {1 , 2 , 3 }});
706
+ const auto oob_idx_lo = id_cast<Dims>(id<3 >{1 , 2 , 3 });
707
+ const auto oob_idx_hi = id_cast<Dims>(id<3 >{7 , 13 , 25 });
708
+ const auto buffer_name = " oob" ;
709
+
710
+ celerity::debug::set_buffer_name (buff_nf, buffer_name);
711
+
712
+ // we need to be careful about the ordering of the construction and destruction
713
+ // of the Celerity queue and the log capturing utility here
714
+ std::unique_ptr<celerity::test_utils::log_capture> lc;
715
+ {
716
+ distr_queue q;
717
+
718
+ lc = std::make_unique<celerity::test_utils::log_capture>();
719
+
720
+ q.submit ([&](handler& cgh){
721
+ accessor acc_nl (buff_nl, cgh, celerity::access::fixed (accessible_sr), celerity::write_only_host_task, celerity::no_init);
722
+ accessor acc_nf (buff_nf, cgh, celerity::access::fixed (accessible_sr), celerity::write_only_host_task, celerity::no_init);
723
+
724
+ cgh.host_task (range<Dims>(unit_range), [=](partition<Dims>) {
725
+ acc_nl[oob_idx_lo] = 0 ;
726
+ acc_nl[oob_idx_hi] = 0 ;
727
+
728
+ acc_nf[oob_idx_lo] = 0 ;
729
+ acc_nf[oob_idx_hi] = 0 ;
730
+ });
731
+ });
732
+
733
+ q.slow_full_sync ();
734
+ }
735
+
736
+ const auto attempted_sr = subrange<3 >{id_cast<3 >(oob_idx_lo), range_cast<3 >(oob_idx_hi - oob_idx_lo + id_cast<Dims>(range<Dims>(unit_range)))};
737
+ const auto error_message_nl = fmt::format (" Out-of-bounds access in host kernel detected: Accessor 0 for buffer 0 attempted to "
738
+ " access indices between {} which are outside of mapped subrange {}" , attempted_sr, subrange_cast<3 >(accessible_sr));
739
+ CHECK_THAT (lc->get_log (), Catch::Matchers::ContainsSubstring (error_message_nl));
740
+
741
+ const auto error_message_nf = fmt::format (" Out-of-bounds access in host kernel detected: Accessor 1 for buffer {} attempted to "
742
+ " access indices between {} which are outside of mapped subrange {}" , buffer_name, attempted_sr, subrange_cast<3 >(accessible_sr));
743
+ CHECK_THAT (lc->get_log (), Catch::Matchers::ContainsSubstring (error_message_nf));
744
+ }
687
745
} // namespace detail
688
746
} // namespace celerity
0 commit comments