Repository navigation
Conversation
fmassa
left a comment
There was a problem hiding this comment.
This looks interesting, thanks for the PR!
I'm just a bit concerned about the perf implications on the indexing kernels on the GPU.
Once we address the sync points there due to cudaFree, do you think the overhead of move_status_to_host(&hs, ds); will be significant?
cc @umanwizard
| static void move_status_to_host(status_t *host_status, status_t *device_status) { | ||
| cudaError_t err; | ||
| err = cudaMemcpy(host_status, device_status, sizeof *host_status, cudaMemcpyDeviceToHost); | ||
| AT_CUDA_CHECK(cudaFree(device_status)); |
There was a problem hiding this comment.
This will imply a sync point in every call to gpu_index_kernel, which will not be great for performance reasons.
We used to have THCudaMemCpy and THCudaFree, but things have changed with the caching allocator and I'm not sure what's the recommended way anymore.
| AT_CUDA_CHECK(cudaMalloc(&status, sizeof *status)); | ||
| err = cudaMemset(status, 0, sizeof *status); | ||
| if (err != cudaSuccess) { | ||
| AT_CUDA_CHECK(cudaFree(status)); |
There was a problem hiding this comment.
same comment here about the sync point
|
We do introduce an extra devicetohost copy, which will slow things down. |
|
Hi @skrah! This is a really interesting patch. We had some internal discussion about it, which I'm going to summarize here: First, we are pretty sure (from @soumith) that this patch is very bad for CUDA perf, so we can't take it as is. All kernel launches would become synchronous because of the device -> host transfer after every launch. Some simple benchmarking should make this obvious. However, @pietern had a very interesting idea: if we associated some pinned memory with every device (stream?) and used that to communicate the information asynchronously? Then, while we wouldn't report information at exactly the correct call site, we would still be able to report detailed information about the failure with negligible perf impact. Then we could stop using device asserts, which is something people complain about a lot. We could record an event for every kernel launch to coordinate when you can read the host side memory for assertion failures. @colesbury pointed out that you may have a bunch of operations dependent on garbage before the asynchronous error is processed, and these may fail in strange ways. This is why device side asserts require a CUDA context reset. However, it might be OK, if you audit all the kernels that can have data dependent failures and ensure they fail in a nice way. You can imagine some strange behavior if the result of a failed indexing operation is copied to the CPU and used there. With device side asserts you'll at least get the failure during the copy. But with the asynchronous errors it would be difficult to ensure that asynchronous error is processed before something on the CPU operates on the data. It might still be worth it, even if some failure modes are slightly more confusing. @pietern finally suggested, you could work around that by maintaining these error structs on a per stream basis and returning early from every kernel if some error is set. Doesn’t solve the problem for cross stream synchronization, and is a bit kludgy but does the trick for 95% of the use cases. Stepping back a moment, I don't think there is any reason we shouldn't take this patch as is for CPU. So if you want to split this into CPU and CUDA bits, we can go ahead and land the CPU parts first. |
|
Hi @fmassa @ezyang, thanks for your detailed comments! Before @ezyang's message I had been looking at alternative approaches. One (not very elegant) way of eliminating the I've added a proof of concept in the latest revision (it also uses a caching allocator), but I'm absolutely not sure if it is a good idea. Short isolated benchmarks don't show much of an impact of The approach also still has Using some "error memory" allocated at a higher level in the call chain like @pietern suggested looks more solid. I can refactor the PR to CPU-only and then proceed later with the GPU related issues. |
| if (dim_post_expr <= 0) { | ||
| AT_CHECK(wrap_scalar, "dimension specified as ", dim, " but tensor has no dimensions"); | ||
| if (!wrap_scalar) { | ||
| AT_INDEX_ERROR("dimension specified as ", dim, " but tensor has no dimensions"); |
There was a problem hiding this comment.
this changes this case of operating over an invalid dimension to be an AT_INDEX_ERROR, but the case below isn't changed.
There was a problem hiding this comment.
Thanks, done in #17114!
I think there are more cases in src/ATen/WrapDimUtils.h; unfortunately these affect test_sparse and it is not always clear to me whether ValueError or IndexError should be raised. In test_indexing the choice was straightforward except for one case where NumPy raises ValueError (I marked that one in a comment).
|
"But with the asynchronous errors it would be difficult to ensure that asynchronous error is processed before something on the CPU operates on the data." "... maintaining these error structs on a per stream basis and returning early from every kernel if some error is set." @ezyang On the surface it seems that there are some parallels to quiet Would the concept of The obvious drawback is that, like in a floating point library, all functions that operate on Tensors would need to start with In the CPU space If that assumption is correct, this scheme would use sync points that arise naturally in an application. |
|
Hi @skrah. I suppose the distinction you are making is, whether or not this error reporting should be associated with a stream (similar to the assert failure we have today, but without totally nuking your CUDA context) or with tensors in a data dependent way (your not a tensor proposal). To me, it seems like the former would be a strict improvement to the situation today (yes, unrelated operations might fail, but at least your interactive session is still working!) whereas the latter might lead to better user experience, but at the cost of substantial complexity and different API tradeoffs:
To me, it makes sense to do a much more (semantically) conservative change to get us a fix for #17425 (and also accurately report IndexError) and not go down the path of NaT. |
| f(out_data, in_data, offset); | ||
| }); | ||
|
|
||
| if (cudaPeekAtLastError() != cudaSuccess) { |
There was a problem hiding this comment.
What makes sure that every assert(0) 'break' inside the async-kernel execution is trapped? Isn't the kernel launched for aync-execution andcudaPeekAtLastError() might miss internal assert() calls?
There is no assurance. But |
|
Hi @skrah! Thank you for your pull request. We require contributors to sign our Contributor License Agreement, and yours needs attention. You currently have a record in our system, but we do not have a signature on file. In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
|
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
I think this PR needs some background information why certain choices were made.
I briefly tried to address this issue directly in
autograd/python_variable_indexing.cpp. However, advanced indexing is so complex that alsoNumPydetects the out-of-bounds conditions inloops.c.That leaves us with a fix in
ATen.The PR introduces
c10::IndexErrorthat inherits fromc10::Error, so that existing code still catches the new exception.For the
CPUthe fixes inATenare straightforward.For
CUDAthe kernelassert(), which translates to aRuntimeErrorwithout detailed information, is replaced by a struct that records the error message details from the first thread that encounters an out-of-bounds condition. The struct is copied back to the host afterlaunch_kernelhas finished and checked for errors.I've tried other schemes of information exchange between the kernel and the host, in particular the closure can capture a pointer to a
cuda::Array. However, with that scheme I haven't managed to get error data back to the host in a reliable manner.