Skip to content

Allow getting and setting CUDA kernel attributes#2369

Merged
emcastillo merged 16 commits intocupy:masterfrom
leofang:function-attributes
Aug 13, 2019
Merged

Allow getting and setting CUDA kernel attributes#2369
emcastillo merged 16 commits intocupy:masterfrom
leofang:function-attributes

Conversation

@leofang
Copy link
Copy Markdown
Member

@leofang leofang commented Aug 8, 2019

Takeover of #2120 (which in turn was based on #1874) as @andravin lost interest 😢

Resolves #2118.

Most of the credit goes to @grlee77 and @andravin. I took over as we really need the ability of setting shared memory size for CUDA kernels. I'd like to see this capability merged asap if possible.

Changes compared to #2120:

  • The FunctionAttributes class is removed. Instead, all function attributes are also RawKernel's attributes now. First, I don't like the idea of having a Python object living in a cdef'd class just for accessing attributes. As suggested in Setting CUDA function attributes #2118 (comment):

...one way to clean up all this attributes stuff without breaking backwards compatibility is to add the "properties" directly to the RawKernel and Device classes. It makes literal sense that function-attributes should be properties of the RawKernel class, and device-attributes should be properties of the Device class.

Second, I don't want to retrieve attributes through a non-standard object. Finally, the current implementation (using @property and @attribute.setter) is more pythonic, even if it's written in Cython.

  • RawKernel.attributes now returns a dict of attributes, as suggested by CuPy core dev earlier. This behavior not only avoids the second concern above, but is also in line with cupy.cuda.device.Device().attributes. (However, this is read-only, and to set the attributes one needs to access the target attribute of RawKernel directly.)
  • The tutorial for RawKernel is updated
  • The test is updated to reflect the change

grlee77 and others added 14 commits December 8, 2018 21:34
add a FuncAttributes class to store all kernel attributes

add an attributes property to the RawKernel class. This can be used to query the register
and memory usage of the kernel.
refactor attributes test as a separate test case

memoize the kernel attributes.
build the dictionary within raw.pyx instead
Moved RawKernel kernel generation into a property to facilitate re-use.
Fixed formatting.
Fixed python 2.x compatibility by making descriptors "new style" classes.
Copy link
Copy Markdown
Member

@emcastillo emcastillo left a comment

Choose a reason for hiding this comment

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

LGTM

@emcastillo
Copy link
Copy Markdown
Member

We are solving some CI related issues so the merge will take a bit.

@emcastillo emcastillo added the cat:feature New features/APIs label Aug 8, 2019
@emcastillo emcastillo added this to the v7.0.0b3 milestone Aug 8, 2019
@grlee77
Copy link
Copy Markdown
Member

grlee77 commented Aug 8, 2019

Thanks for updating & reviving this PR @leofang.

@emcastillo
Copy link
Copy Markdown
Member

Jenkins, test this please

@chainer-ci
Copy link
Copy Markdown
Member

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

@emcastillo
Copy link
Copy Markdown
Member

emcastillo commented Aug 9, 2019

CI has a related failure

uilding 'cupy.cuda.driver' extension
11:11:29     x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -D_FORCE_INLINES=1 -I/usr/local/cuda/include -I/usr/include/python3.5m -c cupy/cuda/driver.cpp -o build/temp.linux-x86_64-3.5/cupy/cuda/driver.o
11:11:29     cc1plus: warning: command line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++
11:11:29     cupy/cuda/driver.cpp: In function 'PyObject* __pyx_f_4cupy_4cuda_6driver_funcSetAttribute(intptr_t, int, int, int)':
11:11:29     cupy/cuda/driver.cpp:4968:133: error: 'cuFuncSetAttribute' was not declared in this scope
11:11:29              __pyx_v_status = cuFuncSetAttribute(((struct CUfunc_st*)__pyx_v_f), ((CUfunction_attribute)__pyx_v_attribute), __pyx_v_value);
11:11:29                                                                                                                                          ^
11:11:29     error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
11:11:29     

https://jenkins.preferred.jp/job/chainer/job/cupy_pr/252/TEST=cupy-example,label=mn1-p100/console

This is happening only with python2
Maybe some Cython incompatibility?

@leofang
Copy link
Copy Markdown
Member Author

leofang commented Aug 9, 2019

@emcastillo what's the version of Cython used in that build? I can't reproduce this error locally in a py27 env.

@leofang
Copy link
Copy Markdown
Member Author

leofang commented Aug 9, 2019

I guess it's caused by Cython, not by Python version. It also failed on py35:
https://jenkins.preferred.jp/job/chainer/job/cupy_pr/252/TEST=cupy-doc,label=mn1-p100/console

@emcastillo
Copy link
Copy Markdown
Member

Let me confirm it tomorrow!

Sorry and thanks!

@leofang
Copy link
Copy Markdown
Member Author

leofang commented Aug 9, 2019

Sure, no worries!

@leofang leofang mentioned this pull request Aug 9, 2019
@emcastillo
Copy link
Copy Markdown
Member

should be 0.28.3

@leofang
Copy link
Copy Markdown
Member Author

leofang commented Aug 10, 2019

Tried 0.28.3, worked fine. I am now guessing earlier CUDA versions do not provide cuFuncSetAttribute. @emcastillo can you check for me what's the CUDA version in the failing builds?

@leofang
Copy link
Copy Markdown
Member Author

leofang commented Aug 10, 2019

It seems cuFuncSetAttribute starts in CUDA v9.0.

@leofang
Copy link
Copy Markdown
Member Author

leofang commented Aug 10, 2019

Please rerun Jenkins for me. Thanks.

@leofang
Copy link
Copy Markdown
Member Author

leofang commented Aug 10, 2019

I am now guessing earlier CUDA versions do not provide cuFuncSetAttribute.

It seems cuFuncSetAttribute starts in CUDA v9.0.

I forgot that I can check it myself! Yeah I think this is the reason. From cupy-py2:

22:11:46     Modules:
22:11:46       cuda      : Yes (version 8000)
22:11:46       cudnn     : Yes (version 5110)

From cupy-doc:

22:11:29     Modules:
22:11:29       cuda      : Yes (version 8000)
22:11:29       cudnn     : Yes (version 6021)

Commit 38fcde8 should fix the problem.

@emcastillo
Copy link
Copy Markdown
Member

Jenkins, test this please

@chainer-ci
Copy link
Copy Markdown
Member

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

@leofang
Copy link
Copy Markdown
Member Author

leofang commented Aug 11, 2019

cupy-py3 errors seem irrelevant. cupy-doc should be fixed in 419711a by skipping doctests. The result varies system by system.

@emcastillo
Copy link
Copy Markdown
Member

Jenkins, test this please

@chainer-ci
Copy link
Copy Markdown
Member

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

@emcastillo
Copy link
Copy Markdown
Member

Failures are unrelated

@emcastillo emcastillo merged commit 66aee51 into cupy:master Aug 13, 2019
@leofang
Copy link
Copy Markdown
Member Author

leofang commented Aug 13, 2019

Thank you, @emcastillo, @andravin, and @grlee77 !

@leofang leofang deleted the function-attributes branch August 13, 2019 14:25
@leofang leofang restored the function-attributes branch August 13, 2019 14:25
@leofang leofang deleted the function-attributes branch August 13, 2019 14:35
@leofang leofang mentioned this pull request Sep 5, 2019
9 tasks
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.

Setting CUDA function attributes

5 participants