     T one = static_cast<T>(1.);
     T neg_100 = static_cast<T>(-100.);
 
+    PADDLE_ENFORCE(
+        (x >= static_cast<T>(0)) && (x <= one),
+        "Input is expected to be within the interval [0, 1], but recieved %f.",
+        x);
+
     T term1 = max(real_log(x), neg_100);
     T term2 = max(real_log(one - x), neg_100);
 

    auto* labels = ctx.Input<Tensor>("Label");
    auto* dout = ctx.Input<Tensor>(framework::GradVarName("Out"));
    auto* dx = ctx.Output<Tensor>(framework::GradVarName("X"));
    auto dx_data = dx->mutable_data<T>(ctx.GetPlace());

    int x_numel = x->numel();
    auto& dev_ctx = ctx.cuda_device_context();
    platform::GpuLaunchConfig config =
        platform::GetGpuLaunchConfig1D(dev_ctx, x_numel);

    auto* labels = ctx.Input<Tensor>("Label");
    auto* out = ctx.Output<Tensor>("Out");

    const auto* x_data = x->data<T>();
    auto* out_data = out->mutable_data<T>(ctx.GetPlace());
    auto x_numel = x->numel();

    auto& dev_ctx = ctx.cuda_device_context();
    platform::GpuLaunchConfig config =
        platform::GetGpuLaunchConfig1D(dev_ctx, x_numel);

    GPUBCELossForward<T><<<config.block_per_grid, config.thread_per_block, 0,
                           dev_ctx.stream()>>>(x_data, labels->data<T>(),
