KOKKOS_INLINE_FUNCTION void operator()( typename policy_type::member_type & , value_type & result ) { #if 0 printf( "\nTestFib(%ld) %d %d\n" , n , int( ! fib_m1.is_null() ) , int( ! fib_m2.is_null() ) ); #endif if ( n < 2 ) { result = n ; } else if ( ! fib_m2.is_null() && ! fib_m1.is_null() ) { result = fib_m1.get() + fib_m2.get(); } else { // Spawn new children and respawn myself to sum their results: // Spawn lower value at higher priority as it has a shorter // path to completion. fib_m2 = policy.task_spawn( TestFib(policy,n-2) , Kokkos::TaskSingle , Kokkos::TaskHighPriority ); fib_m1 = policy.task_spawn( TestFib(policy,n-1) , Kokkos::TaskSingle ); Kokkos::Future<Space> dep[] = { fib_m1 , fib_m2 }; Kokkos::Future<Space> fib_all = policy.when_all( 2 , dep ); if ( ! fib_m2.is_null() && ! fib_m1.is_null() && ! fib_all.is_null() ) { // High priority to retire this branch policy.respawn( this , Kokkos::TaskHighPriority , fib_all ); } else { #if 0 printf( "TestFib(%ld) insufficient memory alloc_capacity(%d) task_max(%d) task_accum(%ld)\n" , n , policy.allocation_capacity() , policy.allocated_task_count_max() , policy.allocated_task_count_accum() ); #endif Kokkos::abort("TestFib insufficient memory"); } } }
static void run( int i, size_t MemoryCapacity = 16000 ) { typedef typename sched_type::memory_space memory_space; enum { MinBlockSize = 64 }; enum { MaxBlockSize = 1024 }; enum { SuperBlockSize = 1u << 12 }; sched_type root_sched( memory_space() , MemoryCapacity , MinBlockSize , MaxBlockSize , SuperBlockSize ); future_type f = Kokkos::host_spawn( Kokkos::TaskSingle( root_sched ) , TestFib( root_sched, i ) ); Kokkos::wait( root_sched ); ASSERT_EQ( eval_fib( i ), f.get() ); #if 0 fprintf( stdout, "\nTestFib::run(%d) spawn_size(%d) when_all_size(%d) alloc_capacity(%d) task_max(%d) task_accum(%ld)\n" , i , int(root_sched.template spawn_allocation_size<TestFib>()) , int(root_sched.when_all_allocation_size(2)) , root_sched.allocation_capacity() , root_sched.allocated_task_count_max() , root_sched.allocated_task_count_accum() ); fflush( stdout ); #endif }
KOKKOS_INLINE_FUNCTION void operator()( typename sched_type::member_type &, value_type & result ) { #if 0 printf( "\nTestFib(%ld) %d %d\n", n, int( !fib_m1.is_null() ), int( !fib_m2.is_null() ) ); #endif if ( n < 2 ) { result = n; } else if ( !fib_m2.is_null() && !fib_m1.is_null() ) { result = fib_m1.get() + fib_m2.get(); } else { // Spawn new children and respawn myself to sum their results. // Spawn lower value at higher priority as it has a shorter // path to completion. fib_m2 = Kokkos::task_spawn( Kokkos::TaskSingle( sched, Kokkos::TaskPriority::High ) , TestFib( sched, n - 2 ) ); fib_m1 = Kokkos::task_spawn( Kokkos::TaskSingle( sched ) , TestFib( sched, n - 1 ) ); Kokkos::Future< Space > dep[] = { fib_m1, fib_m2 }; Kokkos::Future< Space > fib_all = Kokkos::when_all( dep, 2 ); if ( !fib_m2.is_null() && !fib_m1.is_null() && !fib_all.is_null() ) { // High priority to retire this branch. Kokkos::respawn( this, fib_all, Kokkos::TaskPriority::High ); } else { #if 1 printf( "TestFib(%ld) insufficient memory alloc_capacity(%d) task_max(%d) task_accum(%ld)\n" , n , sched.allocation_capacity() , sched.allocated_task_count_max() , sched.allocated_task_count_accum() ); #endif Kokkos::abort( "TestFib insufficient memory" ); } } }
static void run( int i , size_t MemoryCapacity = 16000 ) { typedef typename policy_type::memory_space memory_space ; enum { Log2_SuperBlockSize = 12 }; policy_type root_policy( memory_space() , MemoryCapacity , Log2_SuperBlockSize ); future_type f = root_policy.host_spawn( TestFib(root_policy,i) , Kokkos::TaskSingle ); Kokkos::wait( root_policy ); ASSERT_EQ( eval_fib(i) , f.get() ); #if 0 fprintf( stdout , "\nTestFib::run(%d) spawn_size(%d) when_all_size(%d) alloc_capacity(%d) task_max(%d) task_accum(%ld)\n" , i , int(root_policy.template spawn_allocation_size<TestFib>()) , int(root_policy.when_all_allocation_size(2)) , root_policy.allocation_capacity() , root_policy.allocated_task_count_max() , root_policy.allocated_task_count_accum() ); fflush( stdout ); #endif }