claude-opus-4-1-20250805 / cuda9be3ac
claude-opus-4-1-20250805_cuda_9be3ac · claude-opus-4-1-20250805 · cuda · Apache-2.0
Use it
Vendorable · source mirrored · Apache-2.0View source →
No package. Vendor the mirrored source: 62 lines, Apache-2.0, pinned at da91508.
main.cpp
curl "https://kernelindex.com/api/v1/implementations/flashinfer-claude-opus-4-1-20250805-cuda-9be3ac?include=source"interfacecuda
revisionda915083d4c7
symbolrun
pathmain.cpp
Compatibility
declared hardwareNVIDIA B200
architecturessm_100
dtypesfp32
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:4a3c6fd33143f3ffad5902834c9068b962b2fac4f3107809c7009949af427872
license declaredApache-2.0
license concludedApache-2.0
authorsclaude-opus-4-1-20250805
imported2026-08-20
Kernel source
main.cpp62 lines
#include <torch/extension.h>
#include <cuda_runtime.h>
#include <vector>
#include <stdexcept>
#include "kernel.h"
// Constant for vocabulary size
constexpr int VOCAB_SIZE_CHECK = 128256;
// Main run function
torch::Tensor run(torch::Tensor probs, torch::Tensor top_p) {
// Input validation
TORCH_CHECK(probs.dim() == 2, "probs must be a 2D tensor");
TORCH_CHECK(top_p.dim() == 1, "top_p must be a 1D tensor");
TORCH_CHECK(probs.size(0) == top_p.size(0),
"Batch size mismatch between probs and top_p");
TORCH_CHECK(probs.size(1) == VOCAB_SIZE_CHECK,
"Vocabulary size must be 128256, got ", probs.size(1));
TORCH_CHECK(probs.scalar_type() == torch::kFloat32,
"probs must be float32");
TORCH_CHECK(top_p.scalar_type() == torch::kFloat32,
"top_p must be float32");
TORCH_CHECK(probs.is_cuda(), "probs must be a CUDA tensor");
TORCH_CHECK(top_p.is_cuda(), "top_p must be a CUDA tensor");
TORCH_CHECK(probs.is_contiguous(), "probs must be contiguous");
TORCH_CHECK(top_p.is_contiguous(), "top_p must be contiguous");
const int batch_size = probs.size(0);
// Create output tensor on the same device as input
auto options = torch::TensorOptions()
.dtype(torch::kInt64)
.device(probs.device());
torch::Tensor samples = torch::empty({batch_size}, options);
// Get current CUDA stream for this device
cudaStream_t stream = at::cuda::getCurrentCUDAStream();
// Launch the optimized kernel
launch_top_p_sampling(
probs.data_ptr<float>(),
top_p.data_ptr<float>(),
samples.data_ptr<int64_t>(),
batch_size,
stream
);
// Ensure kernel completion
cudaError_t error = cudaStreamSynchronize(stream);
if (error != cudaSuccess) {
TORCH_CHECK(false, "CUDA error during kernel execution: ",
cudaGetErrorString(error));
}
return samples;
}
// Python bindings using pybind11
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.def("run", &run, "Top-p (nucleus) sampling from probability distributions",
py::arg("probs"), py::arg("top_p"));
}scrolls · 62 lines total
Source code from the importing source · Apache-2.0
No published measurement for this revision
JSON