Skip to content
KernelIndex
Search⌘K

gpt-o3 / cudac9eefe

gpt-o3_cuda_c9eefe · gpt-o3 · 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-gpt-o3-cuda-c9eefe?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:542f03a591559f8a1261c0d4bf604b4991875b9fa0a5dd35cdb9d6b6db8b111d
license declaredApache-2.0
license concludedApache-2.0
authorsgpt-o3
imported2026-08-20

Kernel source

main.cpp72 lines
#include <torch/extension.h>
#include <ATen/cuda/CUDAContext.h>
#include "kernel.h"

/* --------------------------------------------------------------------- */
/* Basic argument checking                                               */
/* --------------------------------------------------------------------- */
static void check_inputs(const torch::Tensor& hidden,
                         const torch::Tensor& weight)
{
  using namespace at;

  TORCH_CHECK(hidden.is_cuda(),  "hidden_states must reside on CUDA");
  TORCH_CHECK(weight.is_cuda(),  "weight must reside on CUDA");

  TORCH_CHECK(hidden.scalar_type() == kBFloat16,
              "hidden_states must be torch.bfloat16");
  TORCH_CHECK(weight.scalar_type() == kBFloat16,
              "weight must be torch.bfloat16");

  TORCH_CHECK(hidden.dim() == 2 && hidden.size(1) == 1536,
              "hidden_states expected shape [batch_size, 1536]");
  TORCH_CHECK(weight.dim() == 1 && weight.size(0) == 1536,
              "weight expected shape [1536]");
}

/* --------------------------------------------------------------------- */
/* Python-visible entry point                                            */
/* --------------------------------------------------------------------- */
torch::Tensor run(torch::Tensor hidden_states,
                  torch::Tensor weight)
{
  check_inputs(hidden_states, weight);

  /* Make sure memory is contiguous for coalesced accesses              */
  hidden_states = hidden_states.contiguous();
  weight        = weight.contiguous();

  auto output = torch::empty_like(hidden_states);

  const __nv_bfloat16* in_ptr =
      reinterpret_cast<const __nv_bfloat16*>(
          hidden_states.data_ptr<at::BFloat16>());
  const __nv_bfloat16* w_ptr  =
      reinterpret_cast<const __nv_bfloat16*>(
          weight.data_ptr<at::BFloat16>());
  __nv_bfloat16* out_ptr =
      reinterpret_cast<__nv_bfloat16*>(
          output.data_ptr<at::BFloat16>());

  cudaStream_t stream = at::cuda::getCurrentCUDAStream();

  rmsnorm_h1536_launcher(in_ptr, w_ptr, out_ptr,
                         static_cast<int>(hidden_states.size(0)),
                         stream);

  /* Stream synchronisation is handled by PyTorch on tensor return.     */
  return output;
}

/* --------------------------------------------------------------------- */
/* PyBind11 binding                                                      */
/* --------------------------------------------------------------------- */
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m)
{
  m.doc() = "Optimised RMSNorm (hidden_size = 1536) for NVIDIA GPUs";
  m.def("run",
        &run,
        pybind11::arg("hidden_states"),
        pybind11::arg("weight"),
        "rmsnorm(hidden_states, weight) → output");
}
scrolls · 72 lines total

Source code from the importing source · Apache-2.0

No published measurement for this revision

JSON