Skip to content
KernelIndex
Search⌘K

submission 779897

Kernel-Zhang · python · License unknown

Use it

Vendorable · source mirrored · license unknownView source →

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

ref.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-sort-v2-779897?include=source"
interfacepython
Compatibility
measured onNVIDIA A100
declared hardwareNVIDIA A100
architecturessm_80
dtypesfp32

Benchmark evidence

1 measurement across 1 GPU, fastest first.

Operation / workload
Hardware
Latency
Rank
Observed
Sortsuite of 5 cases
NVIDIA A100
9.57ms
#15 of 28
2026-04-24

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:400461345f0a789946d7387836649b158fbbe5a2288aedf30146557c1ada1003
license declaredunknown
license concludedunknown
authorsKernel-Zhang
imported2026-08-15

Kernel source

ref.py66 lines
from utils import make_match_reference, DeterministicContext
import torch
from task import input_t, output_t


def custom_kernel(data: input_t) -> output_t:
    data, output = data
    output[...] = torch.sort(data)[0]
    return output
    
def ref_kernel(data: input_t) -> output_t:
    """
    Reference implementation of sort using PyTorch.
    Args:
        data: Input tensor to be sorted
    Returns:
        Sorted tensor
    """
    with DeterministicContext():
        data, output = data
        output[...] = torch.min(data)
        return output


def generate_input(size: int, seed: int) -> torch.Tensor:
    """
    Generates random input tensor where elements are drawn from different distributions.

    Args:
        size: Total size of the final 1D tensor
        seed: Base seed for random generation

    Returns:
        1D tensor of size `size` containing flattened values from different distributions
    """
    # Calculate dimensions for a roughly square 2D matrix
    rows = int(size**0.5)  # Square root for roughly square shape
    cols = (
        size + rows - 1
    ) // rows  # Ceiling division to ensure total size >= requested size

    gen = torch.Generator(device="cuda")
    result = torch.empty((rows, cols), device="cuda", dtype=torch.float32)

    # Different seed for each row!
    for i in range(rows):
        row_seed = seed + i
        gen.manual_seed(row_seed)

        # Generate values for this row with mean=row_seed
        result[i, :] = (
            torch.randn(cols, device="cuda", dtype=torch.float32, generator=gen)
            + row_seed
        )

    # Flatten and trim to exact size requested
    input_tensor = result.flatten()[:size].contiguous()
    output_tensor = torch.empty_like(
        input_tensor, device="cuda", dtype=torch.float32
    ).contiguous()
    return input_tensor, output_tensor


check_implementation = make_match_reference(ref_kernel)

scrolls · 66 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 779896.

⋯ 17 unchanged lines
"""
with DeterministicContext():
data, output = data
- output[...] = torch.sort(data)[0]
+ output[...] = torch.min(data)
return output

Best evidence level for this revision: reported

JSON