Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize performance #18

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 37 additions & 10 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PackageDescription
let package = Package(
name: "Grape",
platforms: [
.macOS(.v11),
.macOS(.v11),
.iOS(.v14),
.watchOS(.v7),
],
Expand All @@ -23,35 +23,62 @@ let package = Package(
name: "ForceSimulation",
targets: ["ForceSimulation"]
),

],

dependencies: [
// other dependencies
.package(url: "https://github.com/apple/swift-docc-plugin", exact: "1.0.0"),
.package(url: "https://github.com/apple/swift-docc-plugin", exact: "1.0.0")
],

targets: [

.target(
name: "NDTree",
path: "Sources/NDTree"
// , swiftSettings:[.unsafeFlags(["-whole-module-optimization", "-Ounchecked"])]
path: "Sources/NDTree",
swiftSettings: [
.unsafeFlags([
"-cross-module-optimization",
// "-whole-module-optimization",
// "-whole-module-optimization",
// "-Ounchecked",
])
]
),

.testTarget(
name: "NDTreeTests",
dependencies: ["NDTree"]),

dependencies: ["NDTree"],
swiftSettings: [
.unsafeFlags([
"-cross-module-optimization",
// "-whole-module-optimization",
])
]
),
.target(
name: "ForceSimulation",
dependencies: ["NDTree"],
path: "Sources/ForceSimulation"
path: "Sources/ForceSimulation",
swiftSettings: [
.unsafeFlags([
"-cross-module-optimization",
// "-whole-module-optimization",
// "-Ounchecked",
])
]
// , swiftSettings:[.unsafeFlags(["-whole-module-optimization", "-Ounchecked"])]
),

.testTarget(
name: "ForceSimulationTests",
dependencies: ["ForceSimulation", "NDTree"]),
dependencies: ["ForceSimulation", "NDTree"],
swiftSettings: [
.unsafeFlags([
"-cross-module-optimization",
// "-whole-module-optimization",
// "-Ounchecked",
])
]),
]
)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ typealias Simulation4D<NodeID: Hashable> = SimulationKD<NodeID, Vector4d>

## Performance

Grape uses simd to calculate position and velocity. Currently it takes ~0.05 seconds to iterate 120 times over the example graph(2D). (77 vertices, 254 edges, with manybody, center, collide and link forces. Release build on a M1 Max, tested with command `swift test -c release`)
Grape uses simd to calculate position and velocity. Currently it takes ~0.04 seconds to iterate 120 times over the example graph(2D). (77 vertices, 254 edges, with manybody, center, collide and link forces. Release build on a M1 Max, tested with command `swift test -c release`)

For 3D simulation, it takes ~0.07 seconds for the same graph and same configs.
For 3D simulation, it takes ~0.05 seconds for the same graph and same configs.


<br/>
Expand Down
62 changes: 31 additions & 31 deletions Sources/NDTree/simd+VectorLike.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,48 @@

#if canImport(simd)

import simd
import simd

extension simd_double2: VectorLike {
@inlinable public func lengthSquared() -> Scalar {
return simd_length_squared(self)
}
extension simd_double2: VectorLike {
@inlinable public func lengthSquared() -> Scalar {
return simd_length_squared(self)
}

@inlinable public func length() -> Scalar {
return simd_length(self)
}
@inlinable public func length() -> Scalar {
return simd_length(self)
}

@inlinable public func distanceSquared(to: SIMD2<Scalar>) -> Scalar {
return simd_length_squared(self - to)
}
@inlinable public func distanceSquared(to: SIMD2<Scalar>) -> Scalar {
return simd_length_squared(self - to)
}

@inlinable public func distance(to: SIMD2<Scalar>) -> Scalar {
return simd_length(self - to)
}

@inlinable public func distance(to: SIMD2<Scalar>) -> Scalar {
return simd_length(self - to)
}

}
extension simd_float3: VectorLike {

extension simd_float3: VectorLike {
@inlinable public func lengthSquared() -> Scalar {
return simd_length_squared(self)
}

@inlinable public func lengthSquared() -> Scalar {
return simd_length_squared(self)
}
@inlinable public func length() -> Scalar {
return simd_length(self)
}

@inlinable public func length() -> Scalar {
return simd_length(self)
}
@inlinable public func distanceSquared(to: SIMD3<Scalar>) -> Scalar {
return simd_length_squared(self - to)
}

@inlinable public func distanceSquared(to: SIMD3<Scalar>) -> Scalar {
return simd_length_squared(self - to)
}
@inlinable public func distance(to: SIMD3<Scalar>) -> Scalar {
return simd_length(self - to)
}

@inlinable public func distance(to: SIMD3<Scalar>) -> Scalar {
return simd_length(self - to)
}

}

public typealias QuadBox = NDBox<simd_double2>
public typealias OctBox = NDBox<simd_float3>
public typealias QuadBox = NDBox<simd_double2>
public typealias OctBox = NDBox<simd_float3>

#endif
#endif