claude-opus-4-1 / cudab1507e
claude-opus-4-1_cuda_b1507e · claude-opus-4-1-20250805 · cuda · Apache-2.0
Use it
Vendorable · source mirrored · Apache-2.0View source →
No package. Vendor the mirrored source: 89 lines, Apache-2.0, pinned at da91508.
main.cpp
curl "https://kernelindex.com/api/v1/implementations/flashinfer-claude-opus-4-1-cuda-b1507e?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:adae2e241478d8eccc7eacbfe9ebbd02ab280ea95d1a2e5adb7c0f4302994c03
license declaredApache-2.0
license concludedApache-2.0
authorsclaude-opus-4-1-20250805
imported2026-08-20
Kernel source
main.cpp89 lines
#include <torch/extension.h>
#include <cuda_runtime.h>
#include "kernel.h"
#include <stdexcept>
#include <string>
// Helper macro for CUDA error checking
#define CHECK_CUDA(x) \
do { \
cudaError_t err = x; \
if (err != cudaSuccess) { \
throw std::runtime_error(std::string("CUDA error: ") + cudaGetErrorString(err) + \
" at " + __FILE__ + ":" + std::to_string(__LINE__)); \
} \
} while (0)
// Helper function to check tensor properties
void check_tensor(const torch::Tensor& tensor, const std::string& name,
torch::ScalarType expected_dtype,
int expected_dims) {
TORCH_CHECK(tensor.is_cuda(), name + " must be a CUDA tensor");
TORCH_CHECK(tensor.is_contiguous(), name + " must be contiguous");
TORCH_CHECK(tensor.scalar_type() == expected_dtype,
name + " must have dtype BFloat16");
TORCH_CHECK(tensor.dim() == expected_dims,
name + " must have " + std::to_string(expected_dims) + " dimensions");
}
torch::Tensor run(
torch::Tensor hidden_states,
torch::Tensor residual,
torch::Tensor weight
) {
// Validate input tensors
check_tensor(hidden_states, "hidden_states", torch::kBFloat16, 2);
check_tensor(residual, "residual", torch::kBFloat16, 2);
check_tensor(weight, "weight", torch::kBFloat16, 1);
// Get dimensions
const int64_t batch_size = hidden_states.size(0);
const int64_t hidden_size = hidden_states.size(1);
// Verify dimensions
TORCH_CHECK(hidden_size == HIDDEN_SIZE,
"hidden_size must be ", HIDDEN_SIZE, ", got ", hidden_size);
TORCH_CHECK(residual.size(0) == batch_size && residual.size(1) == hidden_size,
"residual shape mismatch: expected [", batch_size, ", ", hidden_size,
"], got [", residual.size(0), ", ", residual.size(1), "]");
TORCH_CHECK(weight.size(0) == hidden_size,
"weight shape mismatch: expected [", hidden_size,
"], got [", weight.size(0), "]");
// Allocate output tensor
torch::Tensor output = torch::empty({batch_size, hidden_size},
torch::TensorOptions()
.dtype(torch::kBFloat16)
.device(hidden_states.device()));
// Get current CUDA stream
cudaStream_t stream = at::cuda::getCurrentCUDAStream();
// Launch the kernel
CHECK_CUDA(launch_fused_add_rmsnorm(
hidden_states.data_ptr(),
residual.data_ptr(),
weight.data_ptr(),
output.data_ptr(),
static_cast<int>(batch_size),
stream
));
// Ensure kernel completion for error checking
CHECK_CUDA(cudaGetLastError());
return output;
}
// Python bindings
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.doc() = "Fused Add + RMSNorm kernel optimized for hidden_size=7168 on B200 GPU";
m.def("run", &run,
"Fused Add + RMSNorm forward pass",
pybind11::arg("hidden_states"),
pybind11::arg("residual"),
pybind11::arg("weight"));
}scrolls · 89 lines total
Source code from the importing source · Apache-2.0
No published measurement for this revision
JSON