Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
13fc451
Update README.md
ZweTun Sep 10, 2025
44cae38
CUDA Flocking
ZweTun Sep 10, 2025
e008335
CUDA Flocking
ZweTun Sep 10, 2025
6c03c2c
CUDA Flocking GIF
ZweTun Sep 10, 2025
70bbde5
Update README.md
ZweTun Sep 10, 2025
d388e55
Rename
ZweTun Sep 10, 2025
6820ccd
Rename
ZweTun Sep 10, 2025
ea4159a
Update README.md
ZweTun Sep 10, 2025
c4606ff
Update README.md
ZweTun Sep 11, 2025
5a8eb38
Add Images
ZweTun Sep 11, 2025
966e9b5
Update README.md
ZweTun Sep 11, 2025
93a0ec3
Update README.md
ZweTun Sep 11, 2025
87d7e54
Update README.md
ZweTun Sep 11, 2025
da2caa6
Comments added
ZweTun Sep 11, 2025
554a3dc
Performance Chart
ZweTun Sep 11, 2025
2e9f5fd
Update README.md
ZweTun Sep 11, 2025
0c12b9e
Rename
ZweTun Sep 11, 2025
7b75e53
Update README.md
ZweTun Sep 11, 2025
e80735b
Tests
ZweTun Sep 11, 2025
57d1c34
Update README.md
ZweTun Sep 11, 2025
7eb2fda
Rename
ZweTun Sep 11, 2025
2c86bd9
Update README.md
ZweTun Sep 11, 2025
0ef0906
Update README.md
ZweTun Sep 11, 2025
2c3a08d
block
ZweTun Sep 11, 2025
c5b25e6
Update README.md
ZweTun Sep 11, 2025
4e7ce61
Cell Searched
ZweTun Sep 11, 2025
05f4f2f
Update README.md
ZweTun Sep 11, 2025
e4a435b
Update README.md
ZweTun Sep 11, 2025
6930354
Update
ZweTun Sep 11, 2025
a98046f
Update README.md
ZweTun Sep 11, 2025
288ef82
Update README.md
ZweTun Sep 11, 2025
48cbe3a
Update README.md
ZweTun Sep 11, 2025
de93724
Update README.md
ZweTun Sep 11, 2025
3584661
Update README.md
ZweTun Sep 11, 2025
ad02e41
Update README.md
ZweTun Sep 11, 2025
899af88
Update README.md
ZweTun Sep 11, 2025
540e02b
Update README.md
ZweTun Sep 11, 2025
fdf7cd6
Final
ZweTun Sep 11, 2025
1704ace
Update README.md
ZweTun Sep 11, 2025
051f9ce
Update README.md
ZweTun Sep 11, 2025
a38de18
Update README.md
ZweTun Sep 11, 2025
da08730
Update README.md
ZweTun Sep 11, 2025
162a0eb
Update README.md
ZweTun Sep 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 68 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,71 @@
**University of Pennsylvania, CIS 5650: GPU Programming and Architecture,
Project 1 - Flocking**
# University of Pennsylvania, CIS 5650: GPU Programming and Architecture
## Project 1 - Flocking

* (TODO) YOUR NAME HERE
* (TODO) [LinkedIn](), [personal website](), [twitter](), etc.
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
* Zwe Tun
* LinkedIn: https://www.linkedin.com/in/zwe-tun-6b7191256/
* Tested on: Intel(R) i7-14700HX, 2100 Mhz, RTX 5060 Laptop
![CUDA Flocking](images/CUDA-Flocking.gif)

### (TODO: Your README)
*100,000 boids with Coherent Grid Search*
## Overview
Boids are artificial agents that simulate the behavior of flocking animals. Introduced by Craig Reynolds in 1986, each boid follows three simple rules:
Cohesion - boids move towards the perceived center of mass of their neighbors
Separation - boids avoid getting to close to their neighbors
Alignment - boids generally try to move with the same direction and speed as their neighbors.

Include screenshots, analysis, etc. (Remember, this is public, so don't put
anything here that you don't want to share with the world.)
## Implementation

### Naive
The naive implementation uses a straightforward algorithm: each boid iterates over every other boid in the system to calculate its updated velocity and position based on the three flocking rules (separation, alignment, and cohesion).
While conceptually simple, this approach results in O(n²) time complexity, making it highly inefficient for large numbers of boids. Every boid must check all others regardless of distance, leading to significant computational overhead.
![CUDA Flocking](images/Naive-CUDA-Flocking.gif)

*10,000 boids with Naive*

### Uniform Grid Search
A more effcient algorithm is dividing into 3D cells, and each boid is assigned to a cell based on its position. By storing cell indices and mapping boid data accordingly, each thread can now limit its neighbor search to only nearby cells rather than the entire boid population.
In the scattered version, boid data (position, velocity) is stored in separate buffers, and additional lookup is required to gather information based on the grid cell. This greatly reduces the number of comparisons per boid, improving performance.
![CUDA Flocking](images/Uniform-CUDA-Flocking.gif)

*10,000 boids with Uniform Grid Search*

### Coherent Grid Search
The coherent grid improves on the uniform grid approach by taking advantage of spatial locality to optimize memory access on the GPU. In the scattered grid version, boid data is stored in separate buffers and accessed via indirect lookups, causing threads to read from scattered memory locations. This leads to reduced cache utilization. The coherent grid reorganizes the boid data so that boids located in the same or neighboring grid cells are stored contiguously in memory. By reshuffling the boid data arrays to align with their cell indices, the GPU can access data in adjacent memory locations, further improving performance.
![CUDA Flocking](images/Coherant-CUDA-Flocking.gif)

*10,000 boids with Coherent Grid Search*

## Performance Analysis

All performance tests were conducted on Windows 11, Intel(R) i7-14700HX CPU (2.1 GHz), NVIDIA RTX 5060 Laptop GPU. The primary metric used to evaluate performance is Frames Per Second (FPS). Higher FPS values indicate better performance and smoother real-time simulation.

![CUDA Flocking](images/Off.png)

![CUDA Flocking](images/On.png)

![CUDA Flocking](images/Blocks.png)

![CUDA Flocking](images/CellSearched.png)

## Questions
### For each implementation, how does changing the number of boids affect performance? Why do you think this is?

As the number of boids increases, all 3 methods see a decrease in performance (FPS) due to more computational load. This is shown in the plots where all 3 methods see a decrease in FPS as boid counts increases.

### For each implementation, how does changing the block count and block size affect performance? Why do you think this is?

Yes, increasing or decreasing the block size tends to slightly lower performance across the board. This happens because the GPU scheduler tries to optimize its task based on the given resources, and if the sizes or counts or not well balanced it can lead to poor optimization.

### For the coherent uniform grid: did you experience any performance improvements with the more coherent uniform grid? Was this the outcome you expected? Why or why not?

For the coherent uniform grid, clear performance improvements are found in the graphs above. With 5,000 boids, the coherent grid achieves nearly 2.5× the FPS of the naive implementation. This performance gap is more noticible at higher boid counts—for example, at 100,000 boids, the coherent grid runs at about 55× the FPS of the naive method. This superior performance is expected, as the coherent grid uses spatial locality to get more efficient memory access and reduce unnecessary computations.

### Did changing cell width and checking 27 vs 8 neighboring cells affect performance? Why or why not?

I found that checking 8 neighboring cells results in about a 2× increase in FPS compared to checking 27 cells, for both the uniform and coherent grid implementations. The naive implementation’s performance remains unchanged. This improvement is contributed by checking fewer neighboring cells reducing the number of boids each thread must evaluate. In addition checking a smaller area means that neighbor boids that will not affect the overall are skipped wasting less performance.

## For the Curious: 1,000,000 Boids

![CUDA Flocking](images/Million-CUDA-Flocking.gif)

*1,000,000 boids with Coherent Grid Search*
Binary file added images/Block.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Blocks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/CUDA-Flocking.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/CellSearched.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Coherant-CUDA-Flocking.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Million-CUDA-Flocking.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Naive-CUDA-Flocking.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/On.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Performance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Uniform-CUDA-Flocking.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading