Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions paddle/phi/kernels/cpu/isfinite_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,12 @@ INSTANTIATE_ISFINITE_KERNEL_Isinf(int, CPUContext);
INSTANTIATE_ISFINITE_KERNEL_Isinf(int64_t, CPUContext);
INSTANTIATE_ISFINITE_KERNEL_Isinf(phi::float16, CPUContext);
INSTANTIATE_ISFINITE_KERNEL_Isinf(phi::bfloat16, CPUContext);

INSTANTIATE_ISFINITE_KERNEL_Isfinite(float, CPUContext);
INSTANTIATE_ISFINITE_KERNEL_Isfinite(double, CPUContext);
INSTANTIATE_ISFINITE_KERNEL_Isfinite(int, CPUContext);
INSTANTIATE_ISFINITE_KERNEL_Isfinite(int64_t, CPUContext);
INSTANTIATE_ISFINITE_KERNEL_Isfinite(phi::float16, CPUContext);
INSTANTIATE_ISFINITE_KERNEL_Isfinite(phi::bfloat16, CPUContext);
} // namespace phi
#endif
7 changes: 7 additions & 0 deletions paddle/phi/kernels/gpu/isfinite_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,12 @@ INSTANTIATE_ISFINITE_KERNEL_Isinf(int, GPUContext);
INSTANTIATE_ISFINITE_KERNEL_Isinf(int64_t, GPUContext);
INSTANTIATE_ISFINITE_KERNEL_Isinf(phi::float16, GPUContext);
INSTANTIATE_ISFINITE_KERNEL_Isinf(phi::bfloat16, GPUContext);

INSTANTIATE_ISFINITE_KERNEL_Isfinite(float, GPUContext);
INSTANTIATE_ISFINITE_KERNEL_Isfinite(double, GPUContext);
INSTANTIATE_ISFINITE_KERNEL_Isfinite(int, GPUContext);
INSTANTIATE_ISFINITE_KERNEL_Isfinite(int64_t, GPUContext);
INSTANTIATE_ISFINITE_KERNEL_Isfinite(phi::float16, GPUContext);
INSTANTIATE_ISFINITE_KERNEL_Isfinite(phi::bfloat16, GPUContext);
} // namespace phi
#endif
4 changes: 4 additions & 0 deletions paddle/phi/kernels/isfinite_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@ DEFINE_ISFINITE_KERNEL(IsfiniteKernel)
#define INSTANTIATE_ISFINITE_KERNEL_Isnan(type, context) \
template PADDLE_API void IsnanKernel<type, context>( \
const context&, const DenseTensor&, DenseTensor*)

#define INSTANTIATE_ISFINITE_KERNEL_Isfinite(type, context) \
template PADDLE_API void IsfiniteKernel<type, context>( \
const context&, const DenseTensor&, DenseTensor*)
#endif
} // namespace phi
8 changes: 8 additions & 0 deletions test/cpp/fluid/platform/enforce_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,21 @@ TEST(enforce, cuda_success) {
EXPECT_TRUE(CheckCudaStatusFailure(CUFFT_SETUP_FAILED, "CUFFT error"));
EXPECT_TRUE(CheckCudaStatusFailure(CUFFT_INVALID_SIZE, "CUFFT error"));
EXPECT_TRUE(CheckCudaStatusFailure(CUFFT_UNALIGNED_DATA, "CUFFT error"));

#ifdef CUFFT_INCOMPLETE_PARAMETER_LIST
EXPECT_TRUE(
CheckCudaStatusFailure(CUFFT_INCOMPLETE_PARAMETER_LIST, "CUFFT error"));
#endif
EXPECT_TRUE(CheckCudaStatusFailure(CUFFT_INVALID_DEVICE, "CUFFT error"));

#ifdef CUFFT_PARSE_ERROR
EXPECT_TRUE(CheckCudaStatusFailure(CUFFT_PARSE_ERROR, "CUFFT error"));
#endif
EXPECT_TRUE(CheckCudaStatusFailure(CUFFT_NO_WORKSPACE, "CUFFT error"));
EXPECT_TRUE(CheckCudaStatusFailure(CUFFT_NOT_IMPLEMENTED, "CUFFT error"));
#ifdef CUFFT_LICENSE_ERROR
EXPECT_TRUE(CheckCudaStatusFailure(CUFFT_LICENSE_ERROR, "CUFFT error"));
#endif
EXPECT_TRUE(CheckCudaStatusFailure(CUFFT_NOT_SUPPORTED, "CUFFT error"));

#if !defined(__APPLE__) && defined(PADDLE_WITH_NCCL)
Expand Down
58 changes: 53 additions & 5 deletions test/cpp/inference/tensorrt/test_tensorrt_engine_instruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,64 @@ TEST(TensorRTEngineInstructionTest, test_tensorrt_engine_instruction) {
nvinfer1::DataType::kFLOAT, raw_bias, size);
auto *x = engine->DeclareInput(
"x", nvinfer1::DataType::kFLOAT, nvinfer1::Dims4{-1, 1, 1, 1});
auto *fc_layer = TRT_ENGINE_ADD_LAYER(
engine, FullyConnected, *x, size, weight.get(), bias.get());
PADDLE_ENFORCE_NOT_NULL(fc_layer,
auto *flatten_layer = engine->network()->addShuffle(*x);
PADDLE_ENFORCE_NOT_NULL(
flatten_layer,
common::errors::InvalidArgument(
"TRT shuffle layer building failed when preparing input."));
flatten_layer->setReshapeDimensions(nvinfer1::Dims2{-1, 1});

auto *weight_layer = TRT_ENGINE_ADD_LAYER(
engine, Constant, nvinfer1::Dims2{1, 1}, weight.get());
PADDLE_ENFORCE_NOT_NULL(
weight_layer,
common::errors::InvalidArgument(
"TRT constant layer building failed for weight."));

auto *bias_layer =
TRT_ENGINE_ADD_LAYER(engine, Constant, nvinfer1::Dims2{1, 1}, bias.get());
PADDLE_ENFORCE_NOT_NULL(bias_layer,
common::errors::InvalidArgument(
"TRT fully connected layer building failed."));
"TRT constant layer building failed for bias."));

auto *matmul_layer = TRT_ENGINE_ADD_LAYER(engine,
MatrixMultiply,
*flatten_layer->getOutput(0),
nvinfer1::MatrixOperation::kNONE,
*weight_layer->getOutput(0),
nvinfer1::MatrixOperation::kNONE);
PADDLE_ENFORCE_NOT_NULL(matmul_layer,
common::errors::InvalidArgument(
"TRT matrix multiply layer building failed."));

auto *add_layer = TRT_ENGINE_ADD_LAYER(engine,
ElementWise,
*matmul_layer->getOutput(0),
*bias_layer->getOutput(0),
nvinfer1::ElementWiseOperation::kSUM);
PADDLE_ENFORCE_NOT_NULL(add_layer,
common::errors::InvalidArgument(
"TRT elementwise add layer building failed."));

auto *reshape_layer = engine->network()->addShuffle(*add_layer->getOutput(0));
PADDLE_ENFORCE_NOT_NULL(
reshape_layer,
common::errors::InvalidArgument(
"TRT shuffle layer building failed when restoring output shape."));
reshape_layer->setReshapeDimensions(nvinfer1::Dims4{-1, 1, 1, 1});

engine->DeclareOutput(fc_layer, 0, "y");
engine->DeclareOutput(reshape_layer, 0, "y");
std::vector<std::string> input_names = {"x", ""};
std::vector<std::string> output_names = {"y"};
std::vector<std::vector<int64_t>> outputs_shape = {{1}};
std::vector<phi::DataType> outputs_dtype = {phi::DataType::FLOAT32};
LOG(INFO) << "freeze network";
engine->FreezeNetwork();
#if IS_TRT_VERSION_GE(8600)
ASSERT_EQ(engine->engine()->getNbIOTensors(), 2);
#else
ASSERT_EQ(engine->engine()->getNbBindings(), 2);
#endif
nvinfer1::IHostMemory *serialized_engine_data = engine->Serialize();

std::ofstream outFile("engine_serialized_data.bin", std::ios::binary);
Expand Down Expand Up @@ -417,7 +461,11 @@ TEST(PluginTest, test_generic_plugin) {
std::vector<phi::DataType> outputs_dtype = {phi::DataType::FLOAT32};
LOG(INFO) << "freeze network";
engine->FreezeNetwork();
#if IS_TRT_VERSION_GE(8600)
ASSERT_EQ(engine->engine()->getNbIOTensors(), 2);
#else
ASSERT_EQ(engine->engine()->getNbBindings(), 2);
#endif
nvinfer1::IHostMemory *serialized_engine_data = engine->Serialize();
std::ofstream outFile("engine_serialized_data.bin", std::ios::binary);
outFile.write(static_cast<const char *>(serialized_engine_data->data()),
Expand Down
Loading