Skip to content

Gpu assignment - #231

Open
The9Cat wants to merge 13 commits into
develfrom
GPUassignment
Open

The9Cat wants to merge 13 commits into
develfrom
GPUassignment

Conversation

@The9Cat

@The9Cat The9Cat commented Dec 2, 2026

Copy link
Copy Markdown
Member

Summary

The current GPU assignment assumes that EXP has exclusive access to each
GPU device on the cluster. This is not always possible on large clusters. For
example, a flexible resource assignment using Slurm could result in
EXP leaving ranks without a CUDA device when Slurm binds one GPU
per task. Each rank sees only CUDA ordinal 0, but EXP compared the
rank's node-local index against that process's visible GPU count.

This PR attempts to provide more more flexibility as follows:

  • Fix single-visible-GPU assignment so every rank selects ordinal 0.
  • Add Global.gpu_assignment with three modes:
    • auto (default) preserves the existing multi-GPU mapping and
      honors ngpus.
    • task selects gpu_ordinal from each rank's visible list
      (default 0) and warns when ranks on a node select the same GPU UUID.
    • node requires identical ordered GPU lists across ranks on a node
      and assigns by node-local rank. Set gpu_allow_sharing: true to
      allow round-robin sharing.
  • Log each rank's visible GPU count, CUDA_VISIBLE_DEVICES, selected
    ordinal, and GPU UUID.

EXP continues to use one GPU per MPI rank.

Verification

  • Confirmed the single-visible-GPU fix on the Slurm job that originally failed.
  • Compiled the changed sources and passed eight four-rank MPI checks
    with simulated CUDA devices, covering assignment, sharing, and invalid
    configurations.
  • The explicit modes still need validation on Slurm GPU hardware.
  • Would be good to test on other non-Slurm resource managers

Documentation

The devel branch for the Sphinx documentation describes this new
functionality with examples.

Martin D. Weinberg added 4 commits December 1, 2026 13:13
- freeze0: none (default; false also works), n0 (or true) or all. The
  k=0 field is captured at the first complete coefficient evaluation,
  after the MPI reduce and after multistep assembly. That's the same
  point the existing self_consistent: false freeze uses.
- n0 sets value0 to the measured k=0, n=0 coefficient and turns on
  fixed0, so after capture it is your existing fixed0 path.  all keeps
  every measured k=0 coefficient fixed.
- Measured coefficients are unchanged, so outcoef still records the
  particles' live k=0 field as a diagnostic.
- State file: SlabSL.freeze0.<component>.<runtag>.yml in outdir; you
  can override the name with freeze0file. Root writes it at
  capture. On a restart, root reads and checks it, then broadcasts it
  over MPI. If the file is missing, or its mode or nmaxz differ from
  the config, the run warns and re-measures.
- Logging: stdout logs every decision: pending, captured (with T,
  value0 and all k=0 coefficients), restored, overridden (when
  fixed0/value0 are also given) and ignored (self_consistent: false).
- GPU: no kernel change. For n0, initialize_constants() already copies
  slabFixed0 and slabValue0 to the device on every force call. For
  all, HtoD_coefs() swaps in the frozen k=0 entries before the copy.
- Tests on 2 MPI ranks using a 20k-particle slab
- GPU test TBD
- ExternalForce gains two methods: wantStepEnd(t), which by default
  never asks, and stepEnd(), which by default does nothing. The header
  comment spells out what a module may and may not do there.

- ExternalCollection::stepEnd() calls the hook for each force that
  asks. For a force that isn't CUDA-aware, it first copies particles
  to the host.

- The hook runs at every synchronized point:

  - once in begin.cc, at the initial state;

  - after the closing kick of every full step in step.cc, in both the
    multistep and non-multistep branches, just before output.
- the actual commit on every build is recorded, with no cmake re-run
  needed;
- for uncommitted changes, <hash>-dirty-<8 hex>, a fingerprint of git
  diff HEAD, so each distinct uncommitted state is identifiable.
- Untracked files and changes inside submodules don't count as
  changes. Run199k's header would have read 8c74787…-dirty-… under
  this scheme.
- Rebuild cost: the generated file is rewritten only when the git state changes
- An unchanged rebuild compiles nothing. A change recompiles only
  parse.cc and OutHDF5.cc, plus ModulesVersion.cc
- COMPILE_TIME ("Built:" in the config header) now means the time of
  the first build of that exact source state, not the time of the last
  cmake run.
Mode and behavior are as follows:
- Mode 'auto' selects ordinal 0 when one GPU is visible. Otherwise
  uses the existing node-local rank and ngpus mapping.
- Mode 'task' uses the rank’s visible GPU list. gpu_ordinal defaults
  to 0. Ranks sharing a GPU UUID on the same node trigger a warning.
- Mode 'node' requires ranks on a node to see the same ordered GPU
  list and assigns by node-local rank.
- Set gpu_allow_sharing: true to allow round-robin sharing.

Existing configurations default to 'auto' and keep the current
device-selection behavior.

The changed sources compiled, and eight four-rank MPI checks passed
with simulated CUDA devices, including duplicate UUID warnings and
rejection of mismatched node lists.
@The9Cat The9Cat added the enhancement New feature or request label Dec 2, 2026
@The9Cat
The9Cat requested a balanced review from Copilot December 2, 2026 17:14
@The9Cat The9Cat changed the title Gp uassignment Gpu assignment Dec 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active issues leave hook velocities unsynchronized, risk MPI deadlock on filesystem errors, and make point-evaluated fields inconsistent with the frozen field used for particle forces.

3 open issues
What changed in this PR

Adds flexible GPU assignment for EXP runs with scheduler-controlled device visibility, including one-GPU-per-task configurations.

Changes:

  • Adds auto, task, and node GPU assignment modes with validation and diagnostics.
  • Introduces synchronized external-force hooks and persistent SlabSL frozen-field options.
  • Generates Git provenance at build time.
File Description
src/​step.cc Calls step-end hooks before output.
src/​SlabSL.H Declares and documents frozen-field options.
src/​SlabSL.cc Captures, restores, and applies frozen coefficients.
src/​parse.cc Parses GPU settings and includes provenance.
src/​OutHDF5.cc Includes build-time provenance.
src/​global.H Declares GPU assignment settings.
src/​global.cc Defines GPU assignment defaults.
src/​global_key_set.H Registers GPU configuration keys.
src/​ExternalForce.H Defines optional synchronized hooks.
src/​ExternalCollection.H Declares hook dispatch.
src/​ExternalCollection.cc Dispatches hooks with GPU-to-host synchronization.
src/​cudaSlabSL.cu Uploads frozen coefficients for CUDA evaluation.
src/​CMakeLists.txt Adds provenance-generation dependency.
src/​begin.cc Implements GPU assignment and initialization hooks.
pyEXP/​UtilWrappers.cc Includes build-time provenance.
pyEXP/​PyWrappers.cc Includes build-time provenance.
pyEXP/​CMakeLists.txt Adds Python provenance dependency.
exp_git_version.h_in Defines the generated provenance header.
config_cmake.h_in Removes configure-time provenance definitions.
CMakeLists.txt Schedules build-time provenance generation.
cmake/​GitVersion.cmake Generates provenance with dirty-tree fingerprints.

Review effort: Balanced

Comment thread src/SlabSL.cc Resolved
Comment thread src/SlabSL.cc Resolved
Comment thread src/step.cc Resolved
Updated file existence check to include error handling.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ient

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@The9Cat The9Cat self-assigned this Dec 2, 2026
@The9Cat
The9Cat requested a balanced review from Copilot December 2, 2026 17:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The CUDA host-particle refresh can race with a pending snapshot writer, risking mixed-timestep output unless output threads are synchronized first.

1 open issue
3 resolved since last review

Review effort: Balanced

Comment thread src/ExternalCollection.cc Resolved
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants