Skip to content

ENH: Avoid repeated CUDA device selection queries - #100

Merged
SimonRit merged 1 commit into
RTKConsortium:mainfrom
axel-grc:CudaBuffer
Jul 8, 2026
Merged

ENH: Avoid repeated CUDA device selection queries#100
SimonRit merged 1 commit into
RTKConsortium:mainfrom
axel-grc:CudaBuffer

Conversation

@axel-grc

@axel-grc axel-grc commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

CudaDataManager calls CudaGetMaxFlopsDev during construction, so iterative pipelines can repeatedly query CUDA device properties when many temporary CUDA images or filters are created.

Compute the max-FLOPS device once with function-local static initialization and reuse the selected device for subsequent CudaGetMaxFlopsDev calls.

This avoids repeated cudaGetDeviceProperties and cudaDeviceGetAttribute

Comment thread src/itkCudaUtil.cxx Outdated
}

return max_flops_device;
}();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It wasn't obvious to me why you had parentheses here. I think using std::invoke would make it clearer?

@axel-grc
axel-grc force-pushed the CudaBuffer branch 2 times, most recently from 4bcdd38 to 660d6ac Compare July 8, 2026 12:36
Comment thread src/itkCudaUtil.cxx Outdated

// Return the device that has the maximum FLOPS. The result is cached for future calls.
int
CudaGetCachedDevice()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That's too vague of a name. Maybe CudaGetCachedMaxFlopsDevice?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Actually, I would keep the original name, Cached is not necessary

CudaDataManager calls CudaGetMaxFlopsDev during construction, so iterative
pipelines can repeatedly query CUDA device properties when many temporary
CUDA images or filters are created.

Compute the max-FLOPS device once with function-local static initialization
and reuse the selected device for subsequent CudaGetMaxFlopsDev calls.

This avoids repeated cudaGetDeviceProperties and cudaDeviceGetAttribute

@SimonRit SimonRit left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me. I think you could

@SimonRit
SimonRit merged commit a45e699 into RTKConsortium:main Jul 8, 2026
13 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