reference PyTorch source (the prompt the agent sees)
"""
Unequal virtual shard lengths: x is (R, S_MAX) with a fixed boolean mask marking valid cells.
Output (S_MAX,) is sum_r x[r, j] * mask[r, j] (masked sum along the virtual rank dimension).
Padding positions are masked out so they do not contribute.
"""
import torch
import torch.nn as nn
from kernelbench.distributed_collectives import default_device
R = 4
S_MAX = 20
# mask[r, j] == True iff rank r contributes a real value at column j
_MASK_DATA = [
[1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
]
class Model(nn.Module):
def __init__(self):
super().__init__()
self.register_buffer(
"shard_mask",
torch.tensor(_MASK_DATA, dtype=torch.bool),
persistent=False,
)
def forward(self, x: torch.Tensor) -> torch.Tensor:
m = self.shard_mask.to(dtype=x.dtype, device=x.device)
return (x * m).sum(dim=0)
def get_inputs():
dev = default_device()
p = popcorn_pri
return [torch.randn(p.jitter_int(R), p.jitter_int(S_MAX), device=dev)]
def get_init_inputs():
return []
turn 012.3s turn · 12.3s LLM · 0.0s tools · FINAL
call → submit_kernel
callsubmit_kernel
{
"kernel_code": "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\n\n_cuda_src = r'''\n#include <torch/extension.h>\n#include <ATen/cuda/CUDAContext.h>\n#include <cuda_runtime.h>\n\n__global__ __launch_bounds__(32, 8)\nvoid masked_sum4x20_kernel(const float* __restrict__ x, float* __restrict__ y) {\n int j = threadIdx.x;\n if (j < 20) {\n float v;\n if (j < 8) {\n v = x[j] + x[20 + j] + x[40 + j] + x[60 + j];\n } else if (j < 10) {\n v = x[20 + j] + x[40 + j] + x[60 + j];\n } else if (j < 12) {\n v = x[20 + j] + x[60 + j];\n } else if (j < 18) {\n v = x[60 + j];\n } else {\n v = 0.0f;\n }\n y[j] = v;\n }\n}\n\ntorch::Tensor masked_sum_forward(torch::Tensor x) {\n auto y = torch::empty({20}, x.options());\n masked_sum4x20_kernel<<<1, 32, 0, at::cuda::getCurrentCUDAStream()>>>(\n x.data_ptr<float>(), y.data_ptr<float>());\n return y;\n}\n'''\n\n_ext = load_inline(\n name='masked_sum4x20_ext',\n cpp_sources='',\n cuda_sources=_cuda_src,\n functions=['masked_sum_forward'],\n extra_cuda_cflags=['-O3'],\n extra_cflags=['-O3'],\n verbose=False,\n)\n\nclass ModelNew(nn.Module):\n def __init__(self):\n super().__init__()\n\n def forward(self, x: torch.Tensor) -> torch.Tensor:\n return _ext.masked_sum_forward(x)\n"
}
result ← submit_kernel (fail)
failsubmit_kernel
submit_kernel FAILED: kernel did not compile.
Error building extension 'masked_sum4x20_ext': [1/3] /opt/conda/bin/x86_64-conda-linux-gnu-c++ -MMD -MF main.o.d -DTORCH_EXTENSION_NAME=masked_sum4x20_ext -DTORCH_API_INCLUDE_EXTENSION_H -isystem /scratch/abaner/KernelBench/.venv/lib/python3.10/site-packages/torch/include -isystem /scratch/abaner/KernelBench/.venv/lib/python3.10/site-packages/torch/include/torch/csrc/api/include -isystem /usr/local/cuda/include -isystem /opt/conda/include/python3.10 -fPIC -std=c++17 -O3 -c /scratch/abaner/KernelBench/runs/l123_single_gpt/popcorn/gpt-5.5-priority/level_1_problem_25_cache/k_25129b82ccd3/masked_sum4x20_ext/main.cpp -o main.o
FAILED: [code=1] main.o
/opt/conda/bin/x86_64-conda-linux-gnu-c++ -MMD -MF main.o.d -DTORCH_EXTENSION_NAME=masked_sum4x20_ext -DTORCH_API_INCLUDE_EXTENSION_H -isystem /scratch/abaner/KernelBench/.venv/lib/python3.10/site-packages/torch/include -isystem /scratch/abaner/KernelBench/.venv/lib/python3.10/site-packages/torch/include/torch/csrc/api/include -isystem /usr/local/cuda/include -isystem /opt/conda/include/python3.10 -fPIC -std=c++17 -O3 -c /scratch/abaner/KernelBench/runs/l123_single_gpt/popcorn/gpt-5.5-priority/level_1_problem_25_cache/k_25129b82ccd3/masked_sum4x20_ext/main.cpp -o main.o
/scratch/abaner/KernelBench/runs/l123_single_gpt/popcorn/gpt-5.5-priority/level_1_problem_25_cache/k_25129b82ccd3/masked_sum4x20_ext/main.cpp: In function 'void pybind11_init_masked_sum4x20_ext(pybind11::module_&)':
/scratch/abaner/KernelBench/runs/l123_single_gpt/popcorn/gpt-5.5-priority/level_1_problem_25_cache/k_25129b82ccd3/masked_sum4x20_ext/main.cpp:4:57: error: 'masked_sum_forward' was not declared in this scope
4 | m.def("masked_sum_forward", torch::wrap_pybind_function(masked_sum_forward), "masked_sum_forward");
| ^~~~~~~~~~~~~~~~~~
[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=masked_sum4x20_ext -DTORCH_API_INCLUDE_EXTENSION_H -isystem /scratch/abaner/KernelBench/.venv/lib/python3.10/site-packages/torch/include -isystem /scratch/abaner/KernelBench/.venv/lib/python3.10/site-packages/torch/include/torch/csrc/api/include -isystem /usr/local/cuda/include -isystem /opt/conda/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 -std=c++17 -c /scratch/abaner/KernelBench/runs/l123_single_gpt/popcorn/gpt-5.5-priority/level_1_problem_25_cache/k_25129b82ccd3/masked_sum4x20_ext/cuda.cu -o cuda.cuda.o
nvcc warning : incompatible redefinition for option 'compiler-bindir', the last value of this option was used
ninja: build stopped: subcommand failed.
final submitted kernel (54 lines, 1,368 chars) — full source, untruncated
import torch
import torch.nn as nn
from torch.utils.cpp_extension import load_inline
_cuda_src = r'''
#include <torch/extension.h>
#include <ATen/cuda/CUDAContext.h>
#include <cuda_runtime.h>
__global__ __launch_bounds__(32, 8)
void masked_sum4x20_kernel(const float* __restrict__ x, float* __restrict__ y) {
int j = threadIdx.x;
if (j < 20) {
float v;
if (j < 8) {
v = x[j] + x[20 + j] + x[40 + j] + x[60 + j];
} else if (j < 10) {
v = x[20 + j] + x[40 + j] + x[60 + j];
} else if (j < 12) {
v = x[20 + j] + x[60 + j];
} else if (j < 18) {
v = x[60 + j];
} else {
v = 0.0f;
}
y[j] = v;
}
}
torch::Tensor masked_sum_forward(torch::Tensor x) {
auto y = torch::empty({20}, x.options());
masked_sum4x20_kernel<<<1, 32, 0, at::cuda::getCurrentCUDAStream()>>>(
x.data_ptr<float>(), y.data_ptr<float>());
return y;
}
'''
_ext = load_inline(
name='masked_sum4x20_ext',
cpp_sources='',
cuda_sources=_cuda_src,
functions=['masked_sum_forward'],
extra_cuda_cflags=['-O3'],
extra_cflags=['-O3'],
verbose=False,
)
class ModelNew(nn.Module):
def __init__(self):
super().__init__()
def forward(self, x: torch.Tensor) -> torch.Tensor:
return _ext.masked_sum_forward(x)