Compute histogram performance benchmarks#

This example benchmarks the compute histogram performance for the different algorithms available in Shamrock

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

Use shamrock documentation style for matplotlib

30 shamrock.matplotlib.set_shamrock_mpl_style()
Info: defaulting compute_histogram implementation to impl : {"implementation":"naive_gpu","parameters":{}}  [algs][rank=0]
Current config: {"implementation":"naive_gpu","parameters":{}}
Default config: {"implementation":"naive_gpu","parameters":{}}
Available configs: ['{"implementation":"reference","parameters":{}}', '{"implementation":"naive_gpu","parameters":{}}', '{"implementation":"gpu_team_fetching","parameters":{}}', '{"implementation":"gpu_oversubscribe","parameters":{}}']
Info: setting compute_histogram implementation to impl : {"implementation":"reference","parameters":{}}  [algs][rank=0]
Config: reference, Time f64: 1933.211023ms, Time f32: 1926.4963830000002ms
Info: setting compute_histogram implementation to impl : {"implementation":"naive_gpu","parameters":{}}  [algs][rank=0]
Config: naive_gpu, Time f64: 602.8676135000001ms, Time f32: 945.4414125000002ms
Info: setting compute_histogram implementation to impl : {"implementation":"gpu_team_fetching","parameters":{}}  [algs][rank=0]
Config: gpu_team_fetching, Time f64: 855.4264185ms, Time f32: 854.4192735ms
Info: setting compute_histogram implementation to impl : {"implementation":"gpu_oversubscribe","parameters":{}}  [algs][rank=0]
Config: gpu_oversubscribe, Time f64: 2084.487909ms, Time f32: 1911.281153ms

plot the histogram

run compute histogram

plot the results

105 plt.figure(layout="constrained")
106
107 configs = list(results_f64.keys())
108 vals_f64 = [results_f64[c] for c in configs]
109 vals_f32 = [results_f32[c] for c in configs]
110 x = np.arange(len(configs))
111 bar_w = 0.35
112 plt.bar(x - bar_w / 2, vals_f64, bar_w, label="f64")
113 plt.bar(x + bar_w / 2, vals_f32, bar_w, label="f32")
114 plt.xticks(x, configs, rotation=45, ha="right")
115 default_impl_name = json.loads(default_config)["implementation"]
116 for tick_label, cfg in zip(plt.gca().get_xticklabels(), configs):
117     if cfg == default_impl_name:
118         tick_label.set_color("red")
119
120 plt.ylabel("Time (ms)")
121 plt.yscale("log")
122
123 _ymin, _ymax = plt.gca().get_ylim()
124 _ymin = 10 ** int(np.floor(np.log10(_ymin)))
125 _ymax = 10 ** int(np.ceil(np.log10(_ymax)))
126 plt.ylim(_ymin, _ymax * 1.1)
127
128 plt.title("Compute histogram performance benchmarks")
129 plt.legend()
130 plt.grid(True, alpha=0.3)
131 plt.show()
Compute histogram performance benchmarks

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

Estimated memory usage: 196 MB

Gallery generated by Sphinx-Gallery