gpt-5.5-priority · popcorn · l12_default_gpt
correct 24_VoxelGridPooling.py
model
gpt-5.5-priority
turns / max
7 / 10
tool calls
7
tokens (total)
0
wall clock
—
truncated
no
backend
cuda fp32
variant
popcorn
runtime
0.02 μs
ref runtime
11.90 μs
speedup
550.93x
started
2026-05-02T05:27:24Z
timingkernelbench.timing
kernel runtime
0.02 μs
ref runtime
11.90 μs
speedup
550.93x
kernel mean / median / std
0.02 / — / 3.21e-04 μs
ref mean / median / std
11.90 / — / 0.28 μs
numerical precisioneval_kernel_against_ref
max abs error
7.15e-07
mean abs error
3.81e-10
max rel error
0.01
mean rel error
4.28e-09
gpu memoryextended_metrics.measure_memory
kernel peak
49.15 MB
ref peak
49.85 MB
kernel / ref
0.99x
kernel launches / fusiontorch.profiler
kernel launches
2
ref launches
4484
fusion ratio (ref / kernel)
2242.00x
total cuda time
32 μs
SOL (speed-of-light)nsight_hardware_counters
SOL score (0–1)
0.059
dram util %
5.8%
compute util %
0.0%
bottleneck
unknown
dominant pipe
None
arithmetic intensity
—
ridge point
20.00
roofline / occupancynsight_hardware_counters
dram bandwidth
196.14 GB/s
dram util %
5.9%
fp32 tflops
—
fp32 util %
—
fp16 tflops
—
occupancy %
23.7%
bottleneck
unknown
dominant pipe %
—
arithmetic intensity
—
ridge point
20.00
L1 hit %
—
L2 hit %
166.6%
ld sectors / req
37.95
st sectors / req
—
regs / thread
52
smem / block
5248 B
block size
288
peak bw
3350.00 GB/s
peak fp32 tflops
67.00
peak fp16 tflops
1979.00
warp stalls (top 5)nsight
long_scoreboard
4279.6%
short_scoreboard
752.8%
mio_throttle
93.6%
flagssubmit_kernel guard
excessive speedup
flagged
reference PyTorch source (the prompt the agent sees)
import torch
import torch.nn as nn


class Model(nn.Module):
    """
    Voxel-grid pooling for 3-D molecular point clouds.  Discretizes
    continuous 3-D coordinates into a regular grid and pools per-atom
    features into each voxel.  Used in 3-D-CNN approaches for molecular
    property prediction and ligand docking (e.g., PointVoxel-CNN,
    3D-Infomax).
    """

    def __init__(self, feat_dim, grid_size=32, voxel_size=1.0):
        super().__init__()
        self.feat_dim = feat_dim
        self.grid_size = grid_size
        self.voxel_size = voxel_size
        self.linear = nn.Linear(feat_dim, feat_dim)

    def forward(
        self, coords: torch.Tensor, features: torch.Tensor
    ) -> torch.Tensor:
        """
        Args:
            coords:   (B, N, 3) – atom coordinates
            features: (B, N, feat_dim) – per-atom features
        Returns:
            voxel_grid: (B, feat_dim, G, G, G) – pooled voxel features
        """
        B, N, _ = coords.shape
        G = self.grid_size

        features = self.linear(features)

        # Center coordinates and discretize
        center = coords.mean(dim=1, keepdim=True)
        shifted = (coords - center) / self.voxel_size + G / 2.0
        indices = shifted.long().clamp(0, G - 1)  # (B, N, 3)

        voxel_grid = coords.new_zeros(B, self.feat_dim, G, G, G)
        ix = indices[:, :, 0]
        iy = indices[:, :, 1]
        iz = indices[:, :, 2]

        batch_idx = torch.arange(B, device=coords.device).unsqueeze(1).expand(-1, N)
        for d in range(self.feat_dim):
            feat_d = features[:, :, d]
            voxel_grid[:, d].index_put_(
                (batch_idx.reshape(-1), ix.reshape(-1), iy.reshape(-1), iz.reshape(-1)),
                feat_d.reshape(-1),
                accumulate=True,
            )

        return voxel_grid


feat_dim = 32
grid_size = 32
voxel_size = 1.0
num_atoms = 256
batch_size = 4


def get_inputs():
    p = popcorn_pri
    bs = p.jitter_int(batch_size)
    na = p.jitter_int(num_atoms)
    coords = torch.randn(bs, na, 3) * 5.0
    features = torch.randn(bs, na, feat_dim)
    return [coords, features]


def get_init_inputs():
    return [feat_dim, grid_size, voxel_size]
turn 011.7s turn · 11.7s LLM · 0.0s tools
reasoning
**Optimizing CUDA Module** I need to craft a Python module with a CUDA extension and optimize it. I'm considering fixed shapes—feature dimensions of 32 and grid size of 32, while needing to handle general feature dimensions. Linear weights are essential, and I need to match reference weights for evaluation. I'll instantiate both Model and ModelNew to copy the state and define the linear structure for my calculations. The output needs to efficiently handle 4 million floats with careful attention to atomic operations and precision within certain limits. **Optimizing PyTorch Linear Accumulation** I’m thinking about how PyTorch’s Linear might interact with cuBLAS, especially regarding differences in tolerance. It seems okay if the sum of 32 products is small and the scatter accumulation is non-deterministic. I can probably fuse linear and scatter operations to efficiently compute dot products. For the voxel output, working with 4 million operations seems feasible. I need to compute the center, considering the best way to do this—perhaps by using a scatter kernel with blocks that handle each atom to reduce overhead. **Optimizing Threading for Linear Operations** I'm considering a threading structure where threads loop through indices for thread IDs and sum coordinates. It looks like I can reduce the workload by using shared arrays with 32 threads in a warp/block configuration. Each thread would handle linear dot products for its specific dimension and perform atomic additions. This setup allows for one block per atom, leading to a total of 1,024 blocks with 32 threads each. It seems efficient for my objectives!
call → get_gpu_specs
callget_gpu_specs {}
result ← get_gpu_specs (ok)
okget_gpu_specs GPU specs for NVIDIA H100 80GB HBM3: total memory (runtime): 79.1 GB spec entry: H100 GPU Architecture: Hopper GPU Memory: 80GB Memory Bandwidth: 3.35 TB/s FP64 TFLOPS: 34 FP64 Tensor Core TFLOPS: 67 FP32 TFLOPS: 67 TF32 Tensor Core TFLOPS: 989 with sparsity BFLOAT16 Tensore Core TFLOPS: 1979 with sparsity FP16 Tensor Core TFLOPS: 1979 with sparsity FP8 Tensor Core TFLOPS: 3958 with sparsity INT8 Tensor Core TOPS: 3958 with sparsity Register File Size: 64K 32-bit registers per SM Maximum number of registers per thread: 255 Maximum number of thread blocks per SM: 32 Shared memory capacity per SM: 228 KB Maximum shared memory per thread block: 227 KB
turn 1 · 1 tool call(s) · 26.9s turn · 26.9s LLM · 9,589 chars (click to expand)
turn 126.9s turn · 26.9s LLM · 0.0s tools
reasoning
**Exploring kernel optimization** I'm working through some kernel optimization strategies. For F=32, I'm considering only the first 32 to reduce overhead. I see an alternative where I could use two kernels: a center kernel with B blocks and 128 threads, outputting Bx3, and a scatter kernel for each atom-output. This could avoid center recomputation and manage allocations better. The idea is to scatter blocks per atom with 32 threads. I wonder if using one kernel for both center and indices could streamline things further. **Testing pybind functionality** I'm considering that the auto-generated pybind from the C++ sources might successfully call the declared function. It seems logical that this should work, so I think I’ll go ahead and test it. I'm curious to see if it actually behaves as I expect. It’ll be interesting to observe whether the function gets called properly. Let’s find out what happens when I run this test!
call → compile_kernel
callcompile_kernel { "kernel_code": "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\n\ncpp_src = r'''\n#include <torch/extension.h>\ntorch::Tensor voxel_forward(torch::Tensor coords, torch::Tensor features, torch::Tensor weight, torch::Tensor bias, int64_t grid_size, double voxel_size);\n'''\n\ncuda_src = r'''\n#include <torch/extension.h>\n#include <cuda.h>\n#include <cuda_runtime.h>\n\n__global__ void center_kernel(const float* __restrict__ coords, float* __restrict__ centers, int B, int N) {\n int b = blockIdx.x;\n int tid = threadIdx.x;\n float sx = 0.f, sy = 0.f, sz = 0.f;\n for (int i = tid; i < N; i += blockDim.x) {\n const float* p = coords + ((b * N + i) * 3);\n sx += p[0]; sy += p[1]; sz += p[2];\n }\n __shared__ float shx[256], shy[256], shz[256];\n shx[tid] = sx; shy[tid] = sy; shz[tid] = sz;\n __syncthreads();\n for (int s = blockDim.x >> 1; s > 0; s >>= 1) {\n if (tid < s) { shx[tid] += shx[tid+s]; shy[tid] += shy[tid+s]; shz[tid] += shz[tid+s]; }\n __syncthreads();\n }\n if (tid == 0) {\n float invN = 1.0f / (float)N;\n centers[b*3+0] = shx[0] * invN;\n centers[b*3+1] = shy[0] * invN;\n centers[b*3+2] = shz[0] * invN;\n }\n}\n\n__global__ void scatter_linear_kernel(\n const float* __restrict__ coords,\n const float* __restrict__ features,\n const float* __restrict__ weight,\n const float* __restrict__ bias,\n const float* __restrict__ centers,\n float* __restrict__ out,\n int B, int N, int F, int G, float inv_voxel) {\n int atom = blockIdx.x;\n int b = atom / N;\n int n = atom - b * N;\n int tid = threadIdx.x;\n\n const float* c = coords + ((b * N + n) * 3);\n float gx = (c[0] - centers[b*3+0]) * inv_voxel + (float)G * 0.5f;\n float gy = (c[1] - centers[b*3+1]) * inv_voxel + (float)G * 0.5f;\n float gz = (c[2] - centers[b*3+2]) * inv_voxel + (float)G * 0.5f;\n int ix = (int)gx; int iy = (int)gy; int iz = (int)gz;\n ix = ix < 0 ? 0 : (ix >= G ? G-1 : ix);\n iy = iy < 0 ? 0 : (iy >= G ? G-1 : iy);\n iz = iz < 0 ? 0 : (iz >= G ? G-1 : iz);\n int vox = (ix * G + iy) * G + iz;\n\n const float* fin = features + ((b * N + n) * F);\n for (int d = tid; d < F; d += blockDim.x) {\n float acc = bias[d];\n const float* w = weight + d * F;\n #pragma unroll\n for (int k = 0; k < 32; ++k) {\n if (k < F) acc = fmaf(fin[k], w[k], acc);\n }\n size_t off = (((size_t)b * F + d) * (size_t)G * G * G) + vox;\n atomicAdd(out + off, acc);\n }\n}\n\ntorch::Tensor voxel_forward(torch::Tensor coords, torch::Tensor features, torch::Tensor weight, torch::Tensor bias, int64_t grid_size, double voxel_size) {\n int B = (int)coords.size(0);\n int N = (int)coords.size(1);\n int F = (int)features.size(2);\n int G = (int)grid_size;\n auto out = torch::empty({B, F, G, G, G}, coords.options());\n auto centers = torch::empty({B, 3}, coords.options());\n cudaStream_t stream = at::cuda::getCurrentCUDAStream();\n size_t bytes = (size_t)B * F * G * G * G * sizeof(float);\n cudaMemsetAsync(out.data_ptr<float>(), 0, bytes, stream);\n center_kernel<<<B, 256, 0, stream>>>(coords.data_ptr<float>(), centers.data_ptr<float>(), B, N);\n int threads = 32;\n if (F > 32) threads = 64;\n if (F > 64) threads = 128;\n scatter_linear_kernel<<<B*N, threads, 0, stream>>>(coords.data_ptr<float>(), features.data_ptr<float>(), weight.data_ptr<float>(), bias.data_ptr<float>(), centers.data_ptr<float>(), out.data_ptr<float>(), B, N, F, G, 1.0f/(float)voxel_size);\n return out;\n}\n'''\n\n_ext = load_inline(name='voxel_pool_ext_v1', cpp_sources=cpp_src, cuda_sources=cuda_src, functions=['voxel_forward'], extra_cflags=['-O3'], extra_cuda_cflags=['-O3', '--use_fast_math'], verbose=False)\n\nclass ModelNew(nn.Module):\n def __init__(self, feat_dim, grid_size=32, voxel_size=1.0):\n super().__init__()\n self.feat_dim = feat_dim\n self.grid_size = grid_size\n self.voxel_size = voxel_size\n self.linear = nn.Linear(feat_dim, feat_dim)\n def forward(self, coords: torch.Tensor, features: torch.Tensor) -> torch.Tensor:\n return _ext.voxel_forward(coords.contiguous(), features.contiguous(), self.linear.weight.contiguous(), self.linear.bias.contiguous(), int(self.grid_size), float(self.voxel_size))\n" }
result ← compile_kernel (fail)
failcompile_kernel compile_kernel FAILED: RuntimeError. RuntimeError: Error building extension 'voxel_pool_ext_v1': [1/3] /opt/conda/bin/x86_64-conda-linux-gnu-c++ -MMD -MF main.o.d -DTORCH_EXTENSION_NAME=voxel_pool_ext_v1 -DTORCH_API_INCLUDE_EXTENSION_H -isystem /scratch/tejas/PopcornBench/.venv/lib/python3.10/site-packages/torch/include -isystem /scratch/tejas/PopcornBench/.venv/lib/python3.10/site-packages/torch/include/torch/csrc/api/include -isystem /usr/local/cuda/include -isystem /home/prabhune/.local/share/uv/python/cpython-3.10-linux-x86_64-gnu/include/python3.10 -fPIC -std=c++17 -O3 -c /scratch/tejas/PopcornBench/runs/l12_default/popcorn/gpt-5.5-priority/level_1_problem_24_cache/k_b62655721ed8/voxel_pool_ext_v1/main.cpp -o main.o [2/3] /usr/local/cuda/bin/nvcc -MD -MF cuda.cuda.o.d -ccbin /opt/conda/bin/x86_64-conda-linux-gnu-cc -DTORCH_EXTENSION_NAME=voxel_pool_ext_v1 -DTORCH_API_INCLUDE_EXTENSION_H -isystem /scratch/tejas/PopcornBench/.venv/lib/python3.10/site-packages/torch/include -isystem /scratch/tejas/PopcornBench/.venv/lib/python3.10/site-packages/torch/include/torch/csrc/api/include -isystem /usr/local/cuda/include -isystem /home/prabhune/.local/share/uv/python/cpython-3.10-linux-x86_64-gnu/include/python3.10 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -gencode=arch=compute_90,code=compute_90 -gencode=arch=compute_90,code=sm_90 --compiler-options '-fPIC' -O3 --use_fast_math -std=c++17 -c /scratch/tejas/PopcornBench/runs/l12_default/popcorn/gpt-5.5-priority/level_1_problem_24_cache/k_b62655721ed8/voxel_pool_ext_v1/cuda.cu -o cuda.cuda.o FAILED: [code=2] cuda.cuda.o /usr/local/cuda/bin/nvcc -MD -MF cuda.cuda.o.d -ccbin /opt/conda/bin/x86_64-conda-linux-gnu-cc -DTORCH_EXTENSION_NAME=voxel_pool_ext_v1 -DTORCH_API_INCLUDE_EXTENSION_H -isystem /scratch/tejas/PopcornBench/.venv/lib/python3.10/site-packages/torch/include -isystem /scratch/tejas/PopcornBench/.venv/lib/python3.10/site-packages/torch/include/torch/csrc/api/include -isystem /usr/local/cuda/include -isystem /home/prabhune/.local/share/uv/python/cpython-3.10-linux-x86_64-gnu/include/python3.10 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -gencode=arch=compute_90,code=compute_90 -gencode=arch=compute_90,code=sm_90 --compiler-options '-fPIC' -O3 --use_fast_math -std=c++17 -c /scratch/tejas/PopcornBench/runs/l12_default/popcorn/gpt-5.5-priority/level_1_problem_24_cache/k_b62655721ed8/voxel_pool_ext_v1/cuda.cu -o cuda.cuda.o nvcc warning : incompatible redefinition for option 'compiler-bindir', the last value of this option was used /scratch/tejas/PopcornBench/runs/l12_default/popcorn/gpt-5.5-priority/level_1_problem_24_cache/k_b62655721ed8/voxel_pool_ext_v1/cuda.cu(75): error: namespace "at::cuda" has no member "getCurrentCUDAStream" cudaStream_t stream = at::cuda::getCurrentCUDAStream(); ^ 1 error detected in the compilation of "/scratch/tejas/PopcornBench/runs/l12_default/popcorn/gpt-5.5-priority/level_1_problem_24_cache/k_b62655721ed8/voxel_pool_ext_v1/cuda.cu". ninja: build stopped: subcommand failed.
turn 29.5s turn · 9.5s LLM · 0.0s tools
call → compile_kernel
callcompile_kernel { "kernel_code": "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\n\ncpp_src = r'''\n#include <torch/extension.h>\ntorch::Tensor voxel_forward(torch::Tensor coords, torch::Tensor features, torch::Tensor weight, torch::Tensor bias, int64_t grid_size, double voxel_size);\n'''\n\ncuda_src = r'''\n#include <torch/extension.h>\n#include <ATen/cuda/CUDAContext.h>\n#include <cuda.h>\n#include <cuda_runtime.h>\n\n__global__ void center_kernel(const float* __restrict__ coords, float* __restrict__ centers, int B, int N) {\n int b = blockIdx.x;\n int tid = threadIdx.x;\n float sx = 0.f, sy = 0.f, sz = 0.f;\n for (int i = tid; i < N; i += blockDim.x) {\n const float* p = coords + ((b * N + i) * 3);\n sx += p[0]; sy += p[1]; sz += p[2];\n }\n __shared__ float shx[256], shy[256], shz[256];\n shx[tid] = sx; shy[tid] = sy; shz[tid] = sz;\n __syncthreads();\n for (int s = blockDim.x >> 1; s > 0; s >>= 1) {\n if (tid < s) { shx[tid] += shx[tid+s]; shy[tid] += shy[tid+s]; shz[tid] += shz[tid+s]; }\n __syncthreads();\n }\n if (tid == 0) {\n float invN = 1.0f / (float)N;\n centers[b*3+0] = shx[0] * invN;\n centers[b*3+1] = shy[0] * invN;\n centers[b*3+2] = shz[0] * invN;\n }\n}\n\n__global__ void scatter_linear_kernel(\n const float* __restrict__ coords,\n const float* __restrict__ features,\n const float* __restrict__ weight,\n const float* __restrict__ bias,\n const float* __restrict__ centers,\n float* __restrict__ out,\n int B, int N, int F, int G, float inv_voxel) {\n int atom = blockIdx.x;\n int b = atom / N;\n int n = atom - b * N;\n int tid = threadIdx.x;\n\n const float* c = coords + ((b * N + n) * 3);\n float gx = (c[0] - centers[b*3+0]) * inv_voxel + (float)G * 0.5f;\n float gy = (c[1] - centers[b*3+1]) * inv_voxel + (float)G * 0.5f;\n float gz = (c[2] - centers[b*3+2]) * inv_voxel + (float)G * 0.5f;\n int ix = (int)gx; int iy = (int)gy; int iz = (int)gz;\n ix = ix < 0 ? 0 : (ix >= G ? G-1 : ix);\n iy = iy < 0 ? 0 : (iy >= G ? G-1 : iy);\n iz = iz < 0 ? 0 : (iz >= G ? G-1 : iz);\n int vox = (ix * G + iy) * G + iz;\n\n const float* fin = features + ((b * N + n) * F);\n for (int d = tid; d < F; d += blockDim.x) {\n float acc = bias[d];\n const float* w = weight + d * F;\n for (int k = 0; k < F; ++k) {\n acc = fmaf(fin[k], w[k], acc);\n }\n size_t off = (((size_t)b * F + d) * (size_t)G * G * G) + vox;\n atomicAdd(out + off, acc);\n }\n}\n\ntorch::Tensor voxel_forward(torch::Tensor coords, torch::Tensor features, torch::Tensor weight, torch::Tensor bias, int64_t grid_size, double voxel_size) {\n int B = (int)coords.size(0);\n int N = (int)coords.size(1);\n int F = (int)features.size(2);\n int G = (int)grid_size;\n auto out = torch::empty({B, F, G, G, G}, coords.options());\n auto centers = torch::empty({B, 3}, coords.options());\n cudaStream_t stream = at::cuda::getCurrentCUDAStream();\n size_t bytes = (size_t)B * F * G * G * G * sizeof(float);\n cudaMemsetAsync(out.data_ptr<float>(), 0, bytes, stream);\n center_kernel<<<B, 256, 0, stream>>>(coords.data_ptr<float>(), centers.data_ptr<float>(), B, N);\n int threads = (F <= 32 ? 32 : (F <= 64 ? 64 : 128));\n scatter_linear_kernel<<<B*N, threads, 0, stream>>>(coords.data_ptr<float>(), features.data_ptr<float>(), weight.data_ptr<float>(), bias.data_ptr<float>(), centers.data_ptr<float>(), out.data_ptr<float>(), B, N, F, G, 1.0f/(float)voxel_size);\n return out;\n}\n'''\n\n_ext = load_inline(name='voxel_pool_ext_v2', cpp_sources=cpp_src, cuda_sources=cuda_src, functions=['voxel_forward'], extra_cflags=['-O3'], extra_cuda_cflags=['-O3', '--use_fast_math'], verbose=False)\n\nclass ModelNew(nn.Module):\n def __init__(self, feat_dim, grid_size=32, voxel_size=1.0):\n super().__init__()\n self.feat_dim = feat_dim\n self.grid_size = grid_size\n self.voxel_size = voxel_size\n self.linear = nn.Linear(feat_dim, feat_dim)\n def forward(self, coords: torch.Tensor, features: torch.Tensor) -> torch.Tensor:\n return _ext.voxel_forward(coords.contiguous(), features.contiguous(), self.linear.weight.contiguous(), self.linear.bias.contiguous(), int(self.grid_size), float(self.voxel_size))\n" }
result ← compile_kernel (ok)
okcompile_kernel compile_kernel PASSED: kernel compiled without errors.
turn 39.5s turn · 9.5s LLM · 0.0s tools
call → run_correctness
callrun_correctness { "kernel_code": "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\n\ncpp_src = r'''\n#include <torch/extension.h>\ntorch::Tensor voxel_forward(torch::Tensor coords, torch::Tensor features, torch::Tensor weight, torch::Tensor bias, int64_t grid_size, double voxel_size);\n'''\n\ncuda_src = r'''\n#include <torch/extension.h>\n#include <ATen/cuda/CUDAContext.h>\n#include <cuda.h>\n#include <cuda_runtime.h>\n\n__global__ void center_kernel(const float* __restrict__ coords, float* __restrict__ centers, int B, int N) {\n int b = blockIdx.x;\n int tid = threadIdx.x;\n float sx = 0.f, sy = 0.f, sz = 0.f;\n for (int i = tid; i < N; i += blockDim.x) {\n const float* p = coords + ((b * N + i) * 3);\n sx += p[0]; sy += p[1]; sz += p[2];\n }\n __shared__ float shx[256], shy[256], shz[256];\n shx[tid] = sx; shy[tid] = sy; shz[tid] = sz;\n __syncthreads();\n for (int s = blockDim.x >> 1; s > 0; s >>= 1) {\n if (tid < s) { shx[tid] += shx[tid+s]; shy[tid] += shy[tid+s]; shz[tid] += shz[tid+s]; }\n __syncthreads();\n }\n if (tid == 0) {\n float invN = 1.0f / (float)N;\n centers[b*3+0] = shx[0] * invN;\n centers[b*3+1] = shy[0] * invN;\n centers[b*3+2] = shz[0] * invN;\n }\n}\n\n__global__ void scatter_linear_kernel(\n const float* __restrict__ coords,\n const float* __restrict__ features,\n const float* __restrict__ weight,\n const float* __restrict__ bias,\n const float* __restrict__ centers,\n float* __restrict__ out,\n int B, int N, int F, int G, float inv_voxel) {\n int atom = blockIdx.x;\n int b = atom / N;\n int n = atom - b * N;\n int tid = threadIdx.x;\n\n const float* c = coords + ((b * N + n) * 3);\n float gx = (c[0] - centers[b*3+0]) * inv_voxel + (float)G * 0.5f;\n float gy = (c[1] - centers[b*3+1]) * inv_voxel + (float)G * 0.5f;\n float gz = (c[2] - centers[b*3+2]) * inv_voxel + (float)G * 0.5f;\n int ix = (int)gx; int iy = (int)gy; int iz = (int)gz;\n ix = ix < 0 ? 0 : (ix >= G ? G-1 : ix);\n iy = iy < 0 ? 0 : (iy >= G ? G-1 : iy);\n iz = iz < 0 ? 0 : (iz >= G ? G-1 : iz);\n int vox = (ix * G + iy) * G + iz;\n\n const float* fin = features + ((b * N + n) * F);\n for (int d = tid; d < F; d += blockDim.x) {\n float acc = bias[d];\n const float* w = weight + d * F;\n for (int k = 0; k < F; ++k) {\n acc = fmaf(fin[k], w[k], acc);\n }\n size_t off = (((size_t)b * F + d) * (size_t)G * G * G) + vox;\n atomicAdd(out + off, acc);\n }\n}\n\ntorch::Tensor voxel_forward(torch::Tensor coords, torch::Tensor features, torch::Tensor weight, torch::Tensor bias, int64_t grid_size, double voxel_size) {\n int B = (int)coords.size(0);\n int N = (int)coords.size(1);\n int F = (int)features.size(2);\n int G = (int)grid_size;\n auto out = torch::empty({B, F, G, G, G}, coords.options());\n auto centers = torch::empty({B, 3}, coords.options());\n cudaStream_t stream = at::cuda::getCurrentCUDAStream();\n size_t bytes = (size_t)B * F * G * G * G * sizeof(float);\n cudaMemsetAsync(out.data_ptr<float>(), 0, bytes, stream);\n center_kernel<<<B, 256, 0, stream>>>(coords.data_ptr<float>(), centers.data_ptr<float>(), B, N);\n int threads = (F <= 32 ? 32 : (F <= 64 ? 64 : 128));\n scatter_linear_kernel<<<B*N, threads, 0, stream>>>(coords.data_ptr<float>(), features.data_ptr<float>(), weight.data_ptr<float>(), bias.data_ptr<float>(), centers.data_ptr<float>(), out.data_ptr<float>(), B, N, F, G, 1.0f/(float)voxel_size);\n return out;\n}\n'''\n\n_ext = load_inline(name='voxel_pool_ext_v2c', cpp_sources=cpp_src, cuda_sources=cuda_src, functions=['voxel_forward'], extra_cflags=['-O3'], extra_cuda_cflags=['-O3', '--use_fast_math'], verbose=False)\n\nclass ModelNew(nn.Module):\n def __init__(self, feat_dim, grid_size=32, voxel_size=1.0):\n super().__init__()\n self.feat_dim = feat_dim\n self.grid_size = grid_size\n self.voxel_size = voxel_size\n self.linear = nn.Linear(feat_dim, feat_dim)\n def forward(self, coords: torch.Tensor, features: torch.Tensor) -> torch.Tensor:\n return _ext.voxel_forward(coords.contiguous(), features.contiguous(), self.linear.weight.contiguous(), self.linear.bias.contiguous(), int(self.grid_size), float(self.voxel_size))\n" }
result ← run_correctness (ok)
okrun_correctness run_correctness PASSED: (5 / 5) trials all matched the reference. Numerical precision: max_abs_err=7.15e-07 mean_abs_err=3.81e-10 max_rel_err=6.52e-03
turn 4 · 1 tool call(s) · 29.1s turn · 29.1s LLM · 6,696 chars (click to expand)
turn 429.1s turn · 29.1s LLM · 0.0s tools
call → run_correctness
callrun_correctness { "kernel_code": "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\n\ncpp_src = r'''\n#include <torch/extension.h>\ntorch::Tensor voxel_forward(torch::Tensor coords, torch::Tensor features, torch::Tensor weight, torch::Tensor bias, int64_t grid_size, double voxel_size);\n'''\n\ncuda_src = r'''\n#include <torch/extension.h>\n#include <ATen/cuda/CUDAContext.h>\n#include <cuda.h>\n#include <cuda_runtime.h>\n\n__global__ void center_kernel(const float* __restrict__ coords, float* __restrict__ centers, int B, int N) {\n int b = blockIdx.x, tid = threadIdx.x;\n float sx = 0.f, sy = 0.f, sz = 0.f;\n for (int i = tid; i < N; i += blockDim.x) {\n const float* p = coords + ((b * N + i) * 3);\n sx += p[0]; sy += p[1]; sz += p[2];\n }\n __shared__ float sh[256*3];\n sh[tid] = sx; sh[256+tid] = sy; sh[512+tid] = sz;\n __syncthreads();\n for (int s = blockDim.x >> 1; s > 0; s >>= 1) {\n if (tid < s) { sh[tid] += sh[tid+s]; sh[256+tid] += sh[256+tid+s]; sh[512+tid] += sh[512+tid+s]; }\n __syncthreads();\n }\n if (tid == 0) {\n float invN = 1.0f / (float)N;\n centers[b*3] = sh[0] * invN;\n centers[b*3+1] = sh[256] * invN;\n centers[b*3+2] = sh[512] * invN;\n }\n}\n\n__global__ void scatter_linear32_kernel(\n const float* __restrict__ coords,\n const float* __restrict__ features,\n const float* __restrict__ weight,\n const float* __restrict__ bias,\n const float* __restrict__ centers,\n float* __restrict__ out,\n int N, int G, float inv_voxel) {\n int atom = blockIdx.x;\n int b = atom / N;\n int n = atom - b * N;\n int d = threadIdx.x; // 0..31\n __shared__ float sf[32];\n const float* fin = features + ((b * N + n) * 32);\n sf[d] = fin[d];\n __syncthreads();\n\n const float* c = coords + ((b * N + n) * 3);\n float halfG = (float)G * 0.5f;\n int ix = (int)((c[0] - centers[b*3]) * inv_voxel + halfG);\n int iy = (int)((c[1] - centers[b*3+1]) * inv_voxel + halfG);\n int iz = (int)((c[2] - centers[b*3+2]) * inv_voxel + halfG);\n ix = max(0, min(ix, G-1)); iy = max(0, min(iy, G-1)); iz = max(0, min(iz, G-1));\n int vox = (ix * G + iy) * G + iz;\n\n const float* w = weight + d * 32;\n float acc = bias[d];\n #pragma unroll\n for (int k = 0; k < 32; ++k) acc = fmaf(sf[k], w[k], acc);\n size_t off = (((size_t)b * 32 + d) * (size_t)G * G * G) + vox;\n atomicAdd(out + off, acc);\n}\n\n__global__ void scatter_linear_kernel(\n const float* __restrict__ coords, const float* __restrict__ features,\n const float* __restrict__ weight, const float* __restrict__ bias,\n const float* __restrict__ centers, float* __restrict__ out,\n int B, int N, int F, int G, float inv_voxel) {\n int atom = blockIdx.x; int b = atom / N; int n = atom - b * N; int tid = threadIdx.x;\n const float* c = coords + ((b * N + n) * 3);\n float halfG = (float)G * 0.5f;\n int ix = (int)((c[0] - centers[b*3]) * inv_voxel + halfG);\n int iy = (int)((c[1] - centers[b*3+1]) * inv_voxel + halfG);\n int iz = (int)((c[2] - centers[b*3+2]) * inv_voxel + halfG);\n ix = ix < 0 ? 0 : (ix >= G ? G-1 : ix); iy = iy < 0 ? 0 : (iy >= G ? G-1 : iy); iz = iz < 0 ? 0 : (iz >= G ? G-1 : iz);\n int vox = (ix * G + iy) * G + iz;\n const float* fin = features + ((b * N + n) * F);\n for (int d = tid; d < F; d += blockDim.x) {\n float acc = bias[d]; const float* w = weight + d * F;\n for (int k = 0; k < F; ++k) acc = fmaf(fin[k], w[k], acc);\n size_t off = (((size_t)b * F + d) * (size_t)G * G * G) + vox;\n atomicAdd(out + off, acc);\n }\n}\n\ntorch::Tensor voxel_forward(torch::Tensor coords, torch::Tensor features, torch::Tensor weight, torch::Tensor bias, int64_t grid_size, double voxel_size) {\n int B = (int)coords.size(0), N = (int)coords.size(1), F = (int)features.size(2), G = (int)grid_size;\n auto out = torch::empty({B, F, G, G, G}, coords.options());\n auto centers = torch::empty({B, 3}, coords.options());\n cudaStream_t stream = at::cuda::getCurrentCUDAStream();\n cudaMemsetAsync(out.data_ptr<float>(), 0, (size_t)B * F * G * G * G * sizeof(float), stream);\n center_kernel<<<B, 256, 0, stream>>>(coords.data_ptr<float>(), centers.data_ptr<float>(), B, N);\n if (F == 32) {\n scatter_linear32_kernel<<<B*N, 32, 0, stream>>>(coords.data_ptr<float>(), features.data_ptr<float>(), weight.data_ptr<float>(), bias.data_ptr<float>(), centers.data_ptr<float>(), out.data_ptr<float>(), N, G, 1.0f/(float)voxel_size);\n } else {\n int threads = (F <= 32 ? 32 : (F <= 64 ? 64 : 128));\n scatter_linear_kernel<<<B*N, threads, 0, stream>>>(coords.data_ptr<float>(), features.data_ptr<float>(), weight.data_ptr<float>(), bias.data_ptr<float>(), centers.data_ptr<float>(), out.data_ptr<float>(), B, N, F, G, 1.0f/(float)voxel_size);\n }\n return out;\n}\n'''\n\n_ext = load_inline(name='voxel_pool_ext_v3', cpp_sources=cpp_src, cuda_sources=cuda_src, functions=['voxel_forward'], extra_cflags=['-O3'], extra_cuda_cflags=['-O3', '--use_fast_math'], verbose=False)\n\nclass ModelNew(nn.Module):\n def __init__(self, feat_dim, grid_size=32, voxel_size=1.0):\n super().__init__()\n self.feat_dim = feat_dim\n self.grid_size = grid_size\n self.voxel_size = voxel_size\n self.linear = nn.Linear(feat_dim, feat_dim)\n def forward(self, coords: torch.Tensor, features: torch.Tensor) -> torch.Tensor:\n return _ext.voxel_forward(coords.contiguous(), features.contiguous(), self.linear.weight.contiguous(), self.linear.bias.contiguous(), int(self.grid_size), float(self.voxel_size))\n" }
result ← run_correctness (ok)
okrun_correctness run_correctness PASSED: (5 / 5) trials all matched the reference. Numerical precision: max_abs_err=7.15e-07 mean_abs_err=3.81e-10 max_rel_err=6.52e-03
turn 5 · 1 tool call(s) · 31.0s turn · 31.0s LLM · 7,211 chars (click to expand)
turn 531.0s turn · 31.0s LLM · 0.0s tools
reasoning
**Analyzing block performance** I'm considering the performance of four blocks, each doing substantial operations, but the total seems too low at around 1 million ops. It feels like underutilizing potential since I'm aware of the overhead with the H100 launch and memset. I'm also questioning if a scatter atomic operation is necessary. With low parallelism, I'm thinking that 1024 threads might be enough for this workload, but I'm unsure about the overall runtime, which could only be in the tens of microseconds.
call → static_check
callstatic_check { "kernel_code": "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\n\ncpp_src = r'''\n#include <torch/extension.h>\ntorch::Tensor voxel_forward(torch::Tensor coords, torch::Tensor features, torch::Tensor weight, torch::Tensor bias, int64_t grid_size, double voxel_size);\n'''\n\ncuda_src = r'''\n#include <torch/extension.h>\n#include <ATen/cuda/CUDAContext.h>\n#include <cuda.h>\n#include <cuda_runtime.h>\n\n__global__ void center_kernel(const float* __restrict__ coords, float* __restrict__ centers, int B, int N) {\n int b = blockIdx.x, tid = threadIdx.x;\n float sx = 0.f, sy = 0.f, sz = 0.f;\n for (int i = tid; i < N; i += blockDim.x) {\n const float* p = coords + ((b * N + i) * 3);\n sx += p[0]; sy += p[1]; sz += p[2];\n }\n __shared__ float sh[256*3];\n sh[tid] = sx; sh[256+tid] = sy; sh[512+tid] = sz;\n __syncthreads();\n for (int s = blockDim.x >> 1; s > 0; s >>= 1) {\n if (tid < s) { sh[tid] += sh[tid+s]; sh[256+tid] += sh[256+tid+s]; sh[512+tid] += sh[512+tid+s]; }\n __syncthreads();\n }\n if (tid == 0) {\n float invN = 1.0f / (float)N;\n centers[b*3] = sh[0] * invN;\n centers[b*3+1] = sh[256] * invN;\n centers[b*3+2] = sh[512] * invN;\n }\n}\n\n__global__ void scatter_linear32_kernel(\n const float* __restrict__ coords,\n const float* __restrict__ features,\n const float* __restrict__ weight,\n const float* __restrict__ bias,\n const float* __restrict__ centers,\n float* __restrict__ out,\n int N, int G, float inv_voxel) {\n int atom = blockIdx.x;\n int b = atom / N;\n int n = atom - b * N;\n int d = threadIdx.x;\n __shared__ float sf[32];\n const float* fin = features + ((b * N + n) * 32);\n sf[d] = fin[d];\n __syncthreads();\n\n const float* c = coords + ((b * N + n) * 3);\n float halfG = (float)G * 0.5f;\n int ix = (int)((c[0] - centers[b*3]) * inv_voxel + halfG);\n int iy = (int)((c[1] - centers[b*3+1]) * inv_voxel + halfG);\n int iz = (int)((c[2] - centers[b*3+2]) * inv_voxel + halfG);\n ix = max(0, min(ix, G-1)); iy = max(0, min(iy, G-1)); iz = max(0, min(iz, G-1));\n int vox = (ix * G + iy) * G + iz;\n\n const float* w = weight + d * 32;\n float acc = bias[d];\n #pragma unroll\n for (int k = 0; k < 32; ++k) acc = fmaf(sf[k], w[k], acc);\n size_t off = (((size_t)b * 32 + d) * (size_t)G * G * G) + vox;\n atomicAdd(out + off, acc);\n}\n\n__global__ void scatter_linear_kernel(\n const float* __restrict__ coords, const float* __restrict__ features,\n const float* __restrict__ weight, const float* __restrict__ bias,\n const float* __restrict__ centers, float* __restrict__ out,\n int B, int N, int F, int G, float inv_voxel) {\n int atom = blockIdx.x; int b = atom / N; int n = atom - b * N; int tid = threadIdx.x;\n const float* c = coords + ((b * N + n) * 3);\n float halfG = (float)G * 0.5f;\n int ix = (int)((c[0] - centers[b*3]) * inv_voxel + halfG);\n int iy = (int)((c[1] - centers[b*3+1]) * inv_voxel + halfG);\n int iz = (int)((c[2] - centers[b*3+2]) * inv_voxel + halfG);\n ix = ix < 0 ? 0 : (ix >= G ? G-1 : ix); iy = iy < 0 ? 0 : (iy >= G ? G-1 : iy); iz = iz < 0 ? 0 : (iz >= G ? G-1 : iz);\n int vox = (ix * G + iy) * G + iz;\n const float* fin = features + ((b * N + n) * F);\n for (int d = tid; d < F; d += blockDim.x) {\n float acc = bias[d]; const float* w = weight + d * F;\n for (int k = 0; k < F; ++k) acc = fmaf(fin[k], w[k], acc);\n size_t off = (((size_t)b * F + d) * (size_t)G * G * G) + vox;\n atomicAdd(out + off, acc);\n }\n}\n\ntorch::Tensor voxel_forward(torch::Tensor coords, torch::Tensor features, torch::Tensor weight, torch::Tensor bias, int64_t grid_size, double voxel_size) {\n int B = (int)coords.size(0), N = (int)coords.size(1), F = (int)features.size(2), G = (int)grid_size;\n auto out = torch::empty({B, F, G, G, G}, coords.options());\n auto centers = torch::empty({B, 3}, coords.options());\n cudaStream_t stream = at::cuda::getCurrentCUDAStream();\n cudaMemsetAsync(out.data_ptr<float>(), 0, (size_t)B * F * G * G * G * sizeof(float), stream);\n center_kernel<<<B, 256, 0, stream>>>(coords.data_ptr<float>(), centers.data_ptr<float>(), B, N);\n if (F == 32) {\n scatter_linear32_kernel<<<B*N, 32, 0, stream>>>(coords.data_ptr<float>(), features.data_ptr<float>(), weight.data_ptr<float>(), bias.data_ptr<float>(), centers.data_ptr<float>(), out.data_ptr<float>(), N, G, 1.0f/(float)voxel_size);\n } else {\n int threads = (F <= 32 ? 32 : (F <= 64 ? 64 : 128));\n scatter_linear_kernel<<<B*N, threads, 0, stream>>>(coords.data_ptr<float>(), features.data_ptr<float>(), weight.data_ptr<float>(), bias.data_ptr<float>(), centers.data_ptr<float>(), out.data_ptr<float>(), B, N, F, G, 1.0f/(float)voxel_size);\n }\n return out;\n}\n'''\n\n_ext = load_inline(name='voxel_pool_ext_final', cpp_sources=cpp_src, cuda_sources=cuda_src, functions=['voxel_forward'], extra_cflags=['-O3'], extra_cuda_cflags=['-O3', '--use_fast_math'], verbose=False)\n\nclass ModelNew(nn.Module):\n def __init__(self, feat_dim, grid_size=32, voxel_size=1.0):\n super().__init__()\n self.feat_dim = feat_dim\n self.grid_size = grid_size\n self.voxel_size = voxel_size\n self.linear = nn.Linear(feat_dim, feat_dim)\n def forward(self, coords: torch.Tensor, features: torch.Tensor) -> torch.Tensor:\n return _ext.voxel_forward(coords.contiguous(), features.contiguous(), self.linear.weight.contiguous(), self.linear.bias.contiguous(), int(self.grid_size), float(self.voxel_size))\n" }
result ← static_check (ok)
okstatic_check static_check PASSED: no violations or warnings detected.
turn 6 · FINAL · 1 tool call(s) · 14.9s turn · 14.9s LLM · 7,558 chars (click to expand)
turn 614.9s turn · 14.9s LLM · 0.0s tools · FINAL
reasoning
**Finalizing submission details** I need to submit my code and make sure there’s no name collision. If I have multiple executables, the final extension name will be crucial. The evaluation might run only once, so I need to be careful. If I load the inline cache, it may conflict with an existing name from a static check, but that’s okay. I could make the name unique yet deterministic, ensuring that if it's repeated, it sources the same process. I'll proceed to submit now!
call → submit_kernel
callsubmit_kernel { "kernel_code": "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\n\ncpp_src = r'''\n#include <torch/extension.h>\ntorch::Tensor voxel_forward(torch::Tensor coords, torch::Tensor features, torch::Tensor weight, torch::Tensor bias, int64_t grid_size, double voxel_size);\n'''\n\ncuda_src = r'''\n#include <torch/extension.h>\n#include <ATen/cuda/CUDAContext.h>\n#include <cuda.h>\n#include <cuda_runtime.h>\n\n__global__ void center_kernel(const float* __restrict__ coords, float* __restrict__ centers, int B, int N) {\n int b = blockIdx.x, tid = threadIdx.x;\n float sx = 0.f, sy = 0.f, sz = 0.f;\n for (int i = tid; i < N; i += blockDim.x) {\n const float* p = coords + ((b * N + i) * 3);\n sx += p[0]; sy += p[1]; sz += p[2];\n }\n __shared__ float sh[256*3];\n sh[tid] = sx; sh[256+tid] = sy; sh[512+tid] = sz;\n __syncthreads();\n for (int s = blockDim.x >> 1; s > 0; s >>= 1) {\n if (tid < s) { sh[tid] += sh[tid+s]; sh[256+tid] += sh[256+tid+s]; sh[512+tid] += sh[512+tid+s]; }\n __syncthreads();\n }\n if (tid == 0) {\n float invN = 1.0f / (float)N;\n centers[b*3] = sh[0] * invN;\n centers[b*3+1] = sh[256] * invN;\n centers[b*3+2] = sh[512] * invN;\n }\n}\n\n__global__ void scatter_linear32_kernel(\n const float* __restrict__ coords,\n const float* __restrict__ features,\n const float* __restrict__ weight,\n const float* __restrict__ bias,\n const float* __restrict__ centers,\n float* __restrict__ out,\n int N, int G, float inv_voxel) {\n int atom = blockIdx.x;\n int b = atom / N;\n int n = atom - b * N;\n int d = threadIdx.x;\n __shared__ float sf[32];\n const float* fin = features + ((b * N + n) * 32);\n sf[d] = fin[d];\n __syncthreads();\n\n const float* c = coords + ((b * N + n) * 3);\n float halfG = (float)G * 0.5f;\n int ix = (int)((c[0] - centers[b*3]) * inv_voxel + halfG);\n int iy = (int)((c[1] - centers[b*3+1]) * inv_voxel + halfG);\n int iz = (int)((c[2] - centers[b*3+2]) * inv_voxel + halfG);\n ix = max(0, min(ix, G-1)); iy = max(0, min(iy, G-1)); iz = max(0, min(iz, G-1));\n int vox = (ix * G + iy) * G + iz;\n\n const float* w = weight + d * 32;\n float acc = bias[d];\n #pragma unroll\n for (int k = 0; k < 32; ++k) acc = fmaf(sf[k], w[k], acc);\n size_t off = (((size_t)b * 32 + d) * (size_t)G * G * G) + vox;\n atomicAdd(out + off, acc);\n}\n\n__global__ void scatter_linear_kernel(\n const float* __restrict__ coords, const float* __restrict__ features,\n const float* __restrict__ weight, const float* __restrict__ bias,\n const float* __restrict__ centers, float* __restrict__ out,\n int B, int N, int F, int G, float inv_voxel) {\n int atom = blockIdx.x; int b = atom / N; int n = atom - b * N; int tid = threadIdx.x;\n const float* c = coords + ((b * N + n) * 3);\n float halfG = (float)G * 0.5f;\n int ix = (int)((c[0] - centers[b*3]) * inv_voxel + halfG);\n int iy = (int)((c[1] - centers[b*3+1]) * inv_voxel + halfG);\n int iz = (int)((c[2] - centers[b*3+2]) * inv_voxel + halfG);\n ix = ix < 0 ? 0 : (ix >= G ? G-1 : ix); iy = iy < 0 ? 0 : (iy >= G ? G-1 : iy); iz = iz < 0 ? 0 : (iz >= G ? G-1 : iz);\n int vox = (ix * G + iy) * G + iz;\n const float* fin = features + ((b * N + n) * F);\n for (int d = tid; d < F; d += blockDim.x) {\n float acc = bias[d]; const float* w = weight + d * F;\n for (int k = 0; k < F; ++k) acc = fmaf(fin[k], w[k], acc);\n size_t off = (((size_t)b * F + d) * (size_t)G * G * G) + vox;\n atomicAdd(out + off, acc);\n }\n}\n\ntorch::Tensor voxel_forward(torch::Tensor coords, torch::Tensor features, torch::Tensor weight, torch::Tensor bias, int64_t grid_size, double voxel_size) {\n int B = (int)coords.size(0), N = (int)coords.size(1), F = (int)features.size(2), G = (int)grid_size;\n auto out = torch::empty({B, F, G, G, G}, coords.options());\n auto centers = torch::empty({B, 3}, coords.options());\n cudaStream_t stream = at::cuda::getCurrentCUDAStream();\n cudaMemsetAsync(out.data_ptr<float>(), 0, (size_t)B * F * G * G * G * sizeof(float), stream);\n center_kernel<<<B, 256, 0, stream>>>(coords.data_ptr<float>(), centers.data_ptr<float>(), B, N);\n if (F == 32) {\n scatter_linear32_kernel<<<B*N, 32, 0, stream>>>(coords.data_ptr<float>(), features.data_ptr<float>(), weight.data_ptr<float>(), bias.data_ptr<float>(), centers.data_ptr<float>(), out.data_ptr<float>(), N, G, 1.0f/(float)voxel_size);\n } else {\n int threads = (F <= 32 ? 32 : (F <= 64 ? 64 : 128));\n scatter_linear_kernel<<<B*N, threads, 0, stream>>>(coords.data_ptr<float>(), features.data_ptr<float>(), weight.data_ptr<float>(), bias.data_ptr<float>(), centers.data_ptr<float>(), out.data_ptr<float>(), B, N, F, G, 1.0f/(float)voxel_size);\n }\n return out;\n}\n'''\n\n_ext = load_inline(name='voxel_pool_ext_final', cpp_sources=cpp_src, cuda_sources=cuda_src, functions=['voxel_forward'], extra_cflags=['-O3'], extra_cuda_cflags=['-O3', '--use_fast_math'], verbose=False)\n\nclass ModelNew(nn.Module):\n def __init__(self, feat_dim, grid_size=32, voxel_size=1.0):\n super().__init__()\n self.feat_dim = feat_dim\n self.grid_size = grid_size\n self.voxel_size = voxel_size\n self.linear = nn.Linear(feat_dim, feat_dim)\n def forward(self, coords: torch.Tensor, features: torch.Tensor) -> torch.Tensor:\n return _ext.voxel_forward(coords.contiguous(), features.contiguous(), self.linear.weight.contiguous(), self.linear.bias.contiguous(), int(self.grid_size), float(self.voxel_size))\n" }
result ← submit_kernel (ok)
oksubmit_kernel submit_kernel PASSED: (5 / 5) correctness trials all passed. Kernel runtime: 0.02 μs Runtime stats: mean=0.02μs median=?μs std=0.00μs Numerical precision: max_abs_err=7.15e-07 mean_abs_err=3.81e-10 max_rel_err=6.52e-03 Memory: 49.15 MB peak (ref: 49.85 MB, ratio: 0.9859x) Kernel launches: 2 (ref: 4484, fusion ratio: 2242.0) SOL score: 0.0585 Flagged for excessive speedup — this submission may have been rejected by automated review.
final submitted kernel (121 lines, 5,590 chars) — full source, untruncated
import torch
import torch.nn as nn
from torch.utils.cpp_extension import load_inline

cpp_src = r'''
#include <torch/extension.h>
torch::Tensor voxel_forward(torch::Tensor coords, torch::Tensor features, torch::Tensor weight, torch::Tensor bias, int64_t grid_size, double voxel_size);
'''

cuda_src = r'''
#include <torch/extension.h>
#include <ATen/cuda/CUDAContext.h>
#include <cuda.h>
#include <cuda_runtime.h>

__global__ void center_kernel(const float* __restrict__ coords, float* __restrict__ centers, int B, int N) {
    int b = blockIdx.x, tid = threadIdx.x;
    float sx = 0.f, sy = 0.f, sz = 0.f;
    for (int i = tid; i < N; i += blockDim.x) {
        const float* p = coords + ((b * N + i) * 3);
        sx += p[0]; sy += p[1]; sz += p[2];
    }
    __shared__ float sh[256*3];
    sh[tid] = sx; sh[256+tid] = sy; sh[512+tid] = sz;
    __syncthreads();
    for (int s = blockDim.x >> 1; s > 0; s >>= 1) {
        if (tid < s) { sh[tid] += sh[tid+s]; sh[256+tid] += sh[256+tid+s]; sh[512+tid] += sh[512+tid+s]; }
        __syncthreads();
    }
    if (tid == 0) {
        float invN = 1.0f / (float)N;
        centers[b*3] = sh[0] * invN;
        centers[b*3+1] = sh[256] * invN;
        centers[b*3+2] = sh[512] * invN;
    }
}

__global__ void scatter_linear32_kernel(
    const float* __restrict__ coords,
    const float* __restrict__ features,
    const float* __restrict__ weight,
    const float* __restrict__ bias,
    const float* __restrict__ centers,
    float* __restrict__ out,
    int N, int G, float inv_voxel) {
    int atom = blockIdx.x;
    int b = atom / N;
    int n = atom - b * N;
    int d = threadIdx.x;
    __shared__ float sf[32];
    const float* fin = features + ((b * N + n) * 32);
    sf[d] = fin[d];
    __syncthreads();

    const float* c = coords + ((b * N + n) * 3);
    float halfG = (float)G * 0.5f;
    int ix = (int)((c[0] - centers[b*3]) * inv_voxel + halfG);
    int iy = (int)((c[1] - centers[b*3+1]) * inv_voxel + halfG);
    int iz = (int)((c[2] - centers[b*3+2]) * inv_voxel + halfG);
    ix = max(0, min(ix, G-1)); iy = max(0, min(iy, G-1)); iz = max(0, min(iz, G-1));
    int vox = (ix * G + iy) * G + iz;

    const float* w = weight + d * 32;
    float acc = bias[d];
    #pragma unroll
    for (int k = 0; k < 32; ++k) acc = fmaf(sf[k], w[k], acc);
    size_t off = (((size_t)b * 32 + d) * (size_t)G * G * G) + vox;
    atomicAdd(out + off, acc);
}

__global__ void scatter_linear_kernel(
    const float* __restrict__ coords, const float* __restrict__ features,
    const float* __restrict__ weight, const float* __restrict__ bias,
    const float* __restrict__ centers, float* __restrict__ out,
    int B, int N, int F, int G, float inv_voxel) {
    int atom = blockIdx.x; int b = atom / N; int n = atom - b * N; int tid = threadIdx.x;
    const float* c = coords + ((b * N + n) * 3);
    float halfG = (float)G * 0.5f;
    int ix = (int)((c[0] - centers[b*3]) * inv_voxel + halfG);
    int iy = (int)((c[1] - centers[b*3+1]) * inv_voxel + halfG);
    int iz = (int)((c[2] - centers[b*3+2]) * inv_voxel + halfG);
    ix = ix < 0 ? 0 : (ix >= G ? G-1 : ix); iy = iy < 0 ? 0 : (iy >= G ? G-1 : iy); iz = iz < 0 ? 0 : (iz >= G ? G-1 : iz);
    int vox = (ix * G + iy) * G + iz;
    const float* fin = features + ((b * N + n) * F);
    for (int d = tid; d < F; d += blockDim.x) {
        float acc = bias[d]; const float* w = weight + d * F;
        for (int k = 0; k < F; ++k) acc = fmaf(fin[k], w[k], acc);
        size_t off = (((size_t)b * F + d) * (size_t)G * G * G) + vox;
        atomicAdd(out + off, acc);
    }
}

torch::Tensor voxel_forward(torch::Tensor coords, torch::Tensor features, torch::Tensor weight, torch::Tensor bias, int64_t grid_size, double voxel_size) {
    int B = (int)coords.size(0), N = (int)coords.size(1), F = (int)features.size(2), G = (int)grid_size;
    auto out = torch::empty({B, F, G, G, G}, coords.options());
    auto centers = torch::empty({B, 3}, coords.options());
    cudaStream_t stream = at::cuda::getCurrentCUDAStream();
    cudaMemsetAsync(out.data_ptr<float>(), 0, (size_t)B * F * G * G * G * sizeof(float), stream);
    center_kernel<<<B, 256, 0, stream>>>(coords.data_ptr<float>(), centers.data_ptr<float>(), B, N);
    if (F == 32) {
        scatter_linear32_kernel<<<B*N, 32, 0, stream>>>(coords.data_ptr<float>(), features.data_ptr<float>(), weight.data_ptr<float>(), bias.data_ptr<float>(), centers.data_ptr<float>(), out.data_ptr<float>(), N, G, 1.0f/(float)voxel_size);
    } else {
        int threads = (F <= 32 ? 32 : (F <= 64 ? 64 : 128));
        scatter_linear_kernel<<<B*N, threads, 0, stream>>>(coords.data_ptr<float>(), features.data_ptr<float>(), weight.data_ptr<float>(), bias.data_ptr<float>(), centers.data_ptr<float>(), out.data_ptr<float>(), B, N, F, G, 1.0f/(float)voxel_size);
    }
    return out;
}
'''

_ext = load_inline(name='voxel_pool_ext_final', cpp_sources=cpp_src, cuda_sources=cuda_src, functions=['voxel_forward'], extra_cflags=['-O3'], extra_cuda_cflags=['-O3', '--use_fast_math'], verbose=False)

class ModelNew(nn.Module):
    def __init__(self, feat_dim, grid_size=32, voxel_size=1.0):
        super().__init__()
        self.feat_dim = feat_dim
        self.grid_size = grid_size
        self.voxel_size = voxel_size
        self.linear = nn.Linear(feat_dim, feat_dim)
    def forward(self, coords: torch.Tensor, features: torch.Tensor) -> torch.Tensor:
        return _ext.voxel_forward(coords.contiguous(), features.contiguous(), self.linear.weight.contiguous(), self.linear.bias.contiguous(), int(self.grid_size), float(self.voxel_size))