-
Notifications
You must be signed in to change notification settings - Fork 919
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
Improve the capture of fatal cuda error #10884
Merged
rapids-bot
merged 12 commits into
rapidsai:branch-22.08
from
sperlingxx:catch_cuda_fatal_error
Jun 7, 2022
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
823b145
update
sperlingxx 404ce92
revert style
sperlingxx ef6e881
udpate
sperlingxx 3dcb354
udpate
sperlingxx e0d026f
udpate
sperlingxx b610762
udpate
sperlingxx 7e66695
update
sperlingxx b91e248
update
sperlingxx ac595a2
update
sperlingxx 61058af
remove lines
sperlingxx 3af3cc8
Merge remote-tracking branch 'origin/branch-22.06' into catch_cuda_fa…
sperlingxx 182c15d
Merge remote-tracking branch 'origin/branch-22.08' into catch_cuda_fa…
sperlingxx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (c) 2021-2022, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package ai.rapids.cudf; | ||
|
||
import org.junit.jupiter.api.*; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
// Add prefix zzz to ensure this test suite being executed behind all other tests. Because this | ||
// suite will cause a fatal cuda error which disables the whole device. | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
public class zzzCudaTest { | ||
|
||
@Test | ||
@Order(1) | ||
public void testGetCudaRuntimeInfo() { | ||
// The driver version is not necessarily larger than runtime version. Drivers of previous | ||
// version are also able to support runtime of later version, only if they support same | ||
// kinds of computeModes. | ||
assert Cuda.getDriverVersion() >= 1000; | ||
assert Cuda.getRuntimeVersion() >= 1000; | ||
assertEquals(Cuda.getNativeComputeMode(), Cuda.getComputeMode().nativeId); | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
public void testCudaException() { | ||
assertThrows(CudaException.class, () -> { | ||
try { | ||
Cuda.memset(Long.MAX_VALUE, (byte) 0, 1024); | ||
} catch (CudaFatalException ignored) { | ||
} catch (CudaException ex) { | ||
assertEquals(CudaException.CudaError.cudaErrorInvalidValue, ex.cudaError); | ||
throw ex; | ||
} | ||
} | ||
); | ||
// non-fatal CUDA error will not fail subsequent CUDA calls | ||
try (ColumnVector cv = ColumnVector.fromBoxedInts(1, 2, 3, 4, 5)) { | ||
} | ||
} | ||
|
||
@Test | ||
@Order(3) | ||
public void testCudaFatalException() { | ||
try (ColumnView cv = ColumnView.fromDeviceBuffer(new BadDeviceBuffer(), 0, DType.INT8, 256); | ||
ColumnView ret = cv.sub(cv); | ||
HostColumnVector hcv = ret.copyToHost()) { | ||
} catch (CudaException ignored) { | ||
} | ||
|
||
// CUDA API invoked by libcudf failed because of previous unrecoverable fatal error | ||
assertThrows(CudaFatalException.class, () -> { | ||
try (ColumnView cv = ColumnView.fromDeviceBuffer(new BadDeviceBuffer(), 0, DType.INT8, 256); | ||
HostColumnVector hcv = cv.copyToHost()) { | ||
} catch (CudaFatalException ex) { | ||
assertEquals(CudaException.CudaError.cudaErrorIllegalAddress, ex.cudaError); | ||
throw ex; | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
@Order(4) | ||
public void testCudaFatalExceptionFromRMM() { | ||
// CUDA API invoked by RMM failed because of previous unrecoverable fatal error | ||
assertThrows(CudaFatalException.class, () -> { | ||
try (ColumnVector cv = ColumnVector.fromBoxedInts(1, 2, 3, 4, 5)) { | ||
} catch (CudaFatalException ex) { | ||
assertEquals(CudaException.CudaError.cudaErrorIllegalAddress, ex.cudaError); | ||
throw ex; | ||
} | ||
}); | ||
} | ||
|
||
private static class BadDeviceBuffer extends BaseDeviceMemoryBuffer { | ||
public BadDeviceBuffer() { | ||
super(256L, 256L, (MemoryBufferCleaner) null); | ||
} | ||
|
||
@Override | ||
public MemoryBuffer slice(long offset, long len) { | ||
return null; | ||
} | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Wait, what? The two calls are necessary to detect a fatal error vs a non-fatal. The first call clears any pending error state. If the second call still sees an error, then it's extremely likely that a sticky error has occurred.
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.
While the test case of fatal error can only be passed when I remove this line.
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.
Agree that this seems like a dubious change. What specifically fails with the test without this change? Does it throw too early, in
cudf::binary_operation
or not throw at all? If the error is truly fatal, I don't see how removing acudaGetLastError
call is going to help this test pass. With a fatal error, we should be able to callcudaGetLastError
as many times as we want, and it will never clear.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.
Then that means the error being generated isn't a true sticky error, which is admittedly surprising with the test you're doing here I'd expect an illegal access error (which I'm pretty sure is sticky).
You could condense this down a bit by just launching a kernel like:
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.
Though you'd need to do this in a death test because it will corrupt the process context and leave the GPU unusable. See
cudf/cpp/tests/error/error_handling_test.cu
Lines 89 to 111 in 1db83e3
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'm still not comfortable with removing a line of code without understanding why we're removing it. It may have helped your test case, but we need to understand how that was significant for that test (is it a problem with the test?) or how removing this will not create problems in other scenarios trying to detect fatal errors. If the CUDA error truly is fatal, it should not matter if we read the error an extra time. It should make it even more likely it truly is a fatal error if the error persists despite extra attempts at clearing it.
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.
Hi @jlowe, according to the description in CUDA doc:
Returns the last error that has been produced by any of the runtime calls in the same host thread and resets it to cudaSuccess
, the cudaGetLastError API works like popping the top error from the CUDA error stack ?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.
Yes, normally it clears the error, but there are categories of errors that are unclearable. These are the fatal errors we are trying to detect here. If you're finding that
cudaGetLastError
is able to clear an error then it seems that error is not actually a fatal error and we should not report it as such.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.
@sperlingxx see https://stackoverflow.com/questions/31642520/states-of-memory-data-after-cuda-exceptions/31642573#31642573
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.
Hi @jrhemstad, thank you for the link. However, my simple test suggests the second call of
cudaGetLastError
cleans up fatal errors as well, if I don't misunderstand anything.