```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 exclusive_cumsum_cuda(torch::Tensor x);
"""

_cuda_source = r"""
#include <torch/extension.h>
#include <ATen/cuda/CUDAContext.h>
#include <c10/cuda/CUDAGuard.h>
#include <c10/cuda/CUDAException.h>
#include <cub/block/block_load.cuh>
#include <cub/block/block_scan.cuh>
#include <cub/block/block_store.cuh>
#include <cuda_runtime.h>
#include <cstdint>

constexpr int THREADS = 256;
constexpr int ITEMS = 16;
constexpr int TILE = THREADS * ITEMS;

__global__ void exclusive_cumsum_kernel(
    const float* __restrict__ x,
    float* __restrict__ out,
    int64_t columns
) {
    using Load = cub::BlockLoad<
        float, THREADS, ITEMS, cub::BLOCK_LOAD_VECTORIZE>;
    using Scan = cub::BlockScan<
        float, THREADS, cub::BLOCK_SCAN_WARP_SCANS>;
    using Store = cub::BlockStore<
        float, THREADS, ITEMS, cub::BLOCK_STORE_WARP_TRANSPOSE>;

    __shared__ union {
        typename Load::TempStorage load;
        typename Scan::TempStorage scan;
        typename Store::TempStorage store;
    } storage;

    const int64_t row = static_cast<int64_t>(blockIdx.x);
    const float* input_row = x + row * columns;
    float* output_row = out + row * (columns + 1);
    float carry = 0.0f;

    for (int64_t offset = 0; offset < columns; offset += TILE) {
        float values[ITEMS];
        const int valid = static_cast<int>(
            columns - offset < TILE ? columns - offset : TILE);

        if (valid == TILE) {
            Load(storage.load).Load(input_row + offset, values);
        } else {
            Load(storage.load).Load(input_row + offset, values, valid, 0.0f);
        }
        __syncthreads();

        float aggregate;
        Scan(storage.scan).ExclusiveSum(values, values, aggregate);
        __syncthreads();

        #pragma unroll
        for (int i = 0; i < ITEMS; ++i) {
            values[i] += carry;
        }
        carry += aggregate;

        if (valid == TILE) {
            Store(storage.store).Store(output_row + offset, values);
        } else {
            Store(storage.store).Store(output_row + offset, values, valid);
        }
        __syncthreads();
    }

    if (threadIdx.x == 0) {
        output_row[columns] = carry;
    }
}

torch::Tensor exclusive_cumsum_cuda(torch::Tensor x) {
    TORCH_CHECK(x.is_cuda(), "Expected a CUDA tensor");
    TORCH_CHECK(x.scalar_type() == at::kFloat, "Expected float32");
    TORCH_CHECK(x.dim() == 2 && x.is_contiguous(),
                "Expected a contiguous two-dimensional tensor");
    TORCH_CHECK(x.size(1) > 0, "Expected a nonempty scan dimension");

    const c10::cuda::CUDAGuard device_guard(x.device());

    // The original [:-1] removes the last row, not the last column.
    const int64_t rows = x.size(0) > 0 ? x.size(0) - 1 : 0;
    const int64_t columns = x.size(1);
    auto out = torch::empty({rows, columns + 1}, x.options());

    if (rows > 0) {
        TORCH_CHECK(rows <= 2147483647LL, "Too many rows");
        exclusive_cumsum_kernel<<<
            static_cast<unsigned int>(rows),
            THREADS,
            0,
            at::cuda::getCurrentCUDAStream()
        >>>(
            x.data_ptr<float>(),
            out.data_ptr<float>(),
            columns
        );
        C10_CUDA_KERNEL_LAUNCH_CHECK();
    }

    return out;
}
"""

_extension = load_inline(
    name="exclusive_cumsum_row_cuda_v1",
    cpp_sources=_cpp_source,
    cuda_sources=_cuda_source,
    functions=["exclusive_cumsum_cuda"],
    extra_cflags=["-O3"],
    extra_cuda_cflags=["-O3"],
    verbose=False,
)


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

    def forward(self, x):
        if (
            x.is_cuda
            and x.dtype == torch.float32
            and x.ndim == 2
            and self.dim in (1, -1)
            and x.shape[1] > 0
            and not x.requires_grad
        ):
            return _extension.exclusive_cumsum_cuda(x.contiguous())

        padded = torch.cat(
            (
                torch.zeros_like(
                    x.select(self.dim, 0).unsqueeze(self.dim)
                ),
                x,
            ),
            dim=self.dim,
        )[:-1]
        return torch.cumsum(padded, dim=self.dim)
```