-
-
Notifications
You must be signed in to change notification settings - Fork 366
Allow mode casting for Stores
#2249
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
Merged
Merged
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
efeb440
Allow mode casting
TomAugspurger 501f151
fixup
TomAugspurger b390d7d
Merge remote-tracking branch 'upstream/v3' into fix/modes
TomAugspurger 2ef51f7
fixup
TomAugspurger 3ee37f1
fixup
TomAugspurger 3fd8c46
Merge remote-tracking branch 'upstream/v3' into fix/modes
TomAugspurger 926c71a
fixup
TomAugspurger 7f173d2
match message
TomAugspurger f2fc9c2
Update src/zarr/testing/store.py
TomAugspurger 18ace67
Merge remote-tracking branch 'upstream/v3' into fix/modes
TomAugspurger 10d49c6
Merge remote-tracking branch 'refs/remotes/origin/fix/modes' into fix…
TomAugspurger 4c48a51
Merge remote-tracking branch 'upstream/v3' into fix/modes
TomAugspurger 92f6fec
fixup
TomAugspurger 109afd8
fixup
TomAugspurger f200830
Merge remote-tracking branch 'upstream/v3' into fix/modes
TomAugspurger d180720
fixup
TomAugspurger 3a02ee6
fixup
TomAugspurger a4f83fe
pre-commit
TomAugspurger a4dc888
log methods
TomAugspurger bb29be4
Merge branch 'v3' into fix/modes
jhamman b302a0f
style: pre-commit fixes
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
| from typing import TYPE_CHECKING, Self | ||
|
|
||
| from zarr.abc.store import ByteRangeRequest, Store | ||
| from zarr.core.buffer import Buffer, gpu | ||
|
|
@@ -41,6 +41,9 @@ async def empty(self) -> bool: | |
| async def clear(self) -> None: | ||
| self._store_dict.clear() | ||
|
|
||
| def with_mode(self, mode: AccessModeLiteral) -> Self: | ||
| return type(self)(store_dict=self._store_dict, mode=mode) | ||
|
|
||
| def __str__(self) -> str: | ||
| return f"memory://{id(self._store_dict)}" | ||
|
|
||
|
|
@@ -152,29 +155,58 @@ async def list_dir(self, prefix: str) -> AsyncGenerator[str, None]: | |
|
|
||
| class GpuMemoryStore(MemoryStore): | ||
| """A GPU only memory store that stores every chunk in GPU memory irrespective | ||
| of the original location. This guarantees that chunks will always be in GPU | ||
| memory for downstream processing. For location agnostic use cases, it would | ||
| be better to use `MemoryStore` instead. | ||
| of the original location. | ||
|
|
||
| The dictionary of buffers to initialize this memory store with *must* be | ||
| GPU Buffers. | ||
|
|
||
| Writing data to this store through ``.set`` will move the buffer to the GPU | ||
| if necessary. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| store_dict: MutableMapping, optional | ||
| A mutable mapping with string keys and :class:`zarr.core.buffer.gpu.Buffer` | ||
| values. | ||
| """ | ||
|
|
||
| _store_dict: MutableMapping[str, Buffer] | ||
| _store_dict: MutableMapping[str, gpu.Buffer] # type: ignore[assignment] | ||
|
|
||
| def __init__( | ||
| self, | ||
| store_dict: MutableMapping[str, Buffer] | None = None, | ||
| store_dict: MutableMapping[str, gpu.Buffer] | None = None, | ||
| *, | ||
| mode: AccessModeLiteral = "r", | ||
| ) -> None: | ||
| super().__init__(mode=mode) | ||
| if store_dict: | ||
| self._store_dict = {k: gpu.Buffer.from_buffer(store_dict[k]) for k in iter(store_dict)} | ||
| super().__init__(store_dict=store_dict, mode=mode) # type: ignore[arg-type] | ||
|
|
||
| def __str__(self) -> str: | ||
| return f"gpumemory://{id(self._store_dict)}" | ||
|
|
||
| def __repr__(self) -> str: | ||
| return f"GpuMemoryStore({str(self)!r})" | ||
|
|
||
| @classmethod | ||
| def from_dict(cls, store_dict: MutableMapping[str, Buffer]) -> Self: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this API! |
||
| """ | ||
| Create a GpuMemoryStore from a dictionary of buffers at any location. | ||
|
|
||
| The dictionary backing the newly created ``GpuMemoryStore`` will not be | ||
| the same as ``store_dict``. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| store_dict: mapping | ||
| A mapping of strings keys to arbitrary Buffers. The buffer data | ||
| will be moved into a :class:`gpu.Buffer`. | ||
|
|
||
| Returns | ||
| ------- | ||
| GpuMemoryStore | ||
| """ | ||
| gpu_store_dict = {k: gpu.Buffer.from_buffer(v) for k, v in store_dict.items()} | ||
| return cls(gpu_store_dict) | ||
|
|
||
| async def set(self, key: str, value: Buffer, byte_range: tuple[int, int] | None = None) -> None: | ||
| self._check_writable() | ||
| assert isinstance(key, str) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.