Skip to content
KernelIndex
Search⌘K

claude-opus-4-1-20250805 / cuda8688f2

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

Use it

Vendorable · source mirrored · Apache-2.0View source →

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

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

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

Kernel source

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

// Error checking macros
#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 probs,
    torch::Tensor top_k
) {
    // Input validation
    CHECK_INPUT(probs);
    CHECK_INPUT(top_k);
    
    // Check dimensions
    TORCH_CHECK(probs.dim() == 2, "probs must be 2D tensor");
    TORCH_CHECK(top_k.dim() == 1, "top_k must be 1D tensor");
    
    int batch_size = probs.size(0);
    int vocab_size = probs.size(1);
    
    // Validate vocab size
    TORCH_CHECK(vocab_size == 128256, 
                "vocab_size must be 128256, got " + std::to_string(vocab_size));
    
    // Validate batch sizes match
    TORCH_CHECK(top_k.size(0) == batch_size, 
                "top_k batch size must match probs batch size");
    
    // Ensure correct dtypes
    torch::Tensor probs_f32 = probs.to(torch::kFloat32).contiguous();
    torch::Tensor top_k_i32 = top_k.to(torch::kInt32).contiguous();
    
    // Create output tensor
    auto options = torch::TensorOptions()
        .dtype(torch::kInt64)
        .device(probs.device());
    torch::Tensor samples = torch::empty({batch_size}, options);
    
    // Get current CUDA stream
    cudaStream_t stream = at::cuda::getCurrentCUDAStream();
    
    // Launch kernel
    launchTopKSampling(
        probs_f32.data_ptr<float>(),
        top_k_i32.data_ptr<int32_t>(),
        samples.data_ptr<int64_t>(),
        batch_size,
        stream
    );
    
    // Ensure kernel completion
    cudaError_t error = cudaStreamSynchronize(stream);
    if (error != cudaSuccess) {
        throw std::runtime_error(
            std::string("CUDA synchronization error: ") + cudaGetErrorString(error)
        );
    }
    
    // Check for kernel errors
    error = cudaGetLastError();
    if (error != cudaSuccess) {
        throw std::runtime_error(
            std::string("CUDA kernel error: ") + cudaGetErrorString(error)
        );
    }
    
    return samples;
}

PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
    m.def("run", &run, "Top-k sampling from probability distributions",
          pybind11::arg("probs"), 
          pybind11::arg("top_k"));
}
scrolls · 80 lines total

Source code from the importing source · Apache-2.0

No published measurement for this revision

JSON