-
Notifications
You must be signed in to change notification settings - Fork 208
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
Throw rmm::out_of_memory
when we know for sure
#894
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -60,6 +60,26 @@ class bad_alloc : public std::bad_alloc { | |||||||
std::string _what; | ||||||||
}; | ||||||||
|
||||||||
/** | ||||||||
* @brief Exception thrown when RMM runs out of memory | ||||||||
* | ||||||||
* This is thrown under the following conditions: | ||||||||
* - For `arena_memory_resource`, when the global arena can no longer allocate more memory from | ||||||||
* upstream. | ||||||||
* - For `cuda_async_memory_resource`, when `cudaMallocFromPoolAsync` returns | ||||||||
* `cudaErrorMemoryAllocation`. | ||||||||
* - For `cuda_memory_resource`, when `cudaMalloc` returns `cudaErrorMemoryAllocation`. | ||||||||
* - For `limiting_resource_adapter`, when total allocated bytes exceeds the limit. | ||||||||
* - For `managed_memory_resource`, when `cudaMallocManaged` returns `cudaErrorMemoryAllocation`. | ||||||||
* - For `pool_memory_resource`, when the pool can no longer allocate more memory from upstream. | ||||||||
*/ | ||||||||
class out_of_memory : public bad_alloc { | ||||||||
public: | ||||||||
out_of_memory(const char* msg) : bad_alloc{msg} {} | ||||||||
out_of_memory(std::string const& msg) : bad_alloc{msg} {} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||||
using bad_alloc::bad_alloc; | ||||||||
jrhemstad marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
}; | ||||||||
|
||||||||
/** | ||||||||
* @brief Exception thrown when attempting to access outside of a defined range | ||||||||
* | ||||||||
|
@@ -167,6 +187,31 @@ class out_of_range : public std::out_of_range { | |||||||
} while (0) | ||||||||
#define RMM_CUDA_TRY_1(_call) RMM_CUDA_TRY_2(_call, rmm::cuda_error) | ||||||||
|
||||||||
/** | ||||||||
* @brief Error checking macro for CUDA memory allocation calls. | ||||||||
* | ||||||||
* Invokes a CUDA memory allocation function call. If the call does not return | ||||||||
* `cudaSuccess`, invokes cudaGetLastError() to clear the error and throws an | ||||||||
* exception detailing the CUDA error that occurred | ||||||||
* | ||||||||
* Defaults to throwing `rmm::bad_alloc`, but when `cudaErrorMemoryAllocation` is returned, | ||||||||
* `rmm::out_of_memory` is thrown instead. | ||||||||
*/ | ||||||||
#define RMM_CUDA_TRY_ALLOC(_call) \ | ||||||||
do { \ | ||||||||
cudaError_t const error = (_call); \ | ||||||||
if (cudaSuccess != error) { \ | ||||||||
cudaGetLastError(); \ | ||||||||
auto const msg = std::string{"CUDA error at: "} + __FILE__ + ":" + RMM_STRINGIFY(__LINE__) + \ | ||||||||
": " + cudaGetErrorName(error) + " " + cudaGetErrorString(error); \ | ||||||||
if (cudaErrorMemoryAllocation == error) { \ | ||||||||
throw rmm::out_of_memory{msg}; \ | ||||||||
} else { \ | ||||||||
throw rmm::bad_alloc{msg}; \ | ||||||||
} \ | ||||||||
} \ | ||||||||
} while (0) | ||||||||
|
||||||||
/** | ||||||||
* @brief Error checking macro similar to `assert` for CUDA runtime API calls | ||||||||
* | ||||||||
|
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 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 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
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.
I don't like having a list in a comment that we have to maintain. I think instead we should make it very clear that this error should only be thrown when we know for sure a resource is out of memory.
I don't know for sure that
cudaErrorMemoryAllocation
always means OOM, BTW. Is this documented somewhere?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.
Done.
According to the CUDA Runtime API doc: