diff --git a/CMakeLists.txt b/CMakeLists.txt index e924848a..97231085 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -283,6 +283,7 @@ add_library(carbon SHARED src/data_view.cpp src/dense.cpp src/dense_disg.cpp + src/dense_disg_distributed.cpp src/dense_distributed.cpp src/dense_launch_shape.cpp src/dist_reduce.cpp @@ -304,6 +305,7 @@ target_link_libraries(carbon PUBLIC spdlog::spdlog rapidjson OpenMP::OpenMP_CXX) if(CARBON_BACKEND STREQUAL "Cuda") target_sources(carbon PRIVATE src/cuda_stub.cu + src/dense_disg_distributed_row_copy.cu src/halo_pack.cu src/gpu.cpp) target_link_libraries(carbon PUBLIC CUDA::cudart) @@ -328,12 +330,14 @@ if(CARBON_BACKEND STREQUAL "Cuda") elseif(CARBON_BACKEND STREQUAL "Hip") target_sources(carbon PRIVATE src/hip_stub.cu + src/dense_disg_distributed_row_copy.cu src/halo_pack.cu src/gpu_hip.cpp) # The .cu stub is HIP device code; tell CMake to feed it to the HIP compiler (the .cu # suffix would otherwise be treated as CUDA). The .cpp host source stays on the C++ # compiler. Consumer .cu TUs do the same via set_source_files_properties in tests/. - set_source_files_properties(src/hip_stub.cu src/halo_pack.cu PROPERTIES LANGUAGE HIP) + set_source_files_properties(src/hip_stub.cu src/dense_disg_distributed_row_copy.cu src/halo_pack.cu + PROPERTIES LANGUAGE HIP) if(CARBON_HIP_NVCC) # HIP-on-NVIDIA (nvcc backs the HIP language). The HIP runtime is a thin shim over # CUDA, so host .cpp TUs that include pull in and @@ -418,6 +422,7 @@ elseif(CARBON_BACKEND STREQUAL "Sycl") src/data_view.cpp src/dense.cpp src/dense_disg.cpp + src/dense_disg_distributed.cpp src/dense_distributed.cpp src/dist_reduce.cpp src/io.cpp diff --git a/benchmarks/cg/cg_poisson.cu b/benchmarks/cg/cg_poisson.cu index 6495eb4d..4b968716 100644 --- a/benchmarks/cg/cg_poisson.cu +++ b/benchmarks/cg/cg_poisson.cu @@ -61,7 +61,7 @@ // // CLI // --- -// --grid {dense|dense_distributed|disg|block} +// --grid {dense|dense_distributed|disg|block|disg_distributed} // Grid family (default: dense). dense is the // original Z-slab-only grid; dense_distributed // honours --decomposition. @@ -84,12 +84,11 @@ // triple of P with the smallest max/min ratio. // --dot Dump the inferred main-loop DAGs as GraphViz // DOT on stdout (one block per Skeleton). -// --dot-out prefix Write GraphViz DOT + launch-order listings +// --dot-out prefix Write launch-matrix DOT + launch-order listings // for init / iter_pre / iter_post as -// prefix_.dot and prefix_.txt. -// --dot-matrix With --dot-out, also write launch-matrix and -// kernel-list DOT -// (prefix__matrix.dot / _kernels.dot). +// prefix_.dot / .txt (plus _streams.dot). +// --dot-matrix With --dot-out, also write kernel-list DOT +// (prefix__kernels.dot). // --help Print this help and exit. // // Build + run @@ -110,6 +109,7 @@ #include #include #include +#include #include #include #include @@ -147,6 +147,7 @@ #include #include // NEW: std::is_same_v + #if __has_include() # include # define CARBON_HALO_NVTX_PUSH(name) ::nvtxRangePushA(name) @@ -161,6 +162,7 @@ #endif + namespace { using SB = carbon::detail::block::DefaultStaticBlock; @@ -204,6 +206,96 @@ compute_sample_stats(std::vector values) -> SampleStats { return stats; } +struct PhaseAccumulator { + std::string label; + std::vector milliseconds; +}; + +using SkeletonProfile = std::vector; + +[[nodiscard]] auto +profile_step_label(const carbon::Skeleton::ProfileStep& step) -> std::string { + std::string label = step.name; + if (step.user_kernel_index == carbon::Skeleton::kNoKernel) { + label = "[auto] " + label; + } + if (step.view != carbon::DataView::Standard) { + label += std::string{" ["} + std::string{carbon::to_string(step.view)} + ']'; + } + switch (step.reduce_mode) { + case carbon::reduce::ReduceLaunchMode::Partial: + label += " [partial]"; + break; + case carbon::reduce::ReduceLaunchMode::Merge: + label += " [merge]"; + break; + case carbon::reduce::ReduceLaunchMode::Full: + break; + } + label += " (s" + std::to_string(step.stream_index) + ')'; + return label; +} + +[[nodiscard]] auto +profile_phase_label(const carbon::Skeleton::ProfilePhase& phase) -> std::string { + std::string label; + for (size_t i = 0; i < phase.steps.size(); ++i) { + if (i != 0U) { + label += " + "; + } + label += profile_step_label(phase.steps[i]); + } + if (phase.steps.size() > 1U) { + label = "[overlap] " + label; + } + return label; +} + +auto +record_profile_samples(SkeletonProfile& profile, + const std::vector& phases) -> void { + if (profile.size() < phases.size()) { + profile.resize(phases.size()); + } + for (size_t i = 0; i < phases.size(); ++i) { + if (profile[i].label.empty()) { + profile[i].label = profile_phase_label(phases[i]); + } + profile[i].milliseconds.push_back(phases[i].milliseconds); + } +} + +auto +print_profile_summary(std::string_view grid_tag, + std::string_view skeleton_tag, + const SkeletonProfile& profile) -> void { + if (profile.empty()) { + CARBON_LOG_INFO("cg_poisson_unified[{}]: profile {}: no phases recorded", grid_tag, + skeleton_tag); + return; + } + + double total_mean = 0.0; + size_t phases_with_samples = 0; + for (size_t i = 0; i < profile.size(); ++i) { + if (profile[i].milliseconds.empty()) { + continue; + } + ++phases_with_samples; + const SampleStats stats = compute_sample_stats(profile[i].milliseconds); + total_mean += stats.mean; + CARBON_LOG_INFO( + "cg_poisson_unified[{}]: profile {} phase {}: mean={:.4f} ms, std={:.4f}, median={:.4f} " + "min={:.4f} max={:.4f} n={} steps=[{}]", + grid_tag, skeleton_tag, i, stats.mean, stats.stddev, stats.median, stats.min, stats.max, stats.n, + profile[i].label); + } + if (phases_with_samples != 0U) { + CARBON_LOG_INFO("cg_poisson_unified[{}]: profile {} total phase mean={:.4f} ms", grid_tag, + skeleton_tag, total_mean); + } +} + struct Options { std::string grid_kind = "dense"; int64_t nx = 16; @@ -223,6 +315,7 @@ struct Options { std::string dot_out_prefix; bool dot_matrix = false; std::string vtk_path = ""; // NEW + bool profile_steps = false; }; // Build a clipp parser bound directly to @p opts. Mirrors the structure of the @@ -237,7 +330,7 @@ build_cli(Options& opts) -> clipp::group { return clipp::group( (option("-h", "--help").set(opts.show_help) % "Show this help message and exit"), (option("--grid") & value("kind", opts.grid_kind)) % - "Grid family: dense | disg | block (default: dense)", + "Grid family: dense | disg | block | dense_distributed | disg_distributed (default: dense)", (option("--nx") & integer("nx", opts.nx)) % "Grid x extent (default 16)", (option("--ny") & integer("ny", opts.ny)) % "Grid y extent (default 16)", (option("--nz") & integer("nz", opts.nz)) % "Grid z extent (default 32, must be >= 2)", @@ -257,13 +350,18 @@ build_cli(Options& opts) -> clipp::group { "Iterations excluded from timing statistics (default 10)", (option("--overlap") & value("mode", opts.overlap_raw)) % "Skeleton overlap mode: none | standard | extended | two-way-extended (default: none)", + (option("--profile-steps").set(opts.profile_steps) % + "Report per-phase kernel timings. With --overlap none each phase is one scheduled " + "launch; with overlap, each overlapped region is one phase and its makespan is " + "reported. Inserts host drains at phase boundaries, so use without this flag for " + "headline performance numbers."), (option("--dot").set(opts.dump_dot) % "Dump inferred main-loop Skeleton DAGs as GraphViz DOT on stdout")), (option("--dot-out") & value("prefix", opts.dot_out_prefix)) % - "Write DOT + launch-order files as prefix_.dot / .txt " - "(tag = init | iter_pre | iter_post)", + "Write launch-matrix DOT + launch-order files as prefix_.dot / .txt " + "(plus _streams.dot; tag = init | iter_pre | iter_post)", (option("--dot-matrix").set(opts.dot_matrix)) % - "With --dot-out, also write launch-matrix and kernel-list DOT files", + "With --dot-out, also write kernel-list DOT files", (option("--vtk-out") & value("path", opts.vtk_path)) % "After the solve, dump the solution u and its gradient as a VTK " "legacy STRUCTURED_POINTS file at PATH (appends .rankN under MPI; " @@ -838,16 +936,16 @@ run_cg(Grid& grid, if (!opts.dot_out_prefix.empty()) { const auto export_one = [&](carbon::Skeleton& sk, const char* tag) { const std::string base = opts.dot_out_prefix + "_" + tag; - if (!sk.export_dot_file(base + ".dot", std::string{"cg_"} + tag)) { + if (!sk.export_launch_matrix_dot_file(base + ".dot", std::string{"cg_"} + tag)) { CARBON_LOG_ERROR("cg_poisson_unified: failed to write {}.dot", base); } + if (!sk.export_dot_file(base + "_streams.dot", std::string{"cg_"} + tag)) { + CARBON_LOG_ERROR("cg_poisson_unified: failed to write {}_streams.dot", base); + } if (!sk.export_launch_order_file(base + ".txt")) { CARBON_LOG_ERROR("cg_poisson_unified: failed to write {}.txt", base); } if (opts.dot_matrix) { - if (!sk.export_launch_matrix_dot_file(base + "_matrix.dot", std::string{"cg_"} + tag)) { - CARBON_LOG_ERROR("cg_poisson_unified: failed to write {}_matrix.dot", base); - } if (!sk.export_kernel_list_dot_file(base + "_kernels.dot", std::string{"cg_"} + tag)) { CARBON_LOG_ERROR("cg_poisson_unified: failed to write {}_kernels.dot", base); } @@ -879,16 +977,27 @@ run_cg(Grid& grid, size_t iter = 0; bool converged = (r0_norm <= abs_target); std::vector iteration_ms; + SkeletonProfile iter_pre_profile; + SkeletonProfile iter_post_profile; for (; iter < opts.max_iter && !converged; ++iter) { - nvtxRangePushA("cg_iter"); + CARBON_HALO_NVTX_PUSH("cg_iter"); const auto iter_t0 = std::chrono::steady_clock::now(); + const bool collect_timing = iter >= opts.warmup; beta_host = (delta_old_h > 0.0) ? (delta_new_h / delta_old_h) : 0.0; - iter_pre.run(); - iter_pre.wait(); + if (opts.profile_steps) { + const auto phases = iter_pre.run_profile(); + iter_pre.wait(); + if (collect_timing) { + record_profile_samples(iter_pre_profile, phases); + } + } else { + iter_pre.run(); + iter_pre.wait(); + } pAp.sync(stream); stream.wait(); const double pAp_h = pAp.host_value(); @@ -902,15 +1011,23 @@ run_cg(Grid& grid, } alpha_host = delta_new_h / pAp_h; - iter_post.run(); - iter_post.wait(); + if (opts.profile_steps) { + const auto phases = iter_post.run_profile(); + iter_post.wait(); + if (collect_timing) { + record_profile_samples(iter_post_profile, phases); + } + } else { + iter_post.run(); + iter_post.wait(); + } delta_new.sync(stream); stream.wait(); delta_old_h = delta_new_h; delta_new_h = delta_new.host_value(); const auto iter_t1 = std::chrono::steady_clock::now(); - if (iter >= opts.warmup) { + if (collect_timing) { iteration_ms.push_back(std::chrono::duration(iter_t1 - iter_t0).count()); } const double r_norm = std::sqrt(std::max(0.0, delta_new_h)); @@ -924,8 +1041,10 @@ run_cg(Grid& grid, if (r_norm <= abs_target) { converged = true; } - nvtxRangePop(); + CARBON_HALO_NVTX_POP(); } + + const double final_r_norm = std::sqrt(std::max(0.0, delta_new_h)); if (world_rank == 0) { if (converged) { @@ -949,6 +1068,15 @@ run_cg(Grid& grid, grid_tag, stats.n, opts.warmup, stats.min, stats.max, stats.mean, stats.stddev, stats.median); } + + if (opts.profile_steps) { + CARBON_LOG_INFO( + "cg_poisson_unified[{}]: step profile (host-drained phase makespans; " + "timing is perturbed by --profile-steps)", + grid_tag); + print_profile_summary(grid_tag, "iter_pre", iter_pre_profile); + print_profile_summary(grid_tag, "iter_post", iter_post_profile); + } } @@ -1009,7 +1137,7 @@ run_cg(Grid& grid, if (world_rank == 0) { CARBON_LOG_WARN( "cg_poisson_unified[{}]: --vtk-out is only supported for --grid dense " - "and --grid dense_distributed (no VTK writer for {}); skipping dump.", + "and --grid dense_distributed disg_distributed (no VTK writer for {}); skipping dump.", grid_tag, grid_tag); } } @@ -1097,7 +1225,7 @@ main(int argc, char** argv) -> int { // auto-inserted halo collapses to a no-op. The original Dense is Z-slab only // and splits z across ranks by itself, so it never takes a process grid. std::optional pg; - if (is_distributed && opts.grid_kind == "dense_distributed") { + if (is_distributed && ( opts.grid_kind == "dense_distributed" || opts.grid_kind == "disg_distributed" )) { pg.emplace(carbon::ProcessGrid::make(world_size, dec_mode)); const carbon::int32_3d dims = pg->dims(); if (world_rank == 0) { @@ -1159,8 +1287,19 @@ main(int argc, char** argv) -> int { return run_cg(*block, sys, opts, "block", world_rank); } + if (opts.grid_kind == "disg_distributed") { + std::optional disg_distributed; + if (pg) { + // (System, int64_3d, ProcessGrid, Stencil) + disg_distributed.emplace(sys, global, *pg, stencil); + } else { + // (System, int64_3d, Stencil) + disg_distributed.emplace(sys, global, stencil); + } + return run_cg(*disg_distributed, sys, opts, "disg_distributed", world_rank); + } CARBON_LOG_ERROR( - "cg_poisson_unified: unknown --grid '{}' (expected dense|dense_distributed|disg|block)", + "cg_poisson_unified: unknown --grid '{}' (expected dense|dense_distributed|disg|block|disg_distributed)", opts.grid_kind); return EXIT_FAILURE; } catch (const std::exception& e) { diff --git a/benchmarks/jacobi_nvidia/jacobi_nvidia.cu b/benchmarks/jacobi_nvidia/jacobi_nvidia.cu index 94c474b6..fd4d49cd 100644 --- a/benchmarks/jacobi_nvidia/jacobi_nvidia.cu +++ b/benchmarks/jacobi_nvidia/jacobi_nvidia.cu @@ -472,17 +472,18 @@ run_solver(DenseGrid& grid, if (!dot_prefix.empty()) { for (auto [sk, tag] : {std::pair{&sk_ab, "_ab"}, std::pair{&sk_ba, "_ba"}}) { - if (!sk->export_dot_file(dot_prefix + tag + ".dot")) { + // Default .dot is the launch matrix; stream-cluster graph is optional sidecar. + if (!sk->export_launch_matrix_dot_file(dot_prefix + tag + ".dot", + std::string{"jacobi"} + tag)) { std::fprintf(stderr, "jacobi_nvidia: failed to write %s%s.dot\n", dot_prefix.c_str(), tag); } + if (!sk->export_dot_file(dot_prefix + tag + "_streams.dot")) { + std::fprintf(stderr, "jacobi_nvidia: failed to write %s%s_streams.dot\n", + dot_prefix.c_str(), tag); + } if (!sk->export_launch_order_file(dot_prefix + tag + ".txt")) { std::fprintf(stderr, "jacobi_nvidia: failed to write %s%s.txt\n", dot_prefix.c_str(), tag); } - if (dot_matrix && !sk->export_launch_matrix_dot_file(dot_prefix + tag + "_matrix.dot", - std::string{"jacobi"} + tag)) { - std::fprintf(stderr, "jacobi_nvidia: failed to write %s%s_matrix.dot\n", dot_prefix.c_str(), - tag); - } if (dot_matrix && !sk->export_kernel_list_dot_file(dot_prefix + tag + "_kernels.dot", std::string{"jacobi"} + tag)) { std::fprintf(stderr, "jacobi_nvidia: failed to write %s%s_kernels.dot\n", diff --git a/benchmarks/lbm_lid_driven_cavity/lbm_lid_driven_cavity.cu b/benchmarks/lbm_lid_driven_cavity/lbm_lid_driven_cavity.cu index 44ebe069..4cd98d78 100644 --- a/benchmarks/lbm_lid_driven_cavity/lbm_lid_driven_cavity.cu +++ b/benchmarks/lbm_lid_driven_cavity/lbm_lid_driven_cavity.cu @@ -124,6 +124,7 @@ struct Options { std::string overlap = "none"; std::string export_dot_path = ""; std::string export_dot_png_path = ""; + std::string export_dot_streams_path = ""; // Opt in to carbon::Skeleton CUDA-graph capture + replay of each ping-pong // skeleton. Engaged only for single-GPU / single-stream schedules (the // OverlapMode::None single-GPU case); a no-op fallback otherwise. @@ -191,11 +192,13 @@ build_cli(Options& opts) -> clipp::group { "a second stream — improves multi-GPU significantly on PCIe-only " "hosts where halo otherwise blocks compute.", (option("--export-dot") & value("path", opts.export_dot_path)) % - "Write the compiled Skeleton schedule graph (GraphViz .dot) for the " - "AB ping-pong skeleton to PATH after compile.", + "Write the compiled Skeleton launch-matrix schedule (GraphViz .dot) for " + "the AB ping-pong skeleton to PATH after compile.", (option("--export-dot-png") & value("path", opts.export_dot_png_path)) % - "Render the schedule graph to PNG via GraphViz (requires dot on PATH). " - "Also writes a sibling .dot file.", + "Render the launch-matrix schedule to PNG via GraphViz (requires dot on " + "PATH). Also writes a sibling .dot file.", + (option("--export-dot-streams") & value("path", opts.export_dot_streams_path)) % + "Write the stream-cluster schedule graph (legacy export_dot format) to PATH.", option("--cuda-graph").set(opts.cuda_graph) % "Capture + replay each ping-pong skeleton as a CUDA graph (single-GPU / " "single-stream only; transparently falls back to eager launch otherwise). " @@ -584,20 +587,29 @@ run_benchmark(const Options& opts, sk_ab.effective_kernels().size(), sk_ba.effective_kernels().size()); if (!opts.export_dot_path.empty()) { - if (!sk_ab.export_dot_file(opts.export_dot_path, "lbm_sk_ab")) { + if (!sk_ab.export_launch_matrix_dot_file(opts.export_dot_path, "lbm_sk_ab")) { CARBON_LOG_ERROR("lbm_lid_driven_cavity: --export-dot failed for {}", opts.export_dot_path); return EXIT_FAILURE; } - CARBON_LOG_INFO("lbm_lid_driven_cavity: wrote schedule DOT to {}", opts.export_dot_path); + CARBON_LOG_INFO("lbm_lid_driven_cavity: wrote launch-matrix DOT to {}", opts.export_dot_path); } if (!opts.export_dot_png_path.empty()) { - if (!sk_ab.export_dot_png(opts.export_dot_png_path, "lbm_sk_ab")) { + if (!sk_ab.export_launch_matrix_dot_png(opts.export_dot_png_path, "lbm_sk_ab")) { CARBON_LOG_ERROR( "lbm_lid_driven_cavity: --export-dot-png failed for {} (is graphviz dot on PATH?)", opts.export_dot_png_path); return EXIT_FAILURE; } - CARBON_LOG_INFO("lbm_lid_driven_cavity: wrote schedule PNG to {}", opts.export_dot_png_path); + CARBON_LOG_INFO("lbm_lid_driven_cavity: wrote launch-matrix PNG to {}", opts.export_dot_png_path); + } + if (!opts.export_dot_streams_path.empty()) { + if (!sk_ab.export_dot_file(opts.export_dot_streams_path, "lbm_sk_ab")) { + CARBON_LOG_ERROR("lbm_lid_driven_cavity: --export-dot-streams failed for {}", + opts.export_dot_streams_path); + return EXIT_FAILURE; + } + CARBON_LOG_INFO("lbm_lid_driven_cavity: wrote stream-cluster DOT to {}", + opts.export_dot_streams_path); } using Clock = std::chrono::steady_clock; diff --git a/benchmarks/lbm_lid_driven_cavity/scripts/lbm_sweep_config.py b/benchmarks/lbm_lid_driven_cavity/scripts/lbm_sweep_config.py index 75e34fc4..038d37ea 100644 --- a/benchmarks/lbm_lid_driven_cavity/scripts/lbm_sweep_config.py +++ b/benchmarks/lbm_lid_driven_cavity/scripts/lbm_sweep_config.py @@ -74,7 +74,7 @@ def _as_list(key: str, v: object) -> list: return [v] -def _parse_value(key: str, kind: str, value: object) -> object: +def _parse_value(key: str, kind: str, value: object, choices: dict[str, set[str]]) -> object: if kind == "int": return _as_int(key, value) if kind == "bool": @@ -98,32 +98,44 @@ def _parse_value(key: str, kind: str, value: object) -> object: for x in items: if not isinstance(x, str) or not pattern.match(x): raise SweepConfigError(f"{key} has an invalid value {x!r}") - if key in CHOICES and x not in CHOICES[key]: - raise SweepConfigError(f"{key} value {x!r} not in {sorted(CHOICES[key])}") + if key in choices and x not in choices[key]: + raise SweepConfigError(f"{key} value {x!r} not in {sorted(choices[key])}") return items if kind == "words" else items[0] -def load_sweep_config(text: str) -> dict[str, object]: - """Validate YAML text; returns every key in ``KEYS``, omitted ones at their default.""" +def load_sweep_config( + text: str, + keys: dict[str, tuple[str, str, object]] = KEYS, + choices: dict[str, set[str]] = CHOICES, +) -> dict[str, object]: + """Validate YAML text; returns every key in ``keys``, omitted ones at their default. + + ``keys`` / ``choices`` default to this sweep's tables; other sweeps (e.g. the + distributed benchmark's) pass their own in the same format. + """ import yaml cfg = yaml.safe_load(text) or {} if not isinstance(cfg, dict): raise SweepConfigError("top level must be a mapping") - out = {key: default for key, (_, _, default) in KEYS.items()} + out = {key: default for key, (_, _, default) in keys.items()} for key, value in cfg.items(): - if key not in KEYS: - raise SweepConfigError(f"unknown key {key!r} (known: {', '.join(KEYS)})") - out[key] = _parse_value(key, KEYS[key][1], value) + if key not in keys: + raise SweepConfigError(f"unknown key {key!r} (known: {', '.join(keys)})") + out[key] = _parse_value(key, keys[key][1], value, choices) return out -def read_sweep_config(path: Path) -> dict[str, object]: +def read_sweep_config( + path: Path, + keys: dict[str, tuple[str, str, object]] = KEYS, + choices: dict[str, set[str]] = CHOICES, +) -> dict[str, object]: """Load a sweep YAML file; the path must be an existing ``.yml`` / ``.yaml`` file.""" path = Path(path).resolve() if path.suffix not in (".yml", ".yaml") or not path.is_file(): raise SweepConfigError(f"not a .yml/.yaml file: {path}") - return load_sweep_config(path.read_text()) + return load_sweep_config(path.read_text(), keys, choices) def series_prefixes(cfg: dict[str, object]) -> list[tuple[str, str, str, str]]: @@ -151,13 +163,16 @@ def _shell_value(kind: str, value: object) -> str: return str(value) -def main() -> int: +def main( + keys: dict[str, tuple[str, str, object]] = KEYS, + choices: dict[str, set[str]] = CHOICES, +) -> int: try: - cfg = load_sweep_config(os.environ.get("LBM_SWEEP_CONFIG", "")) + cfg = load_sweep_config(os.environ.get("LBM_SWEEP_CONFIG", ""), keys, choices) except SweepConfigError as e: sys.stderr.write(f"error: config: {e}\n") return 1 - for key, (var, kind, _) in KEYS.items(): + for key, (var, kind, _) in keys.items(): print(f"{var}={_shell_value(kind, cfg[key])}") return 0 diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-disg-vs-dense/disg-vs-dense-speedup.png b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-disg-vs-dense/disg-vs-dense-speedup.png new file mode 100644 index 00000000..ec3b0ef0 Binary files /dev/null and b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-disg-vs-dense/disg-vs-dense-speedup.png differ diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-disg-vs-dense/disg-vs-dense-summary.csv b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-disg-vs-dense/disg-vs-dense-summary.csv new file mode 100644 index 00000000..ba18c142 --- /dev/null +++ b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-disg-vs-dense/disg-vs-dense-summary.csv @@ -0,0 +1,19 @@ +decomp,n,g,dense_mlups,disg_mlups,speedup +brick,256,8,35617.407,24248.140,0.6808 +brick,384,8,44884.536,28672.174,0.6388 +brick,512,8,48408.605,31273.917,0.6460 +pencil,256,4,30206.431,17458.764,0.5780 +pencil,256,8,50375.249,32472.333,0.6446 +pencil,384,4,32029.573,19010.249,0.5935 +pencil,384,8,61085.733,36929.974,0.6046 +pencil,512,4,32614.456,19725.893,0.6048 +pencil,512,8,63194.988,38747.500,0.6131 +slab,256,2,15697.892,9845.159,0.6272 +slab,256,4,30201.093,19039.444,0.6304 +slab,256,8,56927.116,34590.962,0.6076 +slab,384,2,16354.072,10371.083,0.6342 +slab,384,4,31878.404,20620.534,0.6468 +slab,384,8,61392.481,39422.238,0.6421 +slab,512,2,16642.525,10595.283,0.6366 +slab,512,4,32548.910,21353.558,0.6560 +slab,512,8,63975.557,41819.560,0.6537 diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-disg-vs-dense/json/failed.txt b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-disg-vs-dense/json/failed.txt new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-disg-vs-dense/lbm-disg-vs-dense-sweep.yml b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-disg-vs-dense/lbm-disg-vs-dense-sweep.yml new file mode 100644 index 00000000..55722d52 --- /dev/null +++ b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-disg-vs-dense/lbm-disg-vs-dense-sweep.yml @@ -0,0 +1,25 @@ +# Comparison sweep: DenseDistributed vs DenseDisgDistributed. +# Same matrix as lbm-dist-sweep, both grids, hp-halo on (the fair OCC baseline). +configs: [q19:bgk] +grids: [dense_distributed, disg_distributed] +sizes: [256, 384, 512] +decompositions: [slab, pencil, brick] +gpus_slab: [2, 4, 8] +gpus_pencil: [4, 8] +gpus_brick: [8] +transports: [mpi] +hp_halo: ["on"] +overlap: standard +warmup: 400 +iters_per_rep: 400 +reps: 5 +sm_arch: "80" +image: carbon-cuda-nccl-pinned:local +build_dir: build-dist +prefix: lbm-disg-vs-dense +skip_build: true +force: true +run_timeout: 1800 +reference_dir: benchmarks/lbm_lid_driven_cavity/data/lbm-dgx-sweep/json +reference_prefix: lbm-dgx-sweep +reference_label: dense-intra diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/json/failed.txt b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/json/failed.txt new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-eff-vs-gpus-n256.png b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-eff-vs-gpus-n256.png new file mode 100644 index 00000000..da080b34 Binary files /dev/null and b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-eff-vs-gpus-n256.png differ diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-eff-vs-gpus-n320.png b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-eff-vs-gpus-n320.png new file mode 100644 index 00000000..e16644a8 Binary files /dev/null and b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-eff-vs-gpus-n320.png differ diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-eff-vs-gpus-n384.png b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-eff-vs-gpus-n384.png new file mode 100644 index 00000000..27d00404 Binary files /dev/null and b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-eff-vs-gpus-n384.png differ diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-eff-vs-gpus-n448.png b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-eff-vs-gpus-n448.png new file mode 100644 index 00000000..7a6419a1 Binary files /dev/null and b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-eff-vs-gpus-n448.png differ diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-eff-vs-gpus-n512.png b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-eff-vs-gpus-n512.png new file mode 100644 index 00000000..35fa4677 Binary files /dev/null and b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-eff-vs-gpus-n512.png differ diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-eff-vs-n-g8.png b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-eff-vs-n-g8.png new file mode 100644 index 00000000..d3b394e7 Binary files /dev/null and b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-eff-vs-n-g8.png differ diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-hp-speedup-mpi.png b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-hp-speedup-mpi.png new file mode 100644 index 00000000..03db5beb Binary files /dev/null and b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-hp-speedup-mpi.png differ diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-mlups-vs-gpus-n256.png b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-mlups-vs-gpus-n256.png new file mode 100644 index 00000000..a47b6c5f Binary files /dev/null and b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-mlups-vs-gpus-n256.png differ diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-mlups-vs-gpus-n320.png b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-mlups-vs-gpus-n320.png new file mode 100644 index 00000000..e8541ab4 Binary files /dev/null and b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-mlups-vs-gpus-n320.png differ diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-mlups-vs-gpus-n384.png b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-mlups-vs-gpus-n384.png new file mode 100644 index 00000000..c4b30249 Binary files /dev/null and b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-mlups-vs-gpus-n384.png differ diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-mlups-vs-gpus-n448.png b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-mlups-vs-gpus-n448.png new file mode 100644 index 00000000..76b4cd2a Binary files /dev/null and b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-mlups-vs-gpus-n448.png differ diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-mlups-vs-gpus-n512.png b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-mlups-vs-gpus-n512.png new file mode 100644 index 00000000..bc09292b Binary files /dev/null and b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep-q19-bgk-fp32-mlups-vs-gpus-n512.png differ diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep.yml b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep.yml new file mode 100644 index 00000000..eb9f9fa9 --- /dev/null +++ b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/lbm-dist-sweep.yml @@ -0,0 +1,86 @@ +# Sweep configuration for lbm-dist-sweep-run.sh and its plotter. +# +# ./benchmarks/lbm_lid_driven_cavity_distributed/scripts/lbm-dist-sweep-run.sh \ +# benchmarks/lbm_lid_driven_cavity_distributed/scripts/lbm-dist-sweep.yml +# python3 benchmarks/lbm_lid_driven_cavity_distributed/scripts/plotting/plot_dist_scaling.py \ +# --config benchmarks/lbm_lid_driven_cavity_distributed/scripts/lbm-dist-sweep.yml +# +# Every run uses --grid dense_distributed under mpiexec, one rank per GPU. +# Every key is optional; omitted keys use the script defaults, and an env var +# of the same name in upper case (CONFIGS, SIZES, GPUS_LIST, ...) overrides +# the file. + +# Lattice:collision pairs, each its own series (populations are always fp32): +# q19:bgk D3Q19 + BGK +# q27:bgk D3Q27 + BGK +# q27:kbc D3Q27 + KBC (KBC is only implemented for D3Q27) +configs: [q19:bgk] + +# Domain edge lengths N: a list, or an inclusive {start, stop, step} range. +sizes: {start: 256, stop: 512, step: 64} + +# Process decompositions, one plot panel each: +# slab split z +# pencil split y and z +# brick split x, y and z +decompositions: [slab, pencil, brick] + +# GPU counts (= MPI ranks, all >= 2) of each decomposition. ProcessGrid +# factorises the rank count, so pencil only differs from a slab at 4 (1x2x2) +# and 8 (1x2x4), and brick only at 8 (2x2x2); the plots print the process +# grid under each GPU count. +gpus_slab: {start: 2, stop: 8, step: 1} +gpus_pencil: [4, 8] +gpus_brick: [8] + +# 1-GPU efficiency baseline: no 1-GPU run is done here. For size N the +# plotter reads +# /---fp32--n-g1.json +# (reference_dir relative to the carbon repo root), by default the Dense +# Peeraccess run of the single-process DGX sweep. +reference_dir: benchmarks/lbm_lid_driven_cavity/data/lbm-dgx-sweep/json +reference_prefix: lbm-dgx-sweep +reference_label: dense-intra + +# Halo transports, one curve each: +# mpi NCCL (default) +# mpip2p MPI point-to-point (CARBON_DIST_TRANSPORT=mpi) +transports: [mpi] + +# Halo stream priority, one curve each: off = normal priority, on = --hp-halo +# (Skeleton halo_stream_priority = High). Only meaningful with overlap != none. +hp_halo: ["off", "on"] + +# Skeleton OCC mode of every run: none, standard, extended, twoway-extended. +overlap: standard + +# Timing: warmup untimed solver steps, then reps repetitions of +# iters_per_rep solver steps, each closed by a GPU drain and an MPI barrier. +warmup: 400 +iters_per_rep: 1000 +reps: 5 + +# CUDA compute capability the binary is compiled for +# (CMAKE_CUDA_ARCHITECTURES). auto detects it from the GPUs via nvidia-smi. +# Changing it needs a rebuild, so keep skip_build: false for that run. +sm_arch: auto + +# Docker image that builds the binary and does every run. Its NCCL must match +# the host driver: carbon-cuda:local ships an NCCL that needs driver >= 580, +# carbon-cuda-nccl-pinned:local pins NCCL 2.27.7 (CUDA 12.2). +image: carbon-cuda-nccl-pinned:local + +# CUDA+MPI build tree, relative to the carbon repo root. Kept apart from the +# single-process sweep's build-mpi/, which is configured in another image. +build_dir: build-dist + +# Report prefix and output folder: +# benchmarks/lbm_lid_driven_cavity_distributed/data//json/ +prefix: lbm-dist-sweep + +# true reuses the existing build tree; false (re)builds it first. +skip_build: false +# true redoes runs whose JSON already exists; false skips them (resume). +force: true +# Per-run timeout in seconds; a hung run is logged in failed.txt. +run_timeout: 1800 diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/reproduce.sh b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/reproduce.sh new file mode 100755 index 00000000..0f13abfe --- /dev/null +++ b/benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/reproduce.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# +# benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/reproduce.sh +# +# Reproduces this result set: runs the sweep described by lbm-dist-sweep.yml +# (the frozen copy next to this script) and renders every plot in this folder. +# +# D3Q19 + BGK, fp32, --grid dense_distributed, --overlap standard; +# N = 256..512 step 64; one MPI rank per GPU; slab on 2..8 GPUs, pencil on +# 4 and 8, brick on 8; NCCL halos with --hp-halo off and on; +# 400 warmup steps, then 5 timed repetitions of 1000 solver steps. +# Efficiency is relative to the 1-GPU Dense Peeraccess runs of +# benchmarks/lbm_lid_driven_cavity/data/lbm-dgx-sweep/json (no 1-GPU run here). +# +# Original run: 8x A100-SXM4-40GB (NVLink), driver 535.161.08, carbon commit +# 0d504c5, image carbon-cuda-nccl-pinned:local (NCCL 2.27.7, CUDA 12.2). +# +# Usage: +# ./benchmarks/lbm_lid_driven_cavity_distributed/data/lbm-dist-sweep/reproduce.sh [--plot-only] +# +# (no flag) build build-dist/ in Docker, redo every run (force: true +# overwrites json/), then plot; takes about an hour on 8 GPUs +# --plot-only only re-render the PNGs from the reports already in json/ +# +# Needs docker with the NVIDIA container toolkit, the image named in the yml, +# and python3 with PyYAML and matplotlib. Run it from tmux (or similar) because +# the sweep outlives an SSH session. + +set -euo pipefail + +plot_only=0 +case "${1:-}" in + "") ;; + --plot-only) plot_only=1 ;; + *) + echo "usage: $0 [--plot-only]" >&2 + exit 2 + ;; +esac + +here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +repo_root="$(cd "${here}/../../../.." && pwd)" +scripts="${repo_root}/benchmarks/lbm_lid_driven_cavity_distributed/scripts" +config="${here}/lbm-dist-sweep.yml" + +if [[ "${plot_only}" -eq 0 ]]; then + "${scripts}/lbm-dist-sweep-run.sh" "${config}" +fi + +python3 "${scripts}/plotting/plot_dist_scaling.py" --config "${config}" --output-dir "${here}" +echo "==> plots written to ${here}" diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/lbm_lid_driven_cavity_distributed.cu b/benchmarks/lbm_lid_driven_cavity_distributed/lbm_lid_driven_cavity_distributed.cu index 4486cad6..e57d6a14 100644 --- a/benchmarks/lbm_lid_driven_cavity_distributed/lbm_lid_driven_cavity_distributed.cu +++ b/benchmarks/lbm_lid_driven_cavity_distributed/lbm_lid_driven_cavity_distributed.cu @@ -35,6 +35,7 @@ #include #include #include +#include // CARBON_BACKEND_NAME is "cuda" or "sycl" depending on which backend the // library was configured with. Stamped into the JSON report's system block // so a sweep that drives both backends from the same scripts/ directory @@ -55,6 +56,7 @@ #include +#include #include #include #include @@ -108,6 +110,7 @@ struct Options { int64_t n = 128; int64_t iters = 1000; int64_t warmup = 100; + int64_t reps = 1; double re = 100.0; double ulb = 0.05; bool ulb_set = false; @@ -119,10 +122,11 @@ struct Options { // Cartesian z-slabs); "disg" is carbon::DenseDisg (the disaggregated, // five-region-per-slab lattice-Boltzmann layout); "dense_distributed" is // carbon::DenseDistributed, which honours --decomposition and exchanges - // halos along all decomposed axes. All three run the identical hot kernel - // (the pull-stream + half-way bounce-back + symmetric BGK body) — the only + // halos along all decomposed axes; "disg_distributed" is + // carbon::DenseDisgDistributed (disaggregated layout on a ProcessGrid; + // slab, pencil and brick). All run the identical hot kernel — the only // differences are the per-slab storage layout and the auto-inserted halo - // family (Halo / HaloDisg / HaloDistributed). + // family (Halo / HaloDisg / HaloDistributed / HaloDisgDistributed). std::string grid = "dense"; std::string decomposition = "slab"; std::string report_path = ""; @@ -146,6 +150,7 @@ struct Options { bool hp_halo = false; std::string export_dot_path = ""; std::string export_dot_png_path = ""; + std::string export_dot_streams_path = ""; // Opt in to carbon::Skeleton CUDA-graph capture + replay of each ping-pong // skeleton. Engaged only for single-GPU / single-stream schedules (the // OverlapMode::None single-GPU case); a no-op fallback otherwise. @@ -175,6 +180,10 @@ build_cli(Options& opts) -> clipp::group { "Total iterations including warmup (default 1000)", (option("--warmup") & integer("warmup", opts.warmup)) % "Warmup iterations excluded from timing (default 100)", + (option("--reps") & integer("reps", opts.reps)) % + "Split the timed iterations into N equal repetitions, each closed by a GPU drain " + "and (under MPI) a barrier, and report per-repetition MLUPS plus " + "mean/min/max/stddev (default 1). Timed iterations must divide by N.", (option("--re") & number("re", opts.re)) % "Reynolds number (default 1e2)", (option("--ulb") & number("ulb", opts.ulb).set(opts.ulb_set)) % "Override lid velocity in lattice units (default 0.05)", @@ -182,14 +191,16 @@ build_cli(Options& opts) -> clipp::group { "Lattice stencil: q19 (D3Q19, default) or q27 (D3Q27)", (option("--collision") & value("bgk|kbc", opts.collision)) % "Collision model: bgk (default) or kbc (entropic; D3Q27 only)", - (option("--grid") & value("dense|disg|dense_distributed", opts.grid)) % + (option("--grid") & value("dense|disg|dense_distributed|disg_distributed", opts.grid)) % "Grid family: dense (carbon::Dense, default), disg (carbon::DenseDisg, " - "the disaggregated five-region LBM layout), or dense_distributed " - "(carbon::DenseDistributed, honours --decomposition). Same hot kernel on all.", + "the disaggregated five-region LBM layout), dense_distributed " + "(carbon::DenseDistributed, honours --decomposition), or disg_distributed " + "(carbon::DenseDisgDistributed, disaggregated + ProcessGrid). " + "Same hot kernel on all.", (option("--decomposition") & value("slab|pencil|brick", opts.decomposition)) % - "Process decomposition for --grid dense_distributed (default: slab). " - "slab splits z; pencil splits y and z; brick splits all three axes. " - "Auto-factorized across ranks; ignored for dense/disg, which are slab-only.", + "Process decomposition for --grid dense_distributed|disg_distributed " + "(default: slab). slab splits z; pencil splits y and z; brick splits all three " + "axes. Auto-factorized across ranks; ignored for dense/disg, which are slab-only.", (option("-gpus", "--gpus") & integer("n", opts.n_gpus)) % "Use the first N visible CUDA devices (-1 = all visible; default -1). " "Combine with CUDA_VISIBLE_DEVICES to pick physical GPUs.", @@ -217,11 +228,13 @@ build_cli(Options& opts) -> clipp::group { "Boundary kernels get SMs before Internal's pending blocks. Only meaningful with " "--overlap != none.", (option("--export-dot") & value("path", opts.export_dot_path)) % - "Write the compiled Skeleton schedule graph (GraphViz .dot) for the " - "AB ping-pong skeleton to PATH after compile.", + "Write the compiled Skeleton launch-matrix schedule (GraphViz .dot) for " + "the AB ping-pong skeleton to PATH after compile.", (option("--export-dot-png") & value("path", opts.export_dot_png_path)) % - "Render the schedule graph to PNG via GraphViz (requires dot on PATH). " - "Also writes a sibling .dot file.", + "Render the launch-matrix schedule to PNG via GraphViz (requires dot on " + "PATH). Also writes a sibling .dot file.", + (option("--export-dot-streams") & value("path", opts.export_dot_streams_path)) % + "Write the stream-cluster schedule graph (legacy export_dot format) to PATH.", option("--cuda-graph").set(opts.cuda_graph) % "Capture + replay each ping-pong skeleton as a CUDA graph (single-GPU / " "single-stream only; transparently falls back to eager launch otherwise). " @@ -257,6 +270,12 @@ parse_cli(int argc, << " for iters=" << opts.iters << ")\n"; return false; } + const int64_t timed_iters = opts.no_warmup_skip ? opts.iters : opts.iters - opts.warmup; + if (opts.reps < 1 || timed_iters % opts.reps != 0) { + std::cerr << "lbm_lid_driven_cavity: --reps must be >= 1 and divide the " << timed_iters + << " timed iterations (got " << opts.reps << ")\n"; + return false; + } if (opts.lattice != "q19" && opts.lattice != "q27") { std::cerr << "lbm_lid_driven_cavity: --lattice must be q19 or q27 (got '" << opts.lattice << "')\n"; @@ -272,8 +291,10 @@ parse_cli(int argc, "(KBC's moment basis is defined for D3Q27 only)\n"; return false; } - if (opts.grid != "dense" && opts.grid != "disg" && opts.grid != "dense_distributed") { - std::cerr << "lbm_lid_driven_cavity: --grid must be dense, disg, or dense_distributed (got '" + if (opts.grid != "dense" && opts.grid != "disg" && opts.grid != "dense_distributed" && + opts.grid != "disg_distributed") { + std::cerr << "lbm_lid_driven_cavity: --grid must be dense, disg, dense_distributed, or " + "disg_distributed (got '" << opts.grid << "')\n"; return false; } @@ -283,9 +304,11 @@ parse_cli(int argc, << opts.decomposition << "')\n"; return false; } - if (opts.grid != "dense_distributed" && opts.decomposition != "slab") { + if (opts.grid != "dense_distributed" && opts.grid != "disg_distributed" && + opts.decomposition != "slab") { std::cerr << "lbm_lid_driven_cavity: --decomposition " << opts.decomposition - << " requires --grid dense_distributed (dense/disg are slab-only)\n"; + << " requires --grid dense_distributed or disg_distributed " + "(dense/disg are slab-only)\n"; return false; } if (opts.overlap != "none" && opts.overlap != "standard" && opts.overlap != "extended" && @@ -495,9 +518,10 @@ run_benchmark(const Options& opts, const std::string& collision_name, carbon::DecompositionMode dec_mode) -> int { static_assert(std::is_same_v || std::is_same_v || - std::is_same_v, - "LBM benchmark supports carbon::Dense, carbon::DenseDisg, and " - "carbon::DenseDistributed only."); + std::is_same_v || + std::is_same_v, + "LBM benchmark supports carbon::Dense, carbon::DenseDisg, " + "carbon::DenseDistributed, and carbon::DenseDisgDistributed only."); #ifdef CARBON_HAVE_MPI_NCCL // Auto-detect MPI launches: the `Distributed` ctor invokes `MPI_Init` (a // no-op when already initialised) and bootstraps an `ncclComm_t` over every @@ -527,7 +551,8 @@ run_benchmark(const Options& opts, const carbon::int64_3d global{opts.n, opts.n, opts.n}; std::optional pg; - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v || + std::is_same_v) { const int grid_world = use_mpi ? world_size : local_gpu_count; pg.emplace(carbon::ProcessGrid::make(grid_world, dec_mode)); if (world_rank == 0) { @@ -538,15 +563,17 @@ run_benchmark(const Options& opts, } // Construct the selected grid family. Dense/DenseDisg give a radius-1 z-halo - // (D3Q19 / D3Q27 have |c|_inf == 1); DenseDistributed derives per-axis halos - // from the same stencil and honours the requested decomposition. Only one - // branch is instantiated per Grid, so the IIFE's return type is the concrete - // grid type for this instantiation. + // (D3Q19 / D3Q27 have |c|_inf == 1); DenseDistributed / DenseDisgDistributed + // derive per-axis halos from the same stencil and honour the requested + // decomposition. Only one branch is instantiated per Grid, so the IIFE's + // return type is the concrete grid type for this instantiation. Grid grid = [&]() -> Grid { if constexpr (std::is_same_v) { return carbon::Dense(sys, global, stencil); } else if constexpr (std::is_same_v) { return carbon::DenseDisg(sys, global, /*halo_z=*/1); + } else if constexpr (std::is_same_v) { + return carbon::DenseDisgDistributed(sys, global, *pg, stencil); } else { return carbon::DenseDistributed(sys, global, *pg, stencil); } @@ -664,41 +691,78 @@ run_benchmark(const Options& opts, opts.overlap, opts.hp_halo); if (!opts.export_dot_path.empty()) { - if (!sk_ab.export_dot_file(opts.export_dot_path, "lbm_sk_ab")) { + if (!sk_ab.export_launch_matrix_dot_file(opts.export_dot_path, "lbm_sk_ab")) { CARBON_LOG_ERROR("lbm_lid_driven_cavity: --export-dot failed for {}", opts.export_dot_path); return EXIT_FAILURE; } - CARBON_LOG_INFO("lbm_lid_driven_cavity: wrote schedule DOT to {}", opts.export_dot_path); + CARBON_LOG_INFO("lbm_lid_driven_cavity: wrote launch-matrix DOT to {}", opts.export_dot_path); } if (!opts.export_dot_png_path.empty()) { - if (!sk_ab.export_dot_png(opts.export_dot_png_path, "lbm_sk_ab")) { + if (!sk_ab.export_launch_matrix_dot_png(opts.export_dot_png_path, "lbm_sk_ab")) { CARBON_LOG_ERROR( "lbm_lid_driven_cavity: --export-dot-png failed for {} (is graphviz dot on PATH?)", opts.export_dot_png_path); return EXIT_FAILURE; } - CARBON_LOG_INFO("lbm_lid_driven_cavity: wrote schedule PNG to {}", opts.export_dot_png_path); + CARBON_LOG_INFO("lbm_lid_driven_cavity: wrote launch-matrix PNG to {}", opts.export_dot_png_path); + } + if (!opts.export_dot_streams_path.empty()) { + if (!sk_ab.export_dot_file(opts.export_dot_streams_path, "lbm_sk_ab")) { + CARBON_LOG_ERROR("lbm_lid_driven_cavity: --export-dot-streams failed for {}", + opts.export_dot_streams_path); + return EXIT_FAILURE; + } + CARBON_LOG_INFO("lbm_lid_driven_cavity: wrote stream-cluster DOT to {}", + opts.export_dot_streams_path); } using Clock = std::chrono::steady_clock; using Seconds = std::chrono::duration; const int64_t timed_start = opts.no_warmup_skip ? 0 : opts.warmup; + const int64_t iters_per_rep = (opts.iters - timed_start) / opts.reps; + + // Every timing mark is taken after all ranks drained, so rank 0's window spans the + // slowest rank and the reported MLUPS is a true global figure. + auto drain_all_ranks = [&]() { + sk_ab.wait(); + sk_ba.wait(); +#ifdef CARBON_HAVE_MPI_NCCL + if (use_mpi) { + distributed->barrier(); + } +#endif + }; Clock::time_point timing_started{}; + Clock::time_point rep_started{}; Clock::time_point overall_started = Clock::now(); bool timing_running = false; + std::vector rep_seconds; + rep_seconds.reserve(static_cast(opts.reps)); for (int64_t it = 0; it < opts.iters; ++it) { + if (it > timed_start && (it - timed_start) % iters_per_rep == 0) { + try { + drain_all_ranks(); + } catch (const std::exception& e) { + CARBON_LOG_ERROR("lbm_lid_driven_cavity: repetition drain failed at iter {}: {}", it, + e.what()); + return EXIT_FAILURE; + } + const auto now = Clock::now(); + rep_seconds.push_back(Seconds(now - rep_started).count()); + rep_started = now; + } if (it == timed_start) { try { - sk_ab.wait(); - sk_ba.wait(); + drain_all_ranks(); } catch (const std::exception& e) { CARBON_LOG_ERROR("lbm_lid_driven_cavity: pre-timing drain failed at iter {}: {}", it, e.what()); return EXIT_FAILURE; } timing_started = Clock::now(); + rep_started = timing_started; timing_running = true; if (!opts.no_warmup_skip) { CARBON_LOG_INFO("lbm_lid_driven_cavity: warmup complete ({} iters), starting timing window", @@ -733,8 +797,7 @@ run_benchmark(const Options& opts, } try { - sk_ab.wait(); - sk_ba.wait(); + drain_all_ranks(); } catch (const std::exception& e) { CARBON_LOG_ERROR("lbm_lid_driven_cavity: final sync failed: {}", e.what()); return EXIT_FAILURE; @@ -754,10 +817,32 @@ run_benchmark(const Options& opts, const double mlups = (cells_per_iter * static_cast(timed_iters)) / (1.0e6 * timing_seconds); const double overall_seconds = Seconds(timing_ended - overall_started).count(); + rep_seconds.push_back(Seconds(timing_ended - rep_started).count()); - // Under MPI all ranks measure the same `cells_per_iter` (= global N^3) and - // run lock-step (halo exchanges synchronise them), so each rank's `mlups` - // is the global throughput up to small per-rank timing noise. Print only on + std::vector rep_mlups; + rep_mlups.reserve(rep_seconds.size()); + for (const double s : rep_seconds) { + rep_mlups.push_back((cells_per_iter * static_cast(iters_per_rep)) / (1.0e6 * s)); + } + double rep_mlups_mean = 0.0; + double rep_mlups_min = rep_mlups.front(); + double rep_mlups_max = rep_mlups.front(); + for (const double m : rep_mlups) { + rep_mlups_mean += m; + rep_mlups_min = std::min(rep_mlups_min, m); + rep_mlups_max = std::max(rep_mlups_max, m); + } + rep_mlups_mean /= static_cast(rep_mlups.size()); + double rep_mlups_var = 0.0; + for (const double m : rep_mlups) { + rep_mlups_var += (m - rep_mlups_mean) * (m - rep_mlups_mean); + } + const double rep_mlups_stddev = + rep_mlups.size() > 1 ? std::sqrt(rep_mlups_var / static_cast(rep_mlups.size() - 1)) + : 0.0; + + // Under MPI all ranks measure the same `cells_per_iter` (= global N^3) between the + // same barriers, so each rank's `mlups` is the global throughput. Print only on // rank 0 to keep the scrape-friendly headline single-shot. `total_gpu_count` // is the world size under MPI (one rank per GPU) and the local GPU count // otherwise; `local_gpu_count` stays useful on multi-GPU single-process runs. @@ -774,6 +859,12 @@ run_benchmark(const Options& opts, << " ranks=" << world_size << " decomposition=" << decomposition_mode_name(dec_mode) << " lattice=" << lattice_name << " collision=" << collision_name << (use_mpi ? " transport=mpi+nccl" : "") << ")" << '\n'; + if (opts.reps > 1) { + CARBON_LOG_INFO( + "lbm_lid_driven_cavity: {} repetitions x {} iters => MLUPS mean={:.2f} min={:.2f} " + "max={:.2f} stddev={:.2f}", + opts.reps, iters_per_rep, rep_mlups_mean, rep_mlups_min, rep_mlups_max, rep_mlups_stddev); + } } // Optional grid-family parity checksum: Sum-reduce the whole final population @@ -924,10 +1015,17 @@ run_benchmark(const Options& opts, out << " \"n\": " << opts.n << ",\n"; out << " \"iters\": " << opts.iters << ",\n"; out << " \"warmup\": " << opts.warmup << ",\n"; + out << " \"reps\": " << opts.reps << ",\n"; out << " \"lattice\": \"" << json_escape(lattice_name) << "\",\n"; out << " \"collision\": \"" << json_escape(collision_name) << "\",\n"; out << " \"grid\": \"" << json_escape(opts.grid) << "\",\n"; out << " \"decomposition\": \"" << decomposition_mode_name(dec_mode) << "\",\n"; + if (pg) { + const carbon::int32_3d dims = pg->dims(); + out << " \"process_grid\": [" << dims.x << ", " << dims.y << ", " << dims.z << "],\n"; + } else { + out << " \"process_grid\": null,\n"; + } out << " \"q\": " << Lattice::Q << ",\n"; out << " \"re\": " << opts.re << ",\n"; out << " \"ulb\": " << ulb << ",\n"; @@ -980,7 +1078,25 @@ run_benchmark(const Options& opts, out << " \"cells_per_iter\": " << static_cast(cells_per_iter) << ",\n"; out << " \"mlups\": " << mlups << ",\n"; out << " \"mlups_per_gpu\": " << (mlups / static_cast(total_gpu_count)) << ",\n"; - out << " \"effective_bandwidth_gb_s\": " << effective_bandwidth_gb_s << "\n"; + out << " \"effective_bandwidth_gb_s\": " << effective_bandwidth_gb_s << ",\n"; + out << " \"repetitions\": {\n"; + out << " \"count\": " << opts.reps << ",\n"; + out << " \"iters_per_rep\": " << iters_per_rep << ",\n"; + out << " \"seconds\": ["; + for (size_t i = 0; i < rep_seconds.size(); ++i) { + out << (i == 0 ? "" : ", ") << rep_seconds[i]; + } + out << "],\n"; + out << " \"mlups\": ["; + for (size_t i = 0; i < rep_mlups.size(); ++i) { + out << (i == 0 ? "" : ", ") << rep_mlups[i]; + } + out << "],\n"; + out << " \"mlups_mean\": " << rep_mlups_mean << ",\n"; + out << " \"mlups_min\": " << rep_mlups_min << ",\n"; + out << " \"mlups_max\": " << rep_mlups_max << ",\n"; + out << " \"mlups_stddev\": " << rep_mlups_stddev << "\n"; + out << " }\n"; out << " }\n"; out << "}\n"; out.close(); @@ -1049,5 +1165,8 @@ main(int argc, if (opts.grid == "dense_distributed") { return dispatch_grid(std::type_identity{}); } + if (opts.grid == "disg_distributed") { + return dispatch_grid(std::type_identity{}); + } return dispatch_grid(std::type_identity{}); } diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/scripts/lbm-disg-vs-dense-sweep.yml b/benchmarks/lbm_lid_driven_cavity_distributed/scripts/lbm-disg-vs-dense-sweep.yml new file mode 100644 index 00000000..55722d52 --- /dev/null +++ b/benchmarks/lbm_lid_driven_cavity_distributed/scripts/lbm-disg-vs-dense-sweep.yml @@ -0,0 +1,25 @@ +# Comparison sweep: DenseDistributed vs DenseDisgDistributed. +# Same matrix as lbm-dist-sweep, both grids, hp-halo on (the fair OCC baseline). +configs: [q19:bgk] +grids: [dense_distributed, disg_distributed] +sizes: [256, 384, 512] +decompositions: [slab, pencil, brick] +gpus_slab: [2, 4, 8] +gpus_pencil: [4, 8] +gpus_brick: [8] +transports: [mpi] +hp_halo: ["on"] +overlap: standard +warmup: 400 +iters_per_rep: 400 +reps: 5 +sm_arch: "80" +image: carbon-cuda-nccl-pinned:local +build_dir: build-dist +prefix: lbm-disg-vs-dense +skip_build: true +force: true +run_timeout: 1800 +reference_dir: benchmarks/lbm_lid_driven_cavity/data/lbm-dgx-sweep/json +reference_prefix: lbm-dgx-sweep +reference_label: dense-intra diff --git a/benchmarks/lbm_lid_driven_cavity_distributed/scripts/lbm-dist-sweep-run.sh b/benchmarks/lbm_lid_driven_cavity_distributed/scripts/lbm-dist-sweep-run.sh new file mode 100755 index 00000000..16de3368 --- /dev/null +++ b/benchmarks/lbm_lid_driven_cavity_distributed/scripts/lbm-dist-sweep-run.sh @@ -0,0 +1,283 @@ +#!/usr/bin/env bash +# +# benchmarks/lbm_lid_driven_cavity_distributed/scripts/lbm-dist-sweep-run.sh +# +# Strong-scaling sweep of the distributed LBM benchmark on one multi-GPU node: +# lattice/collision x domain size x decomposition x its GPU counts x transport +# x halo priority. Builds the CUDA+MPI Release tree inside Docker and does one +# `mpiexec -n G` run per combination (one rank per GPU, --grid +# dense_distributed, --overlap OVERLAP). +# +# decompositions slab (split z), pencil (y, z), brick (x, y, z), each with its +# own GPU counts (GPUS_SLAB / GPUS_PENCIL / GPUS_BRICK, all >= 2) +# transports mpi = NCCL; mpip2p = MPI point-to-point (CARBON_DIST_TRANSPORT=mpi) +# hp_halo off = normal halo stream; on = --hp-halo (high-priority halo stream) +# +# No 1-GPU run is done: the efficiency baseline of size N is the 1-GPU report +# of another sweep, by default the Dense Peeraccess run of the single-process +# DGX sweep, +# /---fp32--n-g1.json +# The script warns before the runs if one of them is missing. +# +# Timing: after WARMUP solver steps, each run times REPS repetitions of +# ITERS_PER_REP solver steps (binary --reps); every repetition ends with a GPU +# drain and an MPI barrier, so rank 0's clock covers the slowest rank. +# results.mlups is the MLUPS over all timed steps (what the plotter reads); +# results.repetitions holds the per-repetition MLUPS; config.process_grid the +# rank grid ProcessGrid actually chose. +# +# Reports are named +# ---fp32---hp-n-g.json +# in benchmarks/lbm_lid_driven_cavity_distributed/data//json/. A failing +# or hung run (RUN_TIMEOUT) is logged to failed.txt there and the sweep moves on. +# +# Usage: +# ./benchmarks/lbm_lid_driven_cavity_distributed/scripts/lbm-dist-sweep-run.sh [CONFIG.yml] +# +# CONFIG.yml (see lbm-dist-sweep.yml) sets the knobs below by their lowercase +# name. List-valued keys take a list or a space-separated string; sizes and +# gpus_* also accept {start, stop, step} (inclusive). Precedence: env var > +# CONFIG.yml > default. +# +# Knobs (env vars, all optional): +# CONFIGS="q19:bgk" lattice:collision pairs (q19:bgk q27:bgk q27:kbc) +# SIZES="256 320 384 448 512" domain edge lengths +# DECOMPOSITIONS="slab pencil brick" process decompositions +# GPUS_SLAB="2 3 4 5 6 7 8" GPU counts (= MPI ranks) of the slab runs +# GPUS_PENCIL="4 8" ... of the pencil runs +# GPUS_BRICK="8" ... of the brick runs +# REFERENCE_DIR=benchmarks/lbm_lid_driven_cavity/data/lbm-dgx-sweep/json +# 1-GPU baseline reports, relative to the repo root +# REFERENCE_PREFIX=lbm-dgx-sweep their report prefix +# REFERENCE_LABEL=dense-intra their grid-transport label +# TRANSPORTS="mpi" mpi (NCCL) and/or mpip2p +# HP_HALO="off on" halo stream priority variants +# OVERLAP=standard Skeleton OCC mode of every run +# WARMUP=400 untimed solver steps before the first repetition +# ITERS_PER_REP=400 solver steps in each timed repetition +# REPS=4 timed repetitions per run +# SM_ARCH=auto CUDA arch (A100=80, H100=90); auto = detect +# IMAGE=carbon-cuda-nccl-pinned:local image for the build and every run +# BUILD_DIR=build-dist CUDA+MPI build tree under the repo root +# PREFIX=lbm-dist-sweep report prefix and data// folder +# SKIP_BUILD=0 set 1 to reuse the existing build tree +# FORCE=0 set 1 to redo runs whose JSON exists +# RUN_TIMEOUT=1800 per-run timeout in seconds +# DRY_RUN=0 set 1 to print the resolved config and exit + +set -euo pipefail + +if [[ $# -gt 1 ]]; then + echo "usage: $0 [CONFIG.yml]" >&2 + exit 2 +fi +config_path="" +if [[ $# -eq 1 ]]; then + if [[ ! -f "$1" ]]; then + echo "error: config file not found: $1" >&2 + exit 2 + fi + config_path="$(realpath "$1")" +fi + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)" +cd "${repo_root}" + +# Every knob as a validated VAR=value line, defaults filled in, from the parser +# the plotter shares (lbm_dist_sweep_config.py); an empty config yields the defaults. +config_text="" +if [[ -n "${config_path}" ]]; then + config_text="$(<"${config_path}")" +fi +config_vars="$(LBM_SWEEP_CONFIG="${config_text}" \ + python3 "${repo_root}/benchmarks/lbm_lid_driven_cavity_distributed/scripts/lbm_dist_sweep_config.py")" +while IFS='=' read -r key value; do + [[ -z "${key}" ]] && continue + if [[ -z "${!key+x}" ]]; then + export "${key}=${value}" + else + export "${key}" + echo "==> ${key} taken from the environment" + fi +done <<< "${config_vars}" + +check_words() { + local var="$1" allowed="$2" w + for w in ${!var}; do + if [[ " ${allowed} " != *" ${w} "* ]]; then + echo "error: ${var} entry '${w}' is not one of: ${allowed}" >&2 + exit 1 + fi + done +} +check_words CONFIGS "q19:bgk q27:bgk q27:kbc" +check_words GRIDS "dense_distributed disg_distributed" +check_words DECOMPOSITIONS "slab pencil brick" +check_words TRANSPORTS "mpi mpip2p" +check_words HP_HALO "off on" +check_words OVERLAP "none standard extended twoway-extended" +for v in SIZES GPUS_SLAB GPUS_PENCIL GPUS_BRICK WARMUP ITERS_PER_REP REPS RUN_TIMEOUT; do + if [[ ! "${!v}" =~ ^[0-9]+( [0-9]+)*$ ]]; then + echo "error: ${v} must be non-negative integers (got '${!v}')" >&2 + exit 1 + fi +done +for v in GPUS_SLAB GPUS_PENCIL GPUS_BRICK; do + for g in ${!v}; do + if [[ "${g}" -lt 2 ]]; then + echo "error: ${v} entries must be >= 2 (the 1-GPU point is the reference run)" >&2 + exit 1 + fi + done +done +for v in BUILD_DIR PREFIX REFERENCE_PREFIX REFERENCE_LABEL; do + if [[ ! "${!v}" =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ ]]; then + echo "error: ${v} must be a single path component (got '${!v}')" >&2 + exit 1 + fi +done +if [[ ! "${REFERENCE_DIR}" =~ ^[A-Za-z0-9._/-]+$ || "${REFERENCE_DIR}" == /* || + "/${REFERENCE_DIR}/" == */../* ]]; then + echo "error: REFERENCE_DIR must be a path inside the repo (got '${REFERENCE_DIR}')" >&2 + exit 1 +fi +if [[ "${SM_ARCH}" == "auto" ]]; then + SM_ARCH="$(nvidia-smi --query-gpu=compute_cap --format=csv,noheader 2>/dev/null | + tr -d '. ' | sort -u | paste -sd';' -)" || true + if [[ -z "${SM_ARCH}" ]]; then + echo "error: could not detect the GPU compute capability with nvidia-smi;" \ + "set sm_arch / SM_ARCH explicitly (A100=80, H100=90)" >&2 + exit 1 + fi +fi +if [[ ! "${SM_ARCH}" =~ ^[0-9]+(\;[0-9]+)*$ ]]; then + echo "error: SM_ARCH must be auto or numbers separated by ';' (got '${SM_ARCH}')" >&2 + exit 1 +fi + +echo "==> sweep config${config_path:+ (${config_path##*/})}:" +for v in CONFIGS GRIDS SIZES DECOMPOSITIONS GPUS_SLAB GPUS_PENCIL GPUS_BRICK REFERENCE_DIR \ + REFERENCE_PREFIX REFERENCE_LABEL TRANSPORTS HP_HALO OVERLAP WARMUP ITERS_PER_REP \ + REPS SM_ARCH IMAGE BUILD_DIR PREFIX SKIP_BUILD FORCE RUN_TIMEOUT; do + printf ' %-16s %s\n' "${v}" "${!v}" +done +for cfg in ${CONFIGS}; do + for n in ${SIZES}; do + ref="${REFERENCE_DIR}/${REFERENCE_PREFIX}-${cfg%%:*}-${cfg##*:}-fp32-${REFERENCE_LABEL}-n${n}-g1.json" + if [[ ! -f "${repo_root}/${ref}" ]]; then + echo "warning: missing 1-GPU reference ${ref}; N=${n} gets no efficiency plots" >&2 + fi + done +done +if [[ "${DRY_RUN:-0}" -eq 1 ]]; then + exit 0 +fi + +rel_data="benchmarks/lbm_lid_driven_cavity_distributed/data/${PREFIX}/json" +mkdir -p "${repo_root}/${rel_data}" + +docker_run() { + local script="$1" + shift + docker run --rm --gpus all --ipc=host --shm-size=8g \ + -v "${repo_root}:/src:rw" -w /src \ + -e CONFIGS -e GRIDS -e SIZES -e DECOMPOSITIONS -e GPUS_SLAB -e GPUS_PENCIL -e GPUS_BRICK \ + -e TRANSPORTS -e HP_HALO -e OVERLAP \ + -e WARMUP -e ITERS_PER_REP -e REPS -e BUILD_DIR \ + -e FORCE -e RUN_TIMEOUT -e PREFIX -e OUT_DIR="/src/${rel_data}" \ + "${IMAGE}" /bin/bash -lc "${script}" sweep "$@" +} + +if [[ "${SKIP_BUILD}" -eq 0 ]]; then + echo "==> building ${BUILD_DIR}/ (CUDA+MPI Release, SM_${SM_ARCH}) in ${IMAGE}" + docker_run " +set -euo pipefail +export PATH=\"/root/.local/bin:\$PATH\" +cmake -S /src -B \"/src/\${BUILD_DIR}\" -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DCARBON_BACKEND=Cuda '-DCMAKE_CUDA_ARCHITECTURES=${SM_ARCH}' -DCARBON_ENABLE_MPI=ON +cmake --build \"/src/\${BUILD_DIR}\" -j\"\$(nproc)\" \ + --target carbon_benchmark_lbm_lid_driven_cavity_distributed +echo '=== Build complete ===' +" +else + echo "==> SKIP_BUILD=1: reusing ${BUILD_DIR}/" +fi + +# Runs inside the container as `bash -lc "$sweep_body" sweep`. +read -r -d '' sweep_body <<'EOF' || true +set -uo pipefail +bin="/src/${BUILD_DIR}/benchmarks/lbm_lid_driven_cavity_distributed/carbon_benchmark_lbm_lid_driven_cavity_distributed" +if [[ ! -x "${bin}" ]]; then + echo "error: ${bin} not built (run without skip_build)" >&2 + exit 1 +fi +export OMPI_ALLOW_RUN_AS_ROOT=1 OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1 +export NCCL_IB_DISABLE=1 + +mkdir -p "${OUT_DIR}" +failed_log="${OUT_DIR}/failed.txt" +: > "${failed_log}" +iters=$((WARMUP + REPS * ITERS_PER_REP)) + +# run