Skip to content
KernelIndex
Search⌘K

claude-opus-4-1-20250805 / cudaa1d4a7

claude-opus-4-1-20250805_cuda_a1d4a7 · claude-opus-4-1-20250805 · cuda · Apache-2.0

Use it

Vendorable · source mirrored · Apache-2.0View source →

No package. Vendor the mirrored source: 65 lines, Apache-2.0, pinned at da91508.

main.cpp
curl "https://kernelindex.com/api/v1/implementations/flashinfer-claude-opus-4-1-20250805-cuda-a1d4a7?include=source"
interfacecuda
revisionda915083d4c7
symbolrun
pathmain.cpp
Compatibility
declared hardwareNVIDIA B200
architecturessm_100
dtypesfp16

Benchmark evidence

No published measurement for this revision.

No evidence · How evidence levels are derived →

Source and license

sourcehttps://huggingface.co/datasets/flashinfer-ai/flashinfer-trace
commitda915083d4c7c5e61aa3005e3d17ae488e0fc71c
revision digestsha256:6afe6633e4d78437f31fec038526224850fa4e2cb1495e1b979981ad8c7226cc
license declaredApache-2.0
license concludedApache-2.0
authorsclaude-opus-4-1-20250805
imported2026-08-20

Kernel source

main.cpp65 lines
#include <torch/extension.h>
#include <cuda_runtime.h>
#include <cuda_fp16.h>
#include <vector>
#include <stdexcept>
#include "kernel.h"

// Main run function exposed to Python
torch::Tensor run(torch::Tensor A, torch::Tensor B) {
    // Validate input tensors
    TORCH_CHECK(A.dim() == 2, "A must be a 2D tensor");
    TORCH_CHECK(B.dim() == 2, "B must be a 2D tensor");
    TORCH_CHECK(A.scalar_type() == torch::ScalarType::Half, "A must be float16");
    TORCH_CHECK(B.scalar_type() == torch::ScalarType::Half, "B must be float16");
    TORCH_CHECK(A.is_cuda(), "A must be a CUDA tensor");
    TORCH_CHECK(B.is_cuda(), "B must be a CUDA tensor");
    TORCH_CHECK(A.device() == B.device(), "A and B must be on the same device");
    
    // Get dimensions
    const int64_t M = A.size(0);
    const int64_t K_A = A.size(1);
    const int64_t N = B.size(0);
    const int64_t K_B = B.size(1);
    
    // Validate dimensions match specification
    TORCH_CHECK(K_A == K_FIXED, "A must have K=4096 columns, got ", K_A);
    TORCH_CHECK(K_B == K_FIXED, "B must have K=4096 columns, got ", K_B);
    TORCH_CHECK(N == N_FIXED, "B must have N=2048 rows, got ", N);
    
    // Ensure contiguous memory layout for optimal memory access
    A = A.contiguous();
    B = B.contiguous();
    
    // Create output tensor on the same device as inputs
    auto options = torch::TensorOptions()
        .dtype(torch::kHalf)
        .device(A.device())
        .requires_grad(false);
    torch::Tensor C = torch::zeros({M, static_cast<int64_t>(N_FIXED)}, options);
    
    // Get CUDA stream from PyTorch
    cudaStream_t stream = at::cuda::getCurrentCUDAStream();
    
    // Get raw pointers to tensor data
    const half* A_ptr = reinterpret_cast<const half*>(A.data_ptr<at::Half>());
    const half* B_ptr = reinterpret_cast<const half*>(B.data_ptr<at::Half>());
    half* C_ptr = reinterpret_cast<half*>(C.data_ptr<at::Half>());
    
    // Launch CUDA kernel
    launch_gemm(A_ptr, B_ptr, C_ptr, static_cast<int>(M), stream);
    
    // Check for any CUDA errors
    cudaError_t err = cudaGetLastError();
    if (err != cudaSuccess) {
        TORCH_CHECK(false, "CUDA kernel error: ", cudaGetErrorString(err));
    }
    
    return C;
}

// Python module definition
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
    m.def("run", &run, "Optimized GEMM kernel for B200 GPU",
          py::arg("A"), py::arg("B"));
}
scrolls · 65 lines total

Source code from the importing source · Apache-2.0

No published measurement for this revision

JSON