Skip to content

Support MLX v0.32.2 - #123

Merged
andresy merged 16 commits into
mainfrom
mlx-v0.32.0
Aug 27, 2026
Merged

andresy merged 16 commits into
mainfrom
mlx-v0.32.0

Conversation

@andresy

@andresy andresy commented Aug 10, 2026

Copy link
Copy Markdown
Member

No description provided.

@andresy andresy changed the title Support MLX v0.32.0 Support MLX v0.32.2 Aug 25, 2026
Comment thread mlx/c/compile.h
Comment on lines +50 to +52
int mlx_detail_compile_cache(mlx_compile_cache* res);
int mlx_detail_compile_clear_cache(const mlx_compile_cache cache);
int mlx_detail_compile_erase(const mlx_compile_cache cache, uintptr_t fun_id);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To make sure I understand, you use this like:

uintptr_t id = ...;
mlx_compile_cache cache;

// this is roughly attaching the cache to the global?
mlx_detail_compile_cache(&mlx_detail_compile_cache);

mlx_detail_compile_erase(cache, id);

There is no lifecycle on cache? I am not sure what the purpose of the variable is since it seems to be picking up a global.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

mlx_detail_compile_cache returns the cache for current thread and erase/clear_cache takes it to clear the cache on the correct thread, this was used to fix a python bug that a compiled function could be deleted on a thread different from where it was compiled.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, interesting. In swift we may allocate on one thread and deallocate on another thread -- indeed the thread may be gone by the time we delete. Ownership of the compiled function (the closure we retain) is thread safe on the swift side. Can we call mlx_detail_compile_erase() from any thread?

This may be along the lines of the stream: threads are not necessarily the unit of execution in swift.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah mlx_detail_compile_erase() is thread safe to call from anywhere.

Also we do need another public API to free mlx_compile_cache, it is a C++ weak ptr.

Comment thread mlx/c/metal.h

int mlx_metal_get_metallib_path(const char** res);
int mlx_metal_is_available(bool* res);
int mlx_metal_set_metallib_path(const char* path);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This would close #117

davidkoski added a commit to CharlieTLe/mlx-swift that referenced this pull request Aug 26, 2026
Comment thread mlx/c/metal.cpp Outdated
#include "mlx/c/error.h"
#include "mlx/c/private/mlx.h"

extern "C" int mlx_metal_get_metallib_path(const char** res) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be an mlx_string?

Comment thread mlx/c/ops.cpp Outdated
}
return 0;
}
extern "C" int mlx_count_nonzero(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is missing overloads:

  m.def(
      "count_nonzero",
      [](const mx::array& a,
         const IntOrVec& axis,
         bool keepdims,
         mx::StreamOrDevice s) {
        if (std::holds_alternative<std::monostate>(axis)) {
          return mx::count_nonzero(a, keepdims, s);
        } else if (auto pv = std::get_if<int>(&axis); pv) {
          return mx::count_nonzero(a, *pv, keepdims, s);
        } else {
          return mx::count_nonzero(
              a, std::get<std::vector<int>>(axis), keepdims, s);
        }
      },

@andresy
andresy merged commit d4afaec into main Aug 27, 2026
@andresy
andresy deleted the mlx-v0.32.0 branch August 27, 2026 21:44
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