Subrange Support #467
Replies: 6 comments 7 replies
-
|
Gentle opinion: factorize into 3 separate discussions, one for each feature. |
Beta Was this translation helpful? Give feedback.
-
|
prefer square brackets for types BufferView[...] |
Beta Was this translation helpful? Give feedback.
-
|
I have nothing against any of these proposals. Am I right in thinking you intend to AI generate the code?
|
Beta Was this translation helpful? Give feedback.
-
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 ( |
Beta Was this translation helpful? Give feedback.
-
data = qd.ndarray(qd.f32, shape=(N,))
view = data[0:16]For the What's your idea @duburcqa? |
Beta Was this translation helpful? Give feedback.
-
|
Note: update on PR review:
|
Beta Was this translation helpful? Give feedback.
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):
Beta Was this translation helpful? Give feedback.
All reactions