Skip to content
KernelIndex
Search⌘K

submission 212378

kev · python · License unknown

Use it

Vendorable · source mirrored · license unknownView source →

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

vector_add_ks.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-vectoradd-v2-212378?include=source"
interfacepython
Compatibility
measured onNVIDIA A100
declared hardwareNVIDIA A100
architecturessm_80
dtypesfp16

Benchmark evidence

1 measurement across 1 GPU, fastest first.

Operation / workload
Hardware
Latency
Rank
Observed
FP16 vector additionsuite of 5 cases
NVIDIA A100
954.7µs
#37 of 87
2025-12-26

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:55cd6eb6459cc5bd74ee2b79cf8b3aca44e9a03bd81eb1c170dd3f0a1617e113
license declaredunknown
license concludedunknown
authorskev
imported2026-08-15

Kernel source

vector_add_ks.py43 lines
import torch
import typing

# Define type aliases for the vector addition kernel inputs and outputs
input_t_add = typing.Tuple[torch.Tensor, torch.Tensor] # tuple of Tensors
output_t_add = torch.Tensor

def generate_input(N: int, seed: int) -> input_t_add:
    # Initialize a CUDA generator for reproducibility
    gen = torch.Generator(device='cuda')
    gen.manual_seed(seed)

    # Create tensor 'a' of shape (N, N) on CUDA device with float16 type
    # Populate with numbers from a normal distribution (mean=0, variance=1)
    a = torch.empty(N, N, device='cuda', dtype=torch.float16)
    a.normal_(mean=0, std=1, generator=gen)

    # Create tensor 'b' of shape (N, N) on CUDA device with float16 type
    # Populate with numbers from a normal distribution (mean=0, variance=1)
    b = torch.empty(N, N, device='cuda', dtype=torch.float16)
    b.normal_(mean=0, std=1, generator=gen)

    # Return the two tensors as a tuple
    return a, b

def custom_kernel(data: input_t_add) -> output_t_add:
    if len(data) == 3:
        a, b, out = data
        torch.add(a, b, out=out) # In-place into the provided buffer
        return out
    else:
        a, b = data
        return a + b

N_dim = 16 # Choose a multiple of 16 for N, as per common practice for CUDA kernels
seed_add = 42

# Generate the input tensors for addition
input_data_add = generate_input(N_dim, seed_add)

# Invoke the custom_kernel_add function with the generated input
output_tensor_add = custom_kernel(input_data_add)
scrolls · 43 lines total

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

Best evidence level for this revision: reported

JSON