Program Listing for File topology.hpp¶
↰ Return to documentation for file (include/ripple/arch/topology.hpp
)
#ifndef RIPPLE_ARCH_TOPOLOGY_HPP
#define RIPPLE_ARCH_TOPOLOGY_HPP
#include "cpu_info.hpp"
#include "gpu_info.hpp"
#include <map>
namespace ripple {
using StreamMap = std::map<ripple::GpuInfo::Index, ripple::GpuInfo::Id>;
struct Topology {
private:
static constexpr float bytes_to_gb = 1.0f / 1073741824.0f;
public:
Topology() noexcept {
gpus = GpuInfo::create_for_all_devices();
}
auto num_gpus() const noexcept -> size_t {
return gpus.size();
}
auto num_cores() const noexcept -> size_t {
return cpu_info.available_cores();
}
auto combined_gpu_memory() const noexcept -> uint64_t {
uint64_t total_mem = 0;
for (const auto& gpu : gpus) {
total_mem += gpu.mem_size;
}
return total_mem;
}
auto combined_gpu_memory_gb() const noexcept -> float {
return static_cast<float>(combined_gpu_memory()) * bytes_to_gb;
}
auto device_to_device_available(size_t gpu_id1, size_t gpu_id2) const noexcept
-> bool {
return gpu_id1 == gpu_id2 || gpus[gpu_id1].peer_to_peer_available(gpu_id2);
}
std::vector<GpuInfo> gpus;
CpuInfo cpu_info;
};
static inline auto topology() noexcept -> Topology& {
static Topology topo;
return topo;
}
} // namespace ripple
#endif // RIPPLE_ARCH_TOPOLOGY_HPP