Skip to content

Add workspace field to cuTENSOR backend. - #318

Merged
lkdvos merged 4 commits into
QuantumKitHub:mainfrom
jack-dunham:cutensor-workspace
Oct 22, 2026
Merged

lkdvos merged 4 commits into
QuantumKitHub:mainfrom
jack-dunham:cutensor-workspace

Conversation

@jack-dunham

Copy link
Copy Markdown
Contributor

Selects the workspace for the cuTENSOR contraction. Defaults to WORKSPACE_DEFAULT.

Selects the workspace for the cuTENSOR contraction. Defaults to
WORKSPACE_DEFAULT.
Comment thread src/backends.jl Outdated
cuTENSOR's workspace preference for contractions, e.g. `cuTENSOR.WORKSPACE_MAX`; `nothing`
selects `cuTENSOR.WORKSPACE_DEFAULT`.
"""
struct cuTENSORBackend{W} <: AbstractBackend

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.

should this be a @kwdef struct maybe?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't see why not.

@kwdef struct cuTENSORBackend{W}
    workspace::W = nothing
end

Also do we really need to parameterize the type here? I feel like it's unnecessary.

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.

Yeah I don't know if it makes a huge difference not to. Do we ever intend to dispatch on W elsewhere? That seems dubious to me

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.

Do the different values of cuTENSOR.WORKSPACE_MAX, cuTENSOR.WORKSPACE_MIN and cuTENSOR.WORKSPACE_DEFAULT belong to different types, or are they different values of a single type? If the latter, and provided this is a simple primitive type that exists in Base and is not defined in CUTENSOR only, we can declare the type of the newly added workspace field and always fill in the default instead of nothing ?

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.

They're different values of a CEnum

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.

Is that something that exists somewhere in Base? I can't find it right away.

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.

@jack-dunham jack-dunham Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My interpretation of this issue was that a hard dependency would be required to access these enum types.

Another option is to have the workspace field Symbol (with possible values :min, :max and :default) and have a lookup in the extension.

@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
ext/TensorOperationscuTENSORExt.jl 96.15% <100.00%> (+94.09%) ⬆️
src/backends.jl 84.61% <100.00%> (+9.61%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/backends.jl Outdated
selects `cuTENSOR.WORKSPACE_DEFAULT`.
"""
@kwdef struct cuTENSORBackend <: AbstractBackend
workspace = nothing

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.

Can we make this a symbol or enum, so the field access is type stable? I think there are only a few options here so probably exhaustive if-else is fine and fast

@jack-dunham jack-dunham Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'd advocate for Symbol as the more user-friendly choice. I am not really sure what advantage there is to using an Enum as a proxy for the existing CEnum here.

Afaik there's only three options: WORKSPACE_MIN, WORKSPACE_MAX, and WORKSPACE_DEFAULT, so I suggest :min, :max and :default.

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.

I don't have a strong opinion, the only reason to have an enum is this properly validates the input options automatically (you can only construct valid options), and that the cenum is only available in the extension so it's hard to properly get that to work. The symbol is definitely also fine, just requires a bit more careful input checking, but feel free to pick whatever you like!

Jutho
Jutho previously approved these changes Oct 20, 2026
lkdvos
lkdvos previously approved these changes Oct 20, 2026

@lkdvos lkdvos left a comment

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.

Small suggestion, otherwise good to go for me

Comment thread src/backends.jl
"""
struct cuTENSORBackend <: AbstractBackend end
@kwdef struct cuTENSORBackend <: AbstractBackend
workspace::Symbol = :default

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.

Can we validate at construction time?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@jack-dunham
jack-dunham dismissed stale reviews from lkdvos and Jutho via cbaf56f October 21, 2026 15:32
@lkdvos
lkdvos enabled auto-merge (squash) October 21, 2026 22:05
@lkdvos
lkdvos merged commit d8409ee into QuantumKitHub:main Oct 22, 2026
12 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.

4 participants