[BUG]: CUtensorMap owned storage does not honor required alignment
Mantenedores costumam responder em até 1 dia
@isVoid já está trabalhando nisso.
Desde 22/10/2026.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 45/100
Direção de pesquisa
Read cuda_bindings/cuda/bindings/driver.pyx and _v2/driver.pyx at the cited constructors, then inspect the generator's AUTO_LOWPP_CLASS allocation and existing tensor-map tests. Compare owned storage addresses with alignof(CUtensorMap) for the supported CUDA headers, including encoding wrappers and copy-producing construction. Done means owned storage is explicitly aligned, deallocated correctly, and regression tests assert pointer alignment.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Type of Bug
Something else: backing-storage alignment does not meet the C type's declared requirement.
Component
cuda.bindings
Describe the bug
I discovered this alignment issue while reviewing #3095, which adds the _v2.driver API. Checking the existing cuda.bindings.driver.CUtensorMap implementation showed that the same allocation pattern is already present in released versions.
The wrapper embeds the C descriptor inside a Python object and does not explicitly enforce its alignment. The required alignment depends on the CUDA header version: the wrapper documentation specifies 128 bytes in v13.4.4 and 64 bytes in v12.9.9.
Released implementations with this allocation pattern
- v13.4.4:
CUtensorMap_st.__cinit__points_pvt_ptrat the inline_pvt_val; its docstring specifies 128-byte alignment. - v12.9.9: the same constructor pattern is present; its docstring specifies 64-byte alignment.
These are concrete released examples confirmed by source inspection, not a claim about the first affected release. PR #3095 uses equivalent inline storage for _v2.driver.TensorMap. This issue tracks the shared allocation limitation separately from that PR.
In the legacy wrapper, default construction points _pvt_ptr at &self._pvt_val:
The C compiler can align a member's offset within the containing object, but CPython's object allocator does not guarantee a 128-byte-aligned base address. Consequently, the descriptor's actual address need not meet the C type's alignment requirement.
How to Reproduce
Inspect the backing addresses of existing legacy API objects, for example with cuda.bindings v13.4.4; no GPU or CUDA API call is needed:
from cuda.bindings import driver
# Keep the objects alive so the allocator cannot simply reuse one address.
maps = [driver.CUtensorMap() for _ in range(200)]
addresses = [int(m.getPtr()) for m in maps]
print("address residues modulo 128:", sorted({p % 128 for p in addresses}))
print("address residues modulo 64:", sorted({p % 64 for p in addresses}))
assert all(p % 128 == 0 for p in addresses)
For v12.9.9, check modulo 64 instead, matching that version's documented requirement.
The assertion can fail because alignment stronger than the Python allocator's guarantee occurs only incidentally. Exact residues depend on the Python build and allocator; a run that happens to return aligned addresses does not establish a guarantee.
Validation: source inspection confirms the inline allocation in both versions. A separately compiled Cython reproduction using the actual CUDA header and the new wrapper's class layout produced descriptor addresses with residues 0, 16, 32, and 48 modulo 64. The legacy-API script above is provided for validation against an installed build; it was not run as part of that reproduction.
Expected behavior
Owned tensor-map storage should honor alignof(CUtensorMap) (128 bytes in the inspected header), including storage used internally by encoding wrappers. Regression tests should check the pointer alignment directly, not only whether encoding succeeds.
Observed impact and scope
No CUDA encoding failure or protected-memory fault has been demonstrated here. Existing tensor-map tests do not establish a storage-alignment guarantee, and successful encoding alone does not prove that guarantee. This report concerns meeting the documented alignment contract; it should not claim that tensor-map APIs are generally unusable or that #3095 newly breaks them.
Possible fix
Provide explicitly aligned owned storage for tensor-map wrappers, with matching deallocation and support for copy-producing construction paths. The generator's external-storage mode currently uses ordinary allocation, so selecting it alone does not guarantee extended alignment.
A broader generator enhancement could support alignment-aware allocation for AUTO_LOWPP_CLASS; a dedicated tensor-map allocation path is another option. Borrowing an externally aligned pointer is already possible, but does not fix wrappers that construct their output object internally, such as the new tensor_map_encode_tiled.
- Linguagem predominante
- Cython
- Estrelas
- 3.4k
- Forks
- 353
- Merge médio
- 2d 3h
- PRs com merge (30d)
- 163
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de NVIDIA/cuda-python
-
[BUG]: the `__cuda_stream__` deprecation warning points to `Stream(obj)`, which always raisesTalvez já em andamento @Iamsohungrynow assumiu há 5 dias. Abertabug cuda.core P1
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 86/100
NVIDIA/cuda-python#3505 · 3 comentários · 1 reação · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
[BUG]: ProcessInfo.used_gpu_memory returns the NVML_VALUE_NOT_AVAILABLE sentinel as a byte countAbertatriage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 80/100
NVIDIA/cuda-python#3468 · 3 comentários ·
Mantenedores costumam responder em até 1 dia
-
triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
NVIDIA/cuda-python#3409 ·
Mantenedores costumam responder em até 1 dia
-
[BUG]: cleanup-pr-previews never removes previews of deleted PRsTalvez livre de novo @rwgk assumiu há 48 dias e não há nenhum pull request aberto. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
NVIDIA/cuda-python#2952 · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
[BUG]: LocatedHeaderDir is mutable, so callers can poison the cached header-directory lookupTalvez já em andamento @rwgk assumiu há 63 dias. Abertatriage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
NVIDIA/cuda-python#2646 · 1 reação ·
Mantenedores costumam responder em até 1 dia
Todas as issues de NVIDIA/cuda-python
Issues semelhantes
-
bug needs-triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 86/100
dsx-ai-factory/health-validation#368 ·
Mantenedores costumam responder em até 2 dias
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
Tripstack-Corp/spyc#1352 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
vllm-project/vllm#70030 ·
Mantenedores costumam responder em até 1 dia
-
enhancement good first issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
Mantenedores costumam responder em até 1 dia
-
help wanted small extra
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
Mantenedores costumam responder em até 1 dia