Skip to content
KernelIndex
Search⌘K

submission 545074

rajesh0042 · python · License unknown

Use it

Vendorable · source mirrored · license unknownView source →

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

grayscale_v2.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-grayscale-v2-545074?include=source"
interfacepython
Compatibility
measured onNVIDIA L4
declared hardwareNVIDIA L4
architecturessm_89
dtypesfp32

Benchmark evidence

1 measurement across 1 GPU, fastest first.

Operation / workload
Hardware
Latency
Rank
Observed
RGB to grayscalesuite of 6 cases
NVIDIA L4
29.2ms
#12 of 12
2026-03-13

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:66baf33dfd16d9445c886c1389927d7f873e086a9cda01e28b6b3d28b3ed70ff
license declaredunknown
license concludedunknown
authorsrajesh0042
imported2026-08-15

Kernel source

grayscale_v2.py19 lines
import os
os.environ["CUBLAS_WORKSPACE_CONFIG"] = ":4096:8"

import torch
from task import input_t, output_t

# Precompute weights
_w = None

def custom_kernel(data: input_t) -> output_t:
    global _w
    data, output = data
    if _w is None or _w.device != data.device:
        _w = torch.tensor([0.2989, 0.5870, 0.1140], device=data.device, dtype=data.dtype)
    # Matrix multiply: reshape (H*W, 3) @ (3, 1) -> (H*W, 1) -> (H, W)
    h, w, _ = data.shape
    output[...] = (data.reshape(-1, 3) @ _w.unsqueeze(1)).reshape(h, w)
    return output

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 544992.

⋯ 3 unchanged lines
import torch
from task import input_t, output_t
+ # Precompute weights
+ _w = None
+
def custom_kernel(data: input_t) -> output_t:
+ global _w
data, output = data
- weights = torch.tensor([0.2989, 0.5870, 0.1140], device=data.device, dtype=data.dtype)
- torch.sum(data * weights, dim=-1, out=output)
+ if _w is None or _w.device != data.device:
+ _w = torch.tensor([0.2989, 0.5870, 0.1140], device=data.device, dtype=data.dtype)
+ # Matrix multiply: reshape (H*W, 3) @ (3, 1) -> (H*W, 1) -> (H, W)
+ h, w, _ = data.shape
+ output[...] = (data.reshape(-1, 3) @ _w.unsqueeze(1)).reshape(h, w)
return output

Best evidence level for this revision: reported

JSON