mlx icon indicating copy to clipboard operation
mlx copied to clipboard

Is it possible to restrict the dependencies of 'mlx.metallib' at compile time?

Open tqtifnypmb opened this issue 2 years ago • 6 comments

I think that would be nice for embed devices

tqtifnypmb avatar Dec 14 '23 07:12 tqtifnypmb

What dependencies are you trying to remove? You can build without metal -DMLX_BUILD_METAL=OFF when you run cmake if that's what you mean.

awni avatar Dec 16 '23 05:12 awni

My main use case is tensor manipulation, but I need to leverage the advantages of universal memory to reduce the cost of memory copying. I wonder are there ways to avoid bundling mlx.metallib with the compiled binary?

tqtifnypmb avatar Dec 18 '23 09:12 tqtifnypmb

Thinking about possible methods, an option is to just bundle the metal source code and have the metal framework compile everything on the fly from the source - this might add some runtime overhead though (but also you will only have compiled versions of the kernels that you are using, so that might be a benefit depending on the device)

Beyond that, it will have to depend on your use case and what dependancies you want to avoid

jagrit06 avatar Dec 21 '23 22:12 jagrit06

Thinking about possible methods, an option is to just bundle the metal source code and have the metal framework compile everything on the fly from the source - this might add some runtime overhead though (but also you will only have compiled versions of the kernels that you are using, so that might be a benefit depending on the device)

Beyond that, it will have to depend on your use case and what dependancies you want to avoid

I primarily want to use it for iOS/macOS apps. If I include mlx.metallib in the binary, it will make the installation package too large. I'm wondering if it's possible to specify the operations to be used during compilation and then generate mlx.metallib based on these operations.

tqtifnypmb avatar Jan 04 '24 03:01 tqtifnypmb

@tqtifnypmb -- how were you able to include mlx.metallib into the app? I cannot do it. Please see my bug report here: https://github.com/ml-explore/mlx/issues/1286

P.S. You can make the binary much smaller if you don't pre-compile the shaders. See "Binary Size Minimization" here: https://ml-explore.github.io/mlx/build/html/install.html

akuz avatar Jul 25 '24 12:07 akuz

@akuz

I can't recall what I did.

I just copy mlx.metallib next to the compiled executable file, not to framework nor resources dir as you mentioned in #1286.

and

I maybe (maybe not) changed METAL_PATH while compiling.

tqtifnypmb avatar Jul 26 '24 01:07 tqtifnypmb