@@ -578,6 +578,41 @@ namespace detail {
578578 REQUIRE_FALSE (bm.has_active_buffers ());
579579 }
580580
581+ TEST_CASE (" buffer_manager allows buffer deallocation" , " [buffer_manager][dealloc]" ) {
582+ celerity::distr_queue q;
583+ buffer_id b_id;
584+ auto & bm = runtime::get_instance ().get_buffer_manager ();
585+ auto & tm = runtime::get_instance ().get_task_manager ();
586+ constexpr int new_horizon_step = 2 ;
587+ tm.set_horizon_step (new_horizon_step);
588+ {
589+ celerity::buffer<int , 1 > b (celerity::range<1 >(128 ));
590+ b_id = celerity::detail::get_buffer_id (b);
591+ q.submit ([=](celerity::handler& cgh) {
592+ celerity::accessor a{b, cgh, celerity::access::all (), celerity::write_only};
593+ cgh.parallel_for <class UKN (i)>(b.get_range (), [=](celerity::item<1 > it) {});
594+ });
595+ REQUIRE (bm.has_buffer (b_id));
596+ }
597+ celerity::buffer<int , 1 > c (celerity::range<1 >(128 ));
598+ // we need horizon_step_size * 3 + 1 tasks to generate the third horizon,
599+ // and one extra task to trigger the clean_up process
600+ for (int i = 0 ; i < (new_horizon_step * 3 + 2 ); i++) {
601+ q.submit ([=](celerity::handler& cgh) {
602+ celerity::accessor a{c, cgh, celerity::access::all (), celerity::write_only};
603+ cgh.parallel_for <class UKN (i)>(c.get_range (), [=](celerity::item<1 >) {});
604+ });
605+ // this sync is inside the loop because otherwise there is a race between the prepass and the executor informing the TDAG
606+ // of the executed horizons, meaning that task deletion is not guaranteed.
607+ q.slow_full_sync ();
608+ }
609+ // require buffer b was indeed unregistered.
610+ REQUIRE_FALSE (bm.has_buffer (b_id));
611+
612+ // TODO: check whether error was printed or not
613+ maybe_print_graph (celerity::detail::runtime::get_instance ().get_task_manager ());
614+ }
615+
581616 TEST_CASE_METHOD (test_utils::buffer_manager_fixture, " buffer_manager creates appropriately sized buffers as needed" , " [buffer_manager]" ) {
582617 auto & bm = get_buffer_manager ();
583618 auto bid = bm.register_buffer <float , 1 >(cl::sycl::range<3 >(3072 , 1 , 1 ));
0 commit comments