-
Notifications
You must be signed in to change notification settings - Fork 710
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a0b36a
commit ce283ff
Showing
4 changed files
with
41 additions
and
37 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
#include <sstream> | ||
#include <torch/extension.h> | ||
|
||
struct cuda_error : public std::runtime_error { | ||
/** | ||
* @brief Constructs a `cuda_error` object with the given `message`. | ||
* | ||
* @param message The error char array used to construct `cuda_error` | ||
*/ | ||
cuda_error(const char* message) : std::runtime_error(message) {} | ||
/** | ||
* @brief Constructs a `cuda_error` object with the given `message` string. | ||
* | ||
* @param message The `std::string` used to construct `cuda_error` | ||
*/ | ||
cuda_error(std::string const& message) : cuda_error{message.c_str()} {} | ||
}; | ||
|
||
#define CHECK_CUDA_SUCCESS(cmd) \ | ||
do { \ | ||
cudaError_t e = cmd; \ | ||
if (e != cudaSuccess) { \ | ||
std::stringstream _message; \ | ||
auto s = cudaGetErrorString(e); \ | ||
_message << std::string(s) + "\n" << __FILE__ << ':' << __LINE__; \ | ||
throw cuda_error(_message.str()); \ | ||
} \ | ||
} while (0) | ||
|
||
#define CHECK_IS_CUDA(x) TORCH_CHECK(x.device().is_cuda(), #x " must be a CUDA tensor") | ||
#define CHECK_IS_CONTIGUOUS(x) TORCH_CHECK(x.is_contiguous(), #x " must be contiguous") | ||
#define CHECK_CUDA_INPUT(x) \ | ||
CHECK_IS_CUDA(x); \ | ||
CHECK_IS_CONTIGUOUS(x) |
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