in place ex-scan performance benchmarks#

This example benchmarks the scan exclusive sum in place performance for the different algorithms available in Shamrock

 9 import time
10
11 import matplotlib.pyplot as plt
12 import numpy as np
13
14 import shamrock
15
16 # If we use the shamrock executable to run this script instead of the python interpreter,
17 # we should not initialize the system as the shamrock executable needs to handle specific MPI logic
18 if not shamrock.sys.is_initialized():
19     shamrock.change_loglevel(1)
20     shamrock.sys.init("0:0")

Main benchmark functions

26 def benchmark_u32(N, nb_repeat=10):
27     times = []
28     for _ in range(nb_repeat):
29         buf = shamrock.backends.DeviceBuffer_u32()
30         buf.resize(N)
31         buf.fill(0)
32         times.append(shamrock.algs.benchmark_scan_exclusive_sum_in_place(buf, N))
33     return min(times), max(times), sum(times) / nb_repeat

Run the performance test for all parameters

38 def run_performance_sweep():
39
40     # Define parameter ranges
41     # logspace as array
42     particle_counts = np.logspace(2, 7, 20).astype(int).tolist()
43
44     # Initialize results matrix
45     results_u32 = []
46
47     print(f"Particle counts: {particle_counts}")
48
49     total_runs = len(particle_counts)
50     current_run = 0
51
52     for _, N in enumerate(particle_counts):
53         current_run += 1
54
55         print(
56             f"[{current_run:2d}/{total_runs}] Running N={N:5d}...",
57             end=" ",
58         )
59
60         start_time = time.time()
61         min_time, max_time, mean_time = benchmark_u32(N)
62         results_u32.append(min_time)
63         elapsed = time.time() - start_time
64
65         print(f"mean={mean_time:.3f}s (took {elapsed:.1f}s)")
66
67     return particle_counts, results_u32

List current implementation

impl_param(impl_name="decoupled_lookback_512", params="")

List all implementations available

[impl_param(impl_name="std_scan", params=""), impl_param(impl_name="std_scan_single_task_acpp", params=""), impl_param(impl_name="decoupled_lookback_512", params=""), impl_param(impl_name="acpp_alg", params="")]

Run the performance benchmarks for all implementations

 85 for impl in all_default_impls:
 86     shamrock.algs.set_impl_scan_exclusive_sum_in_place(impl.impl_name, impl.params)
 87
 88     print(f"Running ex-scan in place performance benchmarks for {impl}...")
 89
 90     # Run the performance sweep
 91     particle_counts, results_u32 = run_performance_sweep()
 92
 93     plt.plot(particle_counts, results_u32, "--.", label=impl.impl_name + " (u32)")
 94
 95
 96 Nobj = np.array(particle_counts)
 97 Time100M = Nobj / 1e8
 98 plt.plot(particle_counts, Time100M, color="grey", linestyle="-", alpha=0.7, label="100M obj/sec")
 99
100
101 plt.xlabel("Number of elements")
102 plt.ylabel("Time (s)")
103 plt.title("ex-scan in place performance benchmarks")
104
105 plt.xscale("log")
106 plt.yscale("log")
107
108 plt.grid(True)
109
110 plt.legend()
111 plt.show()
ex-scan in place performance benchmarks
Info: setting scan_exclusive_sum_in_place implementation to impl : std_scan          [tree][rank=0]
Running ex-scan in place performance benchmarks for impl_param(impl_name="std_scan", params="")...
Particle counts: [100, 183, 335, 615, 1128, 2069, 3792, 6951, 12742, 23357, 42813, 78475, 143844, 263665, 483293, 885866, 1623776, 2976351, 5455594, 10000000]
[ 1/20] Running N=  100... mean=0.000s (took 0.0s)
[ 2/20] Running N=  183... mean=0.000s (took 0.0s)
[ 3/20] Running N=  335... mean=0.000s (took 0.0s)
[ 4/20] Running N=  615... mean=0.000s (took 0.0s)
[ 5/20] Running N= 1128... mean=0.000s (took 0.0s)
[ 6/20] Running N= 2069... mean=0.000s (took 0.0s)
[ 7/20] Running N= 3792... mean=0.000s (took 0.0s)
[ 8/20] Running N= 6951... mean=0.000s (took 0.0s)
[ 9/20] Running N=12742... mean=0.000s (took 0.0s)
[10/20] Running N=23357... mean=0.000s (took 0.0s)
[11/20] Running N=42813... mean=0.000s (took 0.0s)
[12/20] Running N=78475... mean=0.000s (took 0.0s)
[13/20] Running N=143844... mean=0.000s (took 0.0s)
[14/20] Running N=263665... mean=0.001s (took 0.0s)
[15/20] Running N=483293... mean=0.001s (took 0.0s)
[16/20] Running N=885866... mean=0.002s (took 0.0s)
[17/20] Running N=1623776... mean=0.003s (took 0.0s)
[18/20] Running N=2976351... mean=0.006s (took 0.1s)
[19/20] Running N=5455594... mean=0.012s (took 0.2s)
[20/20] Running N=10000000... mean=0.020s (took 0.3s)
Info: setting scan_exclusive_sum_in_place implementation to impl : std_scan_single_task_acpp  [tree][rank=0]
Running ex-scan in place performance benchmarks for impl_param(impl_name="std_scan_single_task_acpp", params="")...
Particle counts: [100, 183, 335, 615, 1128, 2069, 3792, 6951, 12742, 23357, 42813, 78475, 143844, 263665, 483293, 885866, 1623776, 2976351, 5455594, 10000000]
[ 1/20] Running N=  100... mean=0.000s (took 0.0s)
[ 2/20] Running N=  183... mean=0.000s (took 0.0s)
[ 3/20] Running N=  335... mean=0.000s (took 0.0s)
[ 4/20] Running N=  615... mean=0.000s (took 0.0s)
[ 5/20] Running N= 1128... mean=0.000s (took 0.0s)
[ 6/20] Running N= 2069... mean=0.000s (took 0.0s)
[ 7/20] Running N= 3792... mean=0.000s (took 0.0s)
[ 8/20] Running N= 6951... mean=0.000s (took 0.0s)
[ 9/20] Running N=12742... mean=0.000s (took 0.0s)
[10/20] Running N=23357... mean=0.000s (took 0.0s)
[11/20] Running N=42813... mean=0.000s (took 0.0s)
[12/20] Running N=78475... mean=0.000s (took 0.0s)
[13/20] Running N=143844... mean=0.000s (took 0.0s)
[14/20] Running N=263665... mean=0.000s (took 0.0s)
[15/20] Running N=483293... mean=0.001s (took 0.0s)
[16/20] Running N=885866... mean=0.001s (took 0.0s)
[17/20] Running N=1623776... mean=0.002s (took 0.0s)
[18/20] Running N=2976351... mean=0.004s (took 0.1s)
[19/20] Running N=5455594... mean=0.008s (took 0.1s)
[20/20] Running N=10000000... mean=0.014s (took 0.2s)
Info: setting scan_exclusive_sum_in_place implementation to impl : decoupled_lookback_512  [tree][rank=0]
Running ex-scan in place performance benchmarks for impl_param(impl_name="decoupled_lookback_512", params="")...
Particle counts: [100, 183, 335, 615, 1128, 2069, 3792, 6951, 12742, 23357, 42813, 78475, 143844, 263665, 483293, 885866, 1623776, 2976351, 5455594, 10000000]
[ 1/20] Running N=  100... mean=0.000s (took 0.0s)
[ 2/20] Running N=  183... mean=0.000s (took 0.0s)
[ 3/20] Running N=  335... mean=0.000s (took 0.0s)
[ 4/20] Running N=  615... mean=0.000s (took 0.0s)
[ 5/20] Running N= 1128... mean=0.000s (took 0.0s)
[ 6/20] Running N= 2069... mean=0.000s (took 0.0s)
[ 7/20] Running N= 3792... mean=0.000s (took 0.0s)
[ 8/20] Running N= 6951... mean=0.000s (took 0.0s)
[ 9/20] Running N=12742... mean=0.000s (took 0.0s)
[10/20] Running N=23357... mean=0.000s (took 0.0s)
[11/20] Running N=42813... mean=0.000s (took 0.0s)
[12/20] Running N=78475... mean=0.000s (took 0.0s)
[13/20] Running N=143844... mean=0.000s (took 0.0s)
[14/20] Running N=263665... mean=0.001s (took 0.0s)
[15/20] Running N=483293... mean=0.001s (took 0.0s)
[16/20] Running N=885866... mean=0.002s (took 0.0s)
[17/20] Running N=1623776... mean=0.003s (took 0.0s)
[18/20] Running N=2976351... mean=0.005s (took 0.1s)
[19/20] Running N=5455594... mean=0.009s (took 0.1s)
[20/20] Running N=10000000... mean=0.017s (took 0.2s)
Info: setting scan_exclusive_sum_in_place implementation to impl : acpp_alg          [tree][rank=0]
Running ex-scan in place performance benchmarks for impl_param(impl_name="acpp_alg", params="")...
Particle counts: [100, 183, 335, 615, 1128, 2069, 3792, 6951, 12742, 23357, 42813, 78475, 143844, 263665, 483293, 885866, 1623776, 2976351, 5455594, 10000000]
[ 1/20] Running N=  100... mean=0.000s (took 0.0s)
[ 2/20] Running N=  183... mean=0.000s (took 0.0s)
[ 3/20] Running N=  335... mean=0.000s (took 0.0s)
[ 4/20] Running N=  615... mean=0.000s (took 0.0s)
[ 5/20] Running N= 1128... mean=0.000s (took 0.0s)
[ 6/20] Running N= 2069... mean=0.000s (took 0.0s)
[ 7/20] Running N= 3792... mean=0.000s (took 0.0s)
[ 8/20] Running N= 6951... mean=0.000s (took 0.0s)
[ 9/20] Running N=12742... mean=0.000s (took 0.0s)
[10/20] Running N=23357... mean=0.000s (took 0.0s)
[11/20] Running N=42813... mean=0.000s (took 0.0s)
[12/20] Running N=78475... mean=0.000s (took 0.0s)
[13/20] Running N=143844... mean=0.000s (took 0.0s)
[14/20] Running N=263665... mean=0.000s (took 0.0s)
[15/20] Running N=483293... mean=0.001s (took 0.0s)
[16/20] Running N=885866... mean=0.001s (took 0.0s)
[17/20] Running N=1623776... mean=0.002s (took 0.0s)
[18/20] Running N=2976351... mean=0.004s (took 0.1s)
[19/20] Running N=5455594... mean=0.007s (took 0.1s)
[20/20] Running N=10000000... mean=0.013s (took 0.2s)

Total running time of the script: (0 minutes 3.153 seconds)

Estimated memory usage: 200 MB

Gallery generated by Sphinx-Gallery