Skip to content
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

【Error Message No. 221,225,286,288, BUAA】将CHECK宏进行替换 #66963

Merged
merged 3 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions test/auto_parallel/custom_op/custom_relu_op.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

#include "paddle/extension.h"

#define CHECK_GPU_INPUT(x) PD_CHECK(x.is_gpu(), #x " must be a GPU Tensor.")
#define CHECK_GPU_INPUT(x) \
PADDLE_ENFORCE_EQ( \
x.is_gpu(), true, common::errors::Fatal(#x " must be a GPU Tensor."))

template <typename data_t>
__global__ void relu_cuda_forward_kernel(const data_t* x,
Expand Down Expand Up @@ -42,7 +44,10 @@ std::vector<paddle::Tensor> relu_cuda_forward(const paddle::Tensor& x) {
CHECK_GPU_INPUT(x);
auto out = paddle::empty_like(x);

PD_CHECK(x.place() == paddle::DefaultGPUPlace());
PADDLE_ENFORCE_EQ(
x.place() == paddle::DefaultGPUPlace(),
true,
common::errors::InvalidArgument("Input tensor `x` should be on GPU"));

int64_t numel = x.numel();
int64_t block = 512;
Expand All @@ -64,7 +69,10 @@ std::vector<paddle::Tensor> relu_cuda_backward(const paddle::Tensor& x,
CHECK_GPU_INPUT(grad_out);
auto grad_x = paddle::empty_like(x);

PD_CHECK(x.place() == paddle::DefaultGPUPlace());
PADDLE_ENFORCE_EQ(
x.place() == paddle::DefaultGPUPlace(),
true,
common::errors::InvalidArgument("Input tensor `x` should be on GPU"));

int64_t numel = out.numel();
int64_t block = 512;
Expand Down
10 changes: 8 additions & 2 deletions test/cpp_extension/custom_relu_forward.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "paddle/common/enforce.h"
#include "paddle/extension.h"

#define CHECK_GPU_INPUT(x) PD_CHECK(x.is_gpu(), #x " must be a GPU Tensor.")
#define CHECK_GPU_INPUT(x) \
PADDLE_ENFORCE_EQ( \
x.is_gpu(), true, common::errors::Fatal(#x " must be a GPU Tensor."))

template <typename data_t>
__global__ void relu_cuda_forward_kernel(const data_t* x,
Expand All @@ -30,7 +33,10 @@ paddle::Tensor relu_cuda_forward(const paddle::Tensor& x) {
CHECK_GPU_INPUT(x);
auto out = paddle::empty_like(x);

PD_CHECK(x.place() == paddle::DefaultGPUPlace());
PADDLE_ENFORCE_EQ(
x.place() == paddle::DefaultGPUPlace(),
true,
common::errors::InvalidArgument("Input tensor `x` should be on GPU"));

int64_t numel = x.numel();
int64_t block = 512;
Expand Down
9 changes: 7 additions & 2 deletions test/custom_op/custom_inplace.cu
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

#include "paddle/extension.h"

#define CHECK_GPU_INPUT(x) PD_CHECK(x.is_gpu(), #x " must be a GPU Tensor.")
#define CHECK_GPU_INPUT(x) \
PADDLE_ENFORCE_EQ( \
x.is_gpu(), true, common::errors::Fatal(#x " must be a GPU Tensor."))

template <typename data_t>
__global__ void relu_cuda_forward_kernel(data_t* x, int64_t num) {
Expand All @@ -31,7 +33,10 @@ __global__ void relu_cuda_forward_kernel(data_t* x, int64_t num) {
void ReluForwardInplace(paddle::Tensor& x) { // NOLINT
CHECK_GPU_INPUT(x);

PD_CHECK(x.place() == paddle::DefaultGPUPlace());
PADDLE_ENFORCE_EQ(
x.place() == paddle::DefaultGPUPlace(),
true,
common::errors::InvalidArgument("Input tensor `x` should be on GPU"));

int64_t numel = x.numel();
int64_t block = 512;
Expand Down
14 changes: 11 additions & 3 deletions test/custom_op/custom_relu_op.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

#include "paddle/extension.h"

#define CHECK_GPU_INPUT(x) PD_CHECK(x.is_gpu(), #x " must be a GPU Tensor.")
#define CHECK_GPU_INPUT(x) \
PADDLE_ENFORCE_EQ( \
x.is_gpu(), true, common::errors::Fatal(#x " must be a GPU Tensor."))

template <typename data_t>
__global__ void relu_cuda_forward_kernel(const data_t* x,
Expand Down Expand Up @@ -55,7 +57,10 @@ std::vector<paddle::Tensor> relu_cuda_forward(const paddle::Tensor& x) {
CHECK_GPU_INPUT(x);
auto out = paddle::empty_like(x);

PD_CHECK(x.place() == paddle::DefaultGPUPlace());
PADDLE_ENFORCE_EQ(
x.place() == paddle::DefaultGPUPlace(),
true,
common::errors::InvalidArgument("Input tensor `x` should be on GPU"));

int64_t numel = x.numel();
int64_t block = 512;
Expand All @@ -77,7 +82,10 @@ std::vector<paddle::Tensor> relu_cuda_backward(const paddle::Tensor& x,
CHECK_GPU_INPUT(grad_out);
auto grad_x = paddle::empty_like(x);

PD_CHECK(x.place() == paddle::DefaultGPUPlace());
PADDLE_ENFORCE_EQ(
x.place() == paddle::DefaultGPUPlace(),
true,
common::errors::InvalidArgument("Input tensor `x` should be on GPU"));

int64_t numel = out.numel();
int64_t block = 512;
Expand Down