Skip to content

Propose to add Mojo🔥-based kernels - #175

Open
tolgacangoz wants to merge 3 commits into
gpu-mode:mainfrom
tolgacangoz:add-mojo-max-support
Open

tolgacangoz wants to merge 3 commits into
gpu-mode:mainfrom
tolgacangoz:add-mojo-max-support

Conversation

@tolgacangoz

@tolgacangoz tolgacangoz commented Nov 6, 2026 •

Copy link
Copy Markdown

@owenhilyard

Copy link
Copy Markdown

I'm relatively unfamiliar with GPU Mode's submission process, but is there some way to allow using another file for Mojo source code? Losing LSP support is already not great, but LLMs already have some issues confusing Mojo and Python, and I expect that to be much worse if the Mojo source is embedded in a python string.

Additionally, how is timing handled here? Mojo JIT compiles relevant standard library code and built-in kernels as part of building a python module from Mojo source code. Python modules can also be build ahead of time via a more normal compilation flow, which is what I would expect to do when benching a kernel.

@tolgacangoz

Copy link
Copy Markdown
Author

Thanks a bunch for your reviews @owenhilyard! AFAIU, a competitor usually make their experiments with usual Cuda and Mojo files, then submit within a Python string like that -that .py file is just for the submission part.

@tolgacangoz

tolgacangoz commented Nov 7, 2026 •

Copy link
Copy Markdown
Author

AFAIU, compilation happens at import, before the timer. Runner.py_init() compiles the function while the module loads. The benchmark only times custom_kernel(), which enqueues that compiled kernel.
GPU MODE/reference-kernels/problems/nvidia/eval.py:

        torch.cuda.synchronize()
        start_event = torch.cuda.Event(enable_timing=True)
        end_event = torch.cuda.Event(enable_timing=True)
        clear_l2_cache()

        start_event.record()
        output = custom_kernel(data)
        end_event.record()
        torch.cuda.synchronize()
        duration = start_event.elapsed_time(end_event) * 1e6  # Convert ms to ns

Am I understanding it correctly?

@owenhilyard

Copy link
Copy Markdown

That fragment means Mojo kernels would need to convert from pytorch tensors via dlpack during the timed portion, which isn't exactly cheap. I someone willing to weigh in on whether there can be a "convert to native tensor format" hook that isn't timed? No production kernel would ever end up taking that interop hit, so I don't think it's worth timing.

assert A.shape == B.shape, "Input tensors must have the same shape"
assert C.shape == A.shape, "Output tensor and input tensors must have the same shape"
assert A.dtype == torch.float16 and B.dtype == torch.float16 and C.dtype == torch.float16, "Input/output tensors must be float16"
_LAUNCH(A.data_ptr(), B.data_ptr(), C.data_ptr(), A.numel())

@tolgacangoz tolgacangoz Nov 7, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there currently the usage of DLPack here since we are using .data_ptr()s?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants