Skip to content

Commit

Permalink
Merge pull request #88 from ikbuibui/const_fmt
Browse files Browse the repository at this point in the history
Make fmt format call const
  • Loading branch information
ikbuibui authored Oct 28, 2024
2 parents 1fbd39f + 2c005b5 commit ad87442
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 21 deletions.
1 change: 0 additions & 1 deletion examples/cholesky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ int main(int argc, char* argv[])
n_threads = atoi(argv[3]);

auto rg = redGrapes::init(n_threads);
using RGTask = decltype(rg)::RGTask;

size_t N = nblks * blksz;

Expand Down
2 changes: 1 addition & 1 deletion redGrapes/dispatch/cuda/cuda_worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ struct fmt::formatter<redGrapes::dispatch::cuda::CudaTaskProperties>
}

template<typename FormatContext>
auto format(redGrapes::dispatch::cuda::CudaTaskProperties const& prop, FormatContext& ctx)
auto format(redGrapes::dispatch::cuda::CudaTaskProperties const& prop, FormatContext& ctx) const
{
return fmt::format_to(ctx.out(), "\"cuda_stream_idx\" : {}", *(prop.m_cuda_stream_idx));
}
Expand Down
2 changes: 1 addition & 1 deletion redGrapes/dispatch/cupla/scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ struct fmt::formatter<redGrapes::dispatch::cupla::CuplaTaskProperties>
}

template<typename FormatContext>
auto format(redGrapes::dispatch::cupla::CuplaTaskProperties const& prop, FormatContext& ctx)
auto format(redGrapes::dispatch::cupla::CuplaTaskProperties const& prop, FormatContext& ctx) const
{
if(auto e = prop.cupla_event)
return fmt::format_to(ctx.out(), "\"cupla_event\" : {}", *e);
Expand Down
4 changes: 2 additions & 2 deletions redGrapes/resource/access/area.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace redGrapes

static bool is_serial(AreaAccess const& a, AreaAccess const& b)
{
return !((a[1] <= b[0]) || (a[0] >= b[1]));
return (a[1] > b[0]) && (a[0] < b[1]);
}

bool is_superset_of(AreaAccess const& a) const
Expand Down Expand Up @@ -70,7 +70,7 @@ struct fmt::formatter<redGrapes::access::AreaAccess>
}

template<typename FormatContext>
auto format(redGrapes::access::AreaAccess const& acc, FormatContext& ctx)
auto format(redGrapes::access::AreaAccess const& acc, FormatContext& ctx) const
{
return fmt::format_to(ctx.out(), "{{ \"area\" : {{ \"begin\" : {}, \"end\" : {} }} }}", acc[0], acc[1]);
}
Expand Down
4 changes: 4 additions & 0 deletions redGrapes/resource/access/combine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ struct fmt::formatter<redGrapes::access::ArrayAccess<Access, N, redGrapes::acces

template<typename FormatContext>
auto format(redGrapes::access::ArrayAccess<Access, N, redGrapes::access::And_t> const& acc, FormatContext& ctx)
const
{
auto out = ctx.out();
out = fmt::format_to(out, "{{ \"and\" : [");
Expand All @@ -172,6 +173,7 @@ struct fmt::formatter<redGrapes::access::ArrayAccess<Access, N, redGrapes::acces

template<typename FormatContext>
auto format(redGrapes::access::ArrayAccess<Access, N, redGrapes::access::Or_t> const& acc, FormatContext& ctx)
const
{
auto out = ctx.out();
out = fmt::format_to(out, "{{ \"or\" : [");
Expand All @@ -198,6 +200,7 @@ struct fmt::formatter<redGrapes::access::CombineAccess<Acc1, Acc2, redGrapes::ac

template<typename FormatContext>
auto format(redGrapes::access::CombineAccess<Acc1, Acc2, redGrapes::access::And_t> const& acc, FormatContext& ctx)
const
{
return fmt::format_to(ctx.out(), "{{ \"and\" : [ {}, {} ] }}", acc.first, acc.second);
}
Expand All @@ -213,6 +216,7 @@ struct fmt::formatter<redGrapes::access::CombineAccess<Acc1, Acc2, redGrapes::ac

template<typename FormatContext>
auto format(redGrapes::access::CombineAccess<Acc1, Acc2, redGrapes::access::Or_t> const& acc, FormatContext& ctx)
const
{
return fmt::format_to(ctx.out(), "{{ \"or\" : [ {}, {} ] }}", acc.first, acc.second);
}
Expand Down
2 changes: 1 addition & 1 deletion redGrapes/resource/access/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct fmt::formatter<redGrapes::access::IOAccess>
}

template<typename FormatContext>
auto format(redGrapes::access::IOAccess const& acc, FormatContext& ctx)
auto format(redGrapes::access::IOAccess const& acc, FormatContext& ctx) const
{
std::string mode_str;

Expand Down
8 changes: 4 additions & 4 deletions redGrapes/resource/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ namespace redGrapes
{
MappingFunc mappingFunc;

WorkerId operator()(ResourceId resourceId)
WorkerId operator()(ResourceId resourceId) const
{
return mappingFunc(resourceId);
}
};

struct ModuloMapping
{
WorkerId operator()(ResourceId resourceId)
WorkerId operator()(ResourceId resourceId) const
{
return resourceId % TaskFreeCtx::n_workers;
}
};

static MapResourceIdToWorker<ModuloMapping> map_resource_to_worker{};
static const MapResourceIdToWorker<ModuloMapping> map_resource_to_worker{};

} // namespace mapping

Expand Down Expand Up @@ -396,7 +396,7 @@ struct fmt::formatter<redGrapes::ResourceAccess>
}

template<typename FormatContext>
auto format(redGrapes::ResourceAccess const& acc, FormatContext& ctx)
auto format(redGrapes::ResourceAccess const& acc, FormatContext& ctx) const
{
return fmt::format_to(
ctx.out(),
Expand Down
2 changes: 1 addition & 1 deletion redGrapes/resource/resource_user.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ struct fmt::formatter<redGrapes::ResourceUser>
}

template<typename FormatContext>
auto format(redGrapes::ResourceUser const& r, FormatContext& ctx)
auto format(redGrapes::ResourceUser const& r, FormatContext& ctx) const
{
auto out = ctx.out();
out = fmt::format_to(out, "[");
Expand Down
2 changes: 1 addition & 1 deletion redGrapes/task/property/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ struct fmt::formatter<redGrapes::GraphProperty<TTask>>
}

template<typename FormatContext>
auto format(redGrapes::GraphProperty<TTask> const& sg_prop, FormatContext& ctx)
auto format(redGrapes::GraphProperty<TTask> const& sg_prop, FormatContext& ctx) const
{
return ctx.out();
}
Expand Down
2 changes: 1 addition & 1 deletion redGrapes/task/property/id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct fmt::formatter<redGrapes::IDProperty>
}

template<typename FormatContext>
auto format(redGrapes::IDProperty const& id_prop, FormatContext& ctx)
auto format(redGrapes::IDProperty const& id_prop, FormatContext& ctx) const
{
return fmt::format_to(ctx.out(), "\"id\" : {}", id_prop.task_id);
}
Expand Down
8 changes: 4 additions & 4 deletions redGrapes/task/property/inherit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ struct fmt::formatter<redGrapes::TaskPropertiesInherit<redGrapes::PropEnd_t>>
}

template<typename FormatContext>
auto format(redGrapes::TaskPropertiesInherit<redGrapes::PropEnd_t> const& prop, FormatContext& ctx)
auto format(redGrapes::TaskPropertiesInherit<redGrapes::PropEnd_t> const& prop, FormatContext& ctx) const
{
return ctx.out();
}
Expand All @@ -178,7 +178,7 @@ struct fmt::formatter<redGrapes::TaskPropertiesInherit<T_Head, redGrapes::PropEn
}

template<typename FormatContext>
auto format(redGrapes::TaskPropertiesInherit<T_Head, redGrapes::PropEnd_t> const& prop, FormatContext& ctx)
auto format(redGrapes::TaskPropertiesInherit<T_Head, redGrapes::PropEnd_t> const& prop, FormatContext& ctx) const
{
return fmt::format_to(ctx.out(), "{}", (T_Head const&) prop);
}
Expand All @@ -193,7 +193,7 @@ struct fmt::formatter<redGrapes::TaskPropertiesInherit<T_Head, T_Tail...>>
}

template<typename FormatContext>
auto format(redGrapes::TaskPropertiesInherit<T_Head, T_Tail...> const& prop, FormatContext& ctx)
auto format(redGrapes::TaskPropertiesInherit<T_Head, T_Tail...> const& prop, FormatContext& ctx) const
{
return fmt::format_to(
ctx.out(),
Expand All @@ -212,7 +212,7 @@ struct fmt::formatter<redGrapes::TaskProperties1<Policies...>>
}

template<typename FormatContext>
auto format(redGrapes::TaskProperties1<Policies...> const& prop, FormatContext& ctx)
auto format(redGrapes::TaskProperties1<Policies...> const& prop, FormatContext& ctx) const
{
return fmt::format_to(
ctx.out(),
Expand Down
2 changes: 1 addition & 1 deletion redGrapes/task/property/label.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct fmt::formatter<redGrapes::LabelProperty>
}

template<typename FormatContext>
auto format(redGrapes::LabelProperty const& label_prop, FormatContext& ctx)
auto format(redGrapes::LabelProperty const& label_prop, FormatContext& ctx) const
{
return fmt::format_to(ctx.out(), "\"label\" : \"{}\"", label_prop.label);
}
Expand Down
2 changes: 1 addition & 1 deletion redGrapes/task/property/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ struct fmt::formatter<redGrapes::ResourceProperty<TTask>>
}

template<typename FormatContext>
auto format(redGrapes::ResourceProperty<TTask> const& label_prop, FormatContext& ctx)
auto format(redGrapes::ResourceProperty<TTask> const& label_prop, FormatContext& ctx) const
{
return fmt::format_to(ctx.out(), "\"resources\" : {}", (redGrapes::ResourceUser const&) label_prop);
}
Expand Down
2 changes: 1 addition & 1 deletion redGrapes/task/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace redGrapes
static inline void* malloc(size_t size)
{
// return std::malloc(size);
return (void*) memory::Allocator().allocate(size).ptr;
return reinterpret_cast<void*>(memory::Allocator().allocate(size).ptr);
}

static inline void free(void* ptr)
Expand Down
2 changes: 1 addition & 1 deletion test/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct fmt::formatter<Access>
}

template<typename FormatContext>
auto format([[maybe_unused]] Access const& acc, FormatContext& ctx)
auto format([[maybe_unused]] Access const& acc, FormatContext& ctx) const
{
return fmt::format_to(ctx.out(), "Access");
}
Expand Down

0 comments on commit ad87442

Please sign in to comment.