Skip to content
KernelIndex
Search⌘K

gpt-o3 / cuda9abd34

gpt-o3_cuda_9abd34 · gpt-o3 · cuda · Apache-2.0

Use it

Vendorable · source mirrored · Apache-2.0View source →

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

main.cpp
curl "https://kernelindex.com/api/v1/implementations/flashinfer-gpt-o3-cuda-9abd34?include=source"
interfacecuda
revisionda915083d4c7
symbolrun
pathmain.cpp
Compatibility
measured onNVIDIA B200
declared hardwareNVIDIA B200
architecturessm_100
dtypesbf16, fp32, int32

Benchmark evidence

15 measurements across 1 GPU, fastest first.

Operation / workload
Hardware
Latency
Rank
Observed
GQA ragged prefill causal h32 kv4 d128bf16 · [1, 4, 128] · #ce8167
NVIDIA B200
47.7µs
#5 of 10
2025-10-20
GQA ragged prefill causal h32 kv4 d128bf16 · [1, 4, 128] · #ce8167
NVIDIA B200
48.8µs
#6 of 10
2025-10-20
GQA ragged prefill causal h32 kv4 d128bf16 · [1, 4, 128] · #7c206f
NVIDIA B200
49.7µs
#3 of 5
2025-10-20
GQA ragged prefill causal h32 kv4 d128bf16 · [6, 4, 128] · #55a16d
NVIDIA B200
77.2µs
#5 of 10
2025-10-20
GQA ragged prefill causal h32 kv4 d128bf16 · [6, 4, 128] · #6d6644
NVIDIA B200
78.1µs
#3 of 5
2025-10-20
GQA ragged prefill causal h32 kv4 d128bf16 · [6, 4, 128] · #55a16d
NVIDIA B200
78.1µs
#6 of 10
2025-10-20
GQA ragged prefill causal h32 kv4 d128bf16 · [34, 4, 128] · #641e77
NVIDIA B200
204.7µs
#13 of 20
2025-10-20
GQA ragged prefill causal h32 kv4 d128bf16 · [34, 4, 128] · #641e77
NVIDIA B200
205.1µs
#14 of 20
2025-10-20
GQA ragged prefill causal h32 kv4 d128bf16 · [34, 4, 128] · #641e77
NVIDIA B200
208.4µs
#15 of 20
2025-10-20
GQA ragged prefill causal h32 kv4 d128bf16 · [34, 4, 128] · #641e77
NVIDIA B200
212.6µs
#16 of 20
2025-10-20
Show all 15 measurements ›
GQA ragged prefill causal h32 kv4 d128bf16 · [34, 4, 128] · #816a2c
NVIDIA B200
215.0µs
#4 of 5
2025-10-20
NVIDIA B200
443.2µs
#4 of 5
2025-10-20
NVIDIA B200
1.44ms
#4 of 5
2025-10-20
NVIDIA B200
45.6ms
#4 of 5
2025-10-20
NVIDIA B200
65.4ms
#4 of 5
2025-10-20

Reproduction-ready · How evidence levels are derived →

Source and license

sourcehttps://huggingface.co/datasets/flashinfer-ai/flashinfer-trace
commitda915083d4c7c5e61aa3005e3d17ae488e0fc71c
revision digestsha256:3a73a83021dd9abc23c3f9cf84a55ebd359eadfde4346501fc90586dd7f3116c
license declaredApache-2.0
license concludedApache-2.0
authorsgpt-o3
imported2026-08-20

Kernel source

main.cpp92 lines
#include "kernel.h"

#include <torch/extension.h>
#include <vector>
#include <cmath>
#include <tuple>

/* -------------------------------------------------------------------------- */
/*  Convenience: empty BF16 tensor on a device                                */
/* -------------------------------------------------------------------------- */
static inline torch::Tensor bf16_empty(const std::vector<int64_t>& sizes,
                                       const torch::Device& dev)
{
    return torch::empty(
        sizes,
        torch::TensorOptions()
              .dtype(torch::kBFloat16)
              .device(dev));
}

/* -------------------------------------------------------------------------- */
/*  PUBLIC ENTRY POINT (exposed to Python)                                    */
/* -------------------------------------------------------------------------- */
std::tuple<torch::Tensor, torch::Tensor>
run(torch::Tensor q,
    torch::Tensor k,
    torch::Tensor v,
    torch::Tensor qo_indptr,
    torch::Tensor kv_indptr,
    double        sm_scale_d = 1.0 / std::sqrt(128.0))
{
    TORCH_CHECK(q.is_cuda() && k.is_cuda() && v.is_cuda(),
                "q, k, v must be CUDA tensors");
    TORCH_CHECK(q.scalar_type() == torch::kBFloat16 &&
                k.scalar_type() == torch::kBFloat16 &&
                v.scalar_type() == torch::kBFloat16,
                "q, k, v must be bfloat16");

    TORCH_CHECK(qo_indptr.scalar_type() == torch::kInt32 &&
                kv_indptr.scalar_type() == torch::kInt32,
                "indptr tensors must be int32");

    /* fixed shapes */
    TORCH_CHECK(q.size(1) == NUM_QO_HEADS && q.size(2) == HEAD_DIM,
                "q wrong second/third dimension");
    TORCH_CHECK(k.size(1) == NUM_KV_HEADS && k.size(2) == HEAD_DIM,
                "k wrong second/third dimension");

    const int64_t total_q    = q.size(0);
    const int64_t total_kv   = k.size(0);
    const int64_t len_indptr = qo_indptr.size(0);

    TORCH_CHECK(qo_indptr[len_indptr - 1].item<int32_t>() == total_q,
                "total_q inconsistent with qo_indptr");
    TORCH_CHECK(kv_indptr[len_indptr - 1].item<int32_t>() == total_kv,
                "total_kv inconsistent with kv_indptr");

    /* allocate outputs */
    const auto device = q.device();
    torch::Tensor output = bf16_empty({total_q, NUM_QO_HEADS, HEAD_DIM}, device);
    torch::Tensor lse    = torch::empty({total_q, NUM_QO_HEADS},
                                        torch::TensorOptions()
                                              .dtype(torch::kFloat32)
                                              .device(device));

    /* launch */
    gqa_ragged_prefill_causal_h32_kv4_d128_launcher(
        q, k, v,
        qo_indptr, kv_indptr,
        static_cast<float>(sm_scale_d),
        output, lse);

    return {output, lse};
}

/* -------------------------------------------------------------------------- */
/*  PYBIND11 MODULE                                                           */
/* -------------------------------------------------------------------------- */
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m)
{
    m.doc() =
        "Optimised ragged causal prefill attention "
        "(32 QO heads / 4 KV heads / head_dim 128)";
    m.def("run", &run,
          pybind11::arg("q"),
          pybind11::arg("k"),
          pybind11::arg("v"),
          pybind11::arg("qo_indptr"),
          pybind11::arg("kv_indptr"),
          pybind11::arg("sm_scale") = 1.0 / std::sqrt(128.0),
          "Execute the kernel and return (output, lse)");
}
scrolls · 92 lines total

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

Best evidence level for this revision: reproducible

JSON