Skip to content

perf: vectorized, multithreaded, cuda-available calculation kernel - #107

Merged
sbillinge merged 6 commits into
diffpy:mainfrom
SYMSCAE:cuda
Nov 22, 2026
Merged

sbillinge merged 6 commits into
diffpy:mainfrom
SYMSCAE:cuda

Conversation

@SYMSCAE

@SYMSCAE SYMSCAE commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

This PR updates bindings for libdiffpy commit 994aaf2. See diffpy/libdiffpy#76 and diffpy/libdiffpy#78 for changes and benchmarks.

Additional changes

  • Add diffpy.srreal.calculationkernel to list and select CPU and CUDA kernels for calculators.
  • Add getAtomArrays() and setAtomArrays() to AtomicStructureAdapter for bulk access to atom data, and speed up conversion of diffpy.structure and pyobjcryst structures.
  • Include the cuda and cuda-mixed kernels in x86-64 wheels for Linux and Windows.

SYMSCAE and others added 3 commits November 19, 2026 22:38
Bind libdiffpy's CPU kernels and batch atomic structure conversion through
NumPy arrays. Preserve displacement tensors for shared atoms, honor custom
atom and crystal accessors, and reuse ObjCryst data for native crystals.
Validate site indices and cover converter registration and class lifetime.
Expose CUDA PDF and Debye kernels and their precision controls. Build
CUDA-enabled wheels and cover CPU fallback on Windows hosts without a
CUDA driver. Pin the embedded library to its upstream CUDA merge.
@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.51728% with 46 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.94%. Comparing base (2f2610f) to head (6f0c957).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
tests/test_calculationkernel.py 65.54% 41 Missing ⚠️
tests/test_allpairs.py 97.63% 3 Missing ⚠️
tests/test_objcrystconverters.py 99.17% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #107      +/-   ##
==========================================
- Coverage   98.69%   97.94%   -0.76%     
==========================================
  Files          26       29       +3     
  Lines        3834     4665     +831     
==========================================
+ Hits         3784     4569     +785     
- Misses         50       96      +46     
Files with missing lines Coverage Δ
tests/test_atomarrays.py 100.00% <100.00%> (ø)
tests/test_parallel.py 98.88% <100.00%> (ø)
tests/test_structureadapter.py 99.52% <100.00%> (+0.02%) ⬆️
tests/testutils.py 96.15% <100.00%> (-0.15%) ⬇️
tests/test_objcrystconverters.py 99.32% <99.17%> (-0.68%) ⬇️
tests/test_allpairs.py 97.63% <97.63%> (ø)
tests/test_calculationkernel.py 65.54% <65.54%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SYMSCAE
SYMSCAE marked this pull request as ready for review November 20, 2026 06:58
@SYMSCAE

SYMSCAE commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@sbillinge PR ready for review. Again, codecov is failing because it's not happy with cuda builds not being tested...

@sbillinge

Copy link
Copy Markdown
Contributor

@SYMSCAE here is a review from Fable. It caught a few small things:

The review of PR #107 found six issues worth acting on before merge, but none is confirmed by a build or
test run. Nothing was built or executed, and the libdiffpy submodule commit the PR points to (994aaf2)
isn't available locally, so several findings are things to check rather than proven bugs.

Important

  1. Wheel builds may lose SRREAL_STATIC_DEPS=ON and VCPKG_MANIFEST_INSTALL=OFF (pyproject.toml:78, also 90
    and 106). The PR moves these to a global [tool.cibuildwheel.config-settings] table and sets
    inherit.config-settings = "append" in the linux, macos and windows tables. As far as the reviewer
    recalls, cibuildwheel honours inherit only inside [[tool.cibuildwheel.overrides]], so each platform
    table would replace the global one. Check the resolved options; if so, repeat the two settings per
    platform or move the platform settings into overrides.
  2. Dropped vcpkg ports may break the wheel compile (vcpkg.json:5). boost-ublas and boost-container-hash
    were removed. Nothing in src/extensions includes them, but libdiffpy at 994aaf2 might still. Check it
    for boost/numeric/ublas and boost/functional/hash includes.
  3. Wheels may silently ship without SIMD kernels (vcpkg.json:6). The README says SIMD kernels need xsimd
    14 or newer, but the PR adds xsimd without changing builtin-baseline, which pins the port version. If
    the baseline has 13.x, CMake builds scalar-only with no error, contradicting news/cuda.rst. Check the
    baseline's xsimd version, and consider failing the wheel build when xsimd isn't found.
  4. Converting a pyobjcryst Crystal can return a stale structure
    (src/diffpy/srreal/_objcrystconverters.py:183). convertObjCrystCrystal now returns a clone of a cached
    adapter whenever the crystal's master clock is unchanged. Any mutation that doesn't click that clock is
    missed. Candidates to test:
    • a space group changed through crystal.GetSpaceGroup()
    • RemoveScatteringPower on a power still in use
    • a ScatteringPowerAtom symbol change
  5. The adapter cache is not thread-safe (src/diffpy/srreal/_objcrystconverters.py:133). The module-level
    _crystal_adapters cache is updated in place before cloning, with no lock. Two threads converting the
    same crystal can interleave and one can clone a half-updated structure.
  6. setAtomArrays may leave symmetry-expanded positions out of date
    (src/extensions/wrap_AtomicStructureAdapter.cpp:715). It replaces atoms through a new adpt.assign(...)
    in libdiffpy, and _setSymOps (line 835) returns early when the operations are unchanged. Check that
    assign invalidates the symmetry-position cache. A test that calls setAtomArrays after setting symmetry
    operations and then checks getEquivalentAtoms would cover it.

Nits

  • Loose input validation in setAtomArrays (src/extensions/wrap_AtomicStructureAdapter.cpp:656). A plain
    string for atomtypes is iterated character by character, so "Ni" becomes atoms "N" and "i". Zero-size
    arrays with the wrong trailing shape, such as numpy.zeros((0, 5)), are accepted.

@SYMSCAE

SYMSCAE commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

1 and 2 are stale, rest are all addressed.

@sbillinge
sbillinge merged commit 08f0109 into diffpy:main Nov 22, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants