compile_fail
6_EdgeSoftmaxMultiHeadCSR.py
model
Llama-4-Maverick-17B-128E-Instruct-FP8
started
2026-05-11T08:39:54Z
compile error: load_inline() missing 1 required positional argument: 'cpp_sources'
timingkernelbench.timing
kernel mean / median / std
—
reference PyTorch source (the prompt the agent sees)
import torch
import torch.nn as nn
class Model(nn.Module):
"""
Multi-head row-wise softmax over CSR edge scores.
This extends scalar graph edge softmax to multiple attention heads while
preserving sparse CSR layout. Each row is normalized independently for each
head.
"""
def __init__(self):
super().__init__()
def forward(
self,
row_ptr: torch.Tensor,
edge_scores: torch.Tensor,
) -> torch.Tensor:
num_nodes = row_ptr.numel() - 1
out = torch.empty_like(edge_scores)
for node in range(num_nodes):
start = int(row_ptr[node].item())
end = int(row_ptr[node + 1].item())
if end > start:
out[start:end] = torch.softmax(edge_scores[start:end], dim=0)
return out
num_nodes = 384
avg_degree = 18
num_heads = 8
def get_inputs():
return list(popcorn_pri.make_csr_multihead_edge_scores(num_nodes, avg_degree, num_heads))
def get_init_inputs():
return []
turn 06.0s turn · 5.9s LLM · 0.1s tools · tokens in=1,132 · out=847 · total=1,979 · 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\ncuda_source = '''\n#include <cuda_runtime.h>\n#include <cuda_fp16.h>\n\n__global__ void row_wise_softmax_kernel(\n const int* row_ptr,\n const float* edge_scores,\n float* out,\n int num_nodes,\n int num_heads\n) {\n int node = blockIdx.x;\n if (node >= num_nodes) return;\n\n int start = row_ptr[node];\n int end = row_ptr[node + 1];\n int num_edges = end - start;\n\n if (num_edges == 0) return;\n\n edge_scores += start * num_heads;\n out += start * num_heads;\n\n for (int head = threadIdx.y; head < num_heads; head += blockDim.y) {\n float max_score = edge_scores[head];\n for (int i = threadIdx.x + 1; i < num_edges; i += blockDim.x) {\n max_score = fmaxf(max_score, edge_scores[i * num_heads + head]);\n }\n max_score = __shfl_sync(0xFFFFFFFF, max_score, 0);\n\n float sum_exp = __expf(edge_scores[head] - max_score);\n for (int i = threadIdx.x + 1; i < num_edges; i += blockDim.x) {\n sum_exp += __expf(edge_scores[i * num_heads + head] - max_score);\n }\n#pragma unroll\n for (int offset = blockDim.x / 2; offset > 0; offset /= 2) {\n sum_exp += __shfl_down_sync(0xFFFFFFFF, sum_exp, offset);\n }\n sum_exp = __shfl_sync(0xFFFFFFFF, sum_exp, 0);\n\n out[head] = __expf(edge_scores[head] - max_score) / sum_exp;\n for (int i = threadIdx.x + 1; i < num_edges; i += blockDim.x) {\n out[i * num_heads + head] = __expf(edge_scores[i * num_heads + head] - max_score) / sum_exp;\n }\n }\n}\n\ntorch::Tensor row_wise_softmax(\ntorch::Tensor row_ptr,\ntorch::Tensor edge_scores\n) {\n int num_nodes = row_ptr.numel() - 1;\n int num_edges = row_ptr[num_nodes].item<int>();\n int num_heads = edge_scores.size(1);\n\n auto out = torch::empty_like(edge_scores);\n\n int blockSize = 32;\n dim3 block(blockSize, 8);\n dim3 grid(num_nodes);\n\n row_wise_softmax_kernel<<<grid, block>>>(\n row_ptr.data_ptr<int>(),\n edge_scores.data_ptr<float>(),\n out.data_ptr<float>(),\n num_nodes,\n num_heads\n );\n\n return out;\n}\n'''\n\nmodule = load_inline(\n name='row_wise_softmax_cuda',\n cuda_sources=[cuda_source],\n functions=['row_wise_softmax'],\n extra_cuda_cflags=['-O3', '--use_fast_math'],\n)\n\nclass ModelNew(nn.Module):\n def __init__(self):\n super().__init__()\n\n def forward(\n self,\n row_ptr: torch.Tensor,\n edge_scores: torch.Tensor,\n ) -> torch.Tensor:\n return module.row_wise_softmax(row_ptr, edge_scores)"
}
result ← submit_kernel (fail)
failsubmit_kernel
submit_kernel FAILED: kernel did not compile.
load_inline() missing 1 required positional argument: 'cpp_sources'
final submitted kernel (95 lines, 2,617 chars) — full source, untruncated
import torch
import torch.nn as nn
from torch.utils.cpp_extension import load_inline
cuda_source = '''
#include <cuda_runtime.h>
#include <cuda_fp16.h>
__global__ void row_wise_softmax_kernel(
const int* row_ptr,
const float* edge_scores,
float* out,
int num_nodes,
int num_heads
) {
int node = blockIdx.x;
if (node >= num_nodes) return;
int start = row_ptr[node];
int end = row_ptr[node + 1];
int num_edges = end - start;
if (num_edges == 0) return;
edge_scores += start * num_heads;
out += start * num_heads;
for (int head = threadIdx.y; head < num_heads; head += blockDim.y) {
float max_score = edge_scores[head];
for (int i = threadIdx.x + 1; i < num_edges; i += blockDim.x) {
max_score = fmaxf(max_score, edge_scores[i * num_heads + head]);
}
max_score = __shfl_sync(0xFFFFFFFF, max_score, 0);
float sum_exp = __expf(edge_scores[head] - max_score);
for (int i = threadIdx.x + 1; i < num_edges; i += blockDim.x) {
sum_exp += __expf(edge_scores[i * num_heads + head] - max_score);
}
#pragma unroll
for (int offset = blockDim.x / 2; offset > 0; offset /= 2) {
sum_exp += __shfl_down_sync(0xFFFFFFFF, sum_exp, offset);
}
sum_exp = __shfl_sync(0xFFFFFFFF, sum_exp, 0);
out[head] = __expf(edge_scores[head] - max_score) / sum_exp;
for (int i = threadIdx.x + 1; i < num_edges; i += blockDim.x) {
out[i * num_heads + head] = __expf(edge_scores[i * num_heads + head] - max_score) / sum_exp;
}
}
}
torch::Tensor row_wise_softmax(
torch::Tensor row_ptr,
torch::Tensor edge_scores
) {
int num_nodes = row_ptr.numel() - 1;
int num_edges = row_ptr[num_nodes].item<int>();
int num_heads = edge_scores.size(1);
auto out = torch::empty_like(edge_scores);
int blockSize = 32;
dim3 block(blockSize, 8);
dim3 grid(num_nodes);
row_wise_softmax_kernel<<<grid, block>>>(
row_ptr.data_ptr<int>(),
edge_scores.data_ptr<float>(),
out.data_ptr<float>(),
num_nodes,
num_heads
);
return out;
}
'''
module = load_inline(
name='row_wise_softmax_cuda',
cuda_sources=[cuda_source],
functions=['row_wise_softmax'],
extra_cuda_cflags=['-O3', '--use_fast_math'],
)
class ModelNew(nn.Module):
def __init__(self):
super().__init__()
def forward(
self,
row_ptr: torch.Tensor,
edge_scores: torch.Tensor,
) -> torch.Tensor:
return module.row_wise_softmax(row_ptr, edge_scores)