forked from ml-explore/mlx-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Package.swift
218 lines (193 loc) · 6.79 KB
/
Package.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
// Copyright © 2024 Apple Inc.
import PackageDescription
let package = Package(
name: "mlx-swift",
platforms: [
.macOS("13.3"),
.iOS(.v16),
.visionOS(.v1),
],
products: [
// main targets
.library(name: "MLX", targets: ["MLX"]),
.library(name: "MLXRandom", targets: ["MLXRandom"]),
.library(name: "MLXNN", targets: ["MLXNN"]),
.library(name: "MLXOptimizers", targets: ["MLXOptimizers"]),
.library(name: "MLXFFT", targets: ["MLXFFT"]),
.library(name: "MLXLinalg", targets: ["MLXLinalg"]),
.library(name: "MLXFast", targets: ["MLXFast"]),
],
dependencies: [
// for Complex type
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.0")
],
targets: [
.target(
name: "Cmlx",
exclude: [
// exclude here -- it is part of the include directory (public api)
"mlx-c",
// vendored library, include header only
"json",
// vendored library, do not include driver
"gguf-tools/gguf-tools.c",
// vendored library
"fmt/test",
"fmt/doc",
"fmt/support",
"fmt/src/os.cc",
"fmt/src/fmt.cc",
// these are selected conditionally
// via mlx-conditional/compiled_conditional.cpp
"mlx/mlx/backend/common/compiled_nocpu.cpp",
"mlx/mlx/backend/common/compiled_cpu.cpp",
// mlx files that are not part of the build
"mlx/ACKNOWLEDGMENTS.md",
"mlx/CMakeLists.txt",
"mlx/CODE_OF_CONDUCT.md",
"mlx/CONTRIBUTING.md",
"mlx/LICENSE",
"mlx/MANIFEST.in",
"mlx/README.md",
"mlx/benchmarks",
"mlx/cmake",
"mlx/docs",
"mlx/examples",
"mlx/mlx.pc.in",
"mlx/pyproject.toml",
"mlx/python",
"mlx/setup.py",
"mlx/tests",
// opt-out of these backends (using metal)
"mlx/mlx/backend/no_metal",
"mlx/mlx/backend/no_cpu",
"mlx/mlx/backend/common/default_primitives.cpp",
// this uses neon code and will not build on x86 (e.g. via Release).
// see mlx-conditional/accelerate-softmax.cpp
"mlx/mlx/backend/accelerate/softmax.cpp",
// build variants (we are opting _out_ of these)
"mlx/mlx/io/no_safetensors.cpp",
"mlx/mlx/io/gguf.cpp",
"mlx/mlx/io/gguf_quants.cpp",
// see PrepareMetalShaders -- don't build the kernels in place
"mlx/mlx/backend/metal/kernels",
"mlx/mlx/backend/metal/nojit_kernels.cpp",
// do not build distributed support (yet)
"mlx/mlx/distributed/mpi",
"mlx/mlx/distributed/ops.cpp",
"mlx/mlx/distributed/primitives.cpp",
// the mlx-c side of distributed
"include/mlx/c/distributed.cpp",
"include/mlx/c/distributed_group.cpp",
],
cSettings: [
.headerSearchPath("mlx"),
.headerSearchPath("include/mlx-c"),
],
cxxSettings: [
.headerSearchPath("mlx"),
.headerSearchPath("include/mlx-c"),
.headerSearchPath("metal-cpp"),
.headerSearchPath("json/single_include/nlohmann"),
.headerSearchPath("gguf-tools"),
.headerSearchPath("fmt/include"),
.define("ACCELERATE_NEW_LAPACK"),
.define("_METAL_"),
.define("SWIFTPM_BUNDLE", to: "\"mlx-swift_Cmlx\""),
.define("METAL_PATH", to: "\"default.metallib\""),
],
linkerSettings: [
.linkedFramework("Foundation"),
.linkedFramework("Metal"),
.linkedFramework("Accelerate"),
]
),
.testTarget(
name: "CmlxTests",
dependencies: ["Cmlx"]
),
.target(
name: "MLX",
dependencies: [
"Cmlx",
.product(name: "Numerics", package: "swift-numerics"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.target(
name: "MLXRandom",
dependencies: ["MLX"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.target(
name: "MLXFast",
dependencies: ["MLX", "Cmlx"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.target(
name: "MLXNN",
dependencies: ["MLX", "MLXRandom", "MLXFast"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.target(
name: "MLXOptimizers",
dependencies: ["MLX", "MLXNN"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.target(
name: "MLXFFT",
dependencies: ["MLX"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.target(
name: "MLXLinalg",
dependencies: ["MLX"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.testTarget(
name: "MLXTests",
dependencies: [
"MLX", "MLXRandom", "MLXNN", "MLXOptimizers", "MLXFFT", "MLXLinalg", "MLXFast",
]
),
// ------
// Example programs
.executableTarget(
name: "Example1",
dependencies: ["MLX"],
path: "Source/Examples",
sources: ["Example1.swift"]
),
.executableTarget(
name: "Tutorial",
dependencies: ["MLX"],
path: "Source/Examples",
sources: ["Tutorial.swift"]
),
],
cxxLanguageStandard: .gnucxx17
)
if Context.environment["MLX_SWIFT_BUILD_DOC"] == "1"
|| Context.environment["SPI_GENERATE_DOCS"] == "1"
{
// docc builder
package.dependencies.append(
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0")
)
}