Skip to content
KernelIndex
Search⌘K

submission 779932

shivbhatia · python · License unknown

Use it

Vendorable · source mirrored · license unknownView source →

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

submission.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-grayscale-v2-779932?include=source"
interfacepython
Compatibility
measured onNVIDIA B200
declared hardwareNVIDIA B200
architecturessm_100
dtypesfp32

Benchmark evidence

1 measurement across 1 GPU, fastest first.

Operation / workload
Hardware
Latency
Rank
Observed
RGB to grayscalesuite of 6 cases
NVIDIA B200
600.6µs
#20 of 84
2026-04-24

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:d3f5c38fb34bfffe0a7805f6f517cd7869549faf290a1e162f1ae69065da55e6
license declaredunknown
license concludedunknown
authorsshivbhatia
imported2026-08-15

Techniques

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

vector-width = float4float4 a = __ldg((const float4*)&data[base * 3 + 0]); // R0 G0 B0 R1

Kernel source

submission.py56 lines
from task import input_t, output_t
from torch.utils.cpp_extension import load_inline

cuda_source = """
#include <cuda_runtime.h>

__global__ void grayscale_kernel(
    const float* __restrict__ data,
    float* __restrict__ output
) {
    // each thread handles 4 pixels = 12 floats = 3 x float4 loads
    int base = (blockIdx.x * blockDim.x + threadIdx.x) * 4;

    float4 a = __ldg((const float4*)&data[base * 3 + 0]); // R0 G0 B0 R1
    float4 b = __ldg((const float4*)&data[base * 3 + 4]); // G1 B1 R2 G2
    float4 c = __ldg((const float4*)&data[base * 3 + 8]); // B2 R3 G3 B3

    float v0 = a.x * 0.2989f + a.y * 0.5870f + a.z * 0.1140f;
    float v1 = a.w * 0.2989f + b.x * 0.5870f + b.y * 0.1140f;
    float v2 = b.z * 0.2989f + b.w * 0.5870f + c.x * 0.1140f;
    float v3 = c.y * 0.2989f + c.z * 0.5870f + c.w * 0.1140f;

    // single 128-bit write-through store for all 4 output pixels
    asm("st.global.wt.v4.f32 [%0], {%1, %2, %3, %4};"
        :: "l"(&output[base]), "f"(v0), "f"(v1), "f"(v2), "f"(v3));
}

torch::Tensor grayscale_cuda(torch::Tensor data, torch::Tensor output) {
    int n_pixels = output.numel();
    const int BLOCK_SIZE = 128;
    int grid = n_pixels / (BLOCK_SIZE * 4);
    grayscale_kernel<<<grid, BLOCK_SIZE>>>(
        data.data_ptr<float>(),
        output.data_ptr<float>()
    );
    return output;
}
"""

cpp_source = "torch::Tensor grayscale_cuda(torch::Tensor data, torch::Tensor output);"

_ext = load_inline(
    name="grayscale_b200_bs128",
    cpp_sources=cpp_source,
    cuda_sources=cuda_source,
    functions=["grayscale_cuda"],
    extra_cuda_cflags=["-use_fast_math"],
    verbose=False,
)


def custom_kernel(data: input_t) -> output_t:
    data, output = data
    _ext.grayscale_cuda(data, output)
    return output
scrolls · 56 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 779882.

⋯ 26 unchanged lines
torch::Tensor grayscale_cuda(torch::Tensor data, torch::Tensor output) {
int n_pixels = output.numel();
- const int BLOCK_SIZE = 256;
+ const int BLOCK_SIZE = 128;
int grid = n_pixels / (BLOCK_SIZE * 4);
grayscale_kernel<<<grid, BLOCK_SIZE>>>(
data.data_ptr<float>(),
⋯ 6 unchanged lines
cpp_source = "torch::Tensor grayscale_cuda(torch::Tensor data, torch::Tensor output);"
_ext = load_inline(
- name="grayscale_float4_wt_v4_fm",
+ name="grayscale_b200_bs128",
cpp_sources=cpp_source,
cuda_sources=cuda_source,
functions=["grayscale_cuda"],

Best evidence level for this revision: reported

JSON