```python
import torch
import torch.nn as nn
from torch.utils.cpp_extension import load_inline

_cpp_source = r"""
#include <torch/extension.h>
torch::Tensor gelu_cuda(torch::Tensor x);
"""

_cuda_source = r"""
#include <torch/extension.h>
#include <ATen/AccumulateType.h>
#include <ATen/cuda/CUDAContext.h>
#include <c10/cuda/CUDAGuard.h>
#include <c10/cuda/CUDAException.h>
#include <cuda_runtime.h>
#include <cstdint>

__device__ __forceinline__ float gelu_value(float x) {
    const float z = 0.7978845608028654f *
                    (x + 0.044715f * ((x * x) * x));
    return (0.5f * x) * (1.0f + tanhf(z));
}

__device__ __forceinline__ double gelu_value(double x) {
    const double z = 0.7978845608028654 *
                     (x + 0.044715 * ((x * x) * x));
    return (0.5 * x) * (1.0 + tanh(z));
}

__global__ void gelu_float4_kernel(
    const float* __restrict__ x,
    float* __restrict__ out,
    int64_t n
) {
    const int64_t index =
        static_cast<int64_t>(blockIdx.x) * blockDim.x + threadIdx.x;
    const int64_t stride =
        static_cast<int64_t>(blockDim.x) * gridDim.x;
    const int64_t vectors = n / 4;

    const float4* x4 = reinterpret_cast<const float4*>(x);
    float4* out4 = reinterpret_cast<float4*>(out);

    for (int64_t i = index; i < vectors; i += stride) {
        float4 v = x4[i];
        v.x = gelu_value(v.x);
        v.y = gelu_value(v.y);
        v.z = gelu_value(v.z);
        v.w = gelu_value(v.w);
        out4[i] = v;
    }

    for (int64_t i = vectors * 4 + index; i < n; i += stride) {
        out[i] = gelu_value(x[i]);
    }
}

template <typename scalar_t>
__global__ void gelu_scalar_kernel(
    const scalar_t* __restrict__ x,
    scalar_t* __restrict__ out,
    int64_t n
) {
    using acc_t = at::acc_type<scalar_t, true>;
    const int64_t stride =
        static_cast<int64_t>(blockDim.x) * gridDim.x;

    for (int64_t i =
             static_cast<int64_t>(blockIdx.x) * blockDim.x + threadIdx.x;
         i < n;
         i += stride) {
        out[i] = static_cast<scalar_t>(
            gelu_value(static_cast<acc_t>(x[i])));
    }
}

torch::Tensor gelu_cuda(torch::Tensor x) {
    TORCH_CHECK(x.is_cuda(), "Expected a CUDA tensor");
    c10::cuda::CUDAGuard guard(x.device());

    auto input = x.contiguous();
    auto output = torch::empty_like(input);
    const int64_t n = input.numel();
    if (n == 0) {
        return output;
    }

    constexpr int threads = 256;
    const auto stream = at::cuda::getCurrentCUDAStream();

    if (input.scalar_type() == at::kFloat &&
        reinterpret_cast<uintptr_t>(input.data_ptr<float>()) % 16 == 0) {
        const int64_t work = (n + 3) / 4;
        const int blocks = static_cast<int>(
            std::min<int64_t>((work + threads - 1) / threads, 4096));

        gelu_float4_kernel<<<blocks, threads, 0, stream>>>(
            input.data_ptr<float>(), output.data_ptr<float>(), n);
    } else {
        const int blocks = static_cast<int>(
            std::min<int64_t>((n + threads - 1) / threads, 4096));

        AT_DISPATCH_FLOATING_TYPES_AND2(
            at::ScalarType::Half,
            at::ScalarType::BFloat16,
            input.scalar_type(),
            "fused_gelu",
            [&] {
                gelu_scalar_kernel<scalar_t>
                    <<<blocks, threads, 0, stream>>>(
                        input.data_ptr<scalar_t>(),
                        output.data_ptr<scalar_t>(),
                        n);
            });
    }

    C10_CUDA_KERNEL_LAUNCH_CHECK();
    return output;
}
"""

_gelu = load_inline(
    name="fused_tanh_gelu_cuda",
    cpp_sources=_cpp_source,
    cuda_sources=_cuda_source,
    functions=["gelu_cuda"],
    extra_cflags=["-O3"],
    extra_cuda_cflags=["-O3", "--use_fast_math"],
    verbose=False,
)


class ModelNew(nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, x):
        return _gelu.gelu_cuda(x)
```