Skip to content
KernelIndex
Search⌘K

gemini-2.5-pro / cuda2c7e9e

gemini-2.5-pro_cuda_2c7e9e · gemini-2.5-pro · 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-gemini-2-5-pro-cuda-2c7e9e?include=source"
interfacecuda
revisionda915083d4c7
symbolrun
pathmain.cpp
Compatibility
measured onNVIDIA B200
declared hardwareNVIDIA B200
architecturessm_100
dtypesbf16

Benchmark evidence

14 measurements across 1 GPU, fastest first.

Operation / workload
Hardware
Latency
Rank
Observed
RMSNorm h128bf16 · [128] · batch_size=4
NVIDIA B200
6.21µs
#4 of 9
2025-10-16
RMSNorm h128bf16 · [128] · batch_size=136
NVIDIA B200
6.25µs
#6 of 9
2025-10-16
RMSNorm h128bf16 · [128] · batch_size=1088
NVIDIA B200
6.25µs
#3 of 9
2025-10-16
RMSNorm h128bf16 · [128] · batch_size=32
NVIDIA B200
6.25µs
#5 of 9
2025-10-16
RMSNorm h128bf16 · [128] · batch_size=316
NVIDIA B200
6.27µs
#6 of 9
2025-10-16
RMSNorm h128bf16 · [128] · batch_size=24
NVIDIA B200
6.27µs
#5 of 9
2025-10-16
RMSNorm h128bf16 · [128] · batch_size=192
NVIDIA B200
6.28µs
#6 of 9
2025-10-16
RMSNorm h128bf16 · [128] · batch_size=256
NVIDIA B200
6.28µs
#7 of 9
2025-10-16
RMSNorm h128bf16 · [128] · batch_size=2048
NVIDIA B200
7.47µs
#2 of 9
2025-10-16
RMSNorm h128bf16 · [128] · batch_size=2528
NVIDIA B200
8.07µs
#2 of 9
2025-10-16
Show all 14 measurements ›
RMSNorm h128bf16 · [128] · batch_size=49532
NVIDIA B200
32.0µs
#1 of 9
2025-10-16
RMSNorm h128bf16 · [128] · batch_size=65016
NVIDIA B200
39.2µs
#1 of 9
2025-10-16
RMSNorm h128bf16 · [128] · batch_size=396256
NVIDIA B200
209.8µs
#1 of 9
2025-10-16
RMSNorm h128bf16 · [128] · batch_size=520128
NVIDIA B200
273.7µs
#1 of 9
2025-10-16

Reproduction-ready · How evidence levels are derived →

Source and license

sourcehttps://huggingface.co/datasets/flashinfer-ai/flashinfer-trace
commitda915083d4c7c5e61aa3005e3d17ae488e0fc71c
revision digestsha256:12e2cec56b60a90c0a87ec22fd89806a63dbe2159b08a3adb5a4ff9214679ae9
license declaredApache-2.0
license concludedApache-2.0
authorsgemini-2.5-pro
imported2026-08-20

Kernel source

main.cpp80 lines
#include <torch/extension.h>
#include <c10/cuda/CUDAStream.h>
#include "kernel.h"

// Define helper macros for concise input 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_BF16(x) TORCH_CHECK(x.scalar_type() == torch::kBFloat16, #x " must be a bfloat16 tensor")

// Define constant for the fixed hidden size
constexpr int HIDDEN_SIZE_CONST = 128;

/**
 * @brief C++ and Pybind11 interface for the RMSNorm CUDA kernel.
 *
 * This function acts as the bridge between Python (PyTorch) and the CUDA C++
 * implementation. It handles tensor validation, memory management, and CUDA
 * kernel launching.
 *
 * @param hidden_states The input tensor of shape [batch_size, 128] and dtype bfloat16.
 * @param weight The weight tensor of shape [128] and dtype bfloat16.
 * @return The output tensor of the same shape and dtype as hidden_states.
 */
torch::Tensor run(
    torch::Tensor hidden_states,
    torch::Tensor weight) {

    // --- Input Validation ---
    // Ensure all tensors are on the GPU
    CHECK_CUDA(hidden_states);
    CHECK_CUDA(weight);

    // Ensure all tensors are contiguous in memory for direct pointer access
    CHECK_CONTIGUOUS(hidden_states);
    CHECK_CONTIGUOUS(weight);

    // Check for the correct data type (bfloat16)
    CHECK_BF16(hidden_states);
    CHECK_BF16(weight);

    // Check tensor dimensions
    TORCH_CHECK(hidden_states.dim() == 2, "hidden_states must be a 2D tensor");
    TORCH_CHECK(weight.dim() == 1, "weight must be a 1D tensor");
    
    const int64_t batch_size = hidden_states.size(0);
    const int64_t hidden_size = hidden_states.size(1);

    // Check fixed dimension sizes
    TORCH_CHECK(hidden_size == HIDDEN_SIZE_CONST, "hidden_size must be 128");
    TORCH_CHECK(weight.size(0) == HIDDEN_SIZE_CONST, "weight must have size 128");

    // --- Output Tensor Preparation ---
    // Create an output tensor with the same properties (shape, dtype, device) as the input
    auto output = torch::empty_like(hidden_states);

    // --- Kernel Launch ---
    // Get the current CUDA stream from PyTorch's context
    c10::cuda::CUDAStream stream = c10::cuda::getCurrentCUDAStream();

    rmsnorm_h128_launch(
        output.data_ptr(),
        hidden_states.data_ptr(),
        weight.data_ptr(),
        static_cast<int>(batch_size),
        stream
    );

    return output;
}

// --- Pybind11 Module Definition ---
// This is the entry point that exposes the C++ 'run' function to Python.
// The macro TORCH_EXTENSION_NAME is defined by the build system (e.g., setuptools).
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
    m.def(
        "run",                  // Python function name
        &run,                   // C++ function pointer
        "RMSNorm H=128 kernel (CUDA BFloat16)" // Docstring for the Python function
    );
}
scrolls · 80 lines total

Source code from FlashInfer-Bench (flashinfer-ai/flashinfer-trace) · Apache-2.0

Best evidence level for this revision: reproducible

JSON