Write a custom CUDA kernel to optimize `torch.linalg.vecdot`.

The operation computes the dot product of two vectors (or batches of vectors) along a given dimension. It is mathematically equivalent to `torch.sum(x * y, dim=dim)`.

**Problem Analysis:**
A standard PyTorch execution involves a two-step process that creates a significant memory bottleneck:
1.  **Element-wise Multiplication**: An intermediate tensor, the same size as the inputs, is created by `x * y` and written to global memory.
2.  **Sum Reduction**: A second kernel is launched to read this entire intermediate tensor back from global memory to perform the sum reduction.

This "write-then-read" pattern for a large intermediate tensor is highly inefficient and limited by memory bandwidth.

**Optimization Strategy: Fused Parallel Reduction Kernel**

The strategy is to create a single, fused CUDA kernel that performs both the multiplication and the reduction in one pass, completely eliminating the intermediate tensor.

1.  **Block-per-Dot-Product Parallelism**: The problem is treated as a batch of independent dot products. The kernel is launched with one CUDA thread block for each 1D vector slice that requires a dot product.

2.  **Fused Multiply-Add in Registers**: Within each block, threads collaboratively compute the dot product. Each thread is assigned a portion of the vector slice. It loads the corresponding elements from `x` and `y`, multiplies them, and accumulates the result into a private register, effectively performing a partial sum.

3.  **Efficient Intra-Block Reduction via Shared Memory**: After all threads compute their partial sums, a highly efficient parallel reduction is performed using **shared memory**. Threads write their partial sums to a shared array and then execute a tree-based summation to combine them into a single final value for the dot product.

4.  **Direct Output**: The first thread of each block writes the final scalar result directly to the corresponding location in the output tensor. This single-kernel approach transforms a two-stage, memory-bound operation into a single-pass, compute-efficient one, drastically reducing memory traffic and latency.
  
Here's an example to show you the syntax of inline embedding custom CUDA operators in torch: The example given architecture is:   
  
import torch
import torch.nn as nn

# --- 用于基准测试的配置 ---
BATCH_SIZE = 256
VECTORS = 2048
DIM_SIZE = 1024
SHAPE = (BATCH_SIZE, VECTORS, DIM_SIZE)
DIM = -1

# 使用 double 精度以保证数值稳定性
DTYPE = torch.float64

class Model(nn.Module):
    """
    使用 PyTorch 内置的 torch.linalg.vecdot 作为基准模型。
    """
    def __init__(self, dim):
        super(Model, self).__init__()
        self.dim = dim
    
    def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
        return torch.linalg.vecdot(x, y, dim=self.dim)

def get_inputs():
    x = torch.randn(SHAPE, dtype=DTYPE)
    y = torch.randn(SHAPE, dtype=DTYPE)
    return [x.contiguous(), y.contiguous()]

def get_init_inputs():
    return [DIM]