Subrange Support #467
Replies: 6 comments 7 replies
|
Gentle opinion: factorize into 3 separate discussions, one for each feature. |
|
prefer square brackets for types BufferView[...] |
|
I have nothing against any of these proposals. Am I right in thinking you intend to AI generate the code?
|
Square bracket styleTo make the square bracket style the preferred API, we could expose a PascalCase alias: from quadrants.types.ndarray_type import NdarrayType
class BufferViewType:
"""Type annotation for BufferView kernel parameters.
"""
def __init__(self, dtype=None, boundary="unsafe"):
self.dtype = dtype
self.boundary = boundary
self.ndarray_type = NdarrayType(dtype=dtype, ndim=1, boundary=boundary)
@classmethod
def __class_getitem__(cls, args, **kwargs):
if not isinstance(args, tuple):
args = (args,)
return cls(*args, **kwargs)
def __repr__(self):
return f"BufferViewType(dtype={self.dtype}, boundary={self.boundary})"
BufferView = BufferViewTypeThen the user-facing API becomes: from quadrants import BufferView
@qd.kernel
def kernel(v: BufferView[qd.f32]):
for i in range(v.count):
v[i] *= 2.0This matches Python's generic conventions ( |
data = qd.ndarray(qd.f32, shape=(N,))
view = data[0:16]For the What's your idea @duburcqa? |
|
Note: update on PR review:
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Core Principle
BufferView — Safe Sub-range Access
BufferViewprovides bounds-checked sub-range views, avoiding OOB risks from raw pointer + offset, and which provide us with the ability to support more Logical-Level OOB check.TODO: API discussion.
OOB error in debug mode (includes kernel name, thread ID, full callstack):
All reactions