.. _program_listing_file_include_ripple_arch_topology.hpp: Program Listing for File topology.hpp ===================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/ripple/arch/topology.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #ifndef RIPPLE_ARCH_TOPOLOGY_HPP #define RIPPLE_ARCH_TOPOLOGY_HPP #include "cpu_info.hpp" #include "gpu_info.hpp" #include namespace ripple { using StreamMap = std::map; 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(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 gpus; CpuInfo cpu_info; }; static inline auto topology() noexcept -> Topology& { static Topology topo; return topo; } } // namespace ripple #endif // RIPPLE_ARCH_TOPOLOGY_HPP