Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ endif()
FetchContent_Declare(
mlx-c
GIT_REPOSITORY "https://github.com/ml-explore/mlx-c.git"
GIT_TAG "v0.3.0")
GIT_TAG "v0.4.0")
FetchContent_MakeAvailable(mlx-c)

# swift-numerics
Expand Down
27 changes: 16 additions & 11 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.10
// swift-tools-version: 5.12
// The swift-tools-version declares the minimum version of Swift required to build this package.
// Copyright © 2024 Apple Inc.

Expand All @@ -8,9 +8,9 @@ let package = Package(
name: "mlx-swift",

platforms: [
.macOS("13.3"),
.iOS(.v16),
.tvOS(.v16),
.macOS("14.0"),
.iOS(.v17),
.tvOS(.v17),
.visionOS(.v1),
],

Expand All @@ -33,7 +33,6 @@ let package = Package(
name: "Cmlx",
exclude: [
// vendor docs
"metal-cpp.patch",
"vendor-README.md",

// example code + mlx-c distributed
Expand Down Expand Up @@ -92,20 +91,23 @@ let package = Package(
"mlx/mlx/backend/cuda/fence.cpp",
"mlx/mlx/backend/cuda/indexing.cpp",
"mlx/mlx/backend/cuda/jit_module.cpp",
"mlx/mlx/backend/cuda/load.cpp",
"mlx/mlx/backend/cuda/matmul.cpp",
"mlx/mlx/backend/cuda/primitives.cpp",
"mlx/mlx/backend/cuda/scaled_dot_product_attention.cpp",
"mlx/mlx/backend/cuda/slicing.cpp",
"mlx/mlx/backend/cuda/utils.cpp",
"mlx/mlx/backend/cuda/worker.cpp",
"mlx/mlx/backend/cuda/unary",
"mlx/mlx/backend/cuda/gemms",
"mlx/mlx/backend/cuda/steel",
"mlx/mlx/backend/cuda/reduce",
"mlx/mlx/backend/cuda/quantized",

"mlx/mlx/backend/cuda/binary",
"mlx/mlx/backend/cuda/conv",
"mlx/mlx/backend/cuda/copy",
"mlx/mlx/backend/cuda/device",
"mlx/mlx/backend/cuda/binary",
"mlx/mlx/backend/cuda/gemms",
"mlx/mlx/backend/cuda/quantized",
"mlx/mlx/backend/cuda/reduce",
"mlx/mlx/backend/cuda/steel",
"mlx/mlx/backend/cuda/unary",

// build variants (we are opting _out_ of these)
"mlx/mlx/io/no_safetensors.cpp",
Expand Down Expand Up @@ -145,6 +147,9 @@ let package = Package(
.define("SWIFTPM_BUNDLE", to: "\"mlx-swift_Cmlx\""),
.define("METAL_PATH", to: "\"default.metallib\""),
.define("MLX_VERSION", to: "\"0.24.2\""),

// Note: not set yet
// .define("MLX_ENABLE_NAX", to: "1"),
],
linkerSettings: [
.linkedFramework("Foundation"),
Expand Down
5 changes: 5 additions & 0 deletions Source/Cmlx/include/mlx/c/distributed.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ int mlx_distributed_send(
int dst,
const mlx_distributed_group group /* may be null */,
const mlx_stream s);
int mlx_distributed_sum_scatter(
mlx_array* res,
const mlx_array x,
const mlx_distributed_group group /* may be null */,
const mlx_stream s);
/**@}*/

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion Source/Cmlx/include/mlx/c/fast.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ int mlx_fast_scaled_dot_product_attention(
const mlx_array values,
float scale,
const char* mask_mode,
const mlx_vector_array mask_arrs,
const mlx_array mask_arr /* may be null */,
const mlx_array sinks /* may be null */,
const mlx_stream s);
/**@}*/
Expand Down
42 changes: 34 additions & 8 deletions Source/Cmlx/include/mlx/c/ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,10 @@ int mlx_dequantize(
const mlx_array w,
const mlx_array scales,
const mlx_array biases /* may be null */,
int group_size,
int bits,
mlx_optional_int group_size,
mlx_optional_int bits,
const char* mode,
mlx_optional_dtype dtype,
const mlx_stream s);
int mlx_diag(mlx_array* res, const mlx_array a, int k, const mlx_stream s);
int mlx_diagonal(
Expand Down Expand Up @@ -424,13 +425,24 @@ int mlx_floor_divide(
const mlx_array a,
const mlx_array b,
const mlx_stream s);
int mlx_from_fp8(
mlx_array* res,
const mlx_array x,
mlx_dtype dtype,
const mlx_stream s);
int mlx_full(
mlx_array* res,
const int* shape,
size_t shape_num,
const mlx_array vals,
mlx_dtype dtype,
const mlx_stream s);
int mlx_full_like(
mlx_array* res,
const mlx_array a,
const mlx_array vals,
mlx_dtype dtype,
const mlx_stream s);
int mlx_gather(
mlx_array* res,
const mlx_array a,
Expand All @@ -457,8 +469,8 @@ int mlx_gather_qmm(
const mlx_array lhs_indices /* may be null */,
const mlx_array rhs_indices /* may be null */,
bool transpose,
int group_size,
int bits,
mlx_optional_int group_size,
mlx_optional_int bits,
const char* mode,
bool sorted_indices,
const mlx_stream s);
Expand Down Expand Up @@ -569,6 +581,12 @@ int mlx_logsumexp(
const mlx_array a,
bool keepdims,
const mlx_stream s);
int mlx_masked_scatter(
mlx_array* res,
const mlx_array a,
const mlx_array mask,
const mlx_array src,
const mlx_stream s);
int mlx_matmul(
mlx_array* res,
const mlx_array a,
Expand Down Expand Up @@ -615,6 +633,13 @@ int mlx_mean(
const mlx_array a,
bool keepdims,
const mlx_stream s);
int mlx_median(
mlx_array* res,
const mlx_array a,
const int* axes,
size_t axes_num,
bool keepdims,
const mlx_stream s);
int mlx_meshgrid(
mlx_vector_array* res,
const mlx_vector_array arrays,
Expand Down Expand Up @@ -751,8 +776,8 @@ int mlx_put_along_axis(
int mlx_quantize(
mlx_vector_array* res,
const mlx_array w,
int group_size,
int bits,
mlx_optional_int group_size,
mlx_optional_int bits,
const char* mode,
const mlx_stream s);
int mlx_quantized_matmul(
Expand All @@ -762,8 +787,8 @@ int mlx_quantized_matmul(
const mlx_array scales,
const mlx_array biases /* may be null */,
bool transpose,
int group_size,
int bits,
mlx_optional_int group_size,
mlx_optional_int bits,
const char* mode,
const mlx_stream s);
int mlx_radians(mlx_array* res, const mlx_array a, const mlx_stream s);
Expand Down Expand Up @@ -1069,6 +1094,7 @@ int mlx_tile(
const int* reps,
size_t reps_num,
const mlx_stream s);
int mlx_to_fp8(mlx_array* res, const mlx_array x, const mlx_stream s);
int mlx_topk_axis(
mlx_array* res,
const mlx_array a,
Expand Down
8 changes: 8 additions & 0 deletions Source/Cmlx/include/mlx/c/optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ typedef struct mlx_optional_float_ {
bool has_value;
} mlx_optional_float;

/**
* A dtype optional.
*/
typedef struct mlx_optional_dtype_ {
mlx_dtype value;
bool has_value;
} mlx_optional_dtype;

/**@}*/

#ifdef __cplusplus
Expand Down
74 changes: 0 additions & 74 deletions Source/Cmlx/metal-cpp.patch

This file was deleted.

13 changes: 11 additions & 2 deletions Source/Cmlx/metal-cpp/Foundation/NSArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "NSObject.hpp"
#include "NSTypes.hpp"
#include "NSEnumerator.hpp"

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

Expand All @@ -43,8 +44,9 @@ class Array : public Copying<Array>
Array* init(const class Coder* pCoder);

template <class _Object = Object>
_Object* object(UInteger index) const;
UInteger count() const;
_Object* object(UInteger index) const;
UInteger count() const;
Enumerator<Object>* objectEnumerator() const;
};
}

Expand Down Expand Up @@ -113,3 +115,10 @@ _NS_INLINE _Object* NS::Array::object(UInteger index) const
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

_NS_INLINE NS::Enumerator<NS::Object>* NS::Array::objectEnumerator() const
{
return NS::Object::sendMessage<Enumerator<NS::Object>*>(this, _NS_PRIVATE_SEL(objectEnumerator));
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------
Loading