Skip to content

Add attributes property to Device - #1869

Merged
kmaehashi merged 11 commits into
cupy:masterfrom
grlee77:device_attributes
Dec 21, 2018
Merged

kmaehashi merged 11 commits into
cupy:masterfrom
grlee77:device_attributes

Conversation

@grlee77

@grlee77 grlee77 commented Dec 6, 2018

Copy link
Copy Markdown
Member

This PR adds a memoized attributes property to the Device class for easy querying of device attributes such as the maximum block size, etc.

The approach follows the suggestions made by @kmaehashi in #1867, although I am not certain if all of the changes are located in the expected files.

closes #1867

@hvy
hvy requested a review from kmaehashi December 7, 2018 02:20
@hvy

hvy commented Dec 7, 2018

Copy link
Copy Markdown
Member

@kmaehashi Could you take a look at the changes?

@kmaehashi kmaehashi self-assigned this Dec 7, 2018

@kmaehashi kmaehashi left a comment

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.

Thanks! LGTM except comments.

Comment thread cupy/cuda/__init__.py Outdated
name = k.replace('cudaDevAttr', '')
d[name] = runtime.deviceGetAttribute(v, device_id)
except runtime.CUDARuntimeError:
pass

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.

Reraise the warning if the error code is not cudaErrorInvalidValue.

Comment thread cupy/cuda/__init__.py Outdated
"""Return a dict containing all device attributes."""
d = {}
for k, v in runtime.__dict__.items():
if 'cudaDevAttr' in k:

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.

Use k.startswith('cudaDevAttr').

Comment thread cupy/cuda/__init__.py Outdated


@util.memoize()
def get_attributes_dict(device_id):

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 move this function to device.pyx and name it _get_attributes to make it explicitly private.

Comment thread cupy/cuda/runtime.pxd Outdated

errorMemoryAllocation = 2

cudaDevAttrMaxThreadsPerBlock = 1 # Maximum number of threads per block

@kmaehashi kmaehashi Dec 7, 2018 •

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.

Could you remove the comment part? (our coding rule (PEP8) requires max. 80 chars for each line)

Comment thread cupy/cuda/__init__.py Outdated
for k, v in runtime.__dict__.items():
if 'cudaDevAttr' in k:
try:
name = k.replace('cudaDevAttr', '')

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.

Use k.replace('cudaDevAttr', '', 1).

@kmaehashi kmaehashi added cat:enhancement Improvements to existing features cat:feature New features/APIs labels Dec 7, 2018
@kmaehashi

Copy link
Copy Markdown
Member

Could you try adding documentation for attributes property (like https://github.com/cupy/cupy/pull/1869/files#diff-161ddf2c99cd9824466401215e46e033R217), and also adding test code?

@grlee77

grlee77 commented Dec 9, 2018

Copy link
Copy Markdown
Member Author

Hi @kmaehashi . Thanks for the quick and helpful review!

I have implemented your suggestions and added some tests.

@kmaehashi

Copy link
Copy Markdown
Member

Thanks @grlee77! Will take a look.

This was renamed to _get_attributes and moved to device.pyx
@kmaehashi

Copy link
Copy Markdown
Member

LGTM!

Jenkins, test this please.

@kmaehashi kmaehashi added the st:test-and-merge (deprecated) Ready to merge after test pass. label Dec 21, 2018
@kmaehashi kmaehashi added this to the v6.0.0b2 milestone Dec 21, 2018
@kmaehashi kmaehashi removed the cat:enhancement Improvements to existing features label Dec 21, 2018
@chainer-ci

Copy link
Copy Markdown
Member

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

@kmaehashi kmaehashi changed the title add attributes property to Device Add attributes property to Device Dec 21, 2018
@kmaehashi
kmaehashi merged commit 4601204 into cupy:master Dec 21, 2018
@kmaehashi

Copy link
Copy Markdown
Member

@grlee77 Thanks!

@grlee77
grlee77 deleted the device_attributes branch December 31, 2018 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat:feature New features/APIs st:test-and-merge (deprecated) Ready to merge after test pass.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

easier way to query device attributes?

4 participants