Write a custom CUDA kernel to optimize `LDAM Loss` (Label-Distribution-Aware Margin Loss).

Formula: Loss = -log( exp(s * (z_target - delta_target)) / Sum(exp(s * z_j_modified)) )
Where:
- z is the logit vector.
- delta_j is the class-dependent margin pre-calculated based on class frequency: C / (frequency^0.25).
- For the target class y: z_y' = z_y - delta_y.
- For other classes: z_j' = z_j.
- s is a scaling factor.

Problem Analysis:
1. Memory Bottleneck: The standard implementation involves gathering margins based on targets, creating a one-hot mask (or using scatter), subtracting margins, scaling, and then performing CrossEntropy. This creates multiple intermediate tensors.
2. Latency: The sequence of operations prevents efficient fusion by standard JIT compilers.

Optimization Strategy: Fused Logit-Adjustment Kernel

1. Pre-computation: The class margins `delta` are static. Pass them as a tensor to the kernel.

2. One-Block-per-Row: Assign one CUDA block per sample.

3. Fused Adjustment and Reduction:
   - Load logits using vectorized `float4` instructions.
   - Check condition `if (col_idx == target_idx)`.
   - If true: Load the specific margin `delta[target]` from global memory and subtract it: `val = val - delta`.
   - Apply scale `s`.
   - Perform standard Max and SumExp reductions (Online Softmax) in Shared Memory.

4. Direct Loss Output: Compute the negative log likelihood using the modified target logit and the sum of exponentials, writing only the final loss scalar.
  
Here's an example to show you the syntax of inline embedding custom CUDA operators in torch: The example given architecture is:   
  
```python
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np

BATCH_SIZE = 2048
NUM_CLASSES = 4096
SHAPE = (BATCH_SIZE, NUM_CLASSES)

MAX_M = 0.5
SCALE_S = 30.0
REDUCTION = 'none'

class LDAMLoss(nn.Module):
    """
    LDAM Loss (NeurIPS 2019)
    """
    def __init__(self, cls_num_list, max_m=0.5, s=30.0, reduction='mean'):
        super(LDAMLoss, self).__init__()
        self.s = s
        self.reduction = reduction
        # 预计算 Margins
        # Formula: m_j = C / n_j^(1/4)
        m_list = 1.0 / np.sqrt(np.sqrt(cls_num_list))
        m_list = m_list * (max_m / np.max(m_list))
        m_list = torch.FloatTensor(m_list)
        self.register_buffer('class_margins', m_list)

    def forward(self, logits: torch.Tensor, targets: torch.Tensor) -> torch.Tensor:
        # logits: (N, C)
        # targets: (N)
        
        batch_margins = self.class_margins[targets]

        
        logits_m = logits.clone()
        
        idx = targets.view(-1, 1)
        logits_m.scatter_add_(1, idx, -batch_margins.view(-1, 1))
        
        output = logits_m * self.s
        
        loss = F.cross_entropy(output, targets, reduction='none')
        
        if self.reduction == 'mean':
            return loss.mean()
        elif self.reduction == 'sum':
            return loss.sum()
        return loss

class Model(nn.Module):
    def __init__(self, cls_num_list, max_m=0.5, s=30.0, reduction='none'):
        super(Model, self).__init__()
        self.loss_fn = LDAMLoss(cls_num_list, max_m, s, reduction)
    
    def forward(self, logits, targets):
        return self.loss_fn(logits, targets)

def get_inputs():
    logits = torch.randn(SHAPE, dtype=torch.float32)
    targets = torch.randint(0, NUM_CLASSES, (BATCH_SIZE,), dtype=torch.long)
    return [logits.contiguous(), targets.contiguous()]

def get_init_inputs():
    # 模拟长尾分布的样本计数
    cls_num_list = np.array([10000 * (0.9 ** (i / 10.0)) for i in range(NUM_CLASSES)])
    cls_num_list = np.maximum(cls_num_list, 1) # 避免除0
    
    return [cls_num_list, MAX_M, SCALE_S, REDUCTION]