29
29
#include " legate_defines.h"
30
30
31
31
#include < algorithm>
32
+ #include < fmt/format.h>
33
+ #include < fmt/ostream.h>
34
+ #include < fmt/ranges.h>
32
35
#include < numeric>
33
36
#include < stdexcept>
34
37
#include < utility>
@@ -368,7 +371,7 @@ InternalSharedPtr<StoragePartition> Storage::create_partition(
368
371
369
372
std::string Storage::to_string () const
370
373
{
371
- auto kind_str = [&] {
374
+ const auto kind_str = [&] {
372
375
switch (kind_) {
373
376
case Kind::REGION_FIELD: return " Region" ;
374
377
case Kind::FUTURE: return " Future" ;
@@ -377,12 +380,12 @@ std::string Storage::to_string() const
377
380
LEGATE_UNREACHABLE ();
378
381
}();
379
382
380
- std::stringstream ss;
381
-
382
- ss << " Storage( " << storage_id_ << " ) { " << shape_-> to_string () << " , kind: " << kind_str
383
- << " , type: " << type_-> to_string () << " , level: " << level_ << " } " ;
384
-
385
- return std::move (ss). str ( );
383
+ return fmt::format ( " Storage({}) {{{}, kind: {}, type: {}, level: {}}} " ,
384
+ storage_id_,
385
+ *shape_,
386
+ kind_str,
387
+ *type_,
388
+ level_ );
386
389
}
387
390
388
391
// //////////////////////////////////////////////////
@@ -445,8 +448,8 @@ namespace {
445
448
void assert_fixed_storage_size (const Storage* storage)
446
449
{
447
450
if (storage->type ()->variable_size ()) {
448
- throw std::invalid_argument{" Store cannot be created with variable size type " +
449
- storage->type ()-> to_string ( )};
451
+ throw std::invalid_argument{
452
+ fmt::format ( " Store cannot be created with variable size type {} " , *( storage->type ()) )};
450
453
}
451
454
}
452
455
@@ -510,8 +513,8 @@ void LogicalStore::set_future_map(Legion::FutureMap future_map, std::size_t scal
510
513
InternalSharedPtr<LogicalStore> LogicalStore::promote (std::int32_t extra_dim, std::size_t dim_size)
511
514
{
512
515
if (extra_dim < 0 || extra_dim > static_cast <std::int32_t >(dim ())) {
513
- throw std::invalid_argument{" Invalid promotion on dimension " + std::to_string (extra_dim) +
514
- " for a " + std::to_string ( dim ()) + " -D store " };
516
+ throw std::invalid_argument{
517
+ fmt::format ( " Invalid promotion on dimension {} for a {}-D store " , extra_dim, dim ())};
515
518
}
516
519
517
520
auto new_extents = extents ().insert (extra_dim, dim_size);
@@ -524,13 +527,13 @@ InternalSharedPtr<LogicalStore> LogicalStore::project(std::int32_t d, std::int64
524
527
auto && old_extents = extents ();
525
528
526
529
if (d < 0 || d >= static_cast <std::int32_t >(dim ())) {
527
- throw std::invalid_argument{" Invalid projection on dimension " + std::to_string (d) + " for a " +
528
- std::to_string ( dim ()) + " -D store " };
530
+ throw std::invalid_argument{
531
+ fmt::format ( " Invalid projection on dimension {} for a {}-D store " , d, dim ())};
529
532
}
530
533
531
534
if (index < 0 || index >= static_cast <std::int64_t >(old_extents[d])) {
532
- throw std::invalid_argument{" Projection index " + std::to_string ( index ) +
533
- " is out of bounds [0, " + std::to_string ( old_extents[d]) + " ) " };
535
+ throw std::invalid_argument{
536
+ fmt::format ( " Projection index {} is out of bounds [0, {}) " , index , old_extents[d])};
534
537
}
535
538
536
539
auto new_extents = old_extents.remove (d);
@@ -550,8 +553,8 @@ InternalSharedPtr<LogicalStore> LogicalStore::slice_(const InternalSharedPtr<Log
550
553
{
551
554
LEGATE_ASSERT (self.get () == this );
552
555
if (dim < 0 || dim >= static_cast <std::int32_t >(this ->dim ())) {
553
- throw std::invalid_argument{" Invalid slicing of dimension " + std::to_string (dim) + " for a " +
554
- std::to_string ( this ->dim ()) + " -D store " };
556
+ throw std::invalid_argument{
557
+ fmt::format ( " Invalid slicing of dimension {} for a {}-D store " , dim, this ->dim ())};
555
558
}
556
559
557
560
constexpr auto sanitize_slice = [](const Slice& san_slice, std::int64_t extent) {
@@ -573,9 +576,8 @@ InternalSharedPtr<LogicalStore> LogicalStore::slice_(const InternalSharedPtr<Log
573
576
auto [start, stop] = sanitize_slice (slice, static_cast <std::int64_t >(exts[dim]));
574
577
575
578
if (start < stop && (start >= exts[dim] || stop > exts[dim])) {
576
- throw std::invalid_argument{" Out-of-bounds slicing on dimension " +
577
- std::to_string (this ->dim ()) + " for a store of shape " +
578
- extents ().to_string ()};
579
+ throw std::invalid_argument{fmt::format (
580
+ " Out-of-bounds slicing on dimension {} for a store of shape {}" , this ->dim (), extents ())};
579
581
}
580
582
581
583
exts[dim] = (start < stop) ? (stop - start) : 0 ;
@@ -603,8 +605,8 @@ InternalSharedPtr<LogicalStore> LogicalStore::slice_(const InternalSharedPtr<Log
603
605
InternalSharedPtr<LogicalStore> LogicalStore::transpose (std::vector<std::int32_t > axes)
604
606
{
605
607
if (axes.size () != dim ()) {
606
- throw std::invalid_argument{" Dimension Mismatch: expected " + std::to_string ( dim ()) +
607
- " axes, but got " + std::to_string ( axes.size ())};
608
+ throw std::invalid_argument{
609
+ fmt::format ( " Dimension Mismatch: expected {} axes, but got {} " , dim (), axes.size ())};
608
610
}
609
611
610
612
if (axes.size () != std::set<std::int32_t >{axes.begin (), axes.end ()}.size ()) {
@@ -613,8 +615,7 @@ InternalSharedPtr<LogicalStore> LogicalStore::transpose(std::vector<std::int32_t
613
615
614
616
for (auto && ax_i : axes) {
615
617
if (ax_i < 0 || ax_i >= static_cast <std::int32_t >(dim ())) {
616
- throw std::invalid_argument{" Invalid axis " + std::to_string (ax_i) + " for a " +
617
- std::to_string (dim ()) + " -D store" };
618
+ throw std::invalid_argument{fmt::format (" Invalid axis {} for a {}-D store" , ax_i, dim ())};
618
619
}
619
620
}
620
621
@@ -627,8 +628,8 @@ InternalSharedPtr<LogicalStore> LogicalStore::delinearize(std::int32_t dim,
627
628
std::vector<std::uint64_t > sizes)
628
629
{
629
630
if (dim < 0 || dim >= static_cast <std::int32_t >(this ->dim ())) {
630
- throw std::invalid_argument{" Invalid delinearization on dimension " + std::to_string (dim) +
631
- " for a " + std::to_string ( this ->dim ()) + " -D store " };
631
+ throw std::invalid_argument{
632
+ fmt::format ( " Invalid delinearization on dimension {} for a {}-D store " , dim, this ->dim ())};
632
633
}
633
634
634
635
auto && old_extents = extents ();
@@ -642,9 +643,8 @@ InternalSharedPtr<LogicalStore> LogicalStore::delinearize(std::int32_t dim,
642
643
};
643
644
644
645
if (!delinearizable (old_extents[dim], sizes)) {
645
- throw std::invalid_argument{" Dimension of size " + std::to_string (old_extents[dim]) +
646
- " cannot be delinearized into " +
647
- tuple<std::uint64_t >{sizes}.to_string ()};
646
+ throw std::invalid_argument{
647
+ fmt::format (" Dimension of size {} cannot be delinearized into {}" , old_extents[dim], sizes)};
648
648
}
649
649
650
650
auto new_extents = tuple<std::uint64_t >{};
@@ -669,9 +669,10 @@ InternalSharedPtr<LogicalStorePartition> LogicalStore::partition_by_tiling_(
669
669
{
670
670
LEGATE_ASSERT (self.get () == this );
671
671
if (tile_shape.size () != dim ()) {
672
- throw std::invalid_argument{" Incompatible tile shape: expected a " +
673
- std::to_string (extents ().size ()) + " -tuple, got a " +
674
- std::to_string (tile_shape.size ()) + " -tuple" };
672
+ throw std::invalid_argument{
673
+ fmt::format (" Incompatible tile shape: expected a {}-tuple, got a {}-tuple" ,
674
+ extents ().size (),
675
+ tile_shape.size ())};
675
676
}
676
677
if (tile_shape.volume () == 0 ) {
677
678
throw std::invalid_argument{" Tile shape must have a volume greater than 0" };
@@ -1031,19 +1032,18 @@ std::unique_ptr<Analyzable> LogicalStore::to_launcher_arg_for_fixup_(
1031
1032
1032
1033
std::string LogicalStore::to_string () const
1033
1034
{
1034
- std::stringstream ss ;
1035
+ auto result = fmt::format ( " Store({}) {{shape: " , store_id_) ;
1035
1036
1036
- ss << " Store(" << store_id_ << " ) {shape: " ;
1037
1037
if (unbound ()) {
1038
- ss << " (unbound)" ;
1038
+ fmt::format_to ( std::back_inserter (result), " (unbound)" ) ;
1039
1039
} else {
1040
- ss << extents ();
1040
+ fmt::format_to ( std::back_inserter (result), " {} " , extents () );
1041
1041
}
1042
1042
if (!transform_->identity ()) {
1043
- ss << " , transform: " << *transform_;
1043
+ fmt::format_to ( std::back_inserter (result), " , transform: {} " , fmt::streamed ( *transform_)) ;
1044
1044
}
1045
- ss << " , storage: " << get_storage ()->id () << " } " ;
1046
- return std::move (ss). str () ;
1045
+ fmt::format_to ( std::back_inserter (result), " , storage: {}}} " , get_storage ()->id ()) ;
1046
+ return result ;
1047
1047
}
1048
1048
1049
1049
bool LogicalStore::equal_storage (const LogicalStore& other) const
@@ -1088,9 +1088,8 @@ InternalSharedPtr<LogicalStore> LogicalStorePartition::get_child_store(
1088
1088
const auto * tiling = static_cast <const Tiling*>(partition_.get ());
1089
1089
1090
1090
if (!tiling->has_color (color)) {
1091
- throw std::out_of_range{" Color " + color.to_string () +
1092
- " is invalid for partition of color shape " +
1093
- color_shape ().to_string ()};
1091
+ throw std::out_of_range{
1092
+ fmt::format (" Color {} is invalid for partition of color shape {}" , color, color_shape ())};
1094
1093
}
1095
1094
1096
1095
auto transform = store_->transform ();
0 commit comments