Skip to content
Open
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ playground.xcworkspace
Packages/
Package.pins
Package.resolved
*.xcodeproj
#
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
Expand Down
18 changes: 18 additions & 0 deletions README.xcodeproj.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
See `xcode/MLX.xcodeproj`.

# Cmlx

This is set up to build roughly how Package.swift builds.

- Look at Project -> Cmlx -> Build Phases
- remove all Project headers
- remove all Copy Bundle Resources
- remove any files that should not be built from the Target membership, e.g the items in `exclude`

Public headers are in `include-framework` and this is managed by tools/update-mlx

Settings, including header search paths are in xcode/xcconfig.

# MLX, etc.

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.
36 changes: 36 additions & 0 deletions Source/Cmlx/include-framework/Cmlx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <Cmlx/mlx-c-mlx.h>
#include <Cmlx/mlx-c-transforms_impl.h>
#include <Cmlx/mlx-c-linalg.h>
#include <Cmlx/mlx-c-fast.h>

#include <Cmlx/mlx-array.h>
#include <Cmlx/mlx-backend-cuda-cuda.h>
#include <Cmlx/mlx-backend-gpu-available.h>
#include <Cmlx/mlx-backend-metal-metal.h>
#include <Cmlx/mlx-compile.h>
#include <Cmlx/mlx-device.h>
#include <Cmlx/mlx-distributed-distributed.h>
#include <Cmlx/mlx-distributed-ops.h>
#include <Cmlx/mlx-einsum.h>
#include <Cmlx/mlx-export.h>
#include <Cmlx/mlx-fast.h>
#include <Cmlx/mlx-fft.h>
#include <Cmlx/mlx-io.h>
#include <Cmlx/mlx-linalg.h>
#include <Cmlx/mlx-memory.h>
#include <Cmlx/mlx-ops.h>
#include <Cmlx/mlx-random.h>
#include <Cmlx/mlx-stream.h>
#include <Cmlx/mlx-transforms.h>
#include <Cmlx/mlx-utils.h>
#include <Cmlx/mlx-version.h>
#include <Cmlx/mlx-allocator.h>
#include <Cmlx/mlx-dtype.h>
#include <Cmlx/mlx-event.h>
#include <Cmlx/mlx-small_vector.h>
#include <Cmlx/mlx-types-complex.h>
#include <Cmlx/mlx-types-half_types.h>
#include <Cmlx/mlx-types-bf16.h>
#include <Cmlx/mlx-io-load.h>
#include <Cmlx/mlx-export_impl.h>
#include <Cmlx/mlx-threadpool.h>
54 changes: 54 additions & 0 deletions Source/Cmlx/include-framework/mlx-allocator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifdef __cplusplus
// Copyright © 2023 Apple Inc.

#pragma once

#include <cstdlib>

namespace mlx::core::allocator {

// Simple wrapper around buffer pointers
// WARNING: Only Buffer objects constructed from and those that wrap
// raw pointers from mlx::allocator are supported.
class Buffer {
private:
void* ptr_;

public:
Buffer(void* ptr) : ptr_(ptr) {};

// Get the raw data pointer from the buffer
void* raw_ptr();

// Get the buffer pointer from the buffer
const void* ptr() const {
return ptr_;
};
void* ptr() {
return ptr_;
};
};

Buffer malloc(size_t size);

void free(Buffer buffer);

class Allocator {
/** Abstract base class for a memory allocator. */
public:
virtual Buffer malloc(size_t size) = 0;
virtual void free(Buffer buffer) = 0;
virtual size_t size(Buffer buffer) const = 0;

Allocator() = default;
Allocator(const Allocator& other) = delete;
Allocator(Allocator&& other) = delete;
Allocator& operator=(const Allocator& other) = delete;
Allocator& operator=(Allocator&& other) = delete;
virtual ~Allocator() = default;
};

Allocator& allocator();

} // namespace mlx::core::allocator
#endif
Loading