Add Python bindings for CUDA cluster finder
Build on RHEL8 / build (push) Successful in 2m50s
Build on RHEL9 / build (push) Successful in 2m57s
Run tests using data on local RHEL8 / build (push) Successful in 3m38s

- Add bind_ClusterFinderCUDA.hpp with pybind11 bindings for
  ClusterFinderCUDA
- Build CUDA bindings as separate _aare_cuda.so to avoid
  segfaults from mixing nvcc and gcc compiled code in the
  same shared object
- Re-export CUDA classes onto _aare in __init__.py so user
  code uses `from aare import ClusterFinderCUDA` regardless
  of which .so hosts the class
- Factory in ClusterFinder.py selects backend; RuntimeError
  if GPU requested on CPU-only build
- Update python/CMakeLists.txt: _aare_cuda module gated
  behind AARE_CUDA and AARE_PYTHON_BINDINGS
- Add validation notebook: ~20x speedup vs sequential ClusterFinder
This commit is contained in:
kferjaoui committed 2026-04-23 11:43:40 +02:00
1 parent 3ed773e520
commit e894bdac9b
7 files changed
+766 -29

No files matched your search

+422
View File
@@ -0,0 +1,422 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "789d5aab-0c75-4ed3-94bf-e66172f6737c",
"metadata": {},
"outputs": [],
"source": [
"import sys; sys.path.append('/home/ferjao_k/aare/build')\n",
"\n",
"from pathlib import Path\n",
"import matplotlib.pyplot as plt\n",
"from mpl_toolkits.axes_grid1 import make_axes_locatable\n",
"import numpy as np\n",
"import boost_histogram as bh\n",
"import time\n",
"\n",
"from aare import File, ClusterFinder, ClusterFinderMT, ClusterCollector, ClusterFinderCUDA"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3f6089d6-2245-4aca-aad3-2417c16afae2",
"metadata": {},
"outputs": [],
"source": [
"def make_hist(clusters):\n",
" h = bh.Histogram(bh.axis.Regular(100, -2, 4000))\n",
" h.fill(clusters.sum())\n",
" return h"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "415b09d4-d0d0-4166-8601-9d84302617bd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Image size: (400, 400)\n",
"Pedestal frames: 1000\n",
"Data frames: 40000\n"
]
}
],
"source": [
"base = Path('/mnt/sls_det_storage/matterhorn_data/aare_test_data/')\n",
"f = File(base / 'Moench03new/cu_half_speed_master_4.json')\n",
"\n",
"n_frames_pd = 1000\n",
"N = 40000\n",
"cluster_size = (3, 3)\n",
"image_size = (f.rows, f.cols)\n",
"capacity = 100_000 #3_000_000\n",
"\n",
"print(f'Image size: {image_size}')\n",
"print(f'Pedestal frames: {n_frames_pd}')\n",
"print(f'Data frames: {N}')"
]
},
{
"cell_type": "markdown",
"id": "5531b79d-12ad-4de6-84b7-0224b10d13c3",
"metadata": {},
"source": [
"## Pedestal (both finders trained on identical frames)"
]
},
{
"cell_type": "markdown",
"id": "e33b421f-969a-41d6-8aa6-5bd859a88fb3",
"metadata": {},
"source": [
"- Modify the boolean `SERIAL` to choose between the sequential CPU version (ClusterFinder) and its multi-threaded homologue (ClusterFinderMT)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "6ee7c469-5a23-421a-9bb4-a76e8f57a0c1",
"metadata": {},
"outputs": [],
"source": [
"SERIAL = True"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "9d8f69bf-27f6-48c8-b2da-4157d67e6b04",
"metadata": {},
"outputs": [],
"source": [
"if(SERIAL):\n",
" cf_cpu = ClusterFinder(image_size, cluster_size, capacity=capacity)\n",
"else:\n",
" cf_cpu = ClusterFinderMT(image_size, cluster_size, capacity=capacity, n_threads=24)\n",
" sink = ClusterCollector(cf_cpu)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "cbdcb805-708b-4205-bda9-2aa163d0e81f",
"metadata": {},
"outputs": [],
"source": [
"N_STREAMS = 1 \n",
"cf_cuda = ClusterFinderCUDA(image_size, cluster_size, capacity=capacity, n_streams=N_STREAMS)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "1546f405-1bf6-4073-ab35-8134be695a6c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pedestal (1000 frames): 0.498s\n"
]
}
],
"source": [
"t0 = time.perf_counter()\n",
"for _ in range(n_frames_pd):\n",
" img = f.read_frame()\n",
" cf_cpu.push_pedestal_frame(img.copy())\n",
" cf_cuda.push_pedestal_frame(img.copy())\n",
"print(f'Pedestal ({n_frames_pd} frames): {time.perf_counter() - t0:.3f}s')"
]
},
{
"cell_type": "markdown",
"id": "5df035f0-7a27-4d5a-8f8d-c94e745bcd1a",
"metadata": {},
"source": [
"## Read all data frames into memory (I/O out of the timing loop)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "4573be3d-5ba8-4e18-bab0-c874f2b7dcb2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Reading 40000 frames: 2.002s (19985 FPS, 6098.804 GB/s)\n"
]
}
],
"source": [
"f.seek(n_frames_pd)\n",
"t0 = time.perf_counter()\n",
"data = f.read_n(N)\n",
"t_io = time.perf_counter() - t0\n",
"print(f'Reading {N} frames: {t_io:.3f}s ({N/t_io:.0f} FPS, '\n",
" f'{f.bytes_per_frame * N / 1024**2 / t_io:.3f} GB/s)')"
]
},
{
"cell_type": "markdown",
"id": "c1e9362e-dcc2-41af-bfa1-c62d0968477e",
"metadata": {},
"source": [
"## CPU clustering"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "fbb14fda-2852-4b73-ba2c-9952abac1d99",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU clustering: 73.978s (541 FPS, 55449596 clusters, 1386.24/frame)\n"
]
}
],
"source": [
"t0 = time.perf_counter()\n",
"for frame in data:\n",
" cf_cpu.find_clusters(frame)\n",
"t_cpu = time.perf_counter() - t0\n",
"\n",
"if(SERIAL):\n",
" clusters_cpu = cf_cpu.steal_clusters(realloc_same_capacity=False)\n",
" n_clusters_cpu = clusters_cpu.size\n",
" \n",
" hist_cpu = make_hist(clusters_cpu)\n",
"else:\n",
" cf_cpu.stop()\n",
" sink.stop()\n",
" \n",
" clusters_cpu = sink.steal_clusters() #cf_cpu.steal_clusters(realloc_same_capacity=False)\n",
" \n",
" hist_cpu = bh.Histogram(bh.axis.Regular(100, -2, 4000))\n",
" n_clusters_cpu = 0\n",
" for cv in clusters_cpu:\n",
" hist_cpu.fill(cv.sum())\n",
" n_clusters_cpu += cv.size\n",
" \n",
"print(f'CPU clustering: {t_cpu:.3f}s ({N/t_cpu:.0f} FPS, '\n",
" f'{n_clusters_cpu} clusters, {n_clusters_cpu/N:.2f}/frame)')"
]
},
{
"cell_type": "markdown",
"id": "8cfd7091-8020-49ff-b033-28bf773983d8",
"metadata": {},
"source": [
"## CUDA clustering"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "4b8df93b-9a1b-41a5-9fed-9cda295fb523",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CUDA clustering: 3.880s (10310 FPS, 55810704 clusters, 1395.27/frame)\n",
"Speedup (CPU / CUDA): 19.07×\n"
]
}
],
"source": [
"# Warmup: first kernel launch pays CUDA context + pedestal H2D upload cost\n",
"cf_cuda.find_clusters(data[0])\n",
"_ = cf_cuda.steal_clusters(realloc_same_capacity=False)\n",
"\n",
"t0 = time.perf_counter()\n",
"for frame in data:\n",
" cf_cuda.find_clusters(frame)\n",
"t_cuda = time.perf_counter() - t0\n",
"clusters_cuda = cf_cuda.steal_clusters(realloc_same_capacity=False)\n",
"n_clusters_cuda = clusters_cuda.size\n",
"print(f'CUDA clustering: {t_cuda:.3f}s ({N/t_cuda:.0f} FPS, '\n",
" f'{n_clusters_cuda} clusters, {n_clusters_cuda/N:.2f}/frame)')\n",
"print(f'Speedup (CPU / CUDA): {t_cpu / t_cuda:.2f}×')\n",
"\n",
"hist_cuda = make_hist(clusters_cuda)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "1fda99ee-db54-40c1-8e5b-51168a33fb96",
"metadata": {},
"outputs": [],
"source": [
"# BATCH_SIZE = 500\n",
"\n",
"# # warmup\n",
"# _ = cf_cuda.find_clusters_batched(data[:1], first_frame=0)\n",
"\n",
"# t0 = time.perf_counter()\n",
"# clusters_cuda_per_frame = []\n",
"# for start in range(0, N, BATCH_SIZE):\n",
"# stop = min(start + BATCH_SIZE, N)\n",
"# clusters_cuda_per_frame.extend(\n",
"# cf_cuda.find_clusters_batched(data[start:stop], first_frame=start)\n",
"# )\n",
"# t_cuda = time.perf_counter() - t0\n",
"\n",
"# n_clusters_cuda = sum(cv.size for cv in clusters_cuda_per_frame)\n",
"\n",
"# print(f'CUDA clustering: {t_cuda:.3f}s ({N/t_cuda:.0f} FPS, '\n",
"# f'{n_clusters_cuda} clusters, {n_clusters_cuda/N:.2f}/frame)')\n",
"# print(f'Speedup (CPU / CUDA): {t_cpu / t_cuda:.2f}×')"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "b7df7b9d-6873-46c4-b6bc-7e4238a5bdf7",
"metadata": {},
"outputs": [],
"source": [
"# def make_hist_from_batch(result_list):\n",
"# h = bh.Histogram(bh.axis.Regular(100, -2, 4000))\n",
"# energies = [np.asarray(cv.sum()).ravel() for cv in result_list if cv.size > 0]\n",
"# if energies:\n",
"# h.fill(np.concatenate(energies))\n",
"# return h\n",
"\n",
"# hist_cuda = make_hist_from_batch(clusters_cuda_per_frame)"
]
},
{
"cell_type": "markdown",
"id": "b966cce1-0f73-4565-a707-1aec2a69f75e",
"metadata": {},
"source": [
"## Agreement check: \n",
"- Cluster counts should match closely.\n",
"- However, as the CUDA CF updates the pedestal once per frame rather than per-pixel, a small divergence after the first few frames is expected."
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "d3a850df-7df0-485b-971d-381cfdc6be81",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Cluster count diff: 361108 (0.65%)\n"
]
}
],
"source": [
"diff = abs(n_clusters_cpu - n_clusters_cuda)\n",
"rel = diff / max(n_clusters_cpu, 1)\n",
"print(f'Cluster count diff: {diff} ({rel:.2%})')"
]
},
{
"cell_type": "markdown",
"id": "81638ad3-6112-4bd7-a93a-f4d97f1f94cf",
"metadata": {},
"source": [
"## Plots"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "9adeea2f-9309-4c0a-905b-7d1203ba1f4e",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA3kAAAJOCAYAAAAK+M50AAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjgsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvwVt1zgAAAAlwSFlzAAAPYQAAD2EBqD+naQAAlypJREFUeJzt3Qd4FNXawPF3Nx1SSGiBEJpUqQIqKKKogGDBjvcqomIHFVFR7Ni4lqvop1gRxIZXEUVABa4ConKVJr1EaQIhtDTSs/M978GN2TSSkM22/+95lsnOzM6ePXt2mXffc87YLMuyBAAAAADgF+yeLgAAAAAAoOYQ5AEAAACAHyHIAwAAAAA/QpAHAAAAAH6EIA8AAAAA/AhBHgAAAAD4EYI8AAAAAPAjBHkAAAAA4EcI8gAAAADAjxDkAfAra9askeuvv15atWol4eHhEhkZKT169JDnnntODh06VLTfWWedZW7uMnnyZJk2bZrbjg/f4Y9t4YcffpArr7xSEhISJDQ0VGJiYuS0006T119/XY4cOVK0X8uWLcVmsxXd9PN46qmnyvTp012Op/tdcMEFZT7X8uXLzWO9pQ4r+x1T1df0+OOPu9RVnTp1pFmzZjJo0CD5v//7P8nIyCi3TPn5+RIfH28e99lnn9XwKwbgiwjyAPiNt99+W3r27Cm//vqr3HffffLNN9/IrFmz5IorrpA33nhDRo4cWWtl8ccTe1SPv7WFxx57TPr16ye7d++WJ598UhYsWCAzZsyQc845xwQqDz/8sMv+p59+uvz888/mpvWggciIESNMQOhrauM7Ro+pdaXLF154QZo3by7jxo2TTp06yW+//VbmY+bMmSP79u0zf0+ZMuW4ywDA9wV7ugAAUBP0pOi2226TAQMGyBdffCFhYWFF23TdPffcY06afJllWZKTkyMRERHiC7Kzs32mrN5CMzIaBAUHe+d/z59++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n2WXRsmp2SwOZso5XmR+3tKuo/hCmGZzi9Hu1LJqR0JNznQxGJzjRE9SqTh5R3nuidAKVktca0xNhDVg1A1iV98j5I+GxrvdWXluoSHntsaI2XBseeeQROXz4sAnGy+o+mJmZaYLAqtIJQ8pqJ0oDdudF1I9FZ/bUbqs6AYveNFguq2uwk7Y1zRTrDwkl28rxfsfU1GtS2mZ1KIi2C70IvbPdarvSCZO+//77UjcNZumyCQSugM7kVUT/g9e+/PqLnbNrhM68pr/y6X8c+mWrU3Zr9wn91dDZPeTuu+82M6npLFwAao92u9KTbQ0KdAY8vZ6VdtHSEy8do6XTnms2vuQ4NCftcqcnZRMnTjRj4DQzpF0A9ZIAxelJt54U6o8+bdu2NV3O9POu6zUb4KQBhgYy2jVMfwzSk01dpzM76q/vejFp/b7QcWw6fkwzCnpyrMFNZU/8itOTP53dUWfU0+8m/UFKX4dm0XRmTZ3d0nlJg8rSSxJoTwadlVC7pmu3N+1ept+LehKpM29qUFYRfb16oqkBkZZPMxd6cqrd25XOJlkyY6Jj3HQWSC2zzl55LJV9T5R+n2uXPs3yaWZKZ8bUrI/20nBmpir7HmnXUp2pUcd2aT1rcKgBnbY3PZaOO6uoLVRE61y7ETpn7dQAXrselnWJieOl/4/pmEbtwniscXlaxxroaWCh76GLine truncated
"text/plain": [
"<Figure size 900x600 with 2 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig, (ax_spec, ax_ratio) = plt.subplots(\n",
" 2, 1, figsize=(9, 6), sharex=True,\n",
" gridspec_kw={'height_ratios': [3, 1]}\n",
")\n",
"\n",
"edges = hist_cpu.axes[0].edges\n",
"cpu_vals = hist_cpu.values()\n",
"cuda_vals = hist_cuda.values()\n",
"\n",
"ax_spec.stairs(cpu_vals, edges, label=f'CPU ({n_clusters_cpu} clusters)')\n",
"ax_spec.stairs(cuda_vals, edges, label=f'CUDA ({n_clusters_cuda} clusters)', linestyle='--')\n",
"ax_spec.set_ylabel('Counts')\n",
"ax_spec.set_title('Cluster energy spectrum: CPU vs CUDA')\n",
"ax_spec.legend()\n",
"ax_spec.grid(alpha=0.3)\n",
"\n",
"with np.errstate(divide='ignore', invalid='ignore'):\n",
" ratio = np.where(cpu_vals > 0, cuda_vals / cpu_vals, np.nan)\n",
"\n",
"ax_ratio.stairs(ratio, edges, color='k')\n",
"ax_ratio.axhline(1.0, color='gray', linewidth=0.5)\n",
"ax_ratio.set_ylabel('CUDA / CPU')\n",
"ax_ratio.set_xlabel('Energy [ADU]')\n",
"ax_ratio.set_ylim(0.5, 3.5)\n",
"ax_ratio.grid(alpha=0.3)\n",
"\n",
"plt.tight_layout()\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a6ca4581-bb29-4c74-a34a-bd427551a39b",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.15"
}
},
"nbformat": 4,
"nbformat_minor": 5
}