Star on GitHub

ESACT Algorithm Visualizer

Efficient Sequentially-Addressed Calculating Tree: A Bank-Conflict-Free Technique for Parallel Scan Algorithm

Explore Repository

What Is The Scan Operation?

In parallel computing, a scan (also known as prefix sum) is an operation that computes all the partial results of applying a binary associative operator \( \oplus \) over a sequence. Scans are widely used in algorithms for efficient data parallelism, sorting, stream compaction, and other GPU-accelerated computations.

Inclusive Scan

Computes the combination of elements up to and including the current index.

\[ Y[i] = X[0] \oplus X[1] \oplus \dots \oplus X[i] \]

Exclusive Scan

Computes the combination of elements up to, but not including, the current index. The first element is set to the identity of \( \oplus \).

\[ Y[i] = X[0] \oplus X[1] \oplus \dots \oplus X[i-1] \quad ,\quad Y[0] = \text{identity} \]

Numerical Example

Suppose we have the array:

\[ X = [3, 1, 7, 0, 4, 1, 6, 3] \]

Inclusive Scan (sum operation):

\[ Y = [3, 4, 11, 11, 15, 16, 22, 25] \]

Exclusive Scan (sum operation):

\[ Y = [0, 3, 4, 11, 11, 15, 16, 22] \]

Algorithm Foundation

Key Innovation

ESACT introduces a novel index permutation scheme (\( \Omega_n\)) that transforms traditional interleaved memory access patterns into sequential patterns, eliminating shared memory bank conflicts while maintaining global memory coalescing.

Mathematical Foundation

The recursive permutation formula enables conflict-free access:

\[ \Omega_n[i] = \frac{\Omega_n\left[\left\lfloor\frac{i}{2}\right\rfloor\right] - 1}{2} + \big(1 - \bmod(i, 2)\big) \frac{n}{2} \]

Key Features

  • ✓ 27% faster than traditional Blelloch scan
  • ✓ Zero shared memory padding requirements
  • ✓ Supports arbitrary input sizes
  • ✓ Compatible with modern GPU architectures

Technical Specifications

Metric ESACT Blelloch Padded Blelloch
Bank Conflict Factor (β) 1.0 32.0 1.0
Memory Overhead 0% 0% 12.5%
Throughput (RTX 3060) 4.17μs 5.31μs 4.48μs

Our Scan Algorithms

Algorithm 1: SACT

Input: \( X \in \mathbb{R}^n \), located at global memory
Output: \( Y \in \mathbb{R}^n \), located at global memory
Shared Memory: \( S \)

  1. Precompute permutation matrix \( \mathbf{P} \) using \( \Omega_n \)
  2. Load \( S \) from \( X \):
    • \( S = \mathbf{P}X \)
    • \( S[i] = X[\Omega_n[i]] \quad \forall\ 0 \leq i < n \)
  3. Perform SACT Tree Scan:
    • \( S = FT(S) \)
    • \( \sigma = S[0] \), then \( S[0] = 0 \)
    • \( S = BT(S) \)
  4. Load \( Y \) from \( S \):

    Exclusive scan:

    • \( Y = \mathbf{P}^T S \)
    • \( Y[\Omega_n[i]] = S[i] \)

    Inclusive scan:

    • \( Y = \mathbf{Q}\mathbf{P}^T S + \sigma \mathbf{E}_n \)
    • \( Y[\Omega_n[i-1]] = S[i], \quad 0 < i < n \)
    • \( Y[n - 1] = \sigma \)

Algorithm 2: ESACT (faster and more efficient)

Input: \( X \in \mathbb{R}^n \), located at global memory
Output: \( Y \in \mathbb{R}^n \), located at global memory
Shared Memory: \( S \)

  1. Precompute permutation matrix \( \mathbf{P} \) using \( \Omega_n \)
  2. Load \( S \) from \( X \):
    • \( \mathbf{P}^T S = X \)
    • \( S[\Omega_n[i]] = X[i] \quad \forall\ 0 \leq i < n \)
  3. Perform SACT Tree Scan:
    • \( S = FT(S) \)
    • \( \sigma = S[0] \), then \( S[0] = 0 \)
    • \( S = BT(S) \)
  4. Load \( Y \) from \( S \):

    Exclusive scan:

    • \( Y = \mathbf{P}^T S \)
    • \( Y[i] = S[\Omega_n[i]] \)

    Inclusive scan:

    • \( Y = \mathbf{Q}\mathbf{P}^T S + \sigma \mathbf{E}_n \)
    • \( Y[i - 1] = S[\Omega_n[i]], \quad 0 < i < n \)
    • \( Y[n - 1] = \sigma \)

Algorithm Visualization

Permutation Matrix

ESACT Indices