Skip to content
KernelIndex
Search⌘K

claude-opus-4-1 / cuda37fea8

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

Use it

Vendorable · source mirrored · Apache-2.0View source →

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

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

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:bcf4a960e0af7b5c0caae6c12727d311895cef904fd7a356a0842a0727f517b0
license declaredApache-2.0
license concludedApache-2.0
authorsclaude-opus-4-1-20250805
imported2026-08-20

Kernel source

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

// Helper macros for tensor validation
#define CHECK_CUDA(x) TORCH_CHECK(x.device().is_cuda(), #x " must be a CUDA tensor")
#define CHECK_CONTIGUOUS(x) TORCH_CHECK(x.is_contiguous(), #x " must be contiguous")
#define CHECK_INPUT(x) CHECK_CUDA(x); CHECK_CONTIGUOUS(x)

torch::Tensor run(
    torch::Tensor hidden_states,
    torch::Tensor weight
) {
    // Input validation
    CHECK_INPUT(hidden_states);
    CHECK_INPUT(weight);
    
    // Check data types
    TORCH_CHECK(hidden_states.scalar_type() == torch::kBFloat16,
                "hidden_states must be BFloat16");
    TORCH_CHECK(weight.scalar_type() == torch::kBFloat16,
                "weight must be BFloat16");
    
    // Check dimensions
    TORCH_CHECK(hidden_states.dim() == 2,
                "hidden_states must be 2D tensor");
    TORCH_CHECK(weight.dim() == 1,
                "weight must be 1D tensor");
    
    // Get dimensions
    const int batch_size = hidden_states.size(0);
    const int hidden_size = hidden_states.size(1);
    
    // Check hidden_size constraint
    TORCH_CHECK(hidden_size == 512,
                "hidden_size must be 512");
    TORCH_CHECK(weight.size(0) == 512,
                "weight size must be 512");
    
    // Allocate output tensor
    auto options = torch::TensorOptions()
        .dtype(hidden_states.dtype())
        .device(hidden_states.device());
    torch::Tensor output = torch::empty({batch_size, hidden_size}, options);
    
    // Get CUDA stream
    cudaStream_t stream = at::cuda::getCurrentCUDAStream();
    
    // Launch kernel
    launch_rmsnorm_h512(
        hidden_states.data_ptr(),
        weight.data_ptr(),
        output.data_ptr(),
        batch_size,
        stream
    );
    
    // Check for kernel errors
    cudaError_t err = cudaGetLastError();
    if (err != cudaSuccess) {
        TORCH_CHECK(false, "CUDA kernel launch failed: ", cudaGetErrorString(err));
    }
    
    return output;
}

// Python bindings
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
    m.def("run", &run, "RMSNorm H512 CUDA kernel");
}
scrolls · 72 lines total

Source code from the importing source · Apache-2.0

No published measurement for this revision

JSON