|
| 1 | +// swift-tools-version:5.9 |
| 2 | +import PackageDescription |
| 3 | + |
| 4 | +let package = Package( |
| 5 | + name: "ccv", |
| 6 | + platforms: [ |
| 7 | + .macOS(.v13), |
| 8 | + .iOS(.v16), |
| 9 | + .tvOS(.v16), |
| 10 | + .visionOS(.v1) |
| 11 | + ], |
| 12 | + products: [ |
| 13 | + .library( |
| 14 | + name: "ccv", |
| 15 | + targets: ["C_swiftpm_ccv"]), |
| 16 | + .library( |
| 17 | + name: "nnc", |
| 18 | + targets: ["C_swiftpm_nnc"]), |
| 19 | + .library( |
| 20 | + name: "sfmt", |
| 21 | + targets: ["C_sfmt"]), |
| 22 | + .library( |
| 23 | + name: "lib_nnc_mps_compat", |
| 24 | + targets: ["lib_nnc_mps_compat"]), |
| 25 | + ], |
| 26 | + targets: [ |
| 27 | + // SFMT - SIMD-oriented Fast Mersenne Twister |
| 28 | + .target( |
| 29 | + name: "C_sfmt", |
| 30 | + path: "lib/3rdparty/sfmt", |
| 31 | + exclude: [ |
| 32 | + "SFMT-alti.h", // Altivec (PowerPC) - not available on ARM |
| 33 | + "SFMT-sse2.h", // SSE2 (x86) - not available on ARM |
| 34 | + ], |
| 35 | + sources: ["SFMT.c"], |
| 36 | + publicHeadersPath: ".", |
| 37 | + cSettings: [ |
| 38 | + .headerSearchPath("."), |
| 39 | + .unsafeFlags(["-w"]) |
| 40 | + ] |
| 41 | + ), |
| 42 | + |
| 43 | + // dSFMT - Double-precision SFMT (internal dependency) |
| 44 | + .target( |
| 45 | + name: "dSFMT", |
| 46 | + path: "lib/3rdparty/dsfmt", |
| 47 | + sources: ["dSFMT.c"], |
| 48 | + publicHeadersPath: ".", |
| 49 | + cSettings: [ |
| 50 | + .unsafeFlags(["-w"]) |
| 51 | + ] |
| 52 | + ), |
| 53 | + |
| 54 | + // KissFFT (internal dependency) |
| 55 | + .target( |
| 56 | + name: "kissfft", |
| 57 | + path: "lib/3rdparty/kissfft", |
| 58 | + publicHeadersPath: ".", |
| 59 | + cSettings: [ |
| 60 | + .unsafeFlags(["-w"]) |
| 61 | + ] |
| 62 | + ), |
| 63 | + |
| 64 | + // SipHash (internal dependency) |
| 65 | + .target( |
| 66 | + name: "siphash", |
| 67 | + path: "lib/3rdparty/siphash", |
| 68 | + sources: ["siphash24.c"], |
| 69 | + publicHeadersPath: ".", |
| 70 | + cSettings: [ |
| 71 | + .unsafeFlags(["-w"]) |
| 72 | + ] |
| 73 | + ), |
| 74 | + |
| 75 | + // Main CCV library |
| 76 | + .target( |
| 77 | + name: "C_swiftpm_ccv", |
| 78 | + dependencies: ["C_sfmt", "dSFMT", "kissfft", "siphash"], |
| 79 | + path: "lib", |
| 80 | + exclude: [ |
| 81 | + "3rdparty", |
| 82 | + "nnc", |
| 83 | + "cuda", |
| 84 | + "inc", |
| 85 | + "io", |
| 86 | + "configure", |
| 87 | + "configure.ac", |
| 88 | + "makefile", |
| 89 | + "config.mk", |
| 90 | + "scheme.mk", |
| 91 | + ".ycm_extra_conf.py", |
| 92 | + ], |
| 93 | + publicHeadersPath: ".", |
| 94 | + cSettings: [ |
| 95 | + .headerSearchPath("."), |
| 96 | + .define("HAVE_CBLAS"), |
| 97 | + .define("HAVE_PTHREAD"), |
| 98 | + .define("HAVE_ACCELERATE_FRAMEWORK"), |
| 99 | + .define("USE_DISPATCH"), |
| 100 | + .unsafeFlags(["-fblocks", "-w"]) |
| 101 | + ], |
| 102 | + linkerSettings: [ |
| 103 | + .linkedFramework("Accelerate") |
| 104 | + ] |
| 105 | + ), |
| 106 | + |
| 107 | + // NNC - Neural Network Collection |
| 108 | + .target( |
| 109 | + name: "C_swiftpm_nnc", |
| 110 | + dependencies: ["C_swiftpm_ccv", "C_sfmt", "dSFMT"], |
| 111 | + path: "lib/nnc", |
| 112 | + exclude: [ |
| 113 | + // Exclude CUDA/GPU files (not needed for MPS) |
| 114 | + "gpu", |
| 115 | + // Exclude build artifacts and makefiles |
| 116 | + "mps", |
| 117 | + "makefile", |
| 118 | + "cmd/makefile", |
| 119 | + "cmd/config.mk", |
| 120 | + "mps/makefile", |
| 121 | + "mps/.ycm_extra_conf.py", |
| 122 | + "mfa/makefile", |
| 123 | + // Exclude CUDA command implementations |
| 124 | + "cmd/adam/gpu", |
| 125 | + "cmd/blas/gpu", |
| 126 | + "cmd/comm/gpu", |
| 127 | + "cmd/compare/gpu", |
| 128 | + "cmd/compression/gpu", |
| 129 | + "cmd/convolution/gpu", |
| 130 | + "cmd/dropout/gpu", |
| 131 | + "cmd/ew/gpu", |
| 132 | + "cmd/gelu/gpu", |
| 133 | + "cmd/index/gpu", |
| 134 | + "cmd/isnan/gpu", |
| 135 | + "cmd/lamb/gpu", |
| 136 | + "cmd/leaky_relu/gpu", |
| 137 | + "cmd/loss/gpu", |
| 138 | + "cmd/nms/gpu", |
| 139 | + "cmd/norm/gpu", |
| 140 | + "cmd/pad/gpu", |
| 141 | + "cmd/partition/gpu", |
| 142 | + "cmd/pool/gpu", |
| 143 | + "cmd/rand/gpu", |
| 144 | + "cmd/reduce/gpu", |
| 145 | + "cmd/relu/gpu", |
| 146 | + "cmd/rmsprop/gpu", |
| 147 | + "cmd/rnn/gpu", |
| 148 | + "cmd/roi/gpu", |
| 149 | + "cmd/scaled_dot_product_attention/gpu", |
| 150 | + "cmd/scatter_add/gpu", |
| 151 | + "cmd/sgd/gpu", |
| 152 | + "cmd/sigmoid/gpu", |
| 153 | + "cmd/sigmoid_loss/gpu", |
| 154 | + "cmd/softmax/gpu", |
| 155 | + "cmd/softmax_loss/gpu", |
| 156 | + "cmd/sort/gpu", |
| 157 | + "cmd/swish/gpu", |
| 158 | + "cmd/tanh/gpu", |
| 159 | + "cmd/unique_consecutive/gpu", |
| 160 | + "cmd/upsample/gpu", |
| 161 | + "cmd/util/gpu", |
| 162 | + ], |
| 163 | + publicHeadersPath: ".", |
| 164 | + cSettings: [ |
| 165 | + .headerSearchPath("."), |
| 166 | + .headerSearchPath(".."), |
| 167 | + .headerSearchPath("cmd"), |
| 168 | + .headerSearchPath("mfa"), |
| 169 | + .headerSearchPath("mfa/3rdparty/metal-cpp"), |
| 170 | + .headerSearchPath("mfa/v2"), |
| 171 | + .define("HAVE_CBLAS"), |
| 172 | + .define("HAVE_PTHREAD"), |
| 173 | + .define("HAVE_ACCELERATE_FRAMEWORK"), |
| 174 | + .define("USE_DISPATCH"), |
| 175 | + .define("HAVE_MPS"), |
| 176 | + .unsafeFlags(["-fblocks", "-fno-objc-arc", "-w"]) |
| 177 | + ], |
| 178 | + cxxSettings: [ |
| 179 | + .headerSearchPath("."), |
| 180 | + .headerSearchPath(".."), |
| 181 | + .headerSearchPath("mfa"), |
| 182 | + .headerSearchPath("mfa/3rdparty/metal-cpp"), |
| 183 | + .headerSearchPath("mfa/v2"), |
| 184 | + .define("HAVE_MPS"), |
| 185 | + .unsafeFlags(["-std=c++17", "-w"]) |
| 186 | + ], |
| 187 | + linkerSettings: [ |
| 188 | + .linkedFramework("Accelerate"), |
| 189 | + .linkedFramework("Metal"), |
| 190 | + .linkedFramework("MetalPerformanceShaders"), |
| 191 | + .linkedFramework("MetalPerformanceShadersGraph"), |
| 192 | + .linkedFramework("Foundation"), |
| 193 | + ] |
| 194 | + ), |
| 195 | + // MPS Compatibility layer for NNC |
| 196 | + .target( |
| 197 | + name: "lib_nnc_mps_compat", |
| 198 | + dependencies: ["C_swiftpm_nnc"], |
| 199 | + path: "lib/nnc/mps", |
| 200 | + exclude: [ |
| 201 | + "makefile", |
| 202 | + ".ycm_extra_conf.py", |
| 203 | + ".dep.mk", |
| 204 | + ], |
| 205 | + sources: [ |
| 206 | + "ccv_nnc_mps.m", |
| 207 | + "ccv_nnc_palettize.m", |
| 208 | + ], |
| 209 | + publicHeadersPath: ".", |
| 210 | + cSettings: [ |
| 211 | + .headerSearchPath("."), |
| 212 | + .headerSearchPath(".."), |
| 213 | + .headerSearchPath("../.."), |
| 214 | + .headerSearchPath("../cmd"), |
| 215 | + .headerSearchPath("../mfa"), |
| 216 | + .headerSearchPath("../mfa/3rdparty/metal-cpp"), |
| 217 | + .define("HAVE_CBLAS"), |
| 218 | + .define("HAVE_PTHREAD"), |
| 219 | + .define("HAVE_ACCELERATE_FRAMEWORK"), |
| 220 | + .define("USE_DISPATCH"), |
| 221 | + .define("HAVE_MPS"), |
| 222 | + .unsafeFlags(["-fblocks", "-fno-objc-arc", "-w"]) |
| 223 | + ], |
| 224 | + linkerSettings: [ |
| 225 | + .linkedFramework("Metal"), |
| 226 | + .linkedFramework("MetalPerformanceShaders"), |
| 227 | + .linkedFramework("MetalPerformanceShadersGraph"), |
| 228 | + .linkedFramework("Foundation"), |
| 229 | + ] |
| 230 | + ), |
| 231 | + ], |
| 232 | + cLanguageStandard: .gnu11, |
| 233 | + cxxLanguageStandard: .cxx17 |
| 234 | +) |
0 commit comments