Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/src/dev/extensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,43 @@ the binding does not hard-code either the module or Metal library name:
// bindings
}

To choose Metal library names or build multiple libraries, pass
``extension.MetalLibrary`` objects through ``metal_libraries``:

.. code-block:: python
extension.MetalExtension(
"mlx_sample_metal_extension",
sources=["activation.cpp"],
metal_libraries=[
extension.MetalLibrary(
"activation",
sources=["silu_and_mul.metal"],
extra_compile_args=["-O3"],
deployment_target="14.0",
),
extension.MetalLibrary(
"something_else",
sources=["something_else.metal"],
),
],
)
When ``metal_libraries`` is set, put all ``.metal`` sources in those objects
and keep only C++ sources in ``MetalExtension.sources``. Each library needs a
unique name, given without a path or ``.metallib`` suffix. This example builds
``activation.metallib`` and ``something_else.metallib`` beside the Python
extension.

Each library's ``extra_compile_args`` are added after the extension's shared
``extra_compile_args["metal"]`` options. ``MLX_METAL_LIBRARY_NAME`` still
contains the final component of the Python extension name. Load libraries
explicitly by their configured names:

.. code-block:: C++

auto library = device.get_library("activation", current_binary_dir());

Debug builds include Metal line tables and recorded sources. Metal logging is
enabled when the current ``xcrun metal`` compiler advertises support. The
effective Python
Expand Down
Loading