Skip to content

Parametric Flow struct for g and uBC#277

Draft
TzuYaoHuang wants to merge 3 commits intoWaterLily-jl:masterfrom
TzuYaoHuang:ParametricStruct-g-uBC
Draft

Parametric Flow struct for g and uBC#277
TzuYaoHuang wants to merge 3 commits intoWaterLily-jl:masterfrom
TzuYaoHuang:ParametricStruct-g-uBC

Conversation

@TzuYaoHuang
Copy link
Copy Markdown
Member

Make g and uBC fix type in Flow so it can improcve type stabilty. However, wierdly enough, the allocations are more?

(in bytes)

test master this PR
Pure 224 320
QUICK 224 320
Perdir 2 288 384
Per + Force 320 384

@TzuYaoHuang
Copy link
Copy Markdown
Member Author

The benchmarking between the current branch and the latest master.

The oscillating sphere is the one with varying body force (g) from waterlily example.

Benchmark environment: tgv sim_step! (max_steps=400)
▶ log2p = 6
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│ GPU-NVIDIA │   f539311 │ 1.12.5 │   Float32 │     5736391 │   1.28 │     1.19 │            11.32 │     1.00 │
│ GPU-NVIDIA │   79f3a0b │ 1.12.5 │   Float32 │     5741746 │   1.18 │     1.14 │            10.84 │     1.04 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘
▶ log2p = 7
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│ GPU-NVIDIA │   79f3a0b │ 1.12.5 │   Float32 │     8046503 │   0.34 │     4.55 │             5.42 │     1.00 │
│ GPU-NVIDIA │   f539311 │ 1.12.5 │   Float32 │     8046131 │   0.34 │     4.54 │             5.42 │     1.00 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘
▶ log2p = 8
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│ GPU-NVIDIA │   79f3a0b │ 1.12.5 │   Float32 │     6631315 │   0.07 │    22.50 │             3.35 │     0.99 │
│ GPU-NVIDIA │   f539311 │ 1.12.5 │   Float32 │     6637464 │   0.07 │    22.26 │             3.32 │     1.00 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘
Benchmark environment: cylinder sim_step! (max_steps=400)
▶ log2p = 5
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│ GPU-NVIDIA │   79f3a0b │ 1.12.5 │   Float32 │    12953678 │   9.65 │     8.43 │             5.95 │     0.99 │
│ GPU-NVIDIA │   f539311 │ 1.12.5 │   Float32 │    12954269 │   9.59 │     8.38 │             5.92 │     1.00 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘
▶ log2p = 6
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│ GPU-NVIDIA │   79f3a0b │ 1.12.5 │   Float32 │    14774197 │   1.39 │    56.47 │             4.99 │     1.00 │
│ GPU-NVIDIA │   f539311 │ 1.12.5 │   Float32 │    14794873 │   1.31 │    56.37 │             4.98 │     1.00 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘
▶ log2p = 7
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│ GPU-NVIDIA │   f539311 │ 1.12.5 │   Float32 │    12907147 │   0.19 │   372.53 │             4.11 │     1.00 │
│ GPU-NVIDIA │   79f3a0b │ 1.12.5 │   Float32 │    12905094 │   0.19 │   372.51 │             4.11 │     1.00 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘
Benchmark environment: jelly sim_step! (max_steps=400)
▶ log2p = 6
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│ GPU-NVIDIA │   f539311 │ 1.12.5 │   Float32 │    11489301 │   0.85 │     3.58 │             8.53 │     1.00 │
│ GPU-NVIDIA │   79f3a0b │ 1.12.5 │   Float32 │    11484396 │   0.49 │     3.54 │             8.45 │     1.01 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘
▶ log2p = 7
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│ GPU-NVIDIA │   f539311 │ 1.12.5 │   Float32 │    12523044 │   0.19 │    18.50 │             5.51 │     1.00 │
│ GPU-NVIDIA │   79f3a0b │ 1.12.5 │   Float32 │    12528092 │   0.10 │    18.41 │             5.49 │     1.00 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘
▶ log2p = 8
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│ GPU-NVIDIA │   f539311 │ 1.12.5 │   Float32 │    16093342 │   0.05 │   150.56 │             5.61 │     1.00 │
│ GPU-NVIDIA │   79f3a0b │ 1.12.5 │   Float32 │    16099884 │   0.04 │   150.48 │             5.61 │     1.00 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘
Benchmark environment: oscillatingSphere sim_step! (max_steps=1000)
▶ log2p = 6
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│ GPU-NVIDIA │   f539311 │ 1.12.5 │   Float32 │    22716650 │   1.38 │     4.58 │            17.46 │     1.00 │
│ GPU-NVIDIA │   79f3a0b │ 1.12.5 │   Float32 │    22695622 │   1.42 │     4.54 │            17.31 │     1.01 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘
▶ log2p = 7
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│ GPU-NVIDIA │   79f3a0b │ 1.12.5 │   Float32 │    26425185 │   0.65 │    13.48 │             6.43 │     1.00 │
│ GPU-NVIDIA │   f539311 │ 1.12.5 │   Float32 │    26456518 │   0.65 │    13.48 │             6.43 │     1.00 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘
▶ log2p = 8
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│ GPU-NVIDIA │   79f3a0b │ 1.12.5 │   Float32 │    23541791 │   0.18 │    65.29 │             3.89 │     1.00 │
│ GPU-NVIDIA │   f539311 │ 1.12.5 │   Float32 │    23559961 │   0.16 │    65.16 │             3.88 │     1.00 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘

@b-fg
Copy link
Copy Markdown
Member

b-fg commented Mar 31, 2026

Looks good to me! Can you add CPU tests as well please?

@weymouth
Copy link
Copy Markdown
Member

But if there is no speed up and an increase in allocations, then why are we considering this?

@b-fg
Copy link
Copy Markdown
Member

b-fg commented Mar 31, 2026

Using KA, In some cases allocations decrease though. Having type-stable functions is desirable in any case, and also this allows to dispatch on Flow.uBC type. So I am not against it.

@TzuYaoHuang
Copy link
Copy Markdown
Member Author

TzuYaoHuang commented Mar 31, 2026

This is the results with CPU.

I add another test case on ubc function.

There seems to be no significant difference. Insterestingly, the allocation of Master branch and this branch (ParaGUb) is identical.

Benchmark environment: tgv sim_step! (max_steps=400)
▶ log2p = 6
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│     CPUx16 │   Master  │ 1.12.5 │   Float32 │    20589017 │   0.00 │     9.40 │            89.63 │     1.00 │
│     CPUx16 │   ParaGUb │ 1.12.5 │   Float32 │    20589817 │   0.00 │     9.34 │            89.05 │     1.01 │
│ GPU-NVIDIA │   Master  │ 1.12.5 │   Float32 │     5741023 │   1.16 │     1.18 │            11.28 │     7.94 │
│ GPU-NVIDIA │   ParaGUb │ 1.12.5 │   Float32 │     5745019 │   1.25 │     1.16 │            11.08 │     8.09 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘
▶ log2p = 7
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│     CPUx16 │   Master  │ 1.12.5 │   Float32 │    27767223 │   0.73 │    44.91 │            53.54 │     1.00 │
│     CPUx16 │   ParaGUb │ 1.12.5 │   Float32 │    27768023 │   0.71 │    44.86 │            53.48 │     1.00 │
│ GPU-NVIDIA │   ParaGUb │ 1.12.5 │   Float32 │     8052574 │   0.36 │     4.52 │             5.38 │     9.95 │
│ GPU-NVIDIA │   Master  │ 1.12.5 │   Float32 │     8052737 │   0.35 │     4.45 │             5.31 │    10.08 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘
▶ log2p = 8
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│     CPUx16 │   ParaGUb │ 1.12.5 │   Float32 │    22615209 │   0.10 │   239.18 │            35.64 │     0.98 │
│     CPUx16 │   Master  │ 1.12.5 │   Float32 │    22614409 │   0.09 │   235.33 │            35.07 │     1.00 │
│ GPU-NVIDIA │   ParaGUb │ 1.12.5 │   Float32 │     6640092 │   0.07 │    23.03 │             3.43 │    10.22 │
│ GPU-NVIDIA │   Master  │ 1.12.5 │   Float32 │     6635245 │   0.07 │    22.92 │             3.42 │    10.27 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘

Benchmark environment: oscillatingSphere sim_step! (max_steps=1000)
▶ log2p = 6
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│     CPUx16 │   Master  │ 1.12.5 │   Float32 │    93040526 │   2.60 │    33.78 │           128.85 │     1.00 │
│     CPUx16 │   ParaGUb │ 1.12.5 │   Float32 │    93036526 │   2.59 │    33.08 │           126.21 │     1.02 │
│ GPU-NVIDIA │   Master  │ 1.12.5 │   Float32 │    22706113 │   1.22 │     4.77 │            18.20 │     7.08 │
│ GPU-NVIDIA │   ParaGUb │ 1.12.5 │   Float32 │    22724609 │   1.25 │     4.63 │            17.66 │     7.30 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘
▶ log2p = 7
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│     CPUx16 │   Master  │ 1.12.5 │   Float32 │   104104091 │   0.83 │   118.30 │            56.41 │     1.00 │
│     CPUx16 │   ParaGUb │ 1.12.5 │   Float32 │   104100091 │   0.81 │   117.13 │            55.85 │     1.01 │
│ GPU-NVIDIA │   Master  │ 1.12.5 │   Float32 │    26443221 │   0.66 │    13.56 │             6.47 │     8.72 │
│ GPU-NVIDIA │   ParaGUb │ 1.12.5 │   Float32 │    26442103 │   0.66 │    13.51 │             6.44 │     8.76 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘
▶ log2p = 8
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│     CPUx16 │   ParaGUb │ 1.12.5 │   Float32 │    92473265 │   0.14 │   631.78 │            37.66 │     0.98 │
│     CPUx16 │   Master  │ 1.12.5 │   Float32 │    92477265 │   0.15 │   622.09 │            37.08 │     1.00 │
│ GPU-NVIDIA │   Master  │ 1.12.5 │   Float32 │    23625893 │   0.13 │    67.26 │             4.01 │     9.25 │
│ GPU-NVIDIA │   ParaGUb │ 1.12.5 │   Float32 │    23559139 │   0.14 │    67.20 │             4.01 │     9.26 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘


Benchmark environment: accelSphere sim_step! (max_steps=400)
▶ log2p = 6
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│     CPUx16 │   ParaGUb │ 1.12.5 │   Float32 │    19709609 │   0.00 │    13.85 │            66.05 │     0.99 │
│     CPUx16 │   Master  │ 1.12.5 │   Float32 │    19708809 │   0.00 │    13.71 │            65.38 │     1.00 │
│ GPU-NVIDIA │   Master  │ 1.12.5 │   Float32 │     5826738 │   0.73 │     1.67 │             7.97 │     8.20 │
│ GPU-NVIDIA │   ParaGUb │ 1.12.5 │   Float32 │     5827239 │   0.82 │     1.67 │             7.95 │     8.22 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘
▶ log2p = 7
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│     CPUx16 │   ParaGUb │ 1.12.5 │   Float32 │    21244009 │   0.00 │    75.57 │            45.04 │     0.99 │
│     CPUx16 │   Master  │ 1.12.5 │   Float32 │    21243209 │   0.00 │    75.17 │            44.80 │     1.00 │
│ GPU-NVIDIA │   Master  │ 1.12.5 │   Float32 │     6314859 │   0.20 │     8.24 │             4.91 │     9.13 │
│ GPU-NVIDIA │   ParaGUb │ 1.12.5 │   Float32 │     6321616 │   0.18 │     8.18 │             4.87 │     9.19 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘
▶ log2p = 8
┌────────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────────────┬──────────┐
│    Backend │ WaterLily │  Julia │ Precision │ Allocations │ GC [%] │ Time [s] │ Cost [ns/DOF/dt] │ Speed-up │
├────────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────────────┼──────────┤
│     CPUx16 │   Master  │ 1.12.5 │   Float32 │    22761609 │   0.00 │   452.14 │            33.69 │     1.00 │
│     CPUx16 │   ParaGUb │ 1.12.5 │   Float32 │    22762409 │   0.00 │   450.27 │            33.55 │     1.00 │
│ GPU-NVIDIA │   ParaGUb │ 1.12.5 │   Float32 │     6735082 │   0.03 │    58.37 │             4.35 │     7.75 │
│ GPU-NVIDIA │   Master  │ 1.12.5 │   Float32 │     6743350 │   0.03 │    58.27 │             4.34 │     7.76 │
└────────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────────────┴──────────┘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants