Skip to content

SYCL backend (1/6): build switch, device list and forward projectors - #902

Merged
AnderBiguri merged 8 commits into
CERN:syclfrom
Einse57:sycl-pr1-build-ax
Nov 28, 2026
Merged

AnderBiguri merged 8 commits into
CERN:syclfrom
Einse57:sycl-pr1-build-ax

Conversation

@Einse57

@Einse57 Einse57 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

This is the first of six PRs for the SYCL backend discussed in #885, split so that each one can be
reviewed on its own. It is based on TIGRE 3.3.1. With TIGRE_BACKEND=sycl, the Python build compiles
the extensions from a new Common/SYCL folder with the oneAPI DPC++ compiler (icpx, or icx on
Windows) instead of nvcc. CUDA stays the default. Without TIGRE_BACKEND, the build looks for CUDA
first, then HIP, then the SYCL compiler (TIGRE_SYCL_CXX if set, otherwise icpx/icx), and prints
what it chose. Common/CUDA is not changed.

  • Common/SYCL in this PR: GpuIds.cpp and gpuUtils.cpp (the device list), the four forward
    projectors (Siddon_projection*.cpp, ray_interpolated_projection*.cpp), and the shared SYCL
    helpers (tigre_sycl.cpp/.hpp, tigre_release_on_error.hpp, page_locking.hpp). Each file has
    the name of its Common/CUDA counterpart and uses the same header.
  • Device list: Level Zero GPUs if there are any, otherwise other GPUs, otherwise the other SYCL
    devices (e.g. the CPU). TIGRE_SYCL_ALL_DEVICES=1 lists the other devices after the GPUs.
    TIGRE_SYCL_MEMORY_LIMIT_MB caps the memory TIGRE plans with, so the tests can reach the
    splitting paths on any device.
  • Forward projectors follow 3.3.1's host memory handling (Fix Atb crash with 32-bit voxel counts; fall back to pageable memory when page-locking fails #903, One page-locking rule for all projectors and backprojectors #905, Backprojection on 4+ GPUs: fix the crash when a GPU gets no slices #906, Page-lock the host arrays of unsplit calls only from three GPUs #917):
    • The image is page-locked only on GPUs, and only when it is split or more than 2 devices are
      used. If page-locking fails, a TIGRE:hostRegister warning is shown and pageable memory is used.
    • If a device allocation fails even though the estimate says it fits, the image is split into
      more pieces and retried (tigre::tryMallocPieces), down to one slice per piece.
    • splitImage/splitImageInterp use the Backprojection on 4+ GPUs: fix the crash when a GPU gets no slices #906 fix, so there are no empty pieces.
  • setup.py: sycl is removed from BACKEND_PENDING. TIGRE_SYCL_CXX overrides the compiler. On
    Windows, icx compiles and links instead of cl.exe. The CUDA part is unchanged; it is only
    indented under if USE_SYCL: ... else:.
  • Until the later PRs land, the SYCL build leaves out the extensions not yet in Common/SYCL
    (SYCL_PENDING in setup.py). import tigre still works there, and a function that needs a
    missing extension raises ImportError when it is called (tigre.utilities.gpu._import_extension).
    The CUDA build is unaffected: a missing extension still raises at import. In the tests, the
    ones that need a missing extension are skipped (conftest.py). PR 5/6 removes SYCL_PENDING,
    the stand-ins and the conftest additions again.
  • _gpuUtils.getBackend() returns "cuda" or "sycl". PyTorch CUDA tensors and CuPy arrays
    given to tigre.Ax/tigre.Atb go through host memory on the SYCL build.
  • Tests: test_sycl_low_memory.py (Ax with little device memory), a SYCL case in
    test_siddon_split.py, and device_kinds.py for device lists that mix a GPU and the CPU.
    CUDA-only cases are skipped on the SYCL build.

The CI workflow is the next PR, and the SYCL CI results come with it. Docs and a changelog entry come
in 6/6. MATLAB follows separately.

Which parts of TIGRE does it touch?

  • Python
  • MATLAB
  • CUDA kernels (Common/CUDA). New Common/SYCL; Common/CUDA is unchanged.
  • Docs (in 6/6)

Test environment

  • Linux, Intel Xeon processor, SYCL CPU device (Intel OpenCL CPU runtime 2025.2), oneAPI DPC++
    2025.2.0, Python 3.11.18, NumPy 2.2.6: pytest 166 passed, 129 skipped (most skips are tests that
    need extensions added in 3/6 to 5/6); pytest -m extended 7 passed, 21 skipped.
  • Windows, Intel Arc Pro B70 (Level Zero, driver 32.0.101.8976): forward projections match the SYCL
    CPU device to float rounding, unsplit and split. test_sycl_low_memory, test_siddon_split,
    thin_shapes and projectors_gpu: 44 passed, 44 skipped (36 need _Atb, 8 need 2 GPUs).
  • CUDA build: the existing Build workflow (CUDA wheels) passed (https://github.com/Einse57/TIGRE/actions/runs/45456530781).

Earlier versions of this backend, on TIGRE 3.2.0, Windows 11 Pro, oneAPI 2025.2 (not rerun on this
version): the test suite passed on an Intel Arc 140T, an Intel Arc Pro B50 and an Intel Arc Pro
B70 (Level Zero), and on the Arc Pro B70 together with an Intel Core Ultra 7 265F (Intel OpenCL
CPU runtime) in one device list. On an Intel Core Ultra 9 285H, the projector and TV results were
compared with the other devices' results; the full test suite was not run there.

// if rounding never quite lets a crossing reach aM. One fetch per step, before
// the branch on the axis crossed.
const int maxsteps=(int)geo.nVoxelX+(int)geo.nVoxelY+(int)geo.nVoxelZ+3;
for (int step=0; step<maxsteps; step++){

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The siddon code changed in 3.3.1. I am happy to leave as is, the code that changed was mostly for performance reasons, let me know if you want to leave as is, or imitate 3.3.1

@AnderBiguri

Copy link
Copy Markdown
Member

Thanks, this is nicely split and easy to follow. A few things before merging:

  1. Auto-detection. With sycl out of BACKEND_PENDING, anyone with icpx/icx and no CUDA now silently gets a TIGRE without Atb/FDK/TV until 5/6 lands, possibly in a release. Can SYCL be built only with an explicit TIGRE_BACKEND=sycl until then? Alternatively I can make a sycl branch here, merge 1/6 to 5/6 into it and merge that into master once complete, which would also let you drop the _import_extension/SYCL_PENDING/conftest scaffolding. Wwhat do you think?
  2. Memory budget. tigreSyclMaxAlloc caps the whole budget at max_mem_alloc_size. What does the B70 report there? If it's ~4 GB, large images get split far more than needed.
  3. No GPU: please only fall back to CPU devices (is_cpu()), not other accelerators, and print once that TIGRE is running on the CPU.
  4. Header names: page_locking.hpp and tigre_release_on_error.hpp also exist in Common/CUDA, and which one is used depends on include order. Could the SYCL ones get their own names?
  5. Install docs: they currently say only cuda can be built, so please update those lines in this PR rather than in 6/6.

Fine as follow-up issues, not blocking: the kernels are the 3.3.0 ones (no multi-step Siddon from 3.3.1), and the projectors don't overlap copies with kernels (one buffer per device, a wait per block, split pieces added on the host), unlike CUDA's two streams per GPU.

@Einse57

Einse57 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks Ander, all good points.

  1. Let's go with a sycl branch. Once you create it I'll retarget SYCL backend (1/6): build switch, device list and forward projectors #902 there and send the rest against it. I'd keep the pending-extension scaffolding until 5/6 so the branch builds and imports at every step, then remove it in 5/6 before it goes into master.
  2. Good catch. The B70 reports max_mem_alloc_size equal to its full memory, but an Arc 140T iGPU reports 4 GB out of 36 GB, so it would have split far more than needed. The budget is now min(0.95 × global, free, TIGRE_SYCL_MEMORY_LIMIT_MB), and max_mem_alloc_size only limits the size of each single buffer.
  3. With no GPU it now selects only CPU devices and prints once that TIGRE is running on the CPU.
  4. Renamed to page_locking_sycl.hpp and tigre_release_on_error_sycl.hpp.
  5. Updated docs/install/python.md with a SYCL build section.

I'll keep Siddon as is here and open a follow-up issue to match 3.3.1, plus one for the copy/kernel overlap.

@AnderBiguri

Copy link
Copy Markdown
Member

Thanks, all looks good. I've created the sycl branch from current master (52005d7). Please retarget #902 to it and send the rest there; I'll merge master into it now and then so it doesn't drift.

One heads-up for the rebase: master has moved on since 3.3.1, and #952 moved the compiled modules into the package. They are now tigre.utilities.cuda_interface._Atb etc. (extension names in setup.py and the imports), not top-level _Atb. So #902 now conflicts in setup.py, Atb.py, CTnoise.py, im_3d_denoise.py and iterative_recon_alg.py, and the scaffolding needs the new names too: SYCL_PENDING (it compares against ext.name), _import_extension(...), and the find_spec/import _gpuUtils checks in conftest.py and the tests. If those keep the old names, the pending extensions won't be filtered out of the build and the conftest skips won't trigger. Common/CUDA hasn't changed since 3.3.1, so the SYCL kernels are unaffected.

SYCL counterparts of GpuIds.cpp, gpuUtils.cu and the four forward projectors
in Common/CUDA, with the same headers, plus the shared SYCL helpers
(tigre_sycl.cpp/.hpp, tigre_release_on_error.hpp).
sycl is no longer stopped as pending. Only the extensions whose sources are in
Common/SYCL are built (SYCL_PENDING lists the others). On that build, importing
tigre still works, and a function that needs a missing extension raises
ImportError when it is called. _gpuUtils.getBackend() returns "cuda" or
"sycl", and CUDA arrays given to Ax/Atb go through host memory on SYCL.
Tests that need an extension the SYCL build does not have yet are skipped.
SYCL-only tests: Ax with little device memory, and the Siddon split. Device
lists that mix a GPU and the CPU use one kind of device in the multi-device
tests.
…ge splitting

As Common/CUDA in 3.3.1 (CERN#903, CERN#905, CERN#906, CERN#917):
- page_locking.hpp: tigre::hostRegister, hostUnregister and worthPageLocking.
  The image is page-locked (prepare_for_device_copy) only when it is split or
  more than 2 devices are used, only on GPUs, and pageable memory is used,
  with a warning, if page-locking fails.
- If allocating the image piece and the projection buffer fails although the
  estimate says it fits, the image is split in more pieces and allocated again
  (tigre::tryMallocPieces), down to one slice per piece.
- splitImage and splitImageInterp compute the last piece size signed, as CERN#906.
…dget

Keep the working-set budget at min(0.95*global, free,
TIGRE_SYCL_MEMORY_LIMIT_MB). Split image pieces so each single buffer also
stays within max_mem_alloc_size (TIGRE_SYCL_MAX_ALLOC_MB for tests). On
devices such as the Arc 140T, a 4 GiB allocation cap with a much larger
global memory would otherwise over-split the image.
@Einse57
Einse57 changed the base branch from master to sycl November 28, 2026 14:13
@Einse57

Einse57 commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Retargeted to sycl and rebased onto 52005d7 with the new cuda_interface module names.

@AnderBiguri

Copy link
Copy Markdown
Member

Merged into sycl, thanks! Go ahead with 2/6 against sycl when you're ready. Could you also open the two follow-up issues (Siddon to match 3.3.1, and overlapping copies with kernels) so they don't get lost?

@AnderBiguri
AnderBiguri merged commit f0e0240 into CERN:sycl Nov 28, 2026
8 checks passed
@Einse57 Einse57 mentioned this pull request Nov 29, 2026
1 of 10 tasks
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