-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: refactor storage module and add support for NumPy >= 2.0 #1559
Conversation
TensorShape: TypeAlias = Sequence[ | ||
int | ||
] # TODO(egparedes) figure out if PositiveIntegral can be made to work | ||
BufferStrides: TypeAlias = Sequence[IntScalar] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not used?
@dataclasses.dataclass(frozen=True, init=False) | ||
class _BaseNDArrayBufferAllocator(abc.ABC, Generic[core_defs.DeviceTypeT]): | ||
"""Base class for buffer allocators using NumPy-like modules.""" | ||
class MemoryResourceHandler(Protocol[core_defs.DeviceTypeLiteralT]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just
class MemoryResourceHandler(Protocol[core_defs.DeviceTypeLiteralT]): | |
class Allocator(Protocol[core_defs.DeviceTypeLiteralT]): |
or even _Allocator
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or BufferAllocator
if you think Allocator
is too generic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reading more in this file, my suggestion doesn't make sense for what this is intended to do, but I am not sure I like this grouping into a class with classmethods.
The trigger for this change was byte_bounds
, the following solutions looks cleaner to me:
malloc
returns buffer and address, because that's the only place we use it (if I didn't miss anything)address_of
as single dispatch and we register cupy and numpy buffer
tensorize
is duplicated, it seems cleaner to use a free function and pass the namespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While looking at this I am trying to understand at which abstraction level would we add a low level pool allocator.
requires gridtools_cpp >= 2.3.4 for nanobind 2.x Additional changes: freezes numpy to 1.x until #1559
Close in favor of #1563 |
Refactor the storage module to encapsulate the required functionality from array libraries to allocate memory buffers in a new concept, which simplifies the design at the same time by removing one layer.
Add:
MemoryResourceHandler
concept for low-level memory buffer handling, and two different implementations using NumPy and CuPy, which support newest changes in NumPy 2.0 interfacestorage
modules and a TODO note to migrate the old unit tests fromcartesian
Change:
DeviceType
literal values in_core.definitions
storage.allocators
instead of being duplicated incartesian
andnext
allocatorsDelete:
ValidNumPyLikeAllocationNS
fromstorage.allocators
, which is not longer needed