Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a51265a
Add dense_distributed class enabling slab, pencil and brick domain de…
giumal Nov 2, 2026
c00c0b8
Add test distributed domain
giumal Nov 2, 2026
5115d5f
Diseable barrier in halo_distributed.h file and update CHANGELOG.md
giumal Nov 2, 2026
97cad1e
Add cg benchmark
giumal Nov 2, 2026
96182e8
Add initial porting ldc benchmark to distributed
giumal Nov 2, 2026
bf3df6e
vtk output for pencil and brick
giumal Nov 3, 2026
5b0d192
Checking correctness vtk output
giumal Nov 5, 2026
76364c7
Fixing bug brick decomposition
giumal Nov 4, 2026
8e9c37e
vtk update distributed writing
giumal Nov 5, 2026
8c16cc1
Fix spdlog version and render_ray_march.inl for amd gpus
giumal Nov 5, 2026
3c47490
Add only rank=0 printing iteration time
giumal Nov 5, 2026
6ff6ee9
merge upstream version
giumal Nov 6, 2026
aace22b
Fix decomposition check
giumal Nov 6, 2026
cacaa4b
Add two-band boundary path on dense_distributed iter_extent function …
giumal Nov 6, 2026
dca087d
Add atomic_add fix for hip on amd
giumal Nov 6, 2026
d26b7cc
Fix sycl adp CPU backend
giumal Nov 7, 2026
f5ec6b2
Add MPI backend for sycl-cpu offloading
giumal Nov 7, 2026
ebbc5f5
3D reducee with docs/reduce-2d-stage1-yz-fix-report.md
giumal Nov 7, 2026
543bdd6
add split reduction in SYCL
giumal Nov 7, 2026
a950741
Distributed LBM strong-scaling sweep; benchmark --reps, barrier timin…
massimim Nov 6, 2026
c16a411
lbm-dist-sweep: no 1-GPU runs; per-decomposition GPU counts
massimim Nov 6, 2026
638549e
LBM distributed sweep results: D3Q19 + BGK fp32, N=256..512, slab 2..…
massimim Nov 6, 2026
77c2fd4
Fix cg_poisson.cu nvtx problem
giumal Nov 23, 2026
3056bd7
merge upstream version
giumal Nov 23, 2026
3a83043
Add profiles into skeleton
giumal Nov 24, 2026
be5d640
Fix typo stddev
giumal Nov 24, 2026
601c2fd
DenseDisgDistributed grid + HaloDisgDistributed; slab specialization;…
massimim Nov 24, 2026
fd53fd0
Merge hp-halo-priority
giumal Nov 24, 2026
dc1583d
cg dense_disg
giumal Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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 <hip/hip_runtime.h> pull in <cuda_runtime.h> and
Expand Down Expand Up @@ -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
Expand Down
187 changes: 163 additions & 24 deletions benchmarks/cg/cg_poisson.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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_<tag>.dot and prefix_<tag>.txt.
// --dot-matrix With --dot-out, also write launch-matrix and
// kernel-list DOT
// (prefix_<tag>_matrix.dot / _kernels.dot).
// prefix_<tag>.dot / .txt (plus _streams.dot).
// --dot-matrix With --dot-out, also write kernel-list DOT
// (prefix_<tag>_kernels.dot).
// --help Print this help and exit.
//
// Build + run
Expand All @@ -110,6 +109,7 @@
#include <carbon/dense.h>
#include <carbon/dense_disg.h>
#include <carbon/dense_distributed.h>
#include <carbon/dense_disg_distributed.h>
#include <carbon/detail/backend/select.h>
#include <carbon/devices.h>
#include <carbon/integer3d.h>
Expand Down Expand Up @@ -147,6 +147,7 @@
#include <vector>
#include <type_traits> // NEW: std::is_same_v


#if __has_include(<nvtx3/nvToolsExt.h>)
# include <nvtx3/nvToolsExt.h>
# define CARBON_HALO_NVTX_PUSH(name) ::nvtxRangePushA(name)
Expand All @@ -161,6 +162,7 @@
#endif



namespace {

using SB = carbon::detail::block::DefaultStaticBlock;
Expand Down Expand Up @@ -204,6 +206,96 @@ compute_sample_stats(std::vector<double> values) -> SampleStats {
return stats;
}

struct PhaseAccumulator {
std::string label;
std::vector<double> milliseconds;
};

using SkeletonProfile = std::vector<PhaseAccumulator>;

[[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<carbon::Skeleton::ProfilePhase>& 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;
Expand All @@ -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
Expand All @@ -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)",
Expand All @@ -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_<tag>.dot / .txt "
"(tag = init | iter_pre | iter_post)",
"Write launch-matrix DOT + launch-order files as prefix_<tag>.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; "
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -879,16 +977,27 @@ run_cg(Grid& grid,
size_t iter = 0;
bool converged = (r0_norm <= abs_target);
std::vector<double> 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();
Expand All @@ -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<double, std::milli>(iter_t1 - iter_t0).count());
}
const double r_norm = std::sqrt(std::max(0.0, delta_new_h));
Expand All @@ -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) {
Expand All @@ -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);
}
}


Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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<carbon::ProcessGrid> 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) {
Expand Down Expand Up @@ -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<carbon::DenseDisgDistributed> 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) {
Expand Down
13 changes: 7 additions & 6 deletions benchmarks/jacobi_nvidia/jacobi_nvidia.cu
Original file line number Diff line number Diff line change
Expand Up @@ -472,17 +472,18 @@ run_solver(DenseGrid& grid,
if (!dot_prefix.empty()) {
for (auto [sk, tag] : {std::pair<carbon::Skeleton*, const char*>{&sk_ab, "_ab"},
std::pair<carbon::Skeleton*, const char*>{&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",
Expand Down
Loading
Loading