-
Notifications
You must be signed in to change notification settings - Fork 0
/
Package.swift
75 lines (71 loc) · 2.35 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
// swift-tools-version: 6.0
import PackageDescription
import Foundation
let packageDir = URL(fileURLWithPath: #file).deletingLastPathComponent().path
#if os(Windows)
let cuPath = ProcessInfo.processInfo.environment["CUDA_HOME"] ?? "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.5"
let cuLibPath = "-L\(cuPath)\\lib\\x64"
let cuIncludePath = "-I\(cuPath)\\include"
let cxxLibPath = "-L\(packageDir)\\Sources\\cxxCU\\lib\\Release"
#elseif os(Linux)
let cuPath = ProcessInfo.processInfo.environment["CUDA_HOME"] ?? "/usr/local/cuda"
let cuLibPath = "-L\(cuPath)/lib64"
let cuIncludePath = "-I\(cuPath)/include"
let cxxLibPath = "-L\(packageDir)/Sources/cxxCU/lib"
#else
fatalError("OS not supported \(os)")
#endif
let package = Package(
name: "SwiftCU",
products: [
.library(
name: "SwiftCU",
targets: ["SwiftCU"]),
.library(
name: "cxxCU",
targets: ["cxxCU"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-testing.git", from: "0.10.0"),
],
targets: [
.target(
name: "cxxCU",
publicHeadersPath: "include",
cxxSettings: [
.headerSearchPath(cuIncludePath)
],
linkerSettings: [
.unsafeFlags([
cuLibPath,
cxxLibPath,
]),
.linkedLibrary("cudart"),
]
),
.target(
name: "SwiftCU",
dependencies: ["cxxCU"],
swiftSettings: [
.interoperabilityMode(.Cxx),
.unsafeFlags(["-Xcc", cuIncludePath]),
]
),
.testTarget(
name: "SwiftCUTests",
dependencies: [
"SwiftCU", "cxxCU",
.product(name: "Testing", package: "swift-testing"),
],
swiftSettings: [
.interoperabilityMode(.Cxx),
]
)
],
cxxLanguageStandard: .cxx17
)
/// usage
/// CUDA_HOME=/usr/local/cuda swift test
/// To turn on safetyCheck add -Xswiftc -DsafetyCheck
/// Test on rtx 3090 -Xswiftc -Drtx3090Test -Xcc -Drtx3090Test -Xswiftc -L$(pwd)/Sources/cxxCU/lib -Xswiftc -lcuADD
/// basic test flags -Xswiftc -L/usr/local/cuda/lib64 -Xswiftc -I/usr/local/cuda/include