32#include <unordered_map>
38 static bool SHAMROCK_SMI_USE_HASH
40 "SHAMROCK_SMI_USE_HASH",
"1",
"use hash based string histogram for shamrock --smi")
46 void shamrock_smi_summary() {
53 auto add_array = [&](std::string &
print, std::string header, std::string data) {
56 +
"----------------------------------------------------------------------------"
60 print += (
"| id | Device name | Platform name | Type | "
61 " Memsize | units |\n");
62 print += (
"----------------------------------------------------------------------------"
65 print += (
"----------------------------------------------------------------------------"
69 std::string nodeconfig =
"";
70 for_each_device([&](
u32 key_global,
const sycl::platform &plat,
const sycl::device &dev) {
71 auto PlatformName = plat.get_info<sycl::info::platform::name>();
72 auto DeviceName = dev.get_info<sycl::info::device::name>();
83 nodeconfig += shambase::format(
84 "| {:>2} | {:>25.25} | {:>22.22} | {:>6} | {:>12} | {:>5} | ",
90 device.prop.max_compute_units)
94 std::unordered_map<std::string, int> nodeconfig_histogram
98 std::string
print =
"Available devices :\n";
99 for (
auto &[node_conf, count] : nodeconfig_histogram) {
100 std::string arr =
"";
101 add_array(arr, shambase::format(
"{} x Shamrock process: ", count), node_conf);
102 print += shambase::format(
"\n{}\n", arr);
104 printf(
"%s",
print.data());
116 std::string print_buf =
"";
118 for_each_device([&](
u32 key_global,
const sycl::platform &plat,
const sycl::device &dev) {
119 auto PlatformName = plat.get_info<sycl::info::platform::name>();
120 auto DeviceName = dev.get_info<sycl::info::device::name>();
128 f64 mem = device.prop.global_mem_size;
131 print_buf += shambase::format(
132 "| {:>4} | {:>2} | {:>25.25} | {:>22.22} | {:>6} | {:>12} | {:>5} | ",
139 device.prop.max_compute_units)
144 shamalgs::collective::gather_str(print_buf, recv);
146 std::string print =
"Available devices :\n";
147 print += (
"----------------------------------------------------------------------------"
148 "----------------------\n");
149 print += (
"| rank | id | Device name | Platform name | Type | "
150 " Memsize | units |\n");
151 print += (
"----------------------------------------------------------------------------"
152 "----------------------\n");
154 print += (
"----------------------------------------------------------------------------"
155 "----------------------\n");
156 printf(
"%s\n", print.data());
166 if (shamsys::instance::is_initialized()) {
168 if (list_all_devices) {
169 shamsys::instance::print_queue_map();
175 std::string DeviceName = dev.
prop.
name;
177 auto nolimit_if_too_large = [](
u64 sz) -> std::string {
179 return std::to_string(sz);
185 std::string dev_with_id = shambase::format(
187 - default_work_group_size = {}
188 - global_mem_size = {}
189 - local_mem_size = {}
190 - mem_base_addr_align = {},
191 - max_mem_alloc_size_dev = {},
192 - max_mem_alloc_size_host = {},
193 - pci_address = {})",
205 dev_with_id +=
"\n - Warnings:";
207 dev_with_id += shambase::format(
"\n - {}", warning);
211 std::unordered_map<std::string, int> devicename_histogram
212 = shamalgs::collective::string_histogram(
213 {dev_with_id},
"xxx\nxxx", SHAMROCK_SMI_USE_HASH);
218 f64 total_mem = shamalgs::collective::allreduce_sum(mem);
219 u64 n_compute_units = shamalgs::collective::allreduce_sum(compute_units);
223 std::string print =
"Selected devices : (totals can be wrong if using multiple "
224 "ranks per device)\n";
226 for (
auto &[key, value] : devicename_histogram) {
227 print += shambase::format(
" - {} x {}", value, key) +
"\n";
230 print +=
" Total compute units : " + std::to_string(n_compute_units) +
"\n";
232 printf(
"%s\n", print.data());
239 logger::raw_ln(
" ----- Shamrock SMI ----- \n");
246 if (list_all_devices) {
249 shamrock_smi_summary();
259 "shamrock_smi time:",
262 SHAMROCK_SMI_USE_HASH ?
"yes" :
"no");
Header file describing a Node Instance.
double f64
Alias for double.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
Represents a SYCL device.
usize device_id
The id of the device.
DeviceProperties prop
Properties of the device.
Class Timer measures the time elapsed since the timer was started.
std::string get_time_str() const
Converts the stored nanosecond time to a string representation.
void end()
Stops the timer and stores the elapsed time in nanoseconds.
void start()
Starts the timer.
MPI string gather / allgather helpers (declarations; implementations in shamalgs/src/collective/gathe...
Device sycl_dev_to_sham_dev(usize i, const sycl::device &dev)
Convert a SYCL device to a shamrock backend device.
std::string device_type_name(DeviceType t)
Returns the name of the given device type.
void print()
Prints a log message with no arguments.
std::string readable_sizeof(double size)
given a sizeof value return a readble string Example : readable_sizeof(1024*1024*1024) -> "1....
std::string trunc_str(std::string s, u32 max_len)
Truncate a string to a specified length, adding an ellipsis if necessary.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
T & get_check_ref(const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation())
Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_erro...
std::string getenv_str_default_register(const char *env_var, std::string default_val, std::string desc)
Get the content of the environment variable if it exist and register it documentation,...
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
bool is_mpi_initialized()
Check if MPI is initialized.
namespace for the system handling
void shamrock_smi_all()
Print SMI for all devices.
void shamrock_smi_selected(bool list_all_devices)
Print SMI for selected devices.
u32 for_each_device(std::function< void(u32, const sycl::platform &, const sycl::device &)> fct)
Iterate over all SYCL devices and perform a given function.
void shamrock_smi(bool list_all_devices)
Print information about all available SYCL devices in the cluster.
constexpr u32 u32_max
u32 max value
MPI string gather / allgather helpers (declarations; implementations in shamalgs/src/collective/gathe...
std::unordered_map< std::string, int > string_histogram(const std::vector< std::string > &inputs, std::string delimiter, bool hash_based)
Constructs a histogram from a vector of strings, counting occurrences of each unique string.
usize global_mem_size
The amount of global memory on the device in bytes.
uint64_t max_mem_alloc_size_dev
The maximum size of memory that can be allocated on the device in bytes.
uint32_t max_compute_units
The number of compute units on the device.
std::vector< std::string > warnings
Warnings emitted during property fetching.
uint32_t mem_base_addr_align
The base address alignment for memory allocations on the device in bytes.
std::optional< std::string > pci_address
PCI address of the device.
uint32_t default_work_group_size
Default work group size.
uint64_t max_mem_alloc_size_host
The maximum size of memory that can be allocated on the host in bytes.
usize local_mem_size
The amount of shared local memory on the device in bytes.
std::string name
The name of the device.
Functions related to the MPI communicator.
void Barrier(MPI_Comm comm)
MPI wrapper for MPI_Barrier.