Skip to content

COMP: Use std::atomic for the OpenCLVectorBase reference count - #1504

Open
hjmjohnson wants to merge 1 commit into
SuperElastix:mainfrom
hjmjohnson:use-std-atomic-opencl-vector-refcount
Open

hjmjohnson wants to merge 1 commit into
SuperElastix:mainfrom
hjmjohnson:use-std-atomic-opencl-vector-refcount

Conversation

@hjmjohnson

Copy link
Copy Markdown
Contributor

ELASTIX_USE_OPENCL=ON no longer compiles against ITK main. itkOpenCLVectorBase.cxx includes vcl_atomic_count.h, which ITK dropped when it switched to a VXL stripped down to the numerics code (InsightSoftwareConsortium/ITK#6421, merged June 2026). This PR replaces the counter with std::atomic<int>.
Merge danger: two-way door; blast radius: ELASTIX_USE_OPENCL=ON builds only (off by default).

This is independent of the ITK GPU-module removal discussed in #1503. The header is used by elastix's own OpenCL code, not by ITK's GPU modules.

Shape of the change
-// thread/SMP safe reference counter
-#include <vcl_atomic_count.h>
+#include <atomic>
 ...
-  vcl_atomic_count              referenceCount;
+  std::atomic<int>              referenceCount;

referenceCount is initialized to 1, incremented, decremented, and compared with <= 0. std::atomic<int> supports each of these with the same atomicity.

Evidence

Local, macOS arm64, conda clang, ELASTIX_USE_OPENCL=ON, against an ITK build without vcl_atomic_count.h (ITK main after #6421):

  • Without this change: itkOpenCLVectorBase.cxx:22: fatal error: 'vcl_atomic_count.h' file not found.
  • With this change, together with COMP: Stop requiring ITKGPUCommon for ELASTIX_USE_OPENCL (ITK 6) #1503 (needed because that ITK build has no ITKGPUCommon): 401 of 401 targets build and link with 0 errors.
  • I could not run the OpenCL runtime tests locally. They need an Intel, NVIDIA, or AMD OpenCL SDK, and OpenCLContext rejects Apple's platform with or without this change.
  • ITK 5.4 still ships vcl_atomic_count.h, but std::atomic works there as well, so builds against ITK 5.4.1 or later are unaffected.
  • No elastix or ITK issue or PR mentions vcl_atomic_count.
AI assistance

Prepared with Claude Code (Opus 5.5) under Hans Johnson's direction; reviewed by Hans Johnson.

ITK 6 no longer vendors vcl_atomic_count.h (VXL update of 2026-06-09),
so ELASTIX_USE_OPENCL fails to compile against ITK main. std::atomic<int>
provides the same initialization, increment, decrement, and comparison.
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.

1 participant