Skip to content

Commit

Permalink
Remove all transitive includes from public to internal headers
Browse files Browse the repository at this point in the history
  • Loading branch information
fknorr committed Nov 25, 2024
1 parent deb73bf commit 7eb25b6
Show file tree
Hide file tree
Showing 21 changed files with 195 additions and 157 deletions.
1 change: 1 addition & 0 deletions include/celerity.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "debug.h"
#include "distr_queue.h"
#include "host_utils.h"
#include "log.h"
#include "queue.h"
#include "side_effect.h"
#include "version.h"
Expand Down
2 changes: 0 additions & 2 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ namespace detail {
size_t local_rank = -1;
};

enum class tracy_mode { off, fast, full };

class config {
public:
/**
Expand Down
15 changes: 15 additions & 0 deletions include/device.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <functional>
#include <variant>
#include <vector>

#include <sycl/sycl.hpp>

namespace celerity::detail {

struct auto_select_devices {};
using device_selector = std::function<int(const sycl::device&)>;
using devices_or_selector = std::variant<auto_select_devices, std::vector<sycl::device>, device_selector>;

} // namespace celerity::detail
8 changes: 1 addition & 7 deletions include/device_selection.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#pragma once

#include "config.h"
#include "device.h"
#include "log.h"
#include "types.h"
#include "utils.h"

#include <cassert>
#include <concepts>
#include <cstddef>
#include <functional>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <variant>
#include <vector>

#include <fmt/format.h>
Expand All @@ -23,11 +22,6 @@

namespace celerity::detail {

// TODO these are required by distr_queue.h, but we don't want to pull all include dependencies of the pick_devices implementation into user code!
struct auto_select_devices {};
using device_selector = std::function<int(const sycl::device&)>;
using devices_or_selector = std::variant<auto_select_devices, std::vector<sycl::device>, device_selector>;

template <typename DeviceT>
void check_required_device_aspects(const DeviceT& device) {
if(!device.has(sycl::aspect::usm_device_allocations)) { throw std::runtime_error("device does not support USM device allocations"); }
Expand Down
2 changes: 1 addition & 1 deletion include/distr_queue.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "buffer.h"
#include "device_selection.h"
#include "device.h"
#include "fence.h"
#include "handler.h"
#include "host_object.h"
Expand Down
1 change: 1 addition & 0 deletions include/fence.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "runtime.h"
#include "sycl_wrappers.h"
#include "tracy.h"
#include "utils.h"

#include <future>
#include <memory>
Expand Down
3 changes: 2 additions & 1 deletion include/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "buffer.h"
#include "cgf.h"
#include "cgf_diagnostics.h"
#include "communicator.h"
#include "grid.h"
#include "hint.h"
#include "item.h"
Expand All @@ -13,6 +12,7 @@
#include "reduction.h"
#include "sycl_wrappers.h"
#include "types.h"
#include "utils.h"
#include "version.h"
#include "workaround.h"

Expand Down Expand Up @@ -64,6 +64,7 @@ class collective_group;

namespace celerity {
namespace detail {
class communicator;

template <typename CGF>
raw_command_group invoke_command_group_function(CGF&& cgf);
Expand Down
6 changes: 3 additions & 3 deletions include/partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

#include "communicator.h"
#include "ranges.h"
#include "utils.h"
#include "version.h"

#include <cstddef>

#if CELERITY_ENABLE_MPI
#include "mpi_communicator.h" // TODO only used for type cast - move that function to .cc file
#include <mpi.h>
#endif

Expand All @@ -24,6 +22,8 @@ class collective_partition;

namespace celerity::detail {

class communicator;

template <int Dims>
partition<Dims> make_partition(const range<Dims>& global_size, const subrange<Dims>& range) {
return partition<Dims>(global_size, range);
Expand Down Expand Up @@ -67,7 +67,7 @@ namespace celerity::experimental {
class collective_partition : public partition<1> {
public:
#if CELERITY_ENABLE_MPI
MPI_Comm get_collective_mpi_comm() const { return detail::utils::as<detail::mpi_communicator>(m_collective_comm)->get_native(); }
MPI_Comm get_collective_mpi_comm() const; // defined in mpi_communicator.cc
#else
template <typename E = void>
void get_collective_mpi_comm() const {
Expand Down
139 changes: 0 additions & 139 deletions include/print_utils.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
#pragma once

#include "backend/sycl_backend.h"
#include "command_graph.h"
#include "grid.h"
#include "intrusive_graph.h"
#include "nd_memory.h"
#include "ranges.h"
#include "types.h"
#include "utils.h"

#include <algorithm>
#include <chrono>
#include <cstddef>
#include <cstdlib>
#include <string_view>
#include <type_traits>

#include <fmt/format.h>
#include <matchbox.hh>
Expand Down Expand Up @@ -110,36 +102,6 @@ CELERITY_DETAIL_IMPLEMENT_FMT_FORMATTER_FOR_STRONG_TYPE_ALIAS(message_id)
#undef CELERITY_DETAIL_IMPLEMENT_FMT_FORMATTER_FOR_STRONG_TYPE_ALIAS


template <>
struct fmt::formatter<celerity::detail::dependency_kind> : fmt::formatter<std::string_view> {
format_context::iterator format(const celerity::detail::dependency_kind kind, format_context& ctx) const {
const auto repr = [=]() -> std::string_view {
switch(kind) {
case celerity::detail::dependency_kind::anti_dep: return "anti_dep";
case celerity::detail::dependency_kind::true_dep: return "true_dep";
default: return "???";
}
}();
return std::copy(repr.begin(), repr.end(), ctx.out());
}
};

template <>
struct fmt::formatter<celerity::detail::dependency_origin> : fmt::formatter<std::string_view> {
format_context::iterator format(const celerity::detail::dependency_origin origin, format_context& ctx) const {
const auto repr = [=]() -> std::string_view {
switch(origin) {
case celerity::detail::dependency_origin::dataflow: return "dataflow";
case celerity::detail::dependency_origin::collective_group_serialization: return "collective_group_serialization";
case celerity::detail::dependency_origin::execution_front: return "execution_front";
case celerity::detail::dependency_origin::last_epoch: return "last_epoch";
default: return "???";
}
}();
return std::copy(repr.begin(), repr.end(), ctx.out());
}
};

template <>
struct fmt::formatter<celerity::detail::allocation_id> {
constexpr format_parse_context::iterator parse(format_parse_context& ctx) { return ctx.begin(); }
Expand All @@ -165,104 +127,3 @@ struct fmt::formatter<celerity::detail::transfer_id> {
return ctx.out();
}
};

template <>
struct fmt::formatter<celerity::detail::sycl_backend_type> : fmt::formatter<std::string_view> {
format_context::iterator format(const celerity::detail::sycl_backend_type type, format_context& ctx) const {
const auto repr = [=]() -> std::string_view {
switch(type) {
case celerity::detail::sycl_backend_type::generic: return "generic";
case celerity::detail::sycl_backend_type::cuda: return "CUDA";
default: celerity::detail::utils::unreachable(); // LCOV_EXCL_LINE
}
}();
return std::copy(repr.begin(), repr.end(), ctx.out());
}
};

namespace celerity::detail {

inline const char* print_command_type(const command& cmd) {
return matchbox::match(
cmd, //
[](const epoch_command&) { return "epoch"; }, //
[](const horizon_command&) { return "horizon"; }, //
[](const execution_command&) { return "execution"; }, //
[](const push_command&) { return "push"; }, //
[](const await_push_command&) { return "await push"; }, //
[](const reduction_command&) { return "reduction"; }, //
[](const fence_command&) { return "fence"; });
}

/// Wrap a `std::chrono::duration` in this to auto-format it as seconds, milliseconds, microseconds, or nanoseconds.
struct as_sub_second {
template <typename Rep, typename Period>
as_sub_second(const std::chrono::duration<Rep, Period>& duration) : seconds(std::chrono::duration_cast<std::chrono::duration<double>>(duration)) {}
std::chrono::duration<double> seconds;
};

/// Wrap a byte count in this to auto-format it as KB / MB / etc.
struct as_decimal_size {
template <typename Number, std::enable_if_t<std::is_arithmetic_v<Number>, int> = 0>
as_decimal_size(const Number bytes) : bytes(static_cast<double>(bytes)) {}
double bytes;
};

/// Wrap a byte-per-second ratio in this to auto-format it as KB/s, MB/s, ...
struct as_decimal_throughput {
template <typename Rep, typename Period>
as_decimal_throughput(size_t bytes, const std::chrono::duration<Rep, Period>& duration)
: bytes_per_sec(static_cast<double>(bytes) / std::chrono::duration_cast<std::chrono::duration<double>>(duration).count()) {}
double bytes_per_sec;
};

} // namespace celerity::detail

template <>
struct fmt::formatter<celerity::detail::as_sub_second> : fmt::formatter<double> {
format_context::iterator format(const celerity::detail::as_sub_second ss, format_context& ctx) const {
std::string_view unit = " s";
double unit_time = ss.seconds.count();
if(unit_time != 0.0) {
if(std::abs(unit_time) < 1.0) { unit_time *= 1000.0, unit = " ms"; }
if(std::abs(unit_time) < 1.0) { unit_time *= 1000.0, unit = " µs"; }
if(std::abs(unit_time) < 1.0) { unit_time *= 1000.0, unit = " ns"; }
}
auto out = fmt::formatter<double>::format(unit_time, ctx);
return std::copy(unit.begin(), unit.end(), out);
}
};

template <>
struct fmt::formatter<celerity::detail::as_decimal_size> : fmt::formatter<double> {
format_context::iterator format(const celerity::detail::as_decimal_size bs, format_context& ctx) const {
std::string_view unit = " bytes";
double unit_size = static_cast<double>(bs.bytes);
if(unit_size >= 1000) { unit_size /= 1000, unit = " kB"; }
if(unit_size >= 1000) { unit_size /= 1000, unit = " MB"; }
if(unit_size >= 1000) { unit_size /= 1000, unit = " GB"; }
if(unit_size >= 1000) { unit_size /= 1000, unit = " TB"; }
auto out = fmt::formatter<double>::format(unit_size, ctx);
return std::copy(unit.begin(), unit.end(), out);
}
};

template <>
struct fmt::formatter<celerity::detail::as_decimal_throughput> : fmt::formatter<celerity::detail::as_decimal_size> {
format_context::iterator format(const celerity::detail::as_decimal_throughput bt, format_context& ctx) const {
auto out = fmt::formatter<celerity::detail::as_decimal_size>::format(celerity::detail::as_decimal_size(bt.bytes_per_sec), ctx);
const std::string_view unit = "/s";
return std::copy(unit.begin(), unit.end(), out);
}
};

template <>
struct fmt::formatter<celerity::detail::region_layout> {
constexpr format_parse_context::iterator parse(format_parse_context& ctx) { return ctx.begin(); }

format_context::iterator format(const celerity::detail::region_layout& layout, format_context& ctx) const {
return matchbox::match(
layout, [&](const celerity::detail::strided_layout& layout) { return fmt::format_to(ctx.out(), "({})", layout.allocation); },
[&](const celerity::detail::linearized_layout& layout) { return fmt::format_to(ctx.out(), "+{} bytes", layout.offset_bytes); });
}
};
Loading

0 comments on commit 7eb25b6

Please sign in to comment.