claude-opus-4-1-20250805 / cudab62d75
claude-opus-4-1-20250805_cuda_b62d75 · claude-opus-4-1-20250805 · cuda · Apache-2.0
Use it
Vendorable · source mirrored · Apache-2.0View source →
No package. Vendor the mirrored source: 75 lines, Apache-2.0, pinned at da91508.
main.cpp
curl "https://kernelindex.com/api/v1/implementations/flashinfer-claude-opus-4-1-20250805-cuda-b62d75?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:d0a787e77ccabfdadfbf04fd20cca2a15c89960c3b4c861005742aa7414ec604
license declaredApache-2.0
license concludedApache-2.0
authorsclaude-opus-4-1-20250805
imported2026-08-20
Kernel source
main.cpp75 lines
#include <torch/extension.h>
#include <cuda_runtime.h>
#include <vector>
#include <stdexcept>
#include "kernel.h"
torch::Tensor run(torch::Tensor probs, torch::Tensor top_k) {
// Input validation
TORCH_CHECK(probs.dim() == 2, "probs must be 2-dimensional, got ", probs.dim());
TORCH_CHECK(top_k.dim() == 1, "top_k must be 1-dimensional, got ", top_k.dim());
TORCH_CHECK(probs.size(1) == 151936,
"vocab_size must be 151936, got ", probs.size(1));
TORCH_CHECK(probs.size(0) == top_k.size(0),
"batch dimensions must match: probs has ", probs.size(0),
", top_k has ", top_k.size(0));
// Device checks
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(probs.device() == top_k.device(),
"All inputs must be on the same device");
// Type conversion if needed
if (probs.scalar_type() != torch::kFloat32) {
probs = probs.to(torch::kFloat32);
}
if (top_k.scalar_type() != torch::kInt32) {
top_k = top_k.to(torch::kInt32);
}
// Get batch size
const int batch_size = probs.size(0);
// Ensure contiguous memory layout
probs = probs.contiguous();
top_k = top_k.contiguous();
// Create output tensor
auto options = torch::TensorOptions()
.dtype(torch::kInt64)
.device(probs.device());
torch::Tensor samples = torch::empty({batch_size}, options);
// Get current CUDA stream
cudaStream_t stream = at::cuda::getCurrentCUDAStream();
// Get raw data pointers
const float* probs_ptr = probs.data_ptr<float>();
const int32_t* top_k_ptr = top_k.data_ptr<int32_t>();
int64_t* samples_ptr = samples.data_ptr<int64_t>();
// Launch kernel
launchTopKSampling(
probs_ptr,
top_k_ptr,
samples_ptr,
batch_size,
stream
);
// Synchronize to ensure kernel completion
cudaStreamSynchronize(stream);
// Check for kernel execution errors
cudaError_t err = cudaGetLastError();
TORCH_CHECK(err == cudaSuccess,
"CUDA kernel execution failed: ", cudaGetErrorString(err));
return samples;
}
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.def("run", &run, "Top-k sampling from probability distributions",
py::arg("probs"), py::arg("top_k"));
}scrolls · 75 lines total
Source code from the importing source · Apache-2.0
No published measurement for this revision
JSON