v2: add EmbeddingKernels to Metal compilation pipeline
This commit is contained in:
+1
-1
@@ -17,7 +17,7 @@ let package = Package(
|
||||
targets: [
|
||||
.target(
|
||||
name: "MarkBase",
|
||||
exclude: ["Metal/MetalKernels.metal", "Metal/OptimizedKernels.metal", "Metal/FusionKernels.metal", "Metal/MetalKernels.metallib", "Metal/metallib"],
|
||||
exclude: ["Metal/MetalKernels.metal", "Metal/OptimizedKernels.metal", "Metal/FusionKernels.metal", "Metal/EmbeddingKernels.metal", "Metal/MetalKernels.metallib", "Metal/metallib"],
|
||||
linkerSettings: [
|
||||
.linkedFramework("Metal"),
|
||||
.linkedFramework("Foundation"),
|
||||
|
||||
@@ -109,6 +109,21 @@ public enum MetalKernels {
|
||||
.replacingOccurrences(of: "using namespace metal;\n", with: "")
|
||||
result += "\n" + fusedStripped
|
||||
|
||||
// Strip preamble from embedding kernels source
|
||||
let embStripped = embeddingKernelsSource
|
||||
.replacingOccurrences(of: "#include <metal_stdlib>\n", with: "")
|
||||
.replacingOccurrences(of: "using namespace metal;\n", with: "")
|
||||
result += "\n" + embStripped
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
/// Embedding kernel source for EmbeddingGemma.
|
||||
/// Includes RoPE, bidirectional sliding window attention, Q/K norm, and GELU.
|
||||
public static var embeddingKernelsSource: String {
|
||||
let url = URL(fileURLWithPath: #filePath)
|
||||
.deletingLastPathComponent()
|
||||
.appendingPathComponent("Metal/EmbeddingKernels.metal")
|
||||
return try! String(contentsOf: url, encoding: .utf8)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user