lammps-sys 0.6.0

Generates bindings to LAMMPS' C interface (with optional builds from source)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
/*
//@HEADER
// ************************************************************************
//
//                        Kokkos v. 2.0
//              Copyright (2014) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Christian R. Trott (crtrott@sandia.gov)
//
// ************************************************************************
//@HEADER
*/

#ifndef KOKKOS_TASKSCHEDULER_HPP
#define KOKKOS_TASKSCHEDULER_HPP

//----------------------------------------------------------------------------

#include <Kokkos_Macros.hpp>
#if defined( KOKKOS_ENABLE_TASKDAG )

#include <Kokkos_Core_fwd.hpp>
#include <Kokkos_TaskScheduler_fwd.hpp>
//----------------------------------------------------------------------------

#include <Kokkos_MemoryPool.hpp>
#include <impl/Kokkos_Tags.hpp>

#include <Kokkos_Future.hpp>
#include <impl/Kokkos_TaskQueue.hpp>
#include <impl/Kokkos_SingleTaskQueue.hpp>
#include <impl/Kokkos_TaskQueueMultiple.hpp>
#include <impl/Kokkos_TaskPolicyData.hpp>
#include <impl/Kokkos_TaskTeamMember.hpp>
#include <impl/Kokkos_SimpleTaskScheduler.hpp>

//----------------------------------------------------------------------------
//----------------------------------------------------------------------------

namespace Kokkos {

namespace Impl {

template <class, class>
class TaskExec;

} // end namespace Impl


template<class ExecSpace, class QueueType>
class BasicTaskScheduler : public Impl::TaskSchedulerBase
{
public:

  using scheduler_type = BasicTaskScheduler;
  using execution_space = ExecSpace;
  using queue_type = QueueType;
  using memory_space = typename queue_type::memory_space;
  using memory_pool = typename queue_type::memory_pool;
  using specialization = Impl::TaskQueueSpecialization<BasicTaskScheduler>;
  using member_type = typename specialization::member_type;
  using team_scheduler_type = BasicTaskScheduler;
  template <class Functor>
  using runnable_task_type = Impl::Task<scheduler_type, typename Functor::value_type, Functor>;
  template <class ValueType>
  using future_type = Kokkos::BasicFuture<ValueType, BasicTaskScheduler>;
  template <class FunctorType>
  using future_type_for_functor = future_type<typename FunctorType::value_type>;

private:

  using track_type = Kokkos::Impl::SharedAllocationTracker ;
  using task_base  = Impl::TaskBase;

  track_type m_track;
  queue_type * m_queue;

  //----------------------------------------

  template <typename, typename>
  friend class Impl::TaskQueue;
  template <typename>
  friend struct Impl::TaskQueueSpecialization;
  template <typename, typename>
  friend class Impl::TaskQueueSpecializationConstrained;
  template <typename, typename>
  friend class Impl::TaskTeamMemberAdapter;
  template <typename, typename>
  friend class Impl::TaskExec;

  //----------------------------------------

  KOKKOS_INLINE_FUNCTION
  BasicTaskScheduler(
    track_type arg_track,
    queue_type* arg_queue
  )
    : m_track(std::move(arg_track)),
      m_queue(std::move(arg_queue))
  { }

  KOKKOS_INLINE_FUNCTION
  team_scheduler_type get_team_scheduler(int team_rank) const {
    return { m_track, &m_queue->get_team_queue(team_rank) };
  }

  //----------------------------------------

  KOKKOS_INLINE_FUNCTION
  static constexpr task_base* _get_task_ptr(std::nullptr_t) { return nullptr; }

  template <class ValueType>
  KOKKOS_INLINE_FUNCTION
  static constexpr task_base* _get_task_ptr(future_type<ValueType>&& f)
  {
    return f.m_task;
  }

  template< int TaskEnum , typename DepTaskType , typename FunctorType >
  KOKKOS_FUNCTION
  Kokkos::BasicFuture<typename FunctorType::value_type, scheduler_type>
  _spawn_impl(
    DepTaskType* arg_predecessor_task,
    TaskPriority arg_priority,
    typename task_base::function_type arg_function,
    typename task_base::destroy_type arg_destroy,
    FunctorType&& arg_functor
  )
  {
    using functor_future_type = future_type_for_functor<typename std::decay<FunctorType>::type>;
    using task_type = Impl::Task<BasicTaskScheduler, typename functor_future_type::value_type, FunctorType>;

    //----------------------------------------
    // Give single-thread back-ends an opportunity to clear
    // queue of ready tasks before allocating a new task

    // TODO @tasking @optimization DSH re-enable this, maybe?
    // specialization::iff_single_thread_recursive_execute(scheduler);

    //----------------------------------------

    functor_future_type f ;

    // Allocate task from memory pool

    const size_t alloc_size =
      m_queue->template spawn_allocation_size< FunctorType >();

    void* task_storage = m_queue->allocate(alloc_size);

    if (task_storage) {

      // Placement new construction
      // Reference count starts at two:
      //   +1 for the matching decrement when task is complete
      //   +1 for the future
      f.m_task = new (task_storage) task_type( std::forward<FunctorType>(arg_functor) );

      f.m_task->m_apply      = arg_function;
      //f.m_task->m_destroy    = arg_destroy;
      f.m_task->m_queue      = m_queue;
      f.m_task->m_next       = arg_predecessor_task;
      f.m_task->m_ref_count  = 2;
      f.m_task->m_alloc_size = alloc_size;
      f.m_task->m_task_type  = TaskEnum;
      f.m_task->m_priority   = (int16_t)arg_priority;

      Kokkos::memory_fence();

      // The dependence (if any) is processed immediately
      // within the schedule function, as such the dependence's
      // reference count does not need to be incremented for
      // the assignment.

      m_queue->schedule_runnable( f.m_task );
      // This task may be updated or executed at any moment,
      // even during the call to 'schedule'.
    }

    return f;

  }

public:


  KOKKOS_INLINE_FUNCTION
  BasicTaskScheduler() : m_track(), m_queue(0) {}

  KOKKOS_INLINE_FUNCTION
  BasicTaskScheduler( BasicTaskScheduler && rhs ) noexcept
    : m_track(rhs.m_track),  // probably should be a move, but this is deprecated code anyway
      m_queue(std::move(rhs.m_queue))
  { }

  KOKKOS_INLINE_FUNCTION
  BasicTaskScheduler( BasicTaskScheduler const & rhs )
    : m_track(rhs.m_track),
      m_queue(rhs.m_queue)
  { }

  KOKKOS_INLINE_FUNCTION
  BasicTaskScheduler& operator=(BasicTaskScheduler&& rhs) noexcept
  {
    m_track = rhs.m_track;  // probably should be a move, but this is deprecated code anyway
    m_queue = std::move(rhs.m_queue);
    return *this;
  }

  KOKKOS_INLINE_FUNCTION
  BasicTaskScheduler& operator=(BasicTaskScheduler const& rhs)
  {
    m_track = rhs.m_track;
    m_queue = rhs.m_queue;
    return *this;
  }

  explicit BasicTaskScheduler(memory_pool const & arg_memory_pool) noexcept
    : m_track(), m_queue(0)
    {
      typedef Kokkos::Impl::SharedAllocationRecord
        < memory_space , typename queue_type::Destroy >
          record_type ;

      record_type * record =
        record_type::allocate( memory_space()
                             , "TaskQueue"
                             , sizeof(queue_type)
                             );

      m_queue = new( record->data() ) queue_type( arg_memory_pool );

      record->m_destroy.m_queue = m_queue ;

      m_track.assign_allocated_record_to_uninitialized( record );
    }

  BasicTaskScheduler( memory_space const & arg_memory_space
               , size_t const mempool_capacity
               , unsigned const mempool_min_block_size  // = 1u << 6
               , unsigned const mempool_max_block_size  // = 1u << 10
               , unsigned const mempool_superblock_size // = 1u << 12
               )
    : BasicTaskScheduler( memory_pool( arg_memory_space
                                , mempool_capacity
                                , mempool_min_block_size
                                , mempool_max_block_size
                                , mempool_superblock_size ) )
    {}

  //----------------------------------------

  KOKKOS_INLINE_FUNCTION
  queue_type& queue() const noexcept {
    KOKKOS_EXPECTS(m_queue != nullptr);
    return *m_queue;
  }

  KOKKOS_INLINE_FUNCTION
  memory_pool * memory() const noexcept
    { return m_queue ? &( m_queue->m_memory ) : (memory_pool*) 0 ; }

  //----------------------------------------
  /**\brief  Allocation size for a spawned task */
  template< typename FunctorType >
  KOKKOS_FUNCTION
  size_t spawn_allocation_size() const
    { return m_queue->template spawn_allocation_size< FunctorType >(); }

  /**\brief  Allocation size for a when_all aggregate */
  KOKKOS_FUNCTION
  size_t when_all_allocation_size( int narg ) const
    { return m_queue->when_all_allocation_size( narg ); }


  //----------------------------------------

  template <int TaskEnum, typename DepFutureType, typename FunctorType>
  KOKKOS_FUNCTION static
  Kokkos::BasicFuture<typename FunctorType::value_type, scheduler_type>
  spawn(
    Impl::TaskPolicyWithScheduler<TaskEnum, scheduler_type, DepFutureType>&& arg_policy,
    typename task_base::function_type arg_function,
    typename task_base::destroy_type arg_destroy,
    FunctorType&& arg_functor
  )
  {
    return std::move(arg_policy.scheduler()).template _spawn_impl<TaskEnum>(
      _get_task_ptr(std::move(arg_policy.predecessor())),
      arg_policy.priority(),
      arg_function,
      arg_destroy,
      std::forward<FunctorType>(arg_functor)
    );
  }

  template <int TaskEnum, typename DepFutureType, typename FunctorType>
  KOKKOS_FUNCTION
  future_type_for_functor<typename std::decay<FunctorType>::type>
  spawn(
    Impl::TaskPolicyWithPredecessor<TaskEnum, DepFutureType>&& arg_policy,
    FunctorType&& arg_functor
  )
  {
    using task_type = runnable_task_type<FunctorType>;
    typename task_type::function_type const ptr = task_type::apply;
    typename task_type::destroy_type const dtor = task_type::destroy;

    return _spawn_impl<TaskEnum>(
      _get_task_ptr(std::move(arg_policy).predecessor()),
      arg_policy.priority(),
      ptr, dtor,
      std::forward<FunctorType>(arg_functor)
    );
  }

  template<typename FunctorType, typename ValueType, typename Scheduler>
  KOKKOS_FUNCTION static
  void
  respawn(
    FunctorType* arg_self,
    BasicFuture<ValueType,Scheduler> const & arg_dependence,
    TaskPriority  const & arg_priority
  ) {
    // Precondition: task is in Executing state

    using value_type  = typename FunctorType::value_type ;
    using task_type = Impl::Task<BasicTaskScheduler, value_type, FunctorType>;

    task_type * const task = static_cast< task_type * >( arg_self );

    task->m_priority = static_cast<int>(arg_priority);

    task->add_dependence( arg_dependence.m_task );

    // Postcondition: task is in Executing-Respawn state
  }

  template< typename FunctorType >
  KOKKOS_FUNCTION static
  void
  respawn(
    FunctorType* arg_self,
    BasicTaskScheduler const &,
    TaskPriority  const & arg_priority
  )
  {
    // Precondition: task is in Executing state

    using value_type = typename FunctorType::value_type;
    using task_type = Impl::Task<BasicTaskScheduler, value_type, FunctorType>;

    task_type * const task = static_cast< task_type * >( arg_self );

    task->m_priority = static_cast<int>(arg_priority);

    task->add_dependence( (task_base*) 0 );

    // Postcondition: task is in Executing-Respawn state
  }

  //----------------------------------------
  /**\brief  Return a future that is complete
   *         when all input futures are complete.
   */
  template<typename ValueType>
  KOKKOS_FUNCTION
  BasicFuture< void, scheduler_type >
  when_all(BasicFuture<ValueType, BasicTaskScheduler> const arg[], int narg)
  {

    future_type<void> f ;

    if ( narg ) {

      queue_type* q = m_queue;

      //BasicTaskScheduler const* scheduler_ptr = nullptr;

      for ( int i = 0 ; i < narg ; ++i ) {
        task_base * const t = arg[i].m_task ;
        if ( nullptr != t ) {
          // Increment reference count to track subsequent assignment.
          Kokkos::atomic_increment( &(t->m_ref_count) );
          if(q != static_cast< queue_type const* >(t->m_queue)) {
            Kokkos::abort("Kokkos when_all Futures must be in the same scheduler" );
          }
        }
      }

      if ( q != 0 ) { // this should probably handle the queue == 0 case, but this is deprecated code anyway

        size_t const alloc_size = q->when_all_allocation_size( narg );

        f.m_task =
          reinterpret_cast< task_base * >( q->allocate( alloc_size ) );
        //f.m_scheduler = *scheduler_ptr;

        if ( f.m_task ) {

          // Reference count starts at two:
          // +1 to match decrement when task completes
          // +1 for the future

          new( f.m_task ) task_base();

          f.m_task->m_queue = q;
          f.m_task->m_ref_count = 2 ;
          f.m_task->m_alloc_size = static_cast<int32_t>(alloc_size);
          f.m_task->m_dep_count = narg ;
          f.m_task->m_task_type = task_base::Aggregate ;

          // Assign dependences, reference counts were already incremented

          task_base * volatile * const dep =
            f.m_task->aggregate_dependences();

          for ( int i = 0 ; i < narg ; ++i ) { dep[i] = arg[i].m_task ; }

          Kokkos::memory_fence();

          q->schedule_aggregate( f.m_task );
          // this when_all may be processed at any moment
        }
      }
    }

    return f ;
  }

  template < class F >
  KOKKOS_FUNCTION
  BasicFuture< void, scheduler_type >
  when_all( int narg , F const func )
    {
      using input_type  = decltype( func(0) );

      static_assert( is_future< input_type >::value
                   , "Functor must return a Kokkos::Future" );

      future_type<void> f ;

      if ( 0 == narg ) return f ;

      size_t const alloc_size = m_queue->when_all_allocation_size( narg );

      f.m_task =
        reinterpret_cast< task_base * >( m_queue->allocate( alloc_size ) );

      if ( f.m_task ) {

        // Reference count starts at two:
        // +1 to match decrement when task completes
        // +1 for the future

        new( f.m_task ) task_base();
        //f.m_scheduler = *this;

        //f.m_task->m_scheduler = &f.m_scheduler;
        f.m_task->m_queue = m_queue;
        f.m_task->m_ref_count = 2 ;
        f.m_task->m_alloc_size = static_cast<int32_t>(alloc_size);
        f.m_task->m_dep_count = narg ;
        f.m_task->m_task_type = task_base::Aggregate ;
        //f.m_task->m_apply = nullptr;
        //f.m_task->m_destroy = nullptr;

        // Assign dependences, reference counts were already incremented

        task_base * volatile * const dep =
          f.m_task->aggregate_dependences();

        for ( int i = 0 ; i < narg ; ++i ) {
          const input_type arg_f = func(i);
          if ( 0 != arg_f.m_task ) {

            // Not scheduled, so task scheduler is not yet set
            //if ( m_queue != static_cast< BasicTaskScheduler const * >( arg_f.m_task->m_scheduler )->m_queue ) {
            //  Kokkos::abort("Kokkos when_all Futures must be in the same scheduler" );
            //}
            // Increment reference count to track subsequent assignment.
            Kokkos::atomic_increment( &(arg_f.m_task->m_ref_count) );
            dep[i] = arg_f.m_task ;
          }
        }

        Kokkos::memory_fence();

        m_queue->schedule_aggregate( f.m_task );
        // this when_all may be processed at any moment
      }
      return f ;
    }

  //----------------------------------------

  KOKKOS_INLINE_FUNCTION
  int allocation_capacity() const noexcept
    { return m_queue->m_memory.capacity(); }

  KOKKOS_INLINE_FUNCTION
  int allocated_task_count() const noexcept
    { return m_queue->m_count_alloc ; }

  KOKKOS_INLINE_FUNCTION
  int allocated_task_count_max() const noexcept
    { return m_queue->m_max_alloc ; }

  KOKKOS_INLINE_FUNCTION
  long allocated_task_count_accum() const noexcept
    { return m_queue->m_accum_alloc ; }

  //----------------------------------------

  template<class S, class Q>
  friend
  void wait(Kokkos::BasicTaskScheduler<S, Q> const&);

};

} // namespace Kokkos

//----------------------------------------------------------------------------
//----------------------------------------------------------------------------

namespace Kokkos {

//----------------------------------------------------------------------------
// Construct a TaskTeam execution policy

template <class T, class Scheduler>
Impl::TaskPolicyWithPredecessor<
  Impl::TaskType::TaskTeam,
  Kokkos::BasicFuture<T, Scheduler>
>
KOKKOS_INLINE_FUNCTION
TaskTeam(
  Kokkos::BasicFuture<T, Scheduler> arg_future,
  TaskPriority arg_priority = TaskPriority::Regular
)
{
  return { std::move(arg_future), arg_priority };
}

template <class Scheduler>
Impl::TaskPolicyWithScheduler<
  Impl::TaskType::TaskTeam, Scheduler
>
KOKKOS_INLINE_FUNCTION
TaskTeam(
  Scheduler arg_scheduler,
  typename std::enable_if<
    Kokkos::is_scheduler<Scheduler>::value,
    TaskPriority
  >::type arg_priority = TaskPriority::Regular
)
{
  return { std::move(arg_scheduler), arg_priority };
}

template<
  class Scheduler,
  class PredecessorFuture
>
Impl::TaskPolicyWithScheduler<
  Kokkos::Impl::TaskType::TaskTeam,
  Scheduler,
  PredecessorFuture
>
KOKKOS_INLINE_FUNCTION
TaskTeam(
  Scheduler arg_scheduler,
  PredecessorFuture arg_future,
  typename std::enable_if<
    Kokkos::is_scheduler<Scheduler>::value
      && Kokkos::is_future<PredecessorFuture>::value,
    TaskPriority
  >::type arg_priority = TaskPriority::Regular
)
{
  static_assert(
    std::is_same<typename PredecessorFuture::scheduler_type, Scheduler>::value,
    "Can't create a task policy from a scheduler and a future from a different scheduler"
  );

  return { std::move(arg_scheduler), std::move(arg_future), arg_priority };
}

// Construct a TaskSingle execution policy

template <class T, class Scheduler>
Impl::TaskPolicyWithPredecessor<
  Impl::TaskType::TaskSingle,
  Kokkos::BasicFuture<T, Scheduler>
>
KOKKOS_INLINE_FUNCTION
TaskSingle(
  Kokkos::BasicFuture<T, Scheduler> arg_future,
  TaskPriority arg_priority = TaskPriority::Regular
)
{
  return { std::move(arg_future), arg_priority };
}

template <class Scheduler>
Impl::TaskPolicyWithScheduler<
  Impl::TaskType::TaskSingle, Scheduler
>
KOKKOS_INLINE_FUNCTION
TaskSingle(
  Scheduler arg_scheduler,
  typename std::enable_if<
    Kokkos::is_scheduler<Scheduler>::value,
    TaskPriority
  >::type arg_priority = TaskPriority::Regular
)
{
  return { std::move(arg_scheduler), arg_priority };
}

template<
  class Scheduler,
  class PredecessorFuture
>
Impl::TaskPolicyWithScheduler<
  Kokkos::Impl::TaskType::TaskSingle,
  Scheduler,
  PredecessorFuture
>
KOKKOS_INLINE_FUNCTION
TaskSingle(
  Scheduler arg_scheduler,
  PredecessorFuture arg_future,
  typename std::enable_if<
    Kokkos::is_scheduler<Scheduler>::value
      && Kokkos::is_future<PredecessorFuture>::value,
    TaskPriority
  >::type arg_priority = TaskPriority::Regular
)
{
  static_assert(
    std::is_same<typename PredecessorFuture::scheduler_type, Scheduler>::value,
    "Can't create a task policy from a scheduler and a future from a different scheduler"
  );

  return { std::move(arg_scheduler), std::move(arg_future), arg_priority };
}

//----------------------------------------------------------------------------

/**\brief  A host control thread spawns a task with options
 *
 *  1) Team or Serial
 *  2) With scheduler or dependence
 *  3) High, Normal, or Low priority
 */
template<int TaskEnum, typename Scheduler, typename DepFutureType, typename FunctorType>
typename Scheduler::template future_type_for_functor<typename std::decay<FunctorType>::type>
host_spawn(
  Impl::TaskPolicyWithScheduler<TaskEnum, Scheduler, DepFutureType> arg_policy,
  FunctorType&& arg_functor
) {
  using scheduler_type = Scheduler;
  using task_type =
    typename scheduler_type::template runnable_task_type<FunctorType>;

  static_assert(
    TaskEnum == Impl::TaskType::TaskTeam || TaskEnum == Impl::TaskType::TaskSingle,
    "Kokkos host_spawn requires TaskTeam or TaskSingle"
  );

  // May be spawning a Cuda task, must use the specialization
  // to query on-device function pointer.
  typename task_type::function_type ptr;
  typename task_type::destroy_type dtor;
  Kokkos::Impl::TaskQueueSpecialization< scheduler_type >::
    template get_function_pointer< task_type >(ptr, dtor);

  return scheduler_type::spawn(
    std::move(arg_policy), ptr, dtor, std::forward<FunctorType>(arg_functor)
  );
}

/**\brief  A task spawns a task with options
 *
 *  1) Team or Serial
 *  2) With scheduler or dependence
 *  3) High, Normal, or Low priority
 */
template<int TaskEnum, typename Scheduler, typename DepFutureType, typename FunctorType>
typename Scheduler::template future_type_for_functor<typename std::decay<FunctorType>::type>
KOKKOS_INLINE_FUNCTION
task_spawn(
  Impl::TaskPolicyWithScheduler<TaskEnum, Scheduler, DepFutureType> arg_policy,
  FunctorType&& arg_functor
)
{
  using scheduler_type = Scheduler;

  using task_type =
    typename scheduler_type::template runnable_task_type<FunctorType>;

 #if defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST ) && \
     defined( KOKKOS_ENABLE_CUDA )

   static_assert( ! std::is_same< Kokkos::Cuda , typename Scheduler::execution_space >::value
                , "Error calling Kokkos::task_spawn for Cuda space within Host code" );

 #endif

  static_assert(
    TaskEnum == Impl::TaskType::TaskTeam || TaskEnum == Impl::TaskType::TaskSingle,
    "Kokkos task_spawn requires TaskTeam or TaskSingle"
  );

  typename task_type::function_type const ptr = task_type::apply ;
  typename task_type::destroy_type const dtor = task_type::destroy ;

  return scheduler_type::spawn(std::move(arg_policy), ptr, dtor,
    std::forward<FunctorType>(arg_functor)
  );
}

/**\brief  A task respawns itself with options
 *
 *  1) With scheduler or dependence
 *  2) High, Normal, or Low priority
 */
template< typename FunctorType , typename T >
void
KOKKOS_INLINE_FUNCTION
respawn( FunctorType         * arg_self
       , T             const & arg
       , TaskPriority  const & arg_priority = TaskPriority::Regular
       )
{
  static_assert( Kokkos::is_future<T>::value ||
                 Kokkos::is_scheduler<T>::value
               , "Kokkos respawn argument must be Future or TaskScheduler" );

  T::scheduler_type::respawn(
    arg_self , arg , arg_priority
  );
}

//----------------------------------------------------------------------------

//template<typename ValueType, typename Scheduler>
//KOKKOS_INLINE_FUNCTION
//BasicFuture<void, Scheduler>
//when_all(BasicFuture<ValueType, Scheduler> const arg[], int narg)
//{
//  return BasicFuture<void, Scheduler>::scheduler_type::when_all(arg, narg);
//}

//----------------------------------------------------------------------------
// Wait for all runnable tasks to complete

template<class ExecSpace, class QueueType>
inline
void wait(BasicTaskScheduler<ExecSpace, QueueType> const& scheduler)
{
  using scheduler_type = BasicTaskScheduler<ExecSpace, QueueType>;
  scheduler_type::specialization::execute(scheduler);
  //scheduler.m_queue->execute();
}

} // namespace Kokkos

//----------------------------------------------------------------------------
//----------------------------------------------------------------------------

////////////////////////////////////////////////////////////////////////////////
// END OLD CODE
////////////////////////////////////////////////////////////////////////////////

#endif /* #if defined( KOKKOS_ENABLE_TASKDAG ) */
#endif /* #ifndef KOKKOS_TASKSCHEDULER_HPP */