Skip to content

Metal support: MTLBuffer access and current_work_stream for kDLMetal #578

Description

@ved1beta

Hi! I'd like to help land Metal support but I'm new to tvm-ffi internals
and want to ask before I start coding.

The downstream context: I'm working with huggingface/kernels, which has
Metal kernel-builder support staged on a WIP branch
and a loader-side tvm-ffi-metal variant just landed in PR #506.
@danieldk pointed at two upstream blockers:

  1. current_work_stream returns nullptr for kDLMetal in
    _build_optional_torch_c_dlpack.py
    — so a kernel can't find the producer's MTLCommandQueue.

  2. DLTensor.data for MPS tensors is the buffer's contents pointer, not the
    MTLBuffer object — but [encoder setBuffer:offset:atIndex:] needs the
    buffer object, not a raw pointer.

(1) feels straightforward — add a kDLMetal branch using
at::mps::getCurrentMPSStream(). Happy to send that as a small PR.

(2) is where I'd love guidance on architecture before writing code:

  • Should the MTLBuffer accessor live on DLPackExchangeAPI as a new
    callback (additive, but a dmlc/dlpack spec change)?
  • Or should it be a tvm-ffi-only side API that doesn't touch the DLPack
    standard?
  • Or something else entirely — e.g., reinterpret DLTensor.data as
    id<MTLBuffer> when device_type == kDLMetal?

I don't have strong opinions; I'd rather match whatever direction you'd
prefer. Happy to iterate on a design here before opening any PRs. Thanks!

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions