You write custom CUDA kernels to replace the pytorch operators in the given architecture to get speedups.   
  
You have complete freedom to choose the set of operators you want to replace. You may make the decision to replace some operators with custom CUDA kernels and leave others unchanged. You may replace multiple operators with custom implementations, consider operator fusion opportunities (combining multiple operators into a single kernel, for example, combining matmul+relu), or algorithmic changes (such as online softmax). You are only limited by your imagination.  
  
Key optimization techniques used in this MaxPool1d implementation:

1.Grid-Stride Loop Parallelism: Implements efficient workload distribution across L_out dimension using grid-stride loops for optimal load balancing

2.Warp-Level Reduction: Utilizes warp shuffle instructions for efficient maximum value reduction across threads

3.Memory Access Coalescing: Organized thread-block mapping with 64-bit offset calculations to prevent overflow and ensure coalesced memory access

4.Hierarchical Block Structure: Three-dimensional grid organization (batch × channels × L_out_blocks) for maximal parallelism

5.Efficient Boundary Handling: Optimized window calculation with precise effective range determination considering padding and dilation

Specific Technical Optimizations:

1.Memory Hierarchy Optimization:

2.Global Memory: Coalesced access patterns with proper alignment and 64-bit addressing

3.Register Utilization: Extensive use of registers for local computations and temporary variables

4.Shared Memory: Implicit utilization through warp-level operations

Computational Optimizations:

1.Fast Maximum Operations: Custom optimized_max function and warp-level reduction using fmaxf

2.Efficient Window Processing: Optimized dilation handling with modulo operations

3.Numerical Stability: Proper handling of -FLT_MAX for padding regions

Parallelism Strategy:

1.Grid Structure: 3D grid with (B × C × L_out_blocks) configuration

2.Block Configuration: 256 threads per block for optimal GPU occupancy

3.Dynamic Workload Distribution: Grid-stride loops automatically balance workload across threads

Numerical Precision:

1.Exact Output Dimension Calculation: Matches PyTorch's L_out computation logic precisely

2.Proper Padding Handling: Correctly handles completely padded windows with -FLT_MAX

3.Dilation Support: Full support for dilated pooling operations

Performance Features:

1.Contiguous Memory Access: Ensures input tensor contiguity for optimal memory bandwidth

2.Compiler Optimizations: -O3 flag enables aggressive performance optimizations

3.Kernel Fusion: Single kernel handles all pooling operations including boundary checks

4.The implementation demonstrates significant performance improvements over standard PyTorch operations through careful memory access patterns, efficient parallel reduction, and optimized computational pathways while maintaining full numerical equivalence with the reference implementation.



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
import torch.nn.functional as F

# ======== 基本参数定义 ========
BATCH_SIZE = 32
CHANNELS = 16
LENGTH = 64

KERNEL_SIZE = 3
STRIDE = 2
PADDING = 1
DILATION = 1
CEIL_MODE = False
RETURN_INDICES = False


# ======== 模型定义 ========
class Model(nn.Module):
    def __init__(self):
        super().__init__()
        self.pool = nn.MaxPool1d(
            kernel_size=KERNEL_SIZE,
            stride=STRIDE,
            padding=PADDING,
            dilation=DILATION,
            return_indices=RETURN_INDICES,
            ceil_mode=CEIL_MODE
        )

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        return self.pool(x)


# ======== 输入生成函数 ========
def get_inputs():
    """
    生成随机输入：
    input shape: (BATCH_SIZE, CHANNELS, LENGTH)
    """
    x = torch.randn(BATCH_SIZE, CHANNELS, LENGTH, dtype=torch.float32)
    return [x]


def get_init_inputs():
    """
    与模板保持一致（如果需要初始化参数等）
    """
    return []