v2: add EmbeddingKernels to Metal compilation pipeline

This commit is contained in:
MarkBase Admin
2026-07-06 12:11:31 +08:00
parent 5e060c7aea
commit f122d854dc
2 changed files with 17 additions and 2 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ let package = Package(
targets: [ targets: [
.target( .target(
name: "MarkBase", 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: [ linkerSettings: [
.linkedFramework("Metal"), .linkedFramework("Metal"),
.linkedFramework("Foundation"), .linkedFramework("Foundation"),
+15
View File
@@ -109,6 +109,21 @@ public enum MetalKernels {
.replacingOccurrences(of: "using namespace metal;\n", with: "") .replacingOccurrences(of: "using namespace metal;\n", with: "")
result += "\n" + fusedStripped 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 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)
}
} }