-
-
Notifications
You must be signed in to change notification settings - Fork 955
Solve UnboundLocalError on copy_from_host_async #4900
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
Conversation
As discussed on cupy#4898
Apparently we missed this because there's no test covering any @viantirreau is it possible for you to follow #4562 and add async tests? It should be sufficient to duplicate existing tests with streams. (Even better: parametrize the tests with and without streams.) Let me know if you need any help or me taking over the test part (since it was me who messed up 😅), thanks! |
cupy/cuda/memory.pyx
Outdated
The default uses CUDA stream of the current context. | ||
""" | ||
ptr = mem if isinstance(mem, int) else mem.value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked. Could you move this line to the if size > 0:
block below? This would align with the other function copy_to_host_async
in the same file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem!
I will work on this tonight :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets delete it in +473, now is dupped :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops 😆
Just a heads-up. I'm not very acquainted with Python tests, especially regarding GPUs 😆
By parametrized you mean using the decorator? If that's the case, I was thinking about creating a class especially for the async methods, something in the lines of @testing.parameterize(*testing.product({
'use_streams': [True, False],
}))
@testing.gpu
class TestMemoryPointerAsync(unittest.TestCase):
def setUp(self):
self.stream = stream_module.Stream() if self.use_streams else None
def test_copy_to_and_from_host_async_using_raw_ptr(self):
a_gpu = memory.alloc(4)
a_cpu = ctypes.c_int(100)
a_cpu_ptr = ctypes.cast(ctypes.byref(a_cpu), ctypes.c_void_p)
a_gpu.copy_from_async(a_cpu_ptr.value, 4, stream=self.stream)
b_cpu = ctypes.c_int()
b_cpu_ptr = ctypes.cast(ctypes.byref(b_cpu), ctypes.c_void_p)
a_gpu.copy_to_host_async(b_cpu_ptr.value, 4, stream=self.stream)
assert b_cpu.value == a_cpu.value
def test_copy_from_device_async_using_raw_ptr(self):
a_gpu = memory.alloc(4)
a_cpu = ctypes.c_int(100)
a_cpu_ptr = ctypes.cast(ctypes.byref(a_cpu), ctypes.c_void_p)
a_gpu.copy_from_async(a_cpu_ptr.value, 4, stream=self.stream)
b_gpu = memory.alloc(4)
b_gpu.copy_from_async(a_gpu, 4, stream=self.stream)
b_cpu = ctypes.c_int()
b_cpu_ptr = ctypes.cast(ctypes.byref(b_cpu), ctypes.c_void_p)
b_gpu.copy_to_host_async(b_cpu_ptr.value, 4, stream=self.stream)
assert b_cpu.value == a_cpu.value When defining PS: I'm now thinking that I could just parametrize the existing |
Ended up copying other two synchronous tests and I confirmed that all of them are passing in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot, @viantirreau! I think it makes sense to isolate async tests to a separate class. Just left a few comments, mainly to ensure no race condition happens.
Co-authored-by: Leo Fang <[email protected]>
Co-authored-by: Leo Fang <[email protected]>
Co-authored-by: Leo Fang <[email protected]>
Co-authored-by: Leo Fang <[email protected]>
Co-authored-by: Leo Fang <[email protected]>
Co-authored-by: Leo Fang <[email protected]>
Co-authored-by: Leo Fang <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks again for reporting the bug and for contributing the fix.
Jenkins, test this please |
Wooow! That's a great tip hahaha. Thanks for your help, I enjoyed the challenge :) |
Another tip: @viantirreau you can edit your PR description to include this clause "Close #4898". By the time your PR is merged, the issue will be automatically closed. A GitHub convenience feature. |
Note: I confirm locally that the added tests in this PR would fail if the bug were not fixed. |
Jenkins CI test (for commit 2e4c2b3, target branch master) succeeded! |
@emcastillo Automerge seems to be glitchy? |
Close #4898