Skip to content

Commit 91615bc

Browse files
committed
build MLX, Cmlx via xcodeproj as a framework
tests passing with ml-explore/mlx#2702 locally applied expose C++ API
1 parent 8f9f747 commit 91615bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+11562
-5
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ playground.xcworkspace
4141
Packages/
4242
Package.pins
4343
Package.resolved
44-
*.xcodeproj
4544
#
4645
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
4746
# hence it is not needed unless you have added a package configuration file to your project

README.xcodeproj.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
See `xcode/MLX.xcodeproj`.
2+
3+
# Cmlx
4+
5+
This is set up to build roughly how Package.swift builds.
6+
7+
- Look at Project -> Cmlx -> Build Phases
8+
- remove all Project headers
9+
- remove all Copy Bundle Resources
10+
- remove any files that should not be built from the Target membership, e.g the items in `exclude`
11+
12+
Public headers are in `include-framework` and this is managed by tools/update-mlx
13+
14+
Settings, including header search paths are in xcode/xcconfig.
15+
16+
# MLX, etc.
17+
18+
These are just normal frameworks that link to Cmlx and others as needed. The source files are all swift and there are no special settings needed.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <Cmlx/mlx-c-mlx.h>
2+
#include <Cmlx/mlx-c-transforms_impl.h>
3+
#include <Cmlx/mlx-c-linalg.h>
4+
#include <Cmlx/mlx-c-fast.h>
5+
6+
#include <Cmlx/mlx-array.h>
7+
#include <Cmlx/mlx-backend-cuda-cuda.h>
8+
#include <Cmlx/mlx-backend-gpu-available.h>
9+
#include <Cmlx/mlx-backend-metal-metal.h>
10+
#include <Cmlx/mlx-compile.h>
11+
#include <Cmlx/mlx-device.h>
12+
#include <Cmlx/mlx-distributed-distributed.h>
13+
#include <Cmlx/mlx-distributed-ops.h>
14+
#include <Cmlx/mlx-einsum.h>
15+
#include <Cmlx/mlx-export.h>
16+
#include <Cmlx/mlx-fast.h>
17+
#include <Cmlx/mlx-fft.h>
18+
#include <Cmlx/mlx-io.h>
19+
#include <Cmlx/mlx-linalg.h>
20+
#include <Cmlx/mlx-memory.h>
21+
#include <Cmlx/mlx-ops.h>
22+
#include <Cmlx/mlx-random.h>
23+
#include <Cmlx/mlx-stream.h>
24+
#include <Cmlx/mlx-transforms.h>
25+
#include <Cmlx/mlx-utils.h>
26+
#include <Cmlx/mlx-version.h>
27+
#include <Cmlx/mlx-allocator.h>
28+
#include <Cmlx/mlx-dtype.h>
29+
#include <Cmlx/mlx-event.h>
30+
#include <Cmlx/mlx-small_vector.h>
31+
#include <Cmlx/mlx-types-complex.h>
32+
#include <Cmlx/mlx-types-half_types.h>
33+
#include <Cmlx/mlx-types-bf16.h>
34+
#include <Cmlx/mlx-io-load.h>
35+
#include <Cmlx/mlx-export_impl.h>
36+
#include <Cmlx/mlx-threadpool.h>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#ifdef __cplusplus
2+
// Copyright © 2023 Apple Inc.
3+
4+
#pragma once
5+
6+
#include <cstdlib>
7+
8+
namespace mlx::core::allocator {
9+
10+
// Simple wrapper around buffer pointers
11+
// WARNING: Only Buffer objects constructed from and those that wrap
12+
// raw pointers from mlx::allocator are supported.
13+
class Buffer {
14+
private:
15+
void* ptr_;
16+
17+
public:
18+
Buffer(void* ptr) : ptr_(ptr) {};
19+
20+
// Get the raw data pointer from the buffer
21+
void* raw_ptr();
22+
23+
// Get the buffer pointer from the buffer
24+
const void* ptr() const {
25+
return ptr_;
26+
};
27+
void* ptr() {
28+
return ptr_;
29+
};
30+
};
31+
32+
Buffer malloc(size_t size);
33+
34+
void free(Buffer buffer);
35+
36+
class Allocator {
37+
/** Abstract base class for a memory allocator. */
38+
public:
39+
virtual Buffer malloc(size_t size) = 0;
40+
virtual void free(Buffer buffer) = 0;
41+
virtual size_t size(Buffer buffer) const = 0;
42+
43+
Allocator() = default;
44+
Allocator(const Allocator& other) = delete;
45+
Allocator(Allocator&& other) = delete;
46+
Allocator& operator=(const Allocator& other) = delete;
47+
Allocator& operator=(Allocator&& other) = delete;
48+
virtual ~Allocator() = default;
49+
};
50+
51+
Allocator& allocator();
52+
53+
} // namespace mlx::core::allocator
54+
#endif

0 commit comments

Comments
 (0)