Skip to content
KernelIndex
Search⌘K

submission 68311

P · python · License unknown

Use it

Vendorable · source mirrored · license unknownView source →

No package. Vendor the mirrored source: 72 lines, June 9 Researcher Reciprocity License v1.0.

submission.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-histogram-v2-68311?include=source"
interfacepython
Compatibility
measured onNVIDIA H100
declared hardwareNVIDIA H100
architecturessm_90
dtypesuint8

Benchmark evidence

1 measurement across 1 GPU, fastest first.

Operation / workload
Hardware
Latency
Rank
Observed
Histogramsuite of 6 cases
NVIDIA H100
281.2µs
#17 of 24
2025-11-08

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:1fda3e74ac78c3fdcb619639bf65272292db74071cee6762c8d0410f0e61dcef
license declaredunknown
license concludedunknown
authorsP
imported2026-08-15

Techniques

Extracted from the mirrored source by pattern, never inferred. Each row cites its line.

shared-memory__shared__ unsigned long long T[MAX_VAL];

Kernel source

submission.py72 lines
import torch
from utils import DeterministicContext
from torch.utils.cpp_extension import load_inline
from typing import List
from task import input_t, output_t

cuda_histogram = """
#define BLOCK_SIZE 1024
#define MAX_VAL 256
#include <cstdint>

__global__ void histogram(const unsigned char* __restrict__ A, unsigned long long* __restrict__ output, int len) {
    __shared__ unsigned long long T[MAX_VAL];

    int tid = threadIdx.x;

    // Initialize shared memory histogram
    for (int i = tid; i < MAX_VAL; i += blockDim.x) T[i] = 0;
    __syncthreads();

    // Build histogram in shared memory
    for (int i = blockIdx.x * blockDim.x + tid; i < len; i += blockDim.x * gridDim.x) {
        atomicAdd(&T[A[i]], 1ULL);
    }
    __syncthreads();

    // Accumulate shared memory histogram into global memory
    #pragma unroll
    for (int i = tid; i < MAX_VAL; i += blockDim.x) {
        atomicAdd(&output[i], T[i]);
    }
}

torch::Tensor& histogram(torch::Tensor& A, torch::Tensor& B) {
    int N = A.numel();

    int blocks = min((N + BLOCK_SIZE - 1) / BLOCK_SIZE, 1024);
    histogram<<<blocks, BLOCK_SIZE>>>(
        A.data_ptr<unsigned char>(),
        reinterpret_cast<unsigned long long*>(B.data_ptr<int64_t>()),
        N
    );
    return B;
}
"""

abi = torch._C._GLIBCXX_USE_CXX11_ABI
extra_compile_args={'cxx': [f"-O3", f"-D_GLIBCXX_USE_CXX11_ABI={abi}"],
                    'nvcc': ["-O3"]}

histogram_md = load_inline(
    name='sum_cuda_ext',
    cpp_sources="torch::Tensor& histogram(torch::Tensor& A, torch::Tensor& B);",
    cuda_sources=cuda_histogram,
    functions=['histogram'],
    extra_cflags=extra_compile_args['cxx'],
    extra_cuda_cflags=extra_compile_args['nvcc'],
    verbose=True,
)

def custom_kernel(data: input_t) -> output_t:
    """
    Custom implementation of vector addition using CUDA.
    Args:
        inputs: List of pairs of tensors [A, B] to be added.
    Returns:
        Tensor containing element-wise sum.
    """
    A, B = data
    B.zero_()  # Initialize output tensor to zero
    return histogram_md.histogram(A, B)
scrolls · 72 lines total

Source code from GPU Mode and the KernelBot dataset · June 9 Researcher Reciprocity License v1.0

Changes from previous submission

Against this author's previous submission submission 68301.

⋯ 6 unchanged lines
cuda_histogram = """
#define BLOCK_SIZE 1024
#define MAX_VAL 256
- #include <ATen/ATen.h>
- #include <torch/extension.h>
#include <cstdint>
__global__ void histogram(const unsigned char* __restrict__ A, unsigned long long* __restrict__ output, int len) {
⋯ 12 unchanged lines
__syncthreads();
// Accumulate shared memory histogram into global memory
+ #pragma unroll
for (int i = tid; i < MAX_VAL; i += blockDim.x) {
atomicAdd(&output[i], T[i]);
}
⋯ 2 unchanged lines
torch::Tensor& histogram(torch::Tensor& A, torch::Tensor& B) {
int N = A.numel();
- int blocks = (N + BLOCK_SIZE - 1) / BLOCK_SIZE;
+ int blocks = min((N + BLOCK_SIZE - 1) / BLOCK_SIZE, 1024);
histogram<<<blocks, BLOCK_SIZE>>>(
A.data_ptr<unsigned char>(),
reinterpret_cast<unsigned long long*>(B.data_ptr<int64_t>()),
scrolls · 26 diff lines total

Best evidence level for this revision: reported

JSON