Skip to content

[libcu++] Add new memory pool attributes from CUDA 13.3#9798

Open
pciolkosz wants to merge 3 commits into
NVIDIA:mainfrom
pciolkosz:cuda133-memory-pool-attrs
Open

[libcu++] Add new memory pool attributes from CUDA 13.3#9798
pciolkosz wants to merge 3 commits into
NVIDIA:mainfrom
pciolkosz:cuda133-memory-pool-attrs

Conversation

@pciolkosz

@pciolkosz pciolkosz commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

CUDA 13.3 added a bunch of read-only memory pool attributes. This PR adds support for it for the CCCL memory pool types.

Also includes a fix to make the attribute getter correctly use the type specified in the documentation

@pciolkosz pciolkosz requested review from a team as code owners July 10, 2026 22:51
@pciolkosz pciolkosz requested review from Jacobfaib and gonidelis July 10, 2026 22:51
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jul 10, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jul 10, 2026
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: d0bd69f4-e222-4386-9e24-a4683c3da1c6

📥 Commits

Reviewing files that changed from the base of the PR and between afa9214 and df96b23.

📒 Files selected for processing (2)
  • libcudacxx/include/cuda/__memory_pool/memory_pool_base.h
  • libcudacxx/test/libcudacxx/cuda/memory_resource/resources/memory_pools.cu
🚧 Files skipped from review as they are similar to previous changes (2)
  • libcudacxx/test/libcudacxx/cuda/memory_resource/resources/memory_pools.cu
  • libcudacxx/include/cuda/__memory_pool/memory_pool_base.h

📝 Walkthrough

Summary by CodeRabbit

  • Documentation

    • Updated the “Memory Pool Attributes” docs to describe new CUDA 13.3+ read-only creation attributes, including a note about additional read-only attributes and new queryable fields.
  • New Features

    • Added CUDA 13.3+ support for querying memory pool creation-time read-only attributes: allocation type, export handle types, location id/type, maximum pool size, and hardware decompression enabled.
    • Exposed these attributes through the public memory pool attribute interfaces.
  • Tests

    • Expanded memory pool resource tests to validate default and creation-time attribute values across device, pinned, managed, and shared pools, including read-only enforcement when exceptions are enabled.

Walkthrough

CUDA 13.3 memory-pool creation attributes now use typed driver queries, are exposed through memory_pool_attributes, documented, and validated for device and shared memory pools.

Changes

Memory pool attribute support

Layer / File(s) Summary
Typed attribute access and declarations
libcudacxx/include/cuda/..., docs/libcudacxx/runtime/memory_pools.rst
Memory-pool queries use attribute-specific storage types, while CUDA 13.3 read-only creation attributes are exposed and documented.
Device pool construction validation
libcudacxx/test/libcudacxx/cuda/memory_resource/resources/device_memory_resource.cu, libcudacxx/test/libcudacxx/cuda/memory_resource/resources/memory_pools.cu
Tests validate creation attributes for default, property-based, allocation-handle, and read-only device-pool operations.
Shared pool attribute validation
libcudacxx/test/libcudacxx/cuda/memory_resource/resources/shared_memory_pools.cu
Tests validate CUDA 13.3 creation attributes for pinned and managed shared memory pools.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
libcudacxx/test/libcudacxx/cuda/memory_resource/resources/device_memory_resource.cu (1)

71-102: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Const-qualify and annotate the new helpers.

Lines 73 and 80 only read their parameters. Add const qualification, mark get_raw_attribute [[nodiscard]], and declare the non-template helper inline.

As per coding guidelines, unchanged variables must be const, non-template non-constexpr functions must be inline, and most non-void results should be [[nodiscard]].

Source: Coding guidelines

libcudacxx/test/libcudacxx/cuda/memory_resource/resources/memory_pools.cu (1)

127-157: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Make the creation-attribute checker const-correct.

check_creation_attributes only reads pool, props, and current_device. Use const PoolType&, const cuda::memory_pool_properties, and const int for these parameters.

As per coding guidelines, variables that are not modified must be declared const.

Source: Coding guidelines

libcudacxx/test/libcudacxx/cuda/memory_resource/resources/shared_memory_pools.cu (1)

51-83: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Const-qualify the checker inputs.

check_shared_pool_creation_attributes only reads pool and props. Use const PoolType& and const cuda::memory_pool_properties.

As per coding guidelines, variables that are not modified must be declared const.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 6e27e8f7-12cc-479b-8ebc-6705643498de

📥 Commits

Reviewing files that changed from the base of the PR and between 71e0b9f and 5d8c4ce.

📒 Files selected for processing (6)
  • docs/libcudacxx/runtime/memory_pools.rst
  • libcudacxx/include/cuda/__driver/driver_api.h
  • libcudacxx/include/cuda/__memory_pool/memory_pool_base.h
  • libcudacxx/test/libcudacxx/cuda/memory_resource/resources/device_memory_resource.cu
  • libcudacxx/test/libcudacxx/cuda/memory_resource/resources/memory_pools.cu
  • libcudacxx/test/libcudacxx/cuda/memory_resource/resources/shared_memory_pools.cu

}
# endif // _CCCL_CTK_AT_LEAST(13, 0)

CHECK(pool.attribute(cuda::memory_pool_attributes::allocation_type) == expected_allocation_type);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: prefer REQUIRE(), is there any point in continuing the test if this fails?

CHECK_THROWS_AS(
pool.set_attribute(
cuda::memory_pool_attributes::allocation_type, pool.attribute(cuda::memory_pool_attributes::allocation_type)),
std::invalid_argument);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important: assert the exception message as well to make sure you are triggering exactly the exception you think you're triggering.

}

#if _CCCL_CTK_AT_LEAST(13, 3) && _CCCL_HAS_EXCEPTIONS()
{ // CUDA 13.3 creation attributes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: does it need to be inside a scope?

::cuda::std::size_t __value = 0;
static auto __driver_fn = _CCCLRT_GET_DRIVER_FUNCTION(cuMemPoolGetAttribute);
_Tp __value{};
static auto __driver_fn = _CCCLRT_GET_DRIVER_FUNCTION(cuMemPoolGetAttribute);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important: the driver function will be loaded for every instantiation of this function. Consider having a type-less stub called by the templates to avoid reloading it multiple times (probably also slightly better for compile-time since the compilers don't have to generate all that code every time).

template <::cudaMemPoolAttr _Attr,
typename _Type,
__pool_attr_settable _Settable,
typename _StorageType = _Type>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IMO, if this was such a problem that we need to specify this, then we shouldn't make it a default. Even if it's verbose for a lot of cases, it forces us to consider the type every time we add a new one.

[[nodiscard]] _CCCL_HOST_API type operator()(::cudaMemPool_t __pool) const
{
size_t __value = ::cuda::__driver::__mempoolGetAttribute(__pool, static_cast<::CUmemPool_attribute>(_Attr));
auto __value = ::cuda::__driver::__mempoolGetAttribute<_StorageType>(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
auto __value = ::cuda::__driver::__mempoolGetAttribute<_StorageType>(
const auto __value = ::cuda::__driver::__mempoolGetAttribute<_StorageType>(

(nit, but if you agree, elsewhere as well pls)

_CCCL_THROW(::std::invalid_argument, "This attribute can't be set to a non-zero value.");
}
::cuda::__driver::__mempoolSetAttribute(__pool, __attr, &__value);
::cuuint64_t __value_copy = static_cast<::cuuint64_t>(__value);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe just make __value a cuuint64_t directly? This is only called by us, and we probably want to know where we're using the wrong type.

@pciolkosz pciolkosz force-pushed the cuda133-memory-pool-attrs branch from 5d8c4ce to 8880974 Compare July 10, 2026 23:12
@pciolkosz pciolkosz force-pushed the cuda133-memory-pool-attrs branch from 8880974 to afa9214 Compare July 10, 2026 23:14
@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 2h 31m: Pass: 100%/120 | Total: 2d 22h | Max: 2h 31m | Hits: 69%/524903

See results here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

3 participants