Skip to content

Add APIs for creating NumPy arrays backed by pinned memory#4870

Merged
mergify[bot] merged 20 commits intocupy:masterfrom
leofang:pinned_arrays
Apr 19, 2021
Merged

Add APIs for creating NumPy arrays backed by pinned memory#4870
mergify[bot] merged 20 commits intocupy:masterfrom
leofang:pinned_arrays

Conversation

@leofang
Copy link
Copy Markdown
Member

@leofang leofang commented Mar 11, 2021

Close #3625.

This PR adds a few convenience functions to the cupyx namespace for allocating NumPy arrays backed by pinned/pagelocked memory, see the discussion around #3625 (comment). Currently the provided APIs are as follows:

  • cupyx.empty_pinned()
  • cupyx.empty_like_pinned()
  • cupyx.zeros_pinned()
  • cupyx.zeros_like_pinned()

with exactly the semantics as their NumPy counterparts.

Ideally, we can do better than this if we use NumPy's memory hooks to always allocate NumPy arrays from pinned memory (numpy/numpy#17467), however it's still a WIP, so we can only revisit it when it's in.

TODO:

  • Decide if the name/API is appropriate or not
  • Add docstrings
  • Fix order = 'K'
  • Add tests

leofang added 2 commits March 14, 2021 17:12
TODO: mention it in memory tutorial/reference and else where
@leofang

This comment has been minimized.

@kmaehashi kmaehashi self-assigned this Mar 15, 2021
@kmaehashi kmaehashi added cat:feature New features/APIs prio:medium labels Mar 15, 2021
@leofang leofang changed the title [WIP] Add APIs for creating NumPy arrays backed by pinned memory Add APIs for creating NumPy arrays backed by pinned memory Mar 15, 2021
@leofang leofang marked this pull request as ready for review March 15, 2021 17:10
@leofang
Copy link
Copy Markdown
Member Author

leofang commented Mar 15, 2021

Help needed: I am writing tests and I noticed @testing.numpy_cupy_array_equal() does not work for this PR, because we are comparing two numpy.ndarrays which breaks the assumption of this test utility. Any advice?

So I wrote a decorator @numpy_cupyx_array_equal() to address this need. The tests added in the new tests/cupyx_tests/test_pinned_array.py largely follows tests/cupy_tests/creation_tests/test_basic.py for the four added functions, with this decorator change and some other necessary but minor changes.

@leofang
Copy link
Copy Markdown
Member Author

leofang commented Mar 15, 2021

Flake8 error will be fixed in #4888.

@leofang
Copy link
Copy Markdown
Member Author

leofang commented Mar 15, 2021

Jenkins, test this please

@chainer-ci
Copy link
Copy Markdown
Member

Jenkins CI test (for commit e5f357b, target branch master) failed with status FAILURE.

@leofang
Copy link
Copy Markdown
Member Author

leofang commented Mar 15, 2021

Jenkins, test this please

@chainer-ci
Copy link
Copy Markdown
Member

Jenkins CI test (for commit 31d2338, target branch master) succeeded!

@chainer-ci
Copy link
Copy Markdown
Member

Jenkins CI test (for commit c6804a8, target branch master) succeeded!

@leofang
Copy link
Copy Markdown
Member Author

leofang commented Mar 23, 2021

@kmaehashi Errors are due to OSError: [Errno 28] No space left on device.

@kmaehashi
Copy link
Copy Markdown
Member

I've freed up some space now.

pfnCI, test this please.

@chainer-ci
Copy link
Copy Markdown
Member

Jenkins CI test (for commit c6804a8, target branch master) succeeded!

@leofang
Copy link
Copy Markdown
Member Author

leofang commented Mar 23, 2021

hmmm...I wonder why Jenkins still shows a red cross despite chainer ci says success?

@kmaehashi
Copy link
Copy Markdown
Member

It seems Jenkins github plugin was using deprecated github APIs and now they're removed. I bumped the plugin version so it should work now.

@jakirkham
Copy link
Copy Markdown
Member

Jenkins, test this please

@chainer-ci
Copy link
Copy Markdown
Member

Jenkins CI test (for commit c6804a8, target branch master) succeeded!

@leofang
Copy link
Copy Markdown
Member Author

leofang commented Mar 28, 2021

Resolved conflicts.

Jenkins, test this please

@chainer-ci
Copy link
Copy Markdown
Member

Jenkins CI test (for commit 500d53c, target branch master) failed with status FAILURE.

@leofang
Copy link
Copy Markdown
Member Author

leofang commented Mar 29, 2021

Jenkins, test this please

@chainer-ci
Copy link
Copy Markdown
Member

Jenkins CI test (for commit cc6fe6c, target branch master) succeeded!

@leofang
Copy link
Copy Markdown
Member Author

leofang commented Apr 2, 2021

@kmaehashi as mentioned I'd love to have this PR backported 🙏

@leofang
Copy link
Copy Markdown
Member Author

leofang commented Apr 19, 2021

Jenkins, test this please

Copy link
Copy Markdown
Member

@kmaehashi kmaehashi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@kmaehashi kmaehashi added this to the v10.0.0a1 milestone Apr 19, 2021
@kmaehashi kmaehashi added st:test-and-merge (deprecated) Ready to merge after test pass. to-be-backported Pull-requests to be backported to stable branch labels Apr 19, 2021
@chainer-ci
Copy link
Copy Markdown
Member

Jenkins CI test (for commit cc6fe6c, target branch master) succeeded!

@mergify mergify bot merged commit 81431e5 into cupy:master Apr 19, 2021
chainer-ci pushed a commit to chainer-ci/cupy that referenced this pull request Apr 19, 2021
Add APIs for creating NumPy arrays backed by pinned memory
@leofang leofang deleted the pinned_arrays branch April 19, 2021 06:36
@leofang
Copy link
Copy Markdown
Member Author

leofang commented Apr 19, 2021

Thanks, @kmaehashi and @jakirkham!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat:feature New features/APIs prio:medium st:test-and-merge (deprecated) Ready to merge after test pass. to-be-backported Pull-requests to be backported to stable branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pinned memory allocation returns odd size

4 participants