claude-opus-4-1-20250805 / cudaef57df
claude-opus-4-1-20250805_cuda_ef57df · claude-opus-4-1-20250805 · cuda · Apache-2.0
Use it
Vendorable · source mirrored · Apache-2.0View source →
No package. Vendor the mirrored source: 83 lines, Apache-2.0, pinned at da91508.
main.cpp
curl "https://kernelindex.com/api/v1/implementations/flashinfer-claude-opus-4-1-20250805-cuda-ef57df?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:5972d38952868caaee8dbd6dab39f90af2213676945f69e747d526113f9d5835
license declaredApache-2.0
license concludedApache-2.0
authorsclaude-opus-4-1-20250805
imported2026-08-20
Kernel source
main.cpp83 lines
#include <torch/extension.h>
#include <cuda_runtime.h>
#include "kernel.h"
#include <vector>
#include <stdexcept>
torch::Tensor run(
torch::Tensor probs,
torch::Tensor top_k,
torch::Tensor top_p
) {
// Validate input dimensions
TORCH_CHECK(probs.dim() == 2, "probs must be a 2D tensor");
TORCH_CHECK(top_k.dim() == 1, "top_k must be a 1D tensor");
TORCH_CHECK(top_p.dim() == 1, "top_p must be a 1D tensor");
const int batch_size = probs.size(0);
const int vocab_size = probs.size(1);
// Check vocabulary size
TORCH_CHECK(vocab_size == VOCAB_SIZE,
"Vocabulary size must be exactly 151936, got ", vocab_size);
// Check batch size consistency
TORCH_CHECK(top_k.size(0) == batch_size,
"top_k batch size mismatch: expected ", batch_size, ", got ", top_k.size(0));
TORCH_CHECK(top_p.size(0) == batch_size,
"top_p batch size mismatch: expected ", batch_size, ", got ", top_p.size(0));
// Check data types
TORCH_CHECK(probs.scalar_type() == torch::ScalarType::Float,
"probs must be float32");
TORCH_CHECK(top_k.scalar_type() == torch::ScalarType::Int,
"top_k must be int32");
TORCH_CHECK(top_p.scalar_type() == torch::ScalarType::Float,
"top_p must be float32");
// Ensure tensors are on CUDA device
TORCH_CHECK(probs.is_cuda(), "probs must be on CUDA device");
TORCH_CHECK(top_k.is_cuda(), "top_k must be on CUDA device");
TORCH_CHECK(top_p.is_cuda(), "top_p must be on CUDA device");
// Make tensors contiguous if needed
probs = probs.contiguous();
top_k = top_k.contiguous();
top_p = top_p.contiguous();
// Create output tensor for samples
auto options = torch::TensorOptions()
.dtype(torch::kInt64)
.device(probs.device())
.requires_grad(false);
torch::Tensor samples = torch::empty({batch_size}, options);
// Get current CUDA stream
cudaStream_t stream = at::cuda::getCurrentCUDAStream();
// Launch the kernel
launch_top_k_top_p_sampling(
probs.data_ptr<float>(),
top_k.data_ptr<int>(),
top_p.data_ptr<float>(),
samples.data_ptr<int64_t>(),
batch_size,
stream
);
// Ensure kernel completion before returning
cudaError_t err = cudaStreamSynchronize(stream);
if (err != cudaSuccess) {
TORCH_CHECK(false, "CUDA kernel execution failed: ", cudaGetErrorString(err));
}
return samples;
}
// Python bindings
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.def("run", &run, "Top-k Top-p sampling from probability distributions",
py::arg("probs"),
py::arg("top_k"),
py::arg("top_p"));
}scrolls · 83 lines total
Source code from the importing source · Apache-2.0
No published measurement for this revision
JSON