% Created 2024-11-18 Mon 16:24
% Intended LaTeX compiler: pdflatex
\documentclass[dvipsnames,colorlinks,aspectratio=169]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{color}
\usepackage{listings}
\usepackage{pdfpages}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{xspace}
\usepackage{siunitx}
\usepackage{libertine}
\usepackage{fontawesome}
\mode<beamer>{\usetheme{Boadilla}}
\setbeamertemplate{navigation symbols}{}
\setbeamerfont{alerted text}{series=\bfseries}
\setbeamercolor{alerted text}{fg=blue}
\usecolortheme{default}
\usefonttheme{serif}
\usefonttheme{professionalfonts}
\usetheme{default}
\author{Brett Viren}
\date{\today}
\title{Chunking the 3D pixel sim}
\hypersetup{
 pdfauthor={Brett Viren},
 pdftitle={Chunking the 3D pixel sim},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 28.2 (Org mode 9.7-pre)}, 
 pdflang={English}}
\begin{document}

\maketitle
\begin{frame}[label={sec:org4c24436}]{Topics}
\begin{itemize}
\item Review the pipeline for 3D pixel sim.
\item Consideration for introducing \alert{chunking} the pipeline and data.
\item Grids defining the problem domains.
\item Problems chunking causes and initial solutions at each pipeline stage.
\end{itemize}
\end{frame}
\begin{frame}[label={sec:orgf6f789c}]{The 3D pixel sim pipeline, chunking and grids}
\begin{columns}
\begin{column}{0.75\columnwidth}
Will consider \alert{chunking} these data:

\begin{description}
\item[{diffused}] result of ``rastering'' a drifted step's charge to a \alert{fine grid}.

\item[{currents}] per-impulse-partition (\alert{fine-grid}) and summed per-pixel (\alert{pixel-grid}) current waveforms.
\end{description}

Define intermediate coarse \alert{super-grid}
\begin{itemize}
\item Multiple of and aligned with \alert{fine-grid}.
\item Aligned to pixel edges, coarser than \alert{pixel-grid}.
\end{itemize}

Problem decouples into \alert{dense} many operations on smaller 3D chunks.
\begin{itemize}
\item Name them ``xxx boxes'', characterize each and define operations.
\end{itemize}
Here I give some first conceptual steps, coding likely comes next.
\end{column}
\begin{column}{0.25\columnwidth}
\vspace{-1cm}

\begin{center}
\includegraphics[height=\textheight]{stages2.pdf}
\end{center}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:org7f1d3fc}]{Conceptual basics of chunking}
\[A = [0,1,2,3,4,5,6,7,8,9] \to \{A_i\} = C(A) = [ (0,1), (2,3), (4,5), (6,7), (8,9) ]\]

\[ F(A) \to U(F(C(A))) \]

\begin{itemize}
\item Apply a \alert{chunking} operation \(C(\cdot)\) to get small chunks of large data.
\item Map the original operator \(F(\cdot)\) over the set of chunks.
\item Apply an ``unchunking'' operator \(U(\cdot)\) to ``stitch together'' the set of processed chunks.
\end{itemize}
\end{frame}
\begin{frame}[label={sec:orgc8971fc}]{Problems that chunking brings}
\begin{block}{Overlap}
The chunked outputs from \(F(\{A_i\})\)  can overlap with each other.
\begin{itemize}
\item Eg, two independent steps may accidentally ``cross'' in the post-drift space.
\item Outputs of \(F(\cdot)\) are larger than inputs and will ``grow'' overlaps.
\item Easy to apply overlaps to neighbors, harder to do it fast/parallel.
\end{itemize}
\end{block}
\begin{block}{Alignment}
Unchunking operator \(U(\cdot)\) must collate processed chunks across the full domain (in general).
\begin{itemize}
\item Allowing arbitrary offsets for a chunk collating harder, especially for parallel.
\item We should ``pre align'' outputs of \(F(\cdot)\) in anticipation of downstream unchunking problem.
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[label={sec:org87b6560},fragile]{Stage: raster of diffused charge}
 Conceptually, a locally-dense grid of charge from a post-drift, diffuse step.
\begin{itemize}
\item 2 approaches to charge integral: Gauss-Hermite quadrature or FFT+interpolation.
\end{itemize}

Given G4 maximum step size, max drift time, diffusion coef and 3D grid definition:
\begin{itemize}
\item We can define a maximum box on the grid to contain any rastered step.
\item Enlarge this box to \alert{align} to a coarse \alert{super-grid} (eg aligned to pixel edges, larger ticks).
\item Require the raster stage to output its data on this super-grid \(\to\) produce a \alert{raster box}.
\end{itemize}
This is a 1-to-many mapping, some rastered steps will span multiple raster boxes.


\vfill

We may then apply something similar to PyTorch's \texttt{scatter\_add()} 
\begin{itemize}
\item Serial sum over all raster boxes on a common super-grid point,
\item Parallellize these sums over the super-grid.
\end{itemize}
Gives a set of ``aligned, summed raster boxes'' call it \alert{charge box}.
\end{frame}
\begin{frame}[label={sec:org202fdad}]{Stage: partitioning}
Each \alert{charge box} is split into \(10\times10\) interleaved partitions.
\begin{itemize}
\item Here, rely on the \alert{super-grid} to be defined as an integer multiple of the pixel grid.
\item Call this a \alert{partition box} - which is also a chunk.
\end{itemize}
\end{frame}
\begin{frame}[label={sec:orgc5d1dc2}]{Stage: Apply response}
Each \alert{partition box} chunk is convolved with the FR.
\begin{itemize}
\item Output enlarged by size of FR kernel and edges no longer aligned to super-grid.
\item Overlaps will form with neighbors on each of 8 sides/edges/corners.
\end{itemize}

I envision a \alert{contention-free} overlap-sum algorithm.
\begin{itemize}
\item Requires \(8\times3\times N_{chunk}\) operations.  \(N_{chunk}\) parallel, 24 serial.
\item Requires overlaps to be less than \(\frac{1}{2}\) the size of the chunk.
\end{itemize}

After overlap-sum, we get back to chunks defined on the super-pixel grid.
\begin{itemize}
\item Call one an \alert{impact box}.
\end{itemize}
\end{frame}
\begin{frame}[label={sec:org2a9a7bf}]{Stage: Final sum over pixel}
A many-to-many sum mapping \alert{impact boxes} to \alert{pixel boxes}.
\begin{itemize}
\item A \alert{pixel box} is a region of a pixel vs tick grid - something in between fine-grid and super-grid.
\item Each impact box contributes to a set of pixels over some fixed time duration.
\item Many impact boxes contribute to the same pixel and time duration.
\end{itemize}
I've not yet thought carefully how to parallelized this\ldots{}.
\end{frame}
\end{document}
