[BUG]: cuda.lang Array.slice rejects valid integer bounds as non-tile scalars
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 68/100
Hướng nghiên cứu
Bắt đầu với phần triển khai slice dùng chung trong src/cuda/tile/_ir/ops.py và validator require_signed_integer_0d_tile_type của nó, sau đó so sánh các ánh xạ kiểu và con trỏ của CUDA Lang trong experimental/cuda-lang/src/cuda/lang/_ir/type.py và _ir/ops.py. Trước tiên, hãy chạy reproducer compile_simt được cung cấp. Hoàn tất khi các literal có dấu và các bound CUDA Lang động biên dịch được và tạo ra hành vi view zero-copy như đã được tài liệu hóa.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Version
- cuTile Python source commit:
a9ae75fc9a5fb4e4e07ea71da7407dc4c23330ab cuda-tile:9.9.99cuda-lang:9.9.99- Installation method: source
- CUDA Toolkit: not required for this reproducer; the failure occurs during front-end HIR-to-IR type checking before CUDA code generation. The reproducing environment does not have
nvccinstalled. - Python: 3.10.12
Describe the bug
cuda.lang.Array.slice() fails type checking for valid signed integer bounds, including integer literals.
The inherited API contract says start and stop may be integer scalars or 0D tiles. However, the shared implementation requires CUDA Tile's concrete TileTy, while CUDA Lang represents rank-zero values as ScalarTy.
This prevents natural zero-copy view construction, including compile-time-expanded code such as splitting a one-dimensional array into four equal views:
parts = tuple(
x.slice(0, i * chunk, (i + 1) * chunk)
for i in cl.static_iter(range(4))
)
Minimum reproducible example
import cuda.lang as cl
from cuda.lang.compilation import KernelSignature
def kernel():
a = cl.shared_array((8,), cl.int32)
a.slice(axis=0, start=1, stop=4)
cl.compile_simt(
kernel,
[KernelSignature(())],
gpu_name="sm_80",
arch="compute_80",
)
Expected behavior
Compilation succeeds. The result is a zero-copy view of a[1:4], with shape (3,), sharing the original storage.
This follows the documented Array.slice contract: start and stop may be integer scalars or 0D tiles. Dynamic bounds such as values derived from x.shape[0] should work as well.
Actual behavior
Compilation raises:
cuda.tile._exception.TypeCheckingError:
Invalid argument "start" of slice(): Expected a scalar or a 0D tile, but given value has type int32
"/tmp/cuda_lang_array_slice_repro.py", line 3, col 5-36, in kernel:
a.slice(axis=0, start=1, stop=4)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The message is contradictory: the value is a valid CUDA Lang int32 scalar, but it is rejected.
Likely cause
cuda.lang.Array subclasses cuda.tile.Array, so it inherits slice:
experimental/cuda-lang/src/cuda/lang/_stub/core_api.py:10-15,32src/cuda/tile/_stub.py:177-190
CUDA Lang installs CUDA Tile's shared array implementation registry:
experimental/cuda-lang/src/cuda/lang/_ir/ops.py:40-47,176-181
The shared slice implementation validates both bounds with require_signed_integer_0d_tile_type:
src/cuda/tile/_ir/ops.py:782-787
That validator requires the concrete type to be TileTy, while CUDA Lang maps rank-zero values to ScalarTy:
src/cuda/tile/_ir/op_impl.py:553-559,598-602experimental/cuda-lang/src/cuda/lang/_ir/type.py:43-57,284-295
Consequently, literal and runtime CUDA Lang integer scalars fail before slicing is lowered.
There may be a second representation mismatch after correcting validation: the shared implementation calls CUDA Tile's pointer_offset, while CUDA Lang arrays use PointerTy and their own pointer arithmetic implementation. A complete fix may need a CUDA Lang-specific slice implementation, or a representation-neutral shared implementation.
Workaround
For scalar access, rebase the index manually:
value = a[start + i]
For a contiguous, compile-time-sized view, reconstruct an array from an offset pointer:
ptr = a.get_element_pointer(start)
sub = cl.reinterpret_pointer_as_array(
ptr,
dtype=cl.int32,
shape=(3,),
)
This is not equivalent to the documented slice API: reconstructed shapes must currently be compile-time constants, custom strides are not implemented, and bounds are not checked.
Contributing guidelines
- I agree to follow cuTile Python's contributing guidelines.
- I searched open and closed issues for
Array.slice, CUDA Lang slicing, and the reported error text and found no duplicate.
- Ngôn ngữ chính
- Python
- Star
- 2.2k
- Fork
- 155
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của NVIDIA/cutile-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
NVIDIA/cutile-python#105 · 2 bình luận ·
-
bug status: needs-triage
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
NVIDIA/cutile-python#102 ·
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
NVIDIA/cutile-python#97 · 1 bình luận ·
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
NVIDIA/cutile-python#96 · 1 bình luận ·
-
bug
NVIDIA/cutile-python#95 · 1 bình luận · 1 người được giao ·
Tất cả issue của NVIDIA/cutile-python
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
zostera/django-bootstrap4#894 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
use-agent-os/agent-os#3276 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NousResearch/hermes-agent#117848 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
zilliztech/memsearch#759 ·