@@ -417,13 +417,31 @@ deque<T, Allocator>::empty() const
417
417
return (size () == 0 );
418
418
}
419
419
420
+ template <typename T, typename Allocator>
421
+ template <typename ExecutionPolicy,
422
+ STDGPU_DETAIL_OVERLOAD_DEFINITION_IF (is_execution_policy_v<remove_cvref_t <ExecutionPolicy>>)>
423
+ inline bool
424
+ deque<T, Allocator>::empty(ExecutionPolicy&& policy) const
425
+ {
426
+ return (size (std::forward<ExecutionPolicy>(policy)) == 0 );
427
+ }
428
+
420
429
template <typename T, typename Allocator>
421
430
inline STDGPU_HOST_DEVICE bool
422
431
deque<T, Allocator>::full() const
423
432
{
424
433
return (size () == max_size ());
425
434
}
426
435
436
+ template <typename T, typename Allocator>
437
+ template <typename ExecutionPolicy,
438
+ STDGPU_DETAIL_OVERLOAD_DEFINITION_IF (is_execution_policy_v<remove_cvref_t <ExecutionPolicy>>)>
439
+ inline bool
440
+ deque<T, Allocator>::full(ExecutionPolicy&& policy) const
441
+ {
442
+ return (size (std::forward<ExecutionPolicy>(policy)) == max_size ());
443
+ }
444
+
427
445
template <typename T, typename Allocator>
428
446
inline STDGPU_HOST_DEVICE index_t
429
447
deque<T, Allocator>::size() const
@@ -453,6 +471,37 @@ deque<T, Allocator>::size() const
453
471
return current_size;
454
472
}
455
473
474
+ template <typename T, typename Allocator>
475
+ template <typename ExecutionPolicy,
476
+ STDGPU_DETAIL_OVERLOAD_DEFINITION_IF (is_execution_policy_v<remove_cvref_t <ExecutionPolicy>>)>
477
+ inline index_t
478
+ deque<T, Allocator>::size(ExecutionPolicy&& policy) const
479
+ {
480
+ index_t current_size = _size.load (std::forward<ExecutionPolicy>(policy));
481
+
482
+ // Check boundary cases where the push/pop caused the pointers to be overful/underful
483
+ if (current_size < 0 )
484
+ {
485
+ printf (" stdgpu::deque::size : Size out of bounds: %" STDGPU_PRIINDEX " not in [0, %" STDGPU_PRIINDEX
486
+ " ]. Clamping to 0\n " ,
487
+ current_size,
488
+ capacity ());
489
+ return 0 ;
490
+ }
491
+ if (current_size > capacity ())
492
+ {
493
+ printf (" stdgpu::deque::size : Size out of bounds: %" STDGPU_PRIINDEX " not in [0, %" STDGPU_PRIINDEX
494
+ " ]. Clamping to %" STDGPU_PRIINDEX " \n " ,
495
+ current_size,
496
+ capacity (),
497
+ capacity ());
498
+ return capacity ();
499
+ }
500
+
501
+ STDGPU_ENSURES (current_size <= capacity ());
502
+ return current_size;
503
+ }
504
+
456
505
template <typename T, typename Allocator>
457
506
inline STDGPU_HOST_DEVICE index_t
458
507
deque<T, Allocator>::max_size() const noexcept
@@ -501,18 +550,18 @@ template <typename ExecutionPolicy,
501
550
inline void
502
551
deque<T, Allocator>::clear(ExecutionPolicy&& policy)
503
552
{
504
- if (empty ())
553
+ if (empty (std::forward<ExecutionPolicy>(policy) ))
505
554
{
506
555
return ;
507
556
}
508
557
509
558
if (!detail::is_destroy_optimizable<value_type>())
510
559
{
511
- const index_t begin = static_cast <index_t >(_begin.load ());
512
- const index_t end = static_cast <index_t >(_end.load ());
560
+ const index_t begin = static_cast <index_t >(_begin.load (std::forward<ExecutionPolicy>(policy) ));
561
+ const index_t end = static_cast <index_t >(_end.load (std::forward<ExecutionPolicy>(policy) ));
513
562
514
563
// Full, i.e. one large block and begin == end
515
- if (full ())
564
+ if (full (std::forward<ExecutionPolicy>(policy) ))
516
565
{
517
566
detail::unoptimized_destroy (std::forward<ExecutionPolicy>(policy), device_begin (_data), device_end (_data));
518
567
}
@@ -537,12 +586,12 @@ deque<T, Allocator>::clear(ExecutionPolicy&& policy)
537
586
538
587
_occupied.reset (std::forward<ExecutionPolicy>(policy));
539
588
540
- _size.store (0 );
589
+ _size.store (std::forward<ExecutionPolicy>(policy), 0 );
541
590
542
- _begin.store (0 );
543
- _end.store (0 );
591
+ _begin.store (std::forward<ExecutionPolicy>(policy), 0 );
592
+ _end.store (std::forward<ExecutionPolicy>(policy), 0 );
544
593
545
- STDGPU_ENSURES (empty ());
594
+ STDGPU_ENSURES (empty (std::forward<ExecutionPolicy>(policy) ));
546
595
STDGPU_ENSURES (valid (std::forward<ExecutionPolicy>(policy)));
547
596
}
548
597
@@ -565,7 +614,8 @@ deque<T, Allocator>::valid(ExecutionPolicy&& policy) const
565
614
return true ;
566
615
}
567
616
568
- return (size_valid () && occupied_count_valid (std::forward<ExecutionPolicy>(policy)) &&
617
+ return (size_valid (std::forward<ExecutionPolicy>(policy)) &&
618
+ occupied_count_valid (std::forward<ExecutionPolicy>(policy)) &&
569
619
_locks.valid (std::forward<ExecutionPolicy>(policy)));
570
620
}
571
621
@@ -582,11 +632,11 @@ template <typename ExecutionPolicy,
582
632
stdgpu::device_indexed_range<T>
583
633
deque<T, Allocator>::device_range(ExecutionPolicy&& policy)
584
634
{
585
- const index_t begin = static_cast <index_t >(_begin.load ());
586
- const index_t end = static_cast <index_t >(_end.load ());
635
+ const index_t begin = static_cast <index_t >(_begin.load (std::forward<ExecutionPolicy>(policy) ));
636
+ const index_t end = static_cast <index_t >(_end.load (std::forward<ExecutionPolicy>(policy) ));
587
637
588
638
// Full, i.e. one large block and begin == end
589
- if (full ())
639
+ if (full (std::forward<ExecutionPolicy>(policy) ))
590
640
{
591
641
iota (std::forward<ExecutionPolicy>(policy), device_begin (_range_indices), device_end (_range_indices), 0 );
592
642
}
@@ -611,7 +661,9 @@ deque<T, Allocator>::device_range(ExecutionPolicy&& policy)
611
661
begin);
612
662
}
613
663
614
- return device_indexed_range<value_type>(stdgpu::device_range<index_t >(_range_indices, size ()), data ());
664
+ return device_indexed_range<value_type>(
665
+ stdgpu::device_range<index_t >(_range_indices, size (std::forward<ExecutionPolicy>(policy))),
666
+ data ());
615
667
}
616
668
617
669
template <typename T, typename Allocator>
@@ -627,11 +679,11 @@ template <typename ExecutionPolicy,
627
679
stdgpu::device_indexed_range<const T>
628
680
deque<T, Allocator>::device_range(ExecutionPolicy&& policy) const
629
681
{
630
- const index_t begin = static_cast <index_t >(_begin.load ());
631
- const index_t end = static_cast <index_t >(_end.load ());
682
+ const index_t begin = static_cast <index_t >(_begin.load (std::forward<ExecutionPolicy>(policy) ));
683
+ const index_t end = static_cast <index_t >(_end.load (std::forward<ExecutionPolicy>(policy) ));
632
684
633
685
// Full, i.e. one large block and begin == end
634
- if (full ())
686
+ if (full (std::forward<ExecutionPolicy>(policy) ))
635
687
{
636
688
iota (std::forward<ExecutionPolicy>(policy), device_begin (_range_indices), device_end (_range_indices), 0 );
637
689
}
@@ -656,7 +708,9 @@ deque<T, Allocator>::device_range(ExecutionPolicy&& policy) const
656
708
begin);
657
709
}
658
710
659
- return device_indexed_range<const value_type>(stdgpu::device_range<index_t >(_range_indices, size ()), data ());
711
+ return device_indexed_range<const value_type>(
712
+ stdgpu::device_range<index_t >(_range_indices, size (std::forward<ExecutionPolicy>(policy))),
713
+ data ());
660
714
}
661
715
662
716
template <typename T, typename Allocator>
@@ -672,17 +726,19 @@ template <typename ExecutionPolicy,
672
726
bool
673
727
deque<T, Allocator>::occupied_count_valid(ExecutionPolicy&& policy) const
674
728
{
675
- index_t size_count = size ();
729
+ index_t size_count = size (std::forward<ExecutionPolicy>(policy) );
676
730
index_t size_sum = _occupied.count (std::forward<ExecutionPolicy>(policy));
677
731
678
732
return (size_count == size_sum);
679
733
}
680
734
681
735
template <typename T, typename Allocator>
736
+ template <typename ExecutionPolicy,
737
+ STDGPU_DETAIL_OVERLOAD_DEFINITION_IF (is_execution_policy_v<remove_cvref_t <ExecutionPolicy>>)>
682
738
bool
683
- deque<T, Allocator>::size_valid() const
739
+ deque<T, Allocator>::size_valid(ExecutionPolicy&& policy ) const
684
740
{
685
- int current_size = _size.load ();
741
+ int current_size = _size.load (std::forward<ExecutionPolicy>(policy) );
686
742
return (0 <= current_size && current_size <= static_cast <int >(capacity ()));
687
743
}
688
744
0 commit comments