Skip to content

Introduce cupy.is_available()#247

Merged
okuta merged 3 commits intocupy:masterfrom
niboshi:cupy-available
Jul 13, 2017
Merged

Introduce cupy.is_available()#247
okuta merged 3 commits intocupy:masterfrom
niboshi:cupy-available

Conversation

@niboshi
Copy link
Copy Markdown
Member

@niboshi niboshi commented Jul 4, 2017

Currently, chainer.cuda.available is True even if there is no available CUDA device (by setting CUDA_VISIBLE_DEVICES=-1).
In order to avoid that, this PR introduces cupy.available cupy.is_available() which takes account of device availability.

(Corresponding issue in PyTorch: pytorch/pytorch#306)

@niboshi niboshi added the cat:feature New features/APIs label Jul 4, 2017
import nose
import os
import subprocess
import shutil
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please order import.

@niboshi
Copy link
Copy Markdown
Member Author

niboshi commented Jul 9, 2017

Fixed.

@okuta okuta self-assigned this Jul 11, 2017
@okuta okuta added this to the v2.0.0b1 milestone Jul 11, 2017
@niboshi niboshi force-pushed the cupy-available branch 2 times, most recently from d23d32c to 47e18dc Compare July 11, 2017 15:54
@niboshi
Copy link
Copy Markdown
Member Author

niboshi commented Jul 11, 2017

It seems calling runtime.getDeviceCount() in the module-level code of cupy/cuda/__init__.py causes problem in multi-process environment.
I fixed it by deferring the call with a function (cupy.is_available()) insted of a flag (cupy.available).

@niboshi
Copy link
Copy Markdown
Member Author

niboshi commented Jul 11, 2017

Perhaps chainer.cuda.available should also be deferred. That would be a compatibility-breaking change.

@niboshi niboshi changed the title Introduce cupy.available Introduce cupy.is_available() Jul 12, 2017


def is_available():
return cuda.is_available()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about caching this result.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.

@okuta
Copy link
Copy Markdown
Member

okuta commented Jul 13, 2017

LGTM!

@okuta okuta merged commit 3196d0c into cupy:master Jul 13, 2017
@niboshi niboshi deleted the cupy-available branch October 24, 2017 07:31
kmaehashi added a commit to kmaehashi/cupy that referenced this pull request Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat:feature New features/APIs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants