Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(EXLA): Add support for MLIR compilation #1247

Merged
merged 7 commits into from
Aug 31, 2023
Merged

feat(EXLA): Add support for MLIR compilation #1247

merged 7 commits into from
Aug 31, 2023

Conversation

seanmor5
Copy link
Collaborator

Requires elixir-nx/xla#45

There's a lot of other changes that need to be made as well. Metal requires MLIR and not XLA Op output, so I need to figure out how to bridge those

@@ -170,6 +170,11 @@ defmodule EXLA.Client do
:tpu ->
EXLA.NIF.get_tpu_client()

:metal ->
# TODO: Is this really where/how we want to do this?
:ok = EXLA.NIF.load_pjrt_plugin("METAL", "/opt/homebrew/lib/python3.10/site-packages/jax_plugins/metal_plugin/pjrt_plugin_metal_14.dylib")
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this should be linked in the respective release for elixir-nx/xla directly, and then you can have something like this coming from there:

nx/torchx/c_src/torchx.cpp

Lines 347 to 355 in 219c23e

NIF(mps_is_available)
{
#ifdef MAC_ARM64
bool has_mps = at::hasMPS();
#else
bool has_mps = false;
#endif
return nx::nif::make(env, has_mps);
}

Copy link
Contributor

@polvalente polvalente Jun 12, 2023

Choose a reason for hiding this comment

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

For Torchx, this flag is defined here:

nx/torchx/CMakeLists.txt

Lines 46 to 48 in 219c23e

if(ARM64_SUPPORTED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMAC_ARM64")
endif()

I assume you'd do something similar for :xla

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we want to keep doing it on Elixir land: we can load the plugin on EXLA.Application. I also agree that ideally we would bundle the plugin with the precompiled XLA binary for macOS.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think that's going to work here because the only way to register the plugin as far as I can tell is dynamically through PjRt

Copy link
Collaborator

Choose a reason for hiding this comment

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

What I mean is that we ship the plugin with XLA and in here we point to XLA priv dir to load it. Would that work?

@polvalente polvalente changed the title Add support for Mac GPUs with METAL plugin Add support for MLIR compilation Aug 31, 2023
@polvalente polvalente changed the title Add support for MLIR compilation feat(EXLA): Add support for MLIR compilation Aug 31, 2023
@polvalente polvalente marked this pull request as ready for review August 31, 2023 07:56
@polvalente polvalente merged commit 2ad7782 into main Aug 31, 2023
9 checks passed
@polvalente polvalente deleted the sm-metal branch August 31, 2023 07:57
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.

3 participants