correct
21_RadialBasisFunctionExpansion.py
started
2026-05-04T07:40:44Z
timingkernelbench.timing
kernel mean / median / std
0.07 / — / 2.73e-04 μs
ref mean / median / std
0.51 / — / 0.00 μs
numerical precisioneval_kernel_against_ref
gpu memoryextended_metrics.measure_memory
kernel launches / fusiontorch.profiler
fusion ratio (ref / kernel)
10.00x
SOL (speed-of-light)nsight_hardware_counters
roofline / occupancynsight_hardware_counters
dram bandwidth
1685.18 GB/s
warp stalls (top 5)nsight
reference PyTorch source (the prompt the agent sees)
import torch
import torch.nn as nn
import math
class Model(nn.Module):
"""
Radial Basis Function (RBF) expansion of interatomic distances.
Standard featurization in molecular graph neural networks (SchNet,
DimeNet, GemNet) that converts scalar distances into a feature vector
of Gaussian-basis evaluations.
"""
def __init__(self, num_rbf=64, cutoff=5.0):
super().__init__()
self.num_rbf = num_rbf
self.cutoff = cutoff
offsets = torch.linspace(0.0, cutoff, num_rbf)
self.register_buffer("offsets", offsets)
coeff = -0.5 / (offsets[1] - offsets[0]).item() ** 2
self.coeff = coeff
def forward(self, distances: torch.Tensor) -> torch.Tensor:
"""
Args:
distances: (B, N, N) – pairwise distance matrix (or (B, E) edge list)
Returns:
rbf_features: (*distances.shape, num_rbf) – expanded features
"""
# Cosine cutoff envelope
d_scaled = distances.unsqueeze(-1) # (..., 1)
envelope = 0.5 * (torch.cos(math.pi * d_scaled / self.cutoff) + 1.0)
envelope = envelope * (d_scaled < self.cutoff).float()
rbf = torch.exp(self.coeff * (d_scaled - self.offsets) ** 2)
return rbf * envelope
num_atoms = 256
num_rbf = 64
cutoff = 5.0
batch_size = 8
def get_inputs():
p = popcorn_pri
coords = torch.randn(p.jitter_int(batch_size), p.jitter_int(num_atoms), 3)
diff = coords.unsqueeze(2) - coords.unsqueeze(1)
distances = torch.sqrt((diff ** 2).sum(-1) + 1e-8)
return [distances]
def get_init_inputs():
return [num_rbf, cutoff]
turn 09.8s turn · 9.8s LLM · 0.0s tools
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 127.5s turn · 27.5s LLM · 0.0s tools
reasoning
**Checking calculations for outputs**
I want to ensure that if M equals 64, I need to call a specific function. Otherwise, I should handle it with a more generic approach for output. I’m really focused on getting the values correct, especially when it comes to diagonal distances. It seems important to avoid getting a zero value and stick with something more precise, like using the square root of 1e-8, which is 1e-4 instead.
**Calculating in PyTorch**
I’m considering using cosf and expf with float32 in PyTorch. I need to check the math constants and how torch.cos works with float32, especially regarding tolerances. There's a potential issue with coefficients when calculating. I'm thinking about how to manage offsets and ensure enough precision, particularly with sensitivities at peaks. It seems like I should use a C++ host function and remember to include cuda_runtime.h. Okay, let’s move forward and compile for correctness!
call → compile_kernel
callcompile_kernel
{
"kernel_code": "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\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#include <math_constants.h>\n\n__global__ __launch_bounds__(256, 4)\nvoid rbf64_kernel(const float* __restrict__ distances, float* __restrict__ out,\n long long n, float cutoff, float coeff) {\n __shared__ float sd[4];\n __shared__ float se[4];\n int tid = threadIdx.x;\n int group = tid >> 6; // 0..3\n int k = tid & 63;\n long long i = (long long)blockIdx.x * 4 + group;\n if (i < n && k == 0) {\n float d = distances[i];\n sd[group] = d;\n float e = 0.0f;\n if (d < cutoff) {\n e = 0.5f * (cosf(CUDART_PI_F * d / cutoff) + 1.0f);\n }\n se[group] = e;\n }\n __syncthreads();\n if (i < n) {\n float d = sd[group];\n float center = ((float)k) * cutoff * (1.0f / 63.0f);\n float x = d - center;\n out[i * 64 + k] = expf(coeff * x * x) * se[group];\n }\n}\n\n__global__ __launch_bounds__(256, 4)\nvoid rbf_generic_kernel(const float* __restrict__ distances, float* __restrict__ out,\n long long total, int m, float cutoff, float coeff) {\n long long idx = (long long)blockIdx.x * blockDim.x + threadIdx.x;\n if (idx < total) {\n int k = (int)(idx % m);\n long long i = idx / m;\n float d = distances[i];\n float env = 0.0f;\n if (d < cutoff) env = 0.5f * (cosf(CUDART_PI_F * d / cutoff) + 1.0f);\n float center = ((float)k) * cutoff / ((float)(m - 1));\n float x = d - center;\n out[idx] = expf(coeff * x * x) * env;\n }\n}\n\ntorch::Tensor rbf_forward(torch::Tensor distances, int64_t num_rbf, double cutoff_d, double coeff_d) {\n auto out = torch::empty({distances.numel(), num_rbf}, distances.options());\n long long n = distances.numel();\n float cutoff = (float)cutoff_d;\n float coeff = (float)coeff_d;\n cudaStream_t stream = at::cuda::getCurrentCUDAStream();\n if (num_rbf == 64) {\n dim3 block(256);\n dim3 grid((unsigned int)((n + 3) / 4));\n rbf64_kernel<<<grid, block, 0, stream>>>(distances.data_ptr<float>(), out.data_ptr<float>(), n, cutoff, coeff);\n } else {\n long long total = n * num_rbf;\n dim3 block(256);\n dim3 grid((unsigned int)((total + 255) / 256));\n rbf_generic_kernel<<<grid, block, 0, stream>>>(distances.data_ptr<float>(), out.data_ptr<float>(), total, (int)num_rbf, cutoff, coeff);\n }\n return out.view(torch::IntArrayRef(distances.sizes().vec())).unsqueeze(-1).expand({}).contiguous();\n}\n'''\n\n# The view/expand trick above is not suitable for adding num_rbf; define C++ wrapper returning flat then Python reshapes.\ncpp_src = \"torch::Tensor rbf_forward(torch::Tensor distances, int64_t num_rbf, double cutoff, double coeff);\"\n\n_rbf_ext = load_inline(\n name=\"rbf_ext_v1\",\n cpp_sources=cpp_src,\n cuda_sources=cuda_src,\n functions=[\"rbf_forward\"],\n extra_cuda_cflags=[\"-O3\", \"--use_fast_math\"],\n extra_cflags=[\"-O3\"],\n verbose=False,\n)\n\nclass ModelNew(nn.Module):\n def __init__(self, num_rbf=64, cutoff=5.0):\n super().__init__()\n self.num_rbf = num_rbf\n self.cutoff = cutoff\n offsets = torch.linspace(0.0, cutoff, num_rbf)\n self.register_buffer(\"offsets\", offsets)\n coeff = -0.5 / (offsets[1] - offsets[0]).item() ** 2\n self.coeff = coeff\n\n def forward(self, distances: torch.Tensor) -> torch.Tensor:\n flat_out = _rbf_ext.rbf_forward(distances, int(self.num_rbf), float(self.cutoff), float(self.coeff))\n return flat_out.view(*distances.shape, self.num_rbf)\n"
}
result ← compile_kernel (ok)
okcompile_kernel
compile_kernel PASSED: kernel compiled without errors.
turn 28.1s turn · 8.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\ncuda_src = r'''\n#include <torch/extension.h>\n#include <ATen/cuda/CUDAContext.h>\n#include <cuda.h>\n#include <cuda_runtime.h>\n#include <math_constants.h>\n\n__global__ __launch_bounds__(256, 4)\nvoid rbf64_kernel(const float* __restrict__ distances, float* __restrict__ out,\n long long n, float cutoff, float coeff) {\n __shared__ float sd[4];\n __shared__ float se[4];\n int tid = threadIdx.x;\n int group = tid >> 6;\n int k = tid & 63;\n long long i = (long long)blockIdx.x * 4 + group;\n if (i < n && k == 0) {\n float d = distances[i];\n sd[group] = d;\n float e = 0.0f;\n if (d < cutoff) {\n e = 0.5f * (cosf(CUDART_PI_F * d / cutoff) + 1.0f);\n }\n se[group] = e;\n }\n __syncthreads();\n if (i < n) {\n float d = sd[group];\n float center = ((float)k) * cutoff * (1.0f / 63.0f);\n float x = d - center;\n out[i * 64 + k] = expf(coeff * x * x) * se[group];\n }\n}\n\n__global__ __launch_bounds__(256, 4)\nvoid rbf_generic_kernel(const float* __restrict__ distances, float* __restrict__ out,\n long long total, int m, float cutoff, float coeff) {\n long long idx = (long long)blockIdx.x * blockDim.x + threadIdx.x;\n if (idx < total) {\n int k = (int)(idx % m);\n long long i = idx / m;\n float d = distances[i];\n float env = 0.0f;\n if (d < cutoff) env = 0.5f * (cosf(CUDART_PI_F * d / cutoff) + 1.0f);\n float center = ((float)k) * cutoff / ((float)(m - 1));\n float x = d - center;\n out[idx] = expf(coeff * x * x) * env;\n }\n}\n\ntorch::Tensor rbf_forward(torch::Tensor distances, int64_t num_rbf, double cutoff_d, double coeff_d) {\n auto out = torch::empty({distances.numel(), num_rbf}, distances.options());\n long long n = distances.numel();\n float cutoff = (float)cutoff_d;\n float coeff = (float)coeff_d;\n cudaStream_t stream = at::cuda::getCurrentCUDAStream();\n if (num_rbf == 64) {\n rbf64_kernel<<<(unsigned int)((n + 3) / 4), 256, 0, stream>>>(distances.data_ptr<float>(), out.data_ptr<float>(), n, cutoff, coeff);\n } else {\n long long total = n * num_rbf;\n rbf_generic_kernel<<<(unsigned int)((total + 255) / 256), 256, 0, stream>>>(distances.data_ptr<float>(), out.data_ptr<float>(), total, (int)num_rbf, cutoff, coeff);\n }\n return out;\n}\n'''\ncpp_src = \"torch::Tensor rbf_forward(torch::Tensor distances, int64_t num_rbf, double cutoff, double coeff);\"\n_rbf_ext = load_inline(name=\"rbf_ext_v2\", cpp_sources=cpp_src, cuda_sources=cuda_src, functions=[\"rbf_forward\"], extra_cuda_cflags=[\"-O3\", \"--use_fast_math\"], extra_cflags=[\"-O3\"], verbose=False)\n\nclass ModelNew(nn.Module):\n def __init__(self, num_rbf=64, cutoff=5.0):\n super().__init__()\n self.num_rbf = num_rbf\n self.cutoff = cutoff\n offsets = torch.linspace(0.0, cutoff, num_rbf)\n self.register_buffer(\"offsets\", offsets)\n coeff = -0.5 / (offsets[1] - offsets[0]).item() ** 2\n self.coeff = coeff\n def forward(self, distances: torch.Tensor) -> torch.Tensor:\n flat_out = _rbf_ext.rbf_forward(distances, int(self.num_rbf), float(self.cutoff), float(self.coeff))\n return flat_out.view(*distances.shape, self.num_rbf)\n"
}
result ← run_correctness (ok)
okrun_correctness
run_correctness PASSED: (5 / 5) trials all matched the reference.
Numerical precision: max_abs_err=1.31e-06 mean_abs_err=1.86e-08 max_rel_err=2.98e+04
turn 37.5s turn · 7.5s LLM · 0.0s tools
reasoning
**Deciding on profile submission**
I’m thinking about whether I should profile or submit something. It seems like opting for performance is the priority here. I’ll likely lean towards profiling instead, to ensure I’m focusing on the best way to showcase what needs to be done. I want to make sure I’m on the right track with this decision! Let’s see how I can move forward with profiling it effectively.
call → profile_kernel
callprofile_kernel
{
"kernel_code": "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\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#include <math_constants.h>\n\n__global__ __launch_bounds__(256, 4)\nvoid rbf64_kernel(const float* __restrict__ distances, float* __restrict__ out,\n long long n, float cutoff, float coeff) {\n __shared__ float sd[4];\n __shared__ float se[4];\n int tid = threadIdx.x;\n int group = tid >> 6;\n int k = tid & 63;\n long long i = (long long)blockIdx.x * 4 + group;\n if (i < n && k == 0) {\n float d = distances[i];\n sd[group] = d;\n float e = 0.0f;\n if (d < cutoff) {\n e = 0.5f * (cosf(CUDART_PI_F * d / cutoff) + 1.0f);\n }\n se[group] = e;\n }\n __syncthreads();\n if (i < n) {\n float d = sd[group];\n float center = ((float)k) * cutoff * (1.0f / 63.0f);\n float x = d - center;\n out[i * 64 + k] = expf(coeff * x * x) * se[group];\n }\n}\n\n__global__ __launch_bounds__(256, 4)\nvoid rbf_generic_kernel(const float* __restrict__ distances, float* __restrict__ out,\n long long total, int m, float cutoff, float coeff) {\n long long idx = (long long)blockIdx.x * blockDim.x + threadIdx.x;\n if (idx < total) {\n int k = (int)(idx % m);\n long long i = idx / m;\n float d = distances[i];\n float env = 0.0f;\n if (d < cutoff) env = 0.5f * (cosf(CUDART_PI_F * d / cutoff) + 1.0f);\n float center = ((float)k) * cutoff / ((float)(m - 1));\n float x = d - center;\n out[idx] = expf(coeff * x * x) * env;\n }\n}\n\ntorch::Tensor rbf_forward(torch::Tensor distances, int64_t num_rbf, double cutoff_d, double coeff_d) {\n auto out = torch::empty({distances.numel(), num_rbf}, distances.options());\n long long n = distances.numel();\n float cutoff = (float)cutoff_d;\n float coeff = (float)coeff_d;\n cudaStream_t stream = at::cuda::getCurrentCUDAStream();\n if (num_rbf == 64) {\n rbf64_kernel<<<(unsigned int)((n + 3) / 4), 256, 0, stream>>>(distances.data_ptr<float>(), out.data_ptr<float>(), n, cutoff, coeff);\n } else {\n long long total = n * num_rbf;\n rbf_generic_kernel<<<(unsigned int)((total + 255) / 256), 256, 0, stream>>>(distances.data_ptr<float>(), out.data_ptr<float>(), total, (int)num_rbf, cutoff, coeff);\n }\n return out;\n}\n'''\ncpp_src = \"torch::Tensor rbf_forward(torch::Tensor distances, int64_t num_rbf, double cutoff, double coeff);\"\n_rbf_ext = load_inline(name=\"rbf_ext_v2p\", cpp_sources=cpp_src, cuda_sources=cuda_src, functions=[\"rbf_forward\"], extra_cuda_cflags=[\"-O3\", \"--use_fast_math\"], extra_cflags=[\"-O3\"], verbose=False)\nclass ModelNew(nn.Module):\n def __init__(self, num_rbf=64, cutoff=5.0):\n super().__init__(); self.num_rbf=num_rbf; self.cutoff=cutoff\n offsets=torch.linspace(0.0, cutoff, num_rbf); self.register_buffer('offsets', offsets)\n self.coeff=-0.5/(offsets[1]-offsets[0]).item()**2\n def forward(self, distances):\n return _rbf_ext.rbf_forward(distances, int(self.num_rbf), float(self.cutoff), float(self.coeff)).view(*distances.shape, self.num_rbf)\n"
}
result ← profile_kernel (ok)
okprofile_kernel
profile_kernel PASSED: profiling complete.
=== Kernel Profile Summary ===
--- Kernel Breakdown (by GPU time) ---
#1: aten::empty 944.0μs (97%) calls=1
#2: aten::view 26.0μs (3%) calls=1
--- Timing ---
GPU time: 101.41 μs
--- Memory Bandwidth ---
DRAM BW: 1119.3/3350 GB/s (33.4%)
read=20.7 write=1098.6 GB/s
Hit rates: L2=98.5%
--- Compute Throughput ---
Dominant pipe: FP32 util=12.1%
Pipe util: FMA=12.1%, Tensor=0.0%
--- Roofline Analysis ---
Ridge point (FP32): 20.00 FLOPs/byte
Classification: MEMORY-BOUND
--- Occupancy ---
Achieved: 79.0%
Eligible warps/cycle: 1.23
Launch: regs/thread=16, smem/blk=1152B, block=256, grid=131072
--- Memory Access Quality ---
Global ld coalescing: 1.00 sectors/req (perfect)
--- Warp Stall Reasons (% of issue cycles) ---
long_scoreboard 738.0% ####################
short_scoreboard 154.0% ####################
mio_throttle 9.4% #
--- Optimization Hints ---
-> 738% stalls: global memory latency (waiting for DRAM/L2). Try shared-memory tiling, prefetching, or reducing working set.
turn 412.9s turn · 12.9s 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\ncuda_src = r'''\n#include <torch/extension.h>\n#include <ATen/cuda/CUDAContext.h>\n#include <cuda.h>\n#include <cuda_runtime.h>\n#include <math_constants.h>\n\n__global__ __launch_bounds__(256, 4)\nvoid rbf64_warp_kernel(const float* __restrict__ distances, float* __restrict__ out,\n long long n, float cutoff, float coeff) {\n int tid = threadIdx.x;\n int lane = tid & 31;\n int warp = tid >> 5;\n long long i = (long long)blockIdx.x * 8 + warp;\n float d = 0.0f, env = 0.0f;\n if (i < n && lane == 0) {\n d = distances[i];\n if (d < cutoff) env = 0.5f * (cosf(CUDART_PI_F * d / cutoff) + 1.0f);\n }\n d = __shfl_sync(0xffffffff, d, 0);\n env = __shfl_sync(0xffffffff, env, 0);\n if (i < n) {\n long long base = i * 64;\n float inv63 = 1.0f / 63.0f;\n int k = lane;\n float center = ((float)k) * cutoff * inv63;\n float x = d - center;\n out[base + k] = expf(coeff * x * x) * env;\n k = lane + 32;\n center = ((float)k) * cutoff * inv63;\n x = d - center;\n out[base + k] = expf(coeff * x * x) * env;\n }\n}\n\n__global__ __launch_bounds__(256, 4)\nvoid rbf_generic_kernel(const float* __restrict__ distances, float* __restrict__ out,\n long long total, int m, float cutoff, float coeff) {\n long long idx = (long long)blockIdx.x * blockDim.x + threadIdx.x;\n if (idx < total) {\n int k = (int)(idx % m);\n long long i = idx / m;\n float d = distances[i];\n float env = 0.0f;\n if (d < cutoff) env = 0.5f * (cosf(CUDART_PI_F * d / cutoff) + 1.0f);\n float center = ((float)k) * cutoff / ((float)(m - 1));\n float x = d - center;\n out[idx] = expf(coeff * x * x) * env;\n }\n}\n\ntorch::Tensor rbf_forward(torch::Tensor distances, int64_t num_rbf, double cutoff_d, double coeff_d) {\n auto out = torch::empty({distances.numel(), num_rbf}, distances.options());\n long long n = distances.numel();\n float cutoff = (float)cutoff_d, coeff = (float)coeff_d;\n cudaStream_t stream = at::cuda::getCurrentCUDAStream();\n if (num_rbf == 64) {\n rbf64_warp_kernel<<<(unsigned int)((n + 7) / 8), 256, 0, stream>>>(distances.data_ptr<float>(), out.data_ptr<float>(), n, cutoff, coeff);\n } else {\n long long total = n * num_rbf;\n rbf_generic_kernel<<<(unsigned int)((total + 255) / 256), 256, 0, stream>>>(distances.data_ptr<float>(), out.data_ptr<float>(), total, (int)num_rbf, cutoff, coeff);\n }\n return out;\n}\n'''\ncpp_src = \"torch::Tensor rbf_forward(torch::Tensor distances, int64_t num_rbf, double cutoff, double coeff);\"\n_ext=load_inline(name='rbf_ext_warp1', cpp_sources=cpp_src, cuda_sources=cuda_src, functions=['rbf_forward'], extra_cuda_cflags=['-O3','--use_fast_math'], extra_cflags=['-O3'], verbose=False)\nclass ModelNew(nn.Module):\n def __init__(self,num_rbf=64,cutoff=5.0):\n super().__init__(); self.num_rbf=num_rbf; self.cutoff=cutoff\n offsets=torch.linspace(0.0,cutoff,num_rbf); self.register_buffer('offsets',offsets)\n self.coeff=-0.5/(offsets[1]-offsets[0]).item()**2\n def forward(self,distances):\n return _ext.rbf_forward(distances,int(self.num_rbf),float(self.cutoff),float(self.coeff)).view(*distances.shape,self.num_rbf)\n"
}
result ← run_correctness (ok)
okrun_correctness
run_correctness PASSED: (5 / 5) trials all matched the reference.
Numerical precision: max_abs_err=1.31e-06 mean_abs_err=1.86e-08 max_rel_err=2.98e+04
turn 56.8s turn · 6.8s LLM · 0.0s tools
call → profile_kernel
callprofile_kernel
{
"kernel_code": "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\ncuda_src = r'''\n#include <torch/extension.h>\n#include <ATen/cuda/CUDAContext.h>\n#include <cuda.h>\n#include <cuda_runtime.h>\n#include <math_constants.h>\n__global__ __launch_bounds__(256, 4)\nvoid rbf64_warp_kernel(const float* __restrict__ distances, float* __restrict__ out,long long n,float cutoff,float coeff){int tid=threadIdx.x;int lane=tid&31;int warp=tid>>5;long long i=(long long)blockIdx.x*8+warp;float d=0.0f,env=0.0f;if(i<n&&lane==0){d=distances[i];if(d<cutoff)env=0.5f*(cosf(CUDART_PI_F*d/cutoff)+1.0f);}d=__shfl_sync(0xffffffff,d,0);env=__shfl_sync(0xffffffff,env,0);if(i<n){long long base=i*64;float inv63=1.0f/63.0f;int k=lane;float center=((float)k)*cutoff*inv63;float x=d-center;out[base+k]=expf(coeff*x*x)*env;k=lane+32;center=((float)k)*cutoff*inv63;x=d-center;out[base+k]=expf(coeff*x*x)*env;}}\n__global__ __launch_bounds__(256, 4)\nvoid rbf_generic_kernel(const float* __restrict__ distances,float* __restrict__ out,long long total,int m,float cutoff,float coeff){long long idx=(long long)blockIdx.x*blockDim.x+threadIdx.x;if(idx<total){int k=(int)(idx%m);long long i=idx/m;float d=distances[i];float env=0.0f;if(d<cutoff)env=0.5f*(cosf(CUDART_PI_F*d/cutoff)+1.0f);float center=((float)k)*cutoff/((float)(m-1));float x=d-center;out[idx]=expf(coeff*x*x)*env;}}\ntorch::Tensor rbf_forward(torch::Tensor distances,int64_t num_rbf,double cutoff_d,double coeff_d){auto out=torch::empty({distances.numel(),num_rbf},distances.options());long long n=distances.numel();float cutoff=(float)cutoff_d,coeff=(float)coeff_d;cudaStream_t stream=at::cuda::getCurrentCUDAStream();if(num_rbf==64){rbf64_warp_kernel<<<(unsigned int)((n+7)/8),256,0,stream>>>(distances.data_ptr<float>(),out.data_ptr<float>(),n,cutoff,coeff);}else{long long total=n*num_rbf;rbf_generic_kernel<<<(unsigned int)((total+255)/256),256,0,stream>>>(distances.data_ptr<float>(),out.data_ptr<float>(),total,(int)num_rbf,cutoff,coeff);}return out;}\n'''\ncpp_src=\"torch::Tensor rbf_forward(torch::Tensor distances, int64_t num_rbf, double cutoff, double coeff);\"\n_ext=load_inline(name='rbf_ext_warp1p', cpp_sources=cpp_src, cuda_sources=cuda_src, functions=['rbf_forward'], extra_cuda_cflags=['-O3','--use_fast_math'], extra_cflags=['-O3'], verbose=False)\nclass ModelNew(nn.Module):\n def __init__(self,num_rbf=64,cutoff=5.0):\n super().__init__(); self.num_rbf=num_rbf; self.cutoff=cutoff; offsets=torch.linspace(0.0,cutoff,num_rbf); self.register_buffer('offsets',offsets); self.coeff=-0.5/(offsets[1]-offsets[0]).item()**2\n def forward(self,distances):\n return _ext.rbf_forward(distances,int(self.num_rbf),float(self.cutoff),float(self.coeff)).view(*distances.shape,self.num_rbf)\n"
}
result ← profile_kernel (ok)
okprofile_kernel
profile_kernel PASSED: profiling complete.
=== Kernel Profile Summary ===
--- Kernel Breakdown (by GPU time) ---
#1: aten::empty 753.0μs (97%) calls=1
#2: aten::view 23.0μs (3%) calls=1
--- Timing ---
GPU time: 67.42 μs [↓34.0μs ok]
--- Memory Bandwidth ---
DRAM BW: 1680.9/3350 GB/s (50.2%) [↑16.8% ok]
read=31.2 write=1649.8 GB/s
Hit rates: L2=98.1%
--- Compute Throughput ---
Dominant pipe: FP32 util=14.6% [↑2.5% ok]
Pipe util: FMA=14.6%, Tensor=1.5%
--- Roofline Analysis ---
Ridge point (FP32): 20.00 FLOPs/byte
Classification: MEMORY-BOUND
--- Occupancy ---
Achieved: 78.3% [↓0.7% REGRESSED]
Eligible warps/cycle: 1.62
Launch: regs/thread=16, smem/blk=1024B, block=256, grid=65536
--- Memory Access Quality ---
Global ld coalescing: 1.00 sectors/req (perfect)
--- Warp Stall Reasons (% of issue cycles) ---
long_scoreboard 1744.9% ####################
short_scoreboard 105.3% ####################
mio_throttle 60.8% ############
--- Optimization Hints ---
-> 1745% stalls: global memory latency (waiting for DRAM/L2). Try shared-memory tiling, prefetching, or reducing working set.
--- Delta vs Previous Iteration ---
GPU time: 101.41→67.42μs (↓33.98) ok
DRAM BW%: 33.41→50.18% (↑16.77) ok
Compute%: 12.13→14.62% (↑2.49) ok
Occupancy: 79.02→78.35% (↓0.67) REGRESSED
Eligible warps/cyc: 1.23→1.62 (↑0.39) ok
L2 hit%: 98.49→98.15% (↓0.35) REGRESSED
turn 68.4s turn · 8.4s LLM · 0.0s tools
call → profile_kernel
callprofile_kernel
{
"kernel_code": "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\ncuda_src=r'''\n#include <torch/extension.h>\n#include <ATen/cuda/CUDAContext.h>\n#include <cuda.h>\n#include <cuda_runtime.h>\n#include <math_constants.h>\n__global__ __launch_bounds__(512,2)\nvoid rbf64_warp_kernel(const float* __restrict__ distances,float* __restrict__ out,long long n,float cutoff,float coeff){int tid=threadIdx.x;int lane=tid&31;int warp=tid>>5;long long i=(long long)blockIdx.x*16+warp;float d=0.0f,env=0.0f;if(i<n&&lane==0){d=distances[i];if(d<cutoff)env=0.5f*(cosf(CUDART_PI_F*d/cutoff)+1.0f);}d=__shfl_sync(0xffffffff,d,0);env=__shfl_sync(0xffffffff,env,0);if(i<n){long long base=i*64;float cstep=cutoff*(1.0f/63.0f);float x=d-((float)lane)*cstep;out[base+lane]=expf(coeff*x*x)*env;int k=lane+32;x=d-((float)k)*cstep;out[base+k]=expf(coeff*x*x)*env;}}\n__global__ __launch_bounds__(256,4)\nvoid rbf_generic_kernel(const float* __restrict__ distances,float* __restrict__ out,long long total,int m,float cutoff,float coeff){long long idx=(long long)blockIdx.x*blockDim.x+threadIdx.x;if(idx<total){int k=(int)(idx%m);long long i=idx/m;float d=distances[i];float env=0.0f;if(d<cutoff)env=0.5f*(cosf(CUDART_PI_F*d/cutoff)+1.0f);float center=((float)k)*cutoff/((float)(m-1));float x=d-center;out[idx]=expf(coeff*x*x)*env;}}\ntorch::Tensor rbf_forward(torch::Tensor distances,int64_t num_rbf,double cutoff_d,double coeff_d){auto out=torch::empty({distances.numel(),num_rbf},distances.options());long long n=distances.numel();float cutoff=(float)cutoff_d,coeff=(float)coeff_d;cudaStream_t stream=at::cuda::getCurrentCUDAStream();if(num_rbf==64){rbf64_warp_kernel<<<(unsigned int)((n+15)/16),512,0,stream>>>(distances.data_ptr<float>(),out.data_ptr<float>(),n,cutoff,coeff);}else{long long total=n*num_rbf;rbf_generic_kernel<<<(unsigned int)((total+255)/256),256,0,stream>>>(distances.data_ptr<float>(),out.data_ptr<float>(),total,(int)num_rbf,cutoff,coeff);}return out;}\n'''\ncpp_src='torch::Tensor rbf_forward(torch::Tensor distances, int64_t num_rbf, double cutoff, double coeff);'\n_ext=load_inline(name='rbf_ext_warp512p', cpp_sources=cpp_src, cuda_sources=cuda_src, functions=['rbf_forward'], extra_cuda_cflags=['-O3','--use_fast_math'], extra_cflags=['-O3'], verbose=False)\nclass ModelNew(nn.Module):\n def __init__(self,num_rbf=64,cutoff=5.0):\n super().__init__(); self.num_rbf=num_rbf; self.cutoff=cutoff; offsets=torch.linspace(0.0,cutoff,num_rbf); self.register_buffer('offsets',offsets); self.coeff=-0.5/(offsets[1]-offsets[0]).item()**2\n def forward(self,distances):\n return _ext.rbf_forward(distances,int(self.num_rbf),float(self.cutoff),float(self.coeff)).view(*distances.shape,self.num_rbf)\n"
}
result ← profile_kernel (ok)
okprofile_kernel
profile_kernel PASSED: profiling complete.
=== Kernel Profile Summary ===
--- Kernel Breakdown (by GPU time) ---
#1: aten::empty 922.0μs (97%) calls=1
#2: aten::view 32.0μs (3%) calls=1
--- Timing ---
GPU time: 71.20 μs [↑3.8μs REGRESSED]
--- Memory Bandwidth ---
DRAM BW: 1591.7/3350 GB/s (47.5%) [↓2.7% REGRESSED]
read=29.7 write=1562.1 GB/s
Hit rates: L2=98.2%
--- Compute Throughput ---
Dominant pipe: FP32 util=13.1% [↓1.5% REGRESSED]
Pipe util: FMA=13.1%, Tensor=1.5%
--- Roofline Analysis ---
Ridge point (FP32): 20.00 FLOPs/byte
Classification: MEMORY-BOUND
--- Occupancy ---
Achieved: 84.9% [↑6.6% ok]
Eligible warps/cycle: 1.85
Launch: regs/thread=16, smem/blk=1024B, block=512, grid=32768
--- Memory Access Quality ---
Global ld coalescing: 1.00 sectors/req (perfect)
--- Warp Stall Reasons (% of issue cycles) ---
long_scoreboard 1993.8% ####################
short_scoreboard 135.2% ####################
mio_throttle 112.9% ####################
--- Optimization Hints ---
-> 1994% stalls: global memory latency (waiting for DRAM/L2). Try shared-memory tiling, prefetching, or reducing working set.
--- Delta vs Previous Iteration ---
GPU time: 67.42→71.20μs (↑3.78) REGRESSED
DRAM BW%: 50.18→47.51% (↓2.66) REGRESSED
Compute%: 14.62→13.09% (↓1.53) REGRESSED
Occupancy: 78.35→84.95% (↑6.60) ok
Eligible warps/cyc: 1.62→1.85 (↑0.23) ok
L2 hit%: 98.15→98.22% (↑0.07) ok
turn 77.4s turn · 7.4s LLM · 0.0s tools
call → profile_kernel
callprofile_kernel
{
"kernel_code": "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\ncuda_src=r'''\n#include <torch/extension.h>\n#include <ATen/cuda/CUDAContext.h>\n#include <cuda.h>\n#include <cuda_runtime.h>\n#include <math_constants.h>\n__global__ __launch_bounds__(128,8)\nvoid rbf64_warp_kernel(const float* __restrict__ distances,float* __restrict__ out,long long n,float cutoff,float coeff){int tid=threadIdx.x;int lane=tid&31;int warp=tid>>5;long long i=(long long)blockIdx.x*4+warp;float d=0.0f,env=0.0f;if(i<n&&lane==0){d=distances[i];if(d<cutoff)env=0.5f*(cosf(CUDART_PI_F*d/cutoff)+1.0f);}d=__shfl_sync(0xffffffff,d,0);env=__shfl_sync(0xffffffff,env,0);if(i<n){long long base=i*64;float cstep=cutoff*(1.0f/63.0f);float x=d-((float)lane)*cstep;out[base+lane]=expf(coeff*x*x)*env;int k=lane+32;x=d-((float)k)*cstep;out[base+k]=expf(coeff*x*x)*env;}}\n__global__ __launch_bounds__(256,4)\nvoid rbf_generic_kernel(const float* __restrict__ distances,float* __restrict__ out,long long total,int m,float cutoff,float coeff){long long idx=(long long)blockIdx.x*blockDim.x+threadIdx.x;if(idx<total){int k=(int)(idx%m);long long i=idx/m;float d=distances[i];float env=0.0f;if(d<cutoff)env=0.5f*(cosf(CUDART_PI_F*d/cutoff)+1.0f);float center=((float)k)*cutoff/((float)(m-1));float x=d-center;out[idx]=expf(coeff*x*x)*env;}}\ntorch::Tensor rbf_forward(torch::Tensor distances,int64_t num_rbf,double cutoff_d,double coeff_d){auto out=torch::empty({distances.numel(),num_rbf},distances.options());long long n=distances.numel();float cutoff=(float)cutoff_d,coeff=(float)coeff_d;cudaStream_t stream=at::cuda::getCurrentCUDAStream();if(num_rbf==64){rbf64_warp_kernel<<<(unsigned int)((n+3)/4),128,0,stream>>>(distances.data_ptr<float>(),out.data_ptr<float>(),n,cutoff,coeff);}else{long long total=n*num_rbf;rbf_generic_kernel<<<(unsigned int)((total+255)/256),256,0,stream>>>(distances.data_ptr<float>(),out.data_ptr<float>(),total,(int)num_rbf,cutoff,coeff);}return out;}\n'''\ncpp_src='torch::Tensor rbf_forward(torch::Tensor distances, int64_t num_rbf, double cutoff, double coeff);'\n_ext=load_inline(name='rbf_ext_warp128p', cpp_sources=cpp_src, cuda_sources=cuda_src, functions=['rbf_forward'], extra_cuda_cflags=['-O3','--use_fast_math'], extra_cflags=['-O3'], verbose=False)\nclass ModelNew(nn.Module):\n def __init__(self,num_rbf=64,cutoff=5.0):\n super().__init__(); self.num_rbf=num_rbf; self.cutoff=cutoff; offsets=torch.linspace(0.0,cutoff,num_rbf); self.register_buffer('offsets',offsets); self.coeff=-0.5/(offsets[1]-offsets[0]).item()**2\n def forward(self,distances):\n return _ext.rbf_forward(distances,int(self.num_rbf),float(self.cutoff),float(self.coeff)).view(*distances.shape,self.num_rbf)\n"
}
result ← profile_kernel (ok)
okprofile_kernel
profile_kernel PASSED: profiling complete.
=== Kernel Profile Summary ===
--- Kernel Breakdown (by GPU time) ---
#1: aten::empty 765.0μs (97%) calls=1
#2: aten::view 21.0μs (3%) calls=1
--- Timing ---
GPU time: 82.02 μs [↑10.8μs REGRESSED]
--- Memory Bandwidth ---
DRAM BW: 1381.4/3350 GB/s (41.2%) [↓6.3% REGRESSED]
read=25.6 write=1355.8 GB/s
Hit rates: L2=98.2%
--- Compute Throughput ---
Dominant pipe: FP32 util=11.4% [↓1.7% REGRESSED]
Pipe util: FMA=11.4%, Tensor=1.3%
--- Roofline Analysis ---
Ridge point (FP32): 20.00 FLOPs/byte
Classification: MEMORY-BOUND
--- Occupancy ---
Achieved: 47.9% [↓37.1% REGRESSED]
Eligible warps/cycle: 0.55
WARNING: <1 eligible warp/cycle = latency-bound, needs more parallelism
Launch: regs/thread=16, smem/blk=1024B, block=128, grid=131072
--- Memory Access Quality ---
Global ld coalescing: 1.00 sectors/req (perfect)
--- Warp Stall Reasons (% of issue cycles) ---
long_scoreboard 1376.8% ####################
short_scoreboard 118.9% ####################
mio_throttle 7.4% #
--- Optimization Hints ---
-> 1377% stalls: global memory latency (waiting for DRAM/L2). Try shared-memory tiling, prefetching, or reducing working set.
-> Low eligible warps + low BW% + low compute% = LATENCY-BOUND. Need more parallelism (larger grid, more ILP, prefetching).
--- Delta vs Previous Iteration ---
GPU time: 71.20→82.02μs (↑10.82) REGRESSED
DRAM BW%: 47.51→41.24% (↓6.28) REGRESSED
Compute%: 13.09→11.36% (↓1.73) REGRESSED
Occupancy: 84.95→47.86% (↓37.09) REGRESSED
Eligible warps/cyc: 1.85→0.55 (↓1.30) REGRESSED
L2 hit%: 98.22→98.19% (↓0.03) REGRESSED
turn 812.3s turn · 12.3s LLM · 0.0s tools
call → profile_kernel
callprofile_kernel
{
"kernel_code": "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\ncuda_src=r'''\n#include <torch/extension.h>\n#include <ATen/cuda/CUDAContext.h>\n#include <cuda.h>\n#include <cuda_runtime.h>\n#include <math_constants.h>\n__global__ __launch_bounds__(256,4)\nvoid rbf64_warp_kernel(const float* __restrict__ distances,float* __restrict__ out,long long n,float cutoff,float coeff){int tid=threadIdx.x;int lane=tid&31;int warp=tid>>5;long long i=(long long)blockIdx.x*8+warp;float d=0.0f,env=0.0f;int inside=0;if(i<n&&lane==0){d=distances[i];inside=(d<cutoff);if(inside)env=0.5f*(cosf(CUDART_PI_F*d/cutoff)+1.0f);}d=__shfl_sync(0xffffffff,d,0);env=__shfl_sync(0xffffffff,env,0);inside=__shfl_sync(0xffffffff,inside,0);if(i<n){long long base=i*64;if(inside){float cstep=cutoff*(1.0f/63.0f);float x=d-((float)lane)*cstep;out[base+lane]=expf(coeff*x*x)*env;int k=lane+32;x=d-((float)k)*cstep;out[base+k]=expf(coeff*x*x)*env;}else{out[base+lane]=0.0f;out[base+lane+32]=0.0f;}}}\n__global__ __launch_bounds__(256,4)\nvoid rbf_generic_kernel(const float* __restrict__ distances,float* __restrict__ out,long long total,int m,float cutoff,float coeff){long long idx=(long long)blockIdx.x*blockDim.x+threadIdx.x;if(idx<total){int k=(int)(idx%m);long long i=idx/m;float d=distances[i];float env=0.0f;if(d<cutoff)env=0.5f*(cosf(CUDART_PI_F*d/cutoff)+1.0f);float center=((float)k)*cutoff/((float)(m-1));float x=d-center;out[idx]=(d<cutoff)?(expf(coeff*x*x)*env):0.0f;}}\ntorch::Tensor rbf_forward(torch::Tensor distances,int64_t num_rbf,double cutoff_d,double coeff_d){auto out=torch::empty({distances.numel(),num_rbf},distances.options());long long n=distances.numel();float cutoff=(float)cutoff_d,coeff=(float)coeff_d;cudaStream_t stream=at::cuda::getCurrentCUDAStream();if(num_rbf==64){rbf64_warp_kernel<<<(unsigned int)((n+7)/8),256,0,stream>>>(distances.data_ptr<float>(),out.data_ptr<float>(),n,cutoff,coeff);}else{long long total=n*num_rbf;rbf_generic_kernel<<<(unsigned int)((total+255)/256),256,0,stream>>>(distances.data_ptr<float>(),out.data_ptr<float>(),total,(int)num_rbf,cutoff,coeff);}return out;}\n'''\ncpp_src='torch::Tensor rbf_forward(torch::Tensor distances, int64_t num_rbf, double cutoff, double coeff);'\n_ext=load_inline(name='rbf_ext_branchp', cpp_sources=cpp_src, cuda_sources=cuda_src, functions=['rbf_forward'], extra_cuda_cflags=['-O3','--use_fast_math'], extra_cflags=['-O3'], verbose=False)\nclass ModelNew(nn.Module):\n def __init__(self,num_rbf=64,cutoff=5.0):\n super().__init__(); self.num_rbf=num_rbf; self.cutoff=cutoff; offsets=torch.linspace(0.0,cutoff,num_rbf); self.register_buffer('offsets',offsets); self.coeff=-0.5/(offsets[1]-offsets[0]).item()**2\n def forward(self,distances):\n return _ext.rbf_forward(distances,int(self.num_rbf),float(self.cutoff),float(self.coeff)).view(*distances.shape,self.num_rbf)\n"
}
result ← profile_kernel (ok)
okprofile_kernel
profile_kernel PASSED: profiling complete.
=== Kernel Profile Summary ===
--- Kernel Breakdown (by GPU time) ---
#1: aten::empty 767.0μs (97%) calls=1
#2: aten::view 20.0μs (3%) calls=1
--- Timing ---
GPU time: 69.15 μs [↓12.9μs ok]
--- Memory Bandwidth ---
DRAM BW: 1635.8/3350 GB/s (48.8%) [↑7.6% ok]
read=30.4 write=1605.4 GB/s
Hit rates: L2=98.4%
--- Compute Throughput ---
Dominant pipe: FP32 util=15.0% [↑3.6% ok]
Pipe util: FMA=15.0%, Tensor=0.0%
--- Roofline Analysis ---
Ridge point (FP32): 20.00 FLOPs/byte
Classification: MEMORY-BOUND
--- Occupancy ---
Achieved: 78.8% [↑31.0% ok]
Eligible warps/cycle: 1.61
Launch: regs/thread=16, smem/blk=1024B, block=256, grid=65536
--- Memory Access Quality ---
Global ld coalescing: 1.00 sectors/req (perfect)
--- Warp Stall Reasons (% of issue cycles) ---
long_scoreboard 1653.6% ####################
short_scoreboard 142.1% ####################
mio_throttle 51.4% ##########
--- Optimization Hints ---
-> 1654% stalls: global memory latency (waiting for DRAM/L2). Try shared-memory tiling, prefetching, or reducing working set.
--- Delta vs Previous Iteration ---
GPU time: 82.02→69.15μs (↓12.86) ok
DRAM BW%: 41.24→48.83% (↑7.59) ok
Compute%: 11.36→14.96% (↑3.60) ok
Occupancy: 47.86→78.81% (↑30.96) ok
Eligible warps/cyc: 0.55→1.61 (↑1.06) ok
L2 hit%: 98.19→98.42% (↑0.24) ok
turn 910.6s turn · 10.6s 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\ncuda_src=r'''\n#include <torch/extension.h>\n#include <ATen/cuda/CUDAContext.h>\n#include <cuda.h>\n#include <cuda_runtime.h>\n#include <math_constants.h>\n__global__ __launch_bounds__(256,4)\nvoid rbf64_pair_kernel(const float* __restrict__ distances,float* __restrict__ out,long long n,float cutoff,float coeff){int tid=threadIdx.x;int lane=tid&31;int warp=tid>>5;long long i=(long long)blockIdx.x*8+warp;float d=0.0f,env=0.0f;if(i<n&&lane==0){d=distances[i];if(d<cutoff)env=0.5f*(cosf(CUDART_PI_F*d/cutoff)+1.0f);}d=__shfl_sync(0xffffffff,d,0);env=__shfl_sync(0xffffffff,env,0);if(i<n){float cstep=cutoff*(1.0f/63.0f);int k=lane*2;float x0=d-((float)k)*cstep;float x1=d-((float)(k+1))*cstep;float2 v;v.x=expf(coeff*x0*x0)*env;v.y=expf(coeff*x1*x1)*env;reinterpret_cast<float2*>(out+i*64)[lane]=v;}}\n__global__ __launch_bounds__(256,4)\nvoid rbf_generic_kernel(const float* __restrict__ distances,float* __restrict__ out,long long total,int m,float cutoff,float coeff){long long idx=(long long)blockIdx.x*blockDim.x+threadIdx.x;if(idx<total){int k=(int)(idx%m);long long i=idx/m;float d=distances[i];float env=0.0f;if(d<cutoff)env=0.5f*(cosf(CUDART_PI_F*d/cutoff)+1.0f);float center=((float)k)*cutoff/((float)(m-1));float x=d-center;out[idx]=expf(coeff*x*x)*env;}}\ntorch::Tensor rbf_forward(torch::Tensor distances,int64_t num_rbf,double cutoff_d,double coeff_d){auto out=torch::empty({distances.numel(),num_rbf},distances.options());long long n=distances.numel();float cutoff=(float)cutoff_d,coeff=(float)coeff_d;cudaStream_t stream=at::cuda::getCurrentCUDAStream();if(num_rbf==64){rbf64_pair_kernel<<<(unsigned int)((n+7)/8),256,0,stream>>>(distances.data_ptr<float>(),out.data_ptr<float>(),n,cutoff,coeff);}else{long long total=n*num_rbf;rbf_generic_kernel<<<(unsigned int)((total+255)/256),256,0,stream>>>(distances.data_ptr<float>(),out.data_ptr<float>(),total,(int)num_rbf,cutoff,coeff);}return out;}\n'''\ncpp_src='torch::Tensor rbf_forward(torch::Tensor distances, int64_t num_rbf, double cutoff, double coeff);'\n_ext=load_inline(name='rbf_ext_pair1', cpp_sources=cpp_src, cuda_sources=cuda_src, functions=['rbf_forward'], extra_cuda_cflags=['-O3','--use_fast_math'], extra_cflags=['-O3'], verbose=False)\nclass ModelNew(nn.Module):\n def __init__(self,num_rbf=64,cutoff=5.0):\n super().__init__(); self.num_rbf=num_rbf; self.cutoff=cutoff; offsets=torch.linspace(0.0,cutoff,num_rbf); self.register_buffer('offsets',offsets); self.coeff=-0.5/(offsets[1]-offsets[0]).item()**2\n def forward(self,distances):\n return _ext.rbf_forward(distances,int(self.num_rbf),float(self.cutoff),float(self.coeff)).view(*distances.shape,self.num_rbf)\n"
}
result ← run_correctness (ok)
okrun_correctness
run_correctness PASSED: (5 / 5) trials all matched the reference.
Numerical precision: max_abs_err=1.07e-06 mean_abs_err=1.40e-08 max_rel_err=2.98e+04
turn 108.0s turn · 8.0s LLM · 0.0s tools
call → profile_kernel
callprofile_kernel
{
"kernel_code": "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\ncuda_src=r'''\n#include <torch/extension.h>\n#include <ATen/cuda/CUDAContext.h>\n#include <cuda.h>\n#include <cuda_runtime.h>\n#include <math_constants.h>\n__global__ __launch_bounds__(256,4)\nvoid rbf64_pair_kernel(const float* __restrict__ distances,float* __restrict__ out,long long n,float cutoff,float coeff){int tid=threadIdx.x;int lane=tid&31;int warp=tid>>5;long long i=(long long)blockIdx.x*8+warp;float d=0.0f,env=0.0f;if(i<n&&lane==0){d=distances[i];if(d<cutoff)env=0.5f*(cosf(CUDART_PI_F*d/cutoff)+1.0f);}d=__shfl_sync(0xffffffff,d,0);env=__shfl_sync(0xffffffff,env,0);if(i<n){float cstep=cutoff*(1.0f/63.0f);int k=lane*2;float x0=d-((float)k)*cstep;float x1=d-((float)(k+1))*cstep;float2 v;v.x=expf(coeff*x0*x0)*env;v.y=expf(coeff*x1*x1)*env;reinterpret_cast<float2*>(out+i*64)[lane]=v;}}\n__global__ __launch_bounds__(256,4)\nvoid rbf_generic_kernel(const float* __restrict__ distances,float* __restrict__ out,long long total,int m,float cutoff,float coeff){long long idx=(long long)blockIdx.x*blockDim.x+threadIdx.x;if(idx<total){int k=(int)(idx%m);long long i=idx/m;float d=distances[i];float env=0.0f;if(d<cutoff)env=0.5f*(cosf(CUDART_PI_F*d/cutoff)+1.0f);float center=((float)k)*cutoff/((float)(m-1));float x=d-center;out[idx]=expf(coeff*x*x)*env;}}\ntorch::Tensor rbf_forward(torch::Tensor distances,int64_t num_rbf,double cutoff_d,double coeff_d){auto out=torch::empty({distances.numel(),num_rbf},distances.options());long long n=distances.numel();float cutoff=(float)cutoff_d,coeff=(float)coeff_d;cudaStream_t stream=at::cuda::getCurrentCUDAStream();if(num_rbf==64){rbf64_pair_kernel<<<(unsigned int)((n+7)/8),256,0,stream>>>(distances.data_ptr<float>(),out.data_ptr<float>(),n,cutoff,coeff);}else{long long total=n*num_rbf;rbf_generic_kernel<<<(unsigned int)((total+255)/256),256,0,stream>>>(distances.data_ptr<float>(),out.data_ptr<float>(),total,(int)num_rbf,cutoff,coeff);}return out;}\n'''\ncpp_src='torch::Tensor rbf_forward(torch::Tensor distances, int64_t num_rbf, double cutoff, double coeff);'\n_ext=load_inline(name='rbf_ext_pair1p', cpp_sources=cpp_src, cuda_sources=cuda_src, functions=['rbf_forward'], extra_cuda_cflags=['-O3','--use_fast_math'], extra_cflags=['-O3'], verbose=False)\nclass ModelNew(nn.Module):\n def __init__(self,num_rbf=64,cutoff=5.0):\n super().__init__(); self.num_rbf=num_rbf; self.cutoff=cutoff; offsets=torch.linspace(0.0,cutoff,num_rbf); self.register_buffer('offsets',offsets); self.coeff=-0.5/(offsets[1]-offsets[0]).item()**2\n def forward(self,distances):\n return _ext.rbf_forward(distances,int(self.num_rbf),float(self.cutoff),float(self.coeff)).view(*distances.shape,self.num_rbf)\n"
}
result ← profile_kernel (ok)
okprofile_kernel
profile_kernel PASSED: profiling complete.
=== Kernel Profile Summary ===
--- Kernel Breakdown (by GPU time) ---
#1: aten::empty 3813.0μs (99%) calls=1
#2: aten::view 24.0μs (1%) calls=1
--- Timing ---
GPU time: 66.88 μs [↓2.3μs ok]
--- Memory Bandwidth ---
DRAM BW: 1695.1/3350 GB/s (50.6%) [↑1.8% ok]
read=31.7 write=1663.5 GB/s
Hit rates: L2=98.5%
--- Compute Throughput ---
Dominant pipe: FP32 util=15.5% [↑0.6% ok]
Pipe util: FMA=15.5%, Tensor=1.6%
--- Roofline Analysis ---
Ridge point (FP32): 20.00 FLOPs/byte
Classification: MEMORY-BOUND
--- Occupancy ---
Achieved: 78.6% [↓0.2% REGRESSED]
Eligible warps/cycle: 1.43
Launch: regs/thread=16, smem/blk=1024B, block=256, grid=65536
--- Memory Access Quality ---
Global ld coalescing: 1.00 sectors/req (perfect)
--- Warp Stall Reasons (% of issue cycles) ---
long_scoreboard 1844.5% ####################
short_scoreboard 133.0% ####################
mio_throttle 56.7% ###########
--- Optimization Hints ---
-> 1844% stalls: global memory latency (waiting for DRAM/L2). Try shared-memory tiling, prefetching, or reducing working set.
--- Delta vs Previous Iteration ---
GPU time: 69.15→66.88μs (↓2.27) ok
DRAM BW%: 48.83→50.60% (↑1.77) ok
Compute%: 14.96→15.53% (↑0.57) ok
Occupancy: 78.81→78.64% (↓0.17) REGRESSED
Eligible warps/cyc: 1.61→1.43 (↓0.18) REGRESSED
L2 hit%: 98.42→98.50% (↑0.08) ok
turn 1111.0s turn · 11.0s LLM · 0.0s tools
call → profile_kernel
callprofile_kernel
{
"kernel_code": "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\ncuda_src=r'''\n#include <torch/extension.h>\n#include <ATen/cuda/CUDAContext.h>\n#include <cuda.h>\n#include <cuda_runtime.h>\n#include <math_constants.h>\n__global__ __launch_bounds__(256,4)\nvoid rbf64_float4_kernel(const float* __restrict__ distances,float* __restrict__ out,long long n,float cutoff,float coeff){int tid=threadIdx.x;int lane=tid&31;int warp=tid>>5;long long i=(long long)blockIdx.x*8+warp;float d=0.0f,env=0.0f;if(i<n&&lane==0){d=distances[i];if(d<cutoff)env=0.5f*(cosf(CUDART_PI_F*d/cutoff)+1.0f);}d=__shfl_sync(0xffffffff,d,0);env=__shfl_sync(0xffffffff,env,0);if(i<n && lane<16){float cstep=cutoff*(1.0f/63.0f);int k=lane*4;float4 v;float x=d-((float)k)*cstep;v.x=expf(coeff*x*x)*env;x=d-((float)(k+1))*cstep;v.y=expf(coeff*x*x)*env;x=d-((float)(k+2))*cstep;v.z=expf(coeff*x*x)*env;x=d-((float)(k+3))*cstep;v.w=expf(coeff*x*x)*env;reinterpret_cast<float4*>(out+i*64)[lane]=v;}}\n__global__ __launch_bounds__(256,4)\nvoid rbf_generic_kernel(const float* __restrict__ distances,float* __restrict__ out,long long total,int m,float cutoff,float coeff){long long idx=(long long)blockIdx.x*blockDim.x+threadIdx.x;if(idx<total){int k=(int)(idx%m);long long i=idx/m;float d=distances[i];float env=0.0f;if(d<cutoff)env=0.5f*(cosf(CUDART_PI_F*d/cutoff)+1.0f);float center=((float)k)*cutoff/((float)(m-1));float x=d-center;out[idx]=expf(coeff*x*x)*env;}}\ntorch::Tensor rbf_forward(torch::Tensor distances,int64_t num_rbf,double cutoff_d,double coeff_d){auto out=torch::empty({distances.numel(),num_rbf},distances.options());long long n=distances.numel();float cutoff=(float)cutoff_d,coeff=(float)coeff_d;cudaStream_t stream=at::cuda::getCurrentCUDAStream();if(num_rbf==64){rbf64_float4_kernel<<<(unsigned int)((n+7)/8),256,0,stream>>>(distances.data_ptr<float>(),out.data_ptr<float>(),n,cutoff,coeff);}else{long long total=n*num_rbf;rbf_generic_kernel<<<(unsigned int)((total+255)/256),256,0,stream>>>(distances.data_ptr<float>(),out.data_ptr<float>(),total,(int)num_rbf,cutoff,coeff);}return out;}\n'''\ncpp_src='torch::Tensor rbf_forward(torch::Tensor distances, int64_t num_rbf, double cutoff, double coeff);'\n_ext=load_inline(name='rbf_ext_f4p', cpp_sources=cpp_src, cuda_sources=cuda_src, functions=['rbf_forward'], extra_cuda_cflags=['-O3','--use_fast_math'], extra_cflags=['-O3'], verbose=False)\nclass ModelNew(nn.Module):\n def __init__(self,num_rbf=64,cutoff=5.0):\n super().__init__(); self.num_rbf=num_rbf; self.cutoff=cutoff; offsets=torch.linspace(0.0,cutoff,num_rbf); self.register_buffer('offsets',offsets); self.coeff=-0.5/(offsets[1]-offsets[0]).item()**2\n def forward(self,distances):\n return _ext.rbf_forward(distances,int(self.num_rbf),float(self.cutoff),float(self.coeff)).view(*distances.shape,self.num_rbf)\n"
}
result ← profile_kernel (ok)
okprofile_kernel
profile_kernel PASSED: profiling complete.
=== Kernel Profile Summary ===
--- Kernel Breakdown (by GPU time) ---
#1: aten::empty 751.0μs (97%) calls=1
#2: aten::view 21.0μs (3%) calls=1
--- Timing ---
GPU time: 70.62 μs [↑3.7μs REGRESSED]
--- Memory Bandwidth ---
DRAM BW: 1602.3/3350 GB/s (47.8%) [↓2.8% REGRESSED]
read=29.8 write=1572.6 GB/s
Hit rates: L2=98.5%
--- Compute Throughput ---
Dominant pipe: FP32 util=22.0% [↑6.4% ok]
Pipe util: FMA=22.0%, Tensor=1.5%
--- Roofline Analysis ---
Ridge point (FP32): 20.00 FLOPs/byte
Classification: MEMORY-BOUND
--- Occupancy ---
Achieved: 82.6% [↑4.0% ok]
Eligible warps/cycle: 2.48
Launch: regs/thread=22, smem/blk=1024B, block=256, grid=65536
--- Memory Access Quality ---
Global ld coalescing: 1.00 sectors/req (perfect)
--- Warp Stall Reasons (% of issue cycles) ---
long_scoreboard 1312.9% ####################
short_scoreboard 90.6% ##################
mio_throttle 86.0% #################
--- Optimization Hints ---
-> 1313% stalls: global memory latency (waiting for DRAM/L2). Try shared-memory tiling, prefetching, or reducing working set.
--- Delta vs Previous Iteration ---
GPU time: 66.88→70.62μs (↑3.74) REGRESSED
DRAM BW%: 50.60→47.83% (↓2.77) REGRESSED
Compute%: 15.53→21.97% (↑6.44) ok
Occupancy: 78.64→82.61% (↑3.97) ok
Eligible warps/cyc: 1.43→2.48 (↑1.05) ok
L2 hit%: 98.50→98.49% (↓0.01) REGRESSED
turn 1211.7s turn · 11.7s LLM · 0.0s tools
call → static_check
callstatic_check
{
"kernel_code": "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\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#include <math_constants.h>\n\n__global__ __launch_bounds__(256, 4)\nvoid rbf64_pair_kernel(const float* __restrict__ distances,\n float* __restrict__ out,\n long long n, float cutoff, float coeff) {\n int tid = threadIdx.x;\n int lane = tid & 31;\n int warp = tid >> 5;\n long long i = (long long)blockIdx.x * 8 + warp;\n\n float d = 0.0f;\n float env = 0.0f;\n if (i < n && lane == 0) {\n d = distances[i];\n if (d < cutoff) {\n env = 0.5f * (cosf(CUDART_PI_F * d / cutoff) + 1.0f);\n }\n }\n d = __shfl_sync(0xffffffff, d, 0);\n env = __shfl_sync(0xffffffff, env, 0);\n\n if (i < n) {\n float cstep = cutoff * (1.0f / 63.0f);\n int k = lane * 2;\n float x0 = d - ((float)k) * cstep;\n float x1 = d - ((float)(k + 1)) * cstep;\n float2 v;\n v.x = expf(coeff * x0 * x0) * env;\n v.y = expf(coeff * x1 * x1) * env;\n reinterpret_cast<float2*>(out + i * 64)[lane] = v;\n }\n}\n\n__global__ __launch_bounds__(256, 4)\nvoid rbf_generic_kernel(const float* __restrict__ distances,\n float* __restrict__ out,\n long long total, int m, float cutoff, float coeff) {\n long long idx = (long long)blockIdx.x * blockDim.x + threadIdx.x;\n if (idx < total) {\n int k = (int)(idx % m);\n long long i = idx / m;\n float d = distances[i];\n float env = 0.0f;\n if (d < cutoff) {\n env = 0.5f * (cosf(CUDART_PI_F * d / cutoff) + 1.0f);\n }\n float center = ((float)k) * cutoff / ((float)(m - 1));\n float x = d - center;\n out[idx] = expf(coeff * x * x) * env;\n }\n}\n\ntorch::Tensor rbf_forward(torch::Tensor distances,\n int64_t num_rbf,\n double cutoff_d,\n double coeff_d) {\n auto out = torch::empty({distances.numel(), num_rbf}, distances.options());\n long long n = distances.numel();\n float cutoff = (float)cutoff_d;\n float coeff = (float)coeff_d;\n cudaStream_t stream = at::cuda::getCurrentCUDAStream();\n\n if (num_rbf == 64) {\n rbf64_pair_kernel<<<(unsigned int)((n + 7) / 8), 256, 0, stream>>>(\n distances.data_ptr<float>(), out.data_ptr<float>(), n, cutoff, coeff);\n } else {\n long long total = n * num_rbf;\n rbf_generic_kernel<<<(unsigned int)((total + 255) / 256), 256, 0, stream>>>(\n distances.data_ptr<float>(), out.data_ptr<float>(), total, (int)num_rbf, cutoff, coeff);\n }\n return out;\n}\n'''\n\ncpp_src = \"torch::Tensor rbf_forward(torch::Tensor distances, int64_t num_rbf, double cutoff, double coeff);\"\n\n_rbf_ext = load_inline(\n name=\"rbf_ext_final_pair\",\n cpp_sources=cpp_src,\n cuda_sources=cuda_src,\n functions=[\"rbf_forward\"],\n extra_cuda_cflags=[\"-O3\", \"--use_fast_math\"],\n extra_cflags=[\"-O3\"],\n verbose=False,\n)\n\nclass ModelNew(nn.Module):\n def __init__(self, num_rbf=64, cutoff=5.0):\n super().__init__()\n self.num_rbf = num_rbf\n self.cutoff = cutoff\n offsets = torch.linspace(0.0, cutoff, num_rbf)\n self.register_buffer(\"offsets\", offsets)\n coeff = -0.5 / (offsets[1] - offsets[0]).item() ** 2\n self.coeff = coeff\n\n def forward(self, distances: torch.Tensor) -> torch.Tensor:\n out = _rbf_ext.rbf_forward(distances, int(self.num_rbf), float(self.cutoff), float(self.coeff))\n return out.view(*distances.shape, self.num_rbf)\n"
}
result ← static_check (ok)
okstatic_check
static_check PASSED: no violations or warnings detected.
turn 138.6s turn · 8.6s 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\ncuda_src = r'''\n#include <torch/extension.h>\n#include <ATen/cuda/CUDAContext.h>\n#include <cuda.h>\n#include <cuda_runtime.h>\n#include <math_constants.h>\n\n__global__ __launch_bounds__(256, 4)\nvoid rbf64_pair_kernel(const float* __restrict__ distances,\n float* __restrict__ out,\n long long n, float cutoff, float coeff) {\n int tid = threadIdx.x;\n int lane = tid & 31;\n int warp = tid >> 5;\n long long i = (long long)blockIdx.x * 8 + warp;\n\n float d = 0.0f;\n float env = 0.0f;\n if (i < n && lane == 0) {\n d = distances[i];\n if (d < cutoff) {\n env = 0.5f * (cosf(CUDART_PI_F * d / cutoff) + 1.0f);\n }\n }\n d = __shfl_sync(0xffffffff, d, 0);\n env = __shfl_sync(0xffffffff, env, 0);\n\n if (i < n) {\n float cstep = cutoff * (1.0f / 63.0f);\n int k = lane * 2;\n float x0 = d - ((float)k) * cstep;\n float x1 = d - ((float)(k + 1)) * cstep;\n float2 v;\n v.x = expf(coeff * x0 * x0) * env;\n v.y = expf(coeff * x1 * x1) * env;\n reinterpret_cast<float2*>(out + i * 64)[lane] = v;\n }\n}\n\n__global__ __launch_bounds__(256, 4)\nvoid rbf_generic_kernel(const float* __restrict__ distances,\n float* __restrict__ out,\n long long total, int m, float cutoff, float coeff) {\n long long idx = (long long)blockIdx.x * blockDim.x + threadIdx.x;\n if (idx < total) {\n int k = (int)(idx % m);\n long long i = idx / m;\n float d = distances[i];\n float env = 0.0f;\n if (d < cutoff) {\n env = 0.5f * (cosf(CUDART_PI_F * d / cutoff) + 1.0f);\n }\n float center = ((float)k) * cutoff / ((float)(m - 1));\n float x = d - center;\n out[idx] = expf(coeff * x * x) * env;\n }\n}\n\ntorch::Tensor rbf_forward(torch::Tensor distances,\n int64_t num_rbf,\n double cutoff_d,\n double coeff_d) {\n auto out = torch::empty({distances.numel(), num_rbf}, distances.options());\n long long n = distances.numel();\n float cutoff = (float)cutoff_d;\n float coeff = (float)coeff_d;\n cudaStream_t stream = at::cuda::getCurrentCUDAStream();\n\n if (num_rbf == 64) {\n rbf64_pair_kernel<<<(unsigned int)((n + 7) / 8), 256, 0, stream>>>(\n distances.data_ptr<float>(), out.data_ptr<float>(), n, cutoff, coeff);\n } else {\n long long total = n * num_rbf;\n rbf_generic_kernel<<<(unsigned int)((total + 255) / 256), 256, 0, stream>>>(\n distances.data_ptr<float>(), out.data_ptr<float>(), total, (int)num_rbf, cutoff, coeff);\n }\n return out;\n}\n'''\n\ncpp_src = \"torch::Tensor rbf_forward(torch::Tensor distances, int64_t num_rbf, double cutoff, double coeff);\"\n\n_rbf_ext = load_inline(\n name=\"rbf_ext_final_pair\",\n cpp_sources=cpp_src,\n cuda_sources=cuda_src,\n functions=[\"rbf_forward\"],\n extra_cuda_cflags=[\"-O3\", \"--use_fast_math\"],\n extra_cflags=[\"-O3\"],\n verbose=False,\n)\n\nclass ModelNew(nn.Module):\n def __init__(self, num_rbf=64, cutoff=5.0):\n super().__init__()\n self.num_rbf = num_rbf\n self.cutoff = cutoff\n offsets = torch.linspace(0.0, cutoff, num_rbf)\n self.register_buffer(\"offsets\", offsets)\n coeff = -0.5 / (offsets[1] - offsets[0]).item() ** 2\n self.coeff = coeff\n\n def forward(self, distances: torch.Tensor) -> torch.Tensor:\n out = _rbf_ext.rbf_forward(distances, int(self.num_rbf), float(self.cutoff), float(self.coeff))\n return out.view(*distances.shape, self.num_rbf)\n"
}
result ← submit_kernel (ok)
oksubmit_kernel
submit_kernel PASSED: (5 / 5) correctness trials all passed.
Kernel runtime: 0.07 μs
Runtime stats: mean=0.07μs median=?μs std=0.00μs
Numerical precision: max_abs_err=1.07e-06 mean_abs_err=1.40e-08 max_rel_err=2.98e+04
Memory: 163.0 MB peak (ref: 293.0 MB, ratio: 0.5563x)
Kernel launches: 2 (ref: 20, fusion ratio: 10.0)
SOL score: 0.503
final submitted kernel (110 lines, 3,716 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.h>
#include <cuda_runtime.h>
#include <math_constants.h>
__global__ __launch_bounds__(256, 4)
void rbf64_pair_kernel(const float* __restrict__ distances,
float* __restrict__ out,
long long n, float cutoff, float coeff) {
int tid = threadIdx.x;
int lane = tid & 31;
int warp = tid >> 5;
long long i = (long long)blockIdx.x * 8 + warp;
float d = 0.0f;
float env = 0.0f;
if (i < n && lane == 0) {
d = distances[i];
if (d < cutoff) {
env = 0.5f * (cosf(CUDART_PI_F * d / cutoff) + 1.0f);
}
}
d = __shfl_sync(0xffffffff, d, 0);
env = __shfl_sync(0xffffffff, env, 0);
if (i < n) {
float cstep = cutoff * (1.0f / 63.0f);
int k = lane * 2;
float x0 = d - ((float)k) * cstep;
float x1 = d - ((float)(k + 1)) * cstep;
float2 v;
v.x = expf(coeff * x0 * x0) * env;
v.y = expf(coeff * x1 * x1) * env;
reinterpret_cast<float2*>(out + i * 64)[lane] = v;
}
}
__global__ __launch_bounds__(256, 4)
void rbf_generic_kernel(const float* __restrict__ distances,
float* __restrict__ out,
long long total, int m, float cutoff, float coeff) {
long long idx = (long long)blockIdx.x * blockDim.x + threadIdx.x;
if (idx < total) {
int k = (int)(idx % m);
long long i = idx / m;
float d = distances[i];
float env = 0.0f;
if (d < cutoff) {
env = 0.5f * (cosf(CUDART_PI_F * d / cutoff) + 1.0f);
}
float center = ((float)k) * cutoff / ((float)(m - 1));
float x = d - center;
out[idx] = expf(coeff * x * x) * env;
}
}
torch::Tensor rbf_forward(torch::Tensor distances,
int64_t num_rbf,
double cutoff_d,
double coeff_d) {
auto out = torch::empty({distances.numel(), num_rbf}, distances.options());
long long n = distances.numel();
float cutoff = (float)cutoff_d;
float coeff = (float)coeff_d;
cudaStream_t stream = at::cuda::getCurrentCUDAStream();
if (num_rbf == 64) {
rbf64_pair_kernel<<<(unsigned int)((n + 7) / 8), 256, 0, stream>>>(
distances.data_ptr<float>(), out.data_ptr<float>(), n, cutoff, coeff);
} else {
long long total = n * num_rbf;
rbf_generic_kernel<<<(unsigned int)((total + 255) / 256), 256, 0, stream>>>(
distances.data_ptr<float>(), out.data_ptr<float>(), total, (int)num_rbf, cutoff, coeff);
}
return out;
}
'''
cpp_src = "torch::Tensor rbf_forward(torch::Tensor distances, int64_t num_rbf, double cutoff, double coeff);"
_rbf_ext = load_inline(
name="rbf_ext_final_pair",
cpp_sources=cpp_src,
cuda_sources=cuda_src,
functions=["rbf_forward"],
extra_cuda_cflags=["-O3", "--use_fast_math"],
extra_cflags=["-O3"],
verbose=False,
)
class ModelNew(nn.Module):
def __init__(self, num_rbf=64, cutoff=5.0):
super().__init__()
self.num_rbf = num_rbf
self.cutoff = cutoff
offsets = torch.linspace(0.0, cutoff, num_rbf)
self.register_buffer("offsets", offsets)
coeff = -0.5 / (offsets[1] - offsets[0]).item() ** 2
self.coeff = coeff
def forward(self, distances: torch.Tensor) -> torch.Tensor:
out = _rbf_ext.rbf_forward(distances, int(self.num_rbf), float(self.cutoff), float(self.coeff))
return out.view(*distances.shape, self.num_rbf)