Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
main_test.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
16
25#include "shamcmdopt/cmdopt.hpp"
26#include "shamcmdopt/env.hpp"
27#include "shamcomm/logs.hpp"
30#include "shamrock/version.hpp"
35#include "shamtest/shamtest.hpp"
36#include <pybind11/embed.h>
37#include <string_view>
38#include <cstdlib>
39#include <stdexcept>
40#include <string>
41
44
45int main(int argc, char *argv[]) {
46
47 opts::register_opt("--sycl-cfg", "(idcomp:idalt) ", "specify the compute & alt queue index");
48
50 "--smi", {}, "print information about all available SYCL devices in the cluster");
52 "--smi-full", {}, "print information about EVERY available SYCL devices in the cluster");
53
54 opts::register_opt("--loglevel", "(logvalue)", "specify a log level");
55 opts::register_opt("--benchmark-mpi", {}, "micro benchmark for MPI");
56
57 opts::register_opt("--test-list", {}, "print test availables");
58 opts::register_opt("--gen-test-list", {}, "print test availables");
59 opts::register_opt("--run-only", {"(test name)"}, "run only this test");
60 opts::register_opt("--full-output", {}, "print the assertions in the tests");
61
62 opts::register_opt("--benchmark", {}, "run only benchmarks");
63 opts::register_opt("--validation", {}, "run only validation tests");
64 opts::register_opt("--unittest", {}, "run only unittest");
65 opts::register_opt("--long-test", {}, "run also long tests");
66 opts::register_opt("--force-dgpu-on", {}, "for direct mpi comm on");
67 opts::register_opt("--force-dgpu-off", {}, "for direct mpi comm off");
68
69 opts::register_opt("--pypath", "(sys.path)", "python sys.path to set");
70 opts::register_opt("--pypath-from-bin", "(python binary)", "set sys.path from python binary");
71
72 opts::register_opt("-o", {"(filepath)"}, "output test report in that file");
73
74 // --show-completion zsh should call opts::print_completion_zsh()
75 opts::register_opt("--show-completion-zsh", {}, "show completion for zsh");
76
77 shamcmdopt::register_opt("--feenableexcept", "", "Enable FPE exceptions");
78
79 opts::register_env_var_doc("REF_FILES_PATH", "reference test files path");
80
81 shamcmdopt::register_env_var_doc("SHAM_PROF_PREFIX", "Prefix of shamrock profile outputs");
82 shamcmdopt::register_env_var_doc("SHAM_PROF_USE_NVTX", "Enable NVTX profiling");
83 shamcmdopt::register_env_var_doc("SHAM_PROFILING", "Enable Shamrock profiling");
85 "SHAM_PROF_USE_COMPLETE_EVENT",
86 "Use complete event instead of begin end for chrome tracing");
88 "SHAM_PROF_EVENT_RECORD_THRES", "Change the event recording threshold");
89
90 opts::init(argc, argv);
91 if (opts::is_help_mode()) {
92 return 0;
93 }
94
95 if (opts::has_option("--show-completion-zsh")) {
97 return 0;
98 }
99
100 if (opts::has_option("--feenableexcept")) {
102 }
103
104 if (opts::has_option("--gen-test-list")) {
105 std::string_view outfile = opts::get_option("--gen-test-list");
107 return 0;
108 }
109
110 if (opts::has_option("--loglevel")) {
111 std::string level = std::string(opts::get_option("--loglevel"));
112
113 i32 a = atoi(level.c_str());
114
115 if (i8(a) != a) {
116 logger::err_ln("Cmd OPT", "you must select a loglevel in a 8bit integer range");
118 "you must select a loglevel in a 8bit integer range");
119 } else {
121 }
122 }
123
124 if (opts::has_option("--sycl-cfg")) {
125 shamsys::instance::init(argc, argv);
126 } else {
127 using namespace shamsys::instance;
128 start_mpi(MPIInitInfo{.argc = opts::get_argc(), .argv = opts::get_argv()});
129 if (shamcomm::world_rank() == 0) {
131 "Init", "No kernel can be run without a sycl configuration (--sycl-cfg x:x)");
132 }
133 }
134
135 if (shamcomm::world_rank() == 0) {
136 print_title_bar();
137
140 logger::raw_ln("MPI status : ");
141
142 shamsys::instance::print_mpi_comm_info();
143
145 " - MPI & SYCL init :",
147
148 shamsys::instance::print_mpi_capabilities();
149 }
150 }
151
153 shamsys::instance::check_dgpu_available();
154 auto sptr = shamsys::instance::get_compute_scheduler_ptr();
155 shamcomm::validate_comm(sptr);
156 }
157
158 if (shamcomm::world_rank() == 0) {
161 }
162
163 bool is_smi = opts::has_option("--smi");
164 bool is_smi_full = opts::has_option("--smi-full");
165
166 if (is_smi || is_smi_full) {
167 if (shamcomm::world_rank() == 0) {
169 }
170 shamsys::shamrock_smi(is_smi_full);
171 }
172
173 if (opts::has_option("--benchmark-mpi")) {
174 if (shamcomm::world_rank() == 0) {
176 }
179 } else {
181 "Init",
182 "--benchmark-mpi can't be run without a sycl configuration (--sycl-cfg x:x)");
183 }
184 }
185
188
189 if (opts::has_option("--pypath")) {
190 shambindings::setpypath(std::string(opts::get_option("--pypath")));
191 }
192
193 if (opts::has_option("--pypath-from-bin")) {
194 std::string pybin = std::string(opts::get_option("--pypath-from-bin"));
196 }
197
198 shamsys::register_signals();
199
201
202 cfg.print_test_list_exit = false;
203
204 cfg.full_output = opts::has_option("--full-output");
205
206 cfg.output_tex = true;
207 if (opts::has_option("-o")) {
208 if (opts::get_option("-o").size() == 0) {
210 }
211 cfg.json_output = opts::get_option("-o");
212 }
213
214 cfg.run_long_tests = opts::has_option("--long-test");
215
216 cfg.run_benchmark = opts::has_option("--benchmark");
217 cfg.run_validation = opts::has_option("--validation");
218 cfg.run_unittest = opts::has_option("--unittest");
219 if (!(cfg.run_benchmark || cfg.run_unittest || cfg.run_validation)) {
220 cfg.run_unittest = true;
221 cfg.run_validation = true;
222 cfg.run_benchmark = false;
223 }
224
225 if (opts::has_option("--run-only")) {
226 cfg.run_only = opts::get_option("--run-only");
227 }
228
229 return shamtest::run_all_tests(argc, argv, cfg);
230
231 } else {
232
233 if (shamcomm::world_rank() == 0) {
235 "Init", "No sycl configuration (--sycl-cfg x:x) has been set, early exit");
236 }
238 return 0;
239 }
240}
Shamrock communication buffers.
Header file describing a Node Instance.
void start_mpi(MPIInitInfo mpi_info)
Start MPI.
bool is_initialized()
to check whether the NodeInstance is initialized
void init(int argc, char *argv[])
initialize the NodeInstance from command line args in the main
void close_mpi()
Finalize MPI.
std::int8_t i8
8 bit integer
std::int32_t i32
32 bit integer
This header file contains utility functions related to exception handling in the code.
PYBIND11_EMBEDDED_MODULE(pyshamrock, m)
Call bindings init for the shamrock python module.
Definition main_test.cpp:43
void enable_fpe_exceptions()
Enable floating point exceptions.
void set_loglevel(i8 val)
Set the global log level.
Definition loglevel.hpp:45
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
bool is_help_mode()
Check if the help mode is enabled.
Definition cmdopt.cpp:281
bool has_option(const std::string_view &option_name)
Check if an option is present.
Definition cmdopt.cpp:128
std::string_view get_option(const std::string_view &option_name)
Get the value of an option.
Definition cmdopt.cpp:146
char ** get_argv()
Get the command line arguments.
Definition cmdopt.cpp:204
int get_argc()
Get the number of command line arguments.
Definition cmdopt.cpp:198
void init(int argc, char *argv[])
Initialize the command line option parser. We also process generic options in this call (color detect...
Definition cmdopt.cpp:184
void register_env_var_doc(std::string env_var, std::string desc)
Register the documentation of an environment variable.
Definition env.cpp:43
void print_completion_zsh()
print zsh completion script to be sourced
Definition cmdopt.cpp:232
void register_opt(std::string name, std::optional< std::string > args, std::string description)
Register a command line option.
Definition cmdopt.cpp:165
void print_help()
Print the help message.
Definition cmdopt.cpp:211
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
Definition worldInfo.cpp:40
void run_micro_benchmark()
Run latency & bandwidth benchmark those benchmark where adapted from osu_microbenchmark.
void shamrock_smi(bool list_all_devices)
Print information about all available SYCL devices in the cluster.
void gen_test_list(std::string_view outfile)
output test list to a file
Definition shamtest.cpp:586
int run_all_tests(int argc, char *argv[], TestConfig cfg)
run all the tests
Definition shamtest.cpp:486
void init_embed(py::module &m, bool hook_stdout=true)
Init python bindings and register them to Python API.
void print_active_level()
Prints the active log levels.
Definition logs.cpp:33
void code_init_done_log()
Indicates that the code initialization is complete through various means ;).
Definition logs.cpp:57
void raw_ln(Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:90
void print_faint_row()
Prints a faint separator line to the log.
Definition logs.hpp:100
void warn_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:133
void err_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:133
main include file for testing
void setpypath_from_binary(std::string binary_path)
set the value of sys.path before init from the supplied binary
void setpypath(std::string path)
set the value of sys.path before init
Struct containing MPI Init informations Usage.
Configuration of the test runner.
Definition shamtest.hpp:64
std::optional< std::string > run_only
Run only regex to select tests.
Definition shamtest.hpp:83
bool run_long_tests
run also long tests
Definition shamtest.hpp:78
bool run_benchmark
run benchmarks
Definition shamtest.hpp:81
bool output_tex
Should output a tex report.
Definition shamtest.hpp:73
bool run_unittest
run unittests
Definition shamtest.hpp:79
bool full_output
Should display all logs including all asserts.
Definition shamtest.hpp:70
std::optional< std::string > json_output
Should output a json report.
Definition shamtest.hpp:76
bool print_test_list_exit
Should print test list and then exit.
Definition shamtest.hpp:67
bool run_validation
run validation tests
Definition shamtest.hpp:80
const std::string reset()
Get the reset terminal escape char.
const std::string col8b_green()
Get the green terminal escape char.
typedefs and macros
Functions related to the MPI communicator.