Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project 1: Jason Xie #18

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "CUDA C++: Launch",
"type": "cuda-gdb",
"request": "launch",
"program": ""
},
{
"name": "CUDA C++: Attach",
"type": "cuda-gdb",
"request": "attach",
"processId": "${command:cuda.pickProcess}"
}
]
}
82 changes: 82 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"files.associations": {
"*.sdf": "xml",
"*.world": "xml",
"iostream": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"strstream": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp"
},
"ros.distro": "humble"
}
112 changes: 104 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,107 @@
**University of Pennsylvania, CIS 565: GPU Programming and Architecture,
Project 1 - Flocking**
# CIS 565: GPU Programming and Architecture

* (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)
## Project 1 - Flocking

### (TODO: Your README)
![Boids 1.3](images/boids13.gif)

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

[πŸ€“ LinkedIn](https://linkedin.com/in/jia-chun-xie)

[πŸ˜‡ my website](https://jchunx.dev)

[πŸ₯΅ X (formerly 🐦)](https://x.com/codemonke_)

Tested on: Ubuntu 22.04, i5-8400, RTX 3060Ti, personal machine

## Performance Analysis

### FPS vs. Number of Boids

@ block size 128

![FPS vs. Number of Boids](images/boids-perf.png)

#### Naive

|# Boids| FPS |
|-------|--------|
| 1000 | 1900 |
| 10000 | 220 |
| 100000| 6 |

#### Scattered Uniform

|# Boids| FPS |
|-------|--------|
| 1000 | 4000 |
| 10000 | 2100 |
| 100000| 270 |
| 1000000| 6 |

#### Coherent Uniform

|# Boids| FPS |
|-------|--------|
| 1000 | 3800 |
| 10000 | 2800 |
| 100000| 280 |
| 1000000| 1 |

### FPS vs. Block Size

@ 10000 boids

![FPS vs. Block Size](images/boids-block-perf.png)

#### Naive

|Block Size| FPS |
|-------|--------|
| 32 | 220 |
| 64 | 225 |
| 128| 220 |
| 256| 225 |

#### Scattered Uniform

|Block Size| FPS |
|-------|--------|
| 32 | 2100 |
| 64 | 2050 |
| 128| 2100 |
| 256| 2250 |

#### Coherent Uniform

|Block Size| FPS |
|-------|--------|
| 32 | 2600 |
| 64 | 2760 |
| 128| 2800 |
| 256| 2780 |

## Q&A

### Boids vs. performance

Increasing the number of boids dramatically reduces the framerate. This is due to the quadratic nature of neighbor checking. Using uniform grids reduces the number of checks, resulting in $O(NlogN)$-like performance.

### Blocks vs. performance

For lower block sizes, increasing the number of blocks resulted in higher performance. However, for higher block sizes, increasing the number of blocks resulted in lower performance. For lower block sizes, the number of blocks is not limited by the number of SMs, so increasing the number of blocks increases the number of threads that can be run in parallel. But increasing block sizes further likely introduces more overhead than the performance gained from parallelization.

### Coherent vs. scattered uniform grids

Coherent uniform grids performed generally the same as scattered uniform grids. This is not a very surprising outcome, as the primitive rearrangement kernel simply performed the same swapping operation done on the scattered uniform kernel.

### 27 vs. 8 neighbors

@ 10000 boids, uniform grid, block size 128

|Neighbor Count| FPS |
|-------|--------|
| 27 | 3140 |
| 8 | 2100 |

Changing cell width and increasing the number of neighbors to 27 resulted in an increase of performance. This is due to the fact that a finer grid results in fewer neighbors outside of the checking radius, resulting in fewer checks.
26 changes: 26 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Create build directory if it doesn't exist
mkdir -p build

# Change into the build directory
cd build

# Default build type to Release
build_type="Release"

# Check for argument "debug" to change build type
if [ "$1" == "debug" ]; then
echo "Building in debug mode"
build_type="Debug"
fi

# Run cmake with the specified build type
cmake -DCMAKE_BUILD_TYPE=$build_type ..

# Build the project with dbg if debug was specified
if [ "$1" == "debug" ]; then
make dbg=1
else
make
fi
Binary file added images/boids-block-perf.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/boids-perf.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/boids13.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading