Skip to content
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
145 changes: 137 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,142 @@
Project 0 Getting Started
====================
# CUDA Setup and Development Environment Setup

**University of Pennsylvania, CIS 5650: GPU Programming and Architecture, Project 0**

* (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)
* Amy Liu
* [Personal Website](https://amyliu.dev/), [LinkedIn](https://linkedin.com/in/miyalana), [Github](https://github.com/mialana).
* Tested on: Ubuntu 24.04.3 LTS, Intel(R) Core(TM) Ultra 9 275HX 32GiB, NVIDIA GeForce RTX 5070Ti 12227MiB

### (TODO: Your README)
## Part 1: Installation and Setup

NVIDIA Drivers:
- **Version:** 580.76.05
- **Method:** Added Ubuntu PPA repository to local APT registry in order to install latest 580 beta driver. ([primary followed guide](https://linuxconfig.org/how-to-install-the-nvidia-drivers-on-ubuntu-22-04))

CUDA:
- **Version:** 13.0
- **Method:** From NVIDIA `.run` file. Deselected auto-install of drivers in execution menu. ([primary followed guide](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/#runfile-installation))

## Part 2.1: Development Environment Testing

### Part 2.1.1: Project Build & Run

#### GPU Optimus Mode

On Linux Wayland, NVIDIA GPU is not the primary GPU. Build & run without modification leads to the following error:

```bash
Cuda error: Kernel failed!: CUDA-capable device(s) is/are busy or unavailable.
```

To solve this, two environment variables must be added wherever I run the executable (e.g. from command line, from all Nsight applications, etc ):

```bash
__PRIME_RENDER_OFFLOAD=1
__GLX_VENDOR_LIBRARY_NAME=nvidia
```

Alternatively, modify the `/etc/environment` file to contain:

```bash
QT_QPA_PLATFORMTHEME="wayland;xcb"
GBM_BACKEND=nvidia-drm
__GLX_VENDOR_LIBRARY_NAME=nvidia
ENABLE_VKBASALT=1
LIBVA_DRIVER_NAME=nvidia
WLR_NO_HARDWARE_CURSORS=1
```

#### GLFW and Wayland incompability

When using GLFW on Wayland, the `glfwInit()` function does not work (program will exit at `Line 49` of `main.cpp`). To counter this, set two environment variables:

```bash
WAYLAND_DISPLAY=""
XDG_SESSION_TYPE=x11
```

#### CMakeLists.txt Modification

Due to having a very new GPU model, I changed the `CUDA_ARCHITECTURES` variable from `native` to my explicit arch, i.e. `120`.

```bash
if(CMAKE_VERSION VERSION_LESS "3.23.0")
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES CUDA_ARCHITECTURES OFF)
elseif(CMAKE_VERSION VERSION_LESS "3.24.0")
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES CUDA_ARCHITECTURES all-major)
else()
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES CUDA_ARCHITECTURES 120)
endif()
```

#### `run.sh`

Wrote a simple run script to facilitate 1. build + run as well as 2. run without build from command line. Simplifies environment variable requirements mentioned above.

Located at `cuda-gl-check/run.sh`.

### Part 2.1.2: CUDA Project UI Modification

![img](images/modified_project_2.1.2.png)

### Part 2.1.3: Nsight Debugger

Final `launch.json` configuration:

```json
{
"version": "0.2.0",
"configurations": [
{
"name": "CUDA C++: Launch",
"type": "cuda-gdb",
"request": "launch",
"program": "${workspaceFolder}/build/bin/cuda-gl-check",
"environment": [
{ "name": "__NV_PRIME_RENDER_OFFLOAD", "value": "1" },
{ "name": "__GLX_VENDOR_LIBRARY_NAME", "value": "nvidia" }
]
}
]
}
```

### Part 2.1.4: Nsight Systems

Configuration:\
![img](images/nsight_systems_config.png)

Timeline Window:
![img](images/nsight_systems_timeline.png)

Analysis Summary Window:
![img](images/nsight_systems_analysis_summary.png)


### Part 2.1.5: Nsight Compute

Configuration:
![img](images/nsight_compute_config.png)

Summary Window:
![img](images/nsight_compute_summary.png)

Details Window:
![img](images/nsight_compute_details.png)


## Part 2.2: WebGL

Works on both Zen (Firefox-based) and Arc (Chromium) browsers.
![img](images/webgl_report.png)

## Part 2.3: WebGPU

Does **not** work on Linux Wayland.

![img](images/webgpu_report_wayland.png)

Works on Linux Xorg. This requires logging out and toggling a startup option.

![img](images/webgpu_report_xorg.png)

Include screenshots, analysis, etc. (Remember, this is public, so don't put
anything here that you don't want to share with the world.)
2 changes: 2 additions & 0 deletions cuda-gl-check/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*.xcodeproj
build

compute

# Created by https://www.gitignore.io/api/linux,osx,sublimetext,windows,jetbrains,vim,emacs,cmake,c++,cuda,visualstudio,webstorm,eclipse,xcode

### Linux ###
Expand Down
15 changes: 15 additions & 0 deletions cuda-gl-check/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "CUDA C++: Launch",
"type": "cuda-gdb",
"request": "launch",
"program": "${workspaceFolder}/build/bin/cuda-gl-check",
"environment": [
{ "name": "__NV_PRIME_RENDER_OFFLOAD", "value": "1" },
{ "name": "__GLX_VENDOR_LIBRARY_NAME", "value": "nvidia" }
]
}
]
}
6 changes: 6 additions & 0 deletions cuda-gl-check/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.associations": {
"cpp": "cuda-cpp",
"hpp": "cuda-cpp"
}
}
2 changes: 1 addition & 1 deletion cuda-gl-check/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ if(CMAKE_VERSION VERSION_LESS "3.23.0")
elseif(CMAKE_VERSION VERSION_LESS "3.24.0")
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES CUDA_ARCHITECTURES all-major)
else()
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES CUDA_ARCHITECTURES native)
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES CUDA_ARCHITECTURES 120)
endif()
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE "$<$<AND:$<CONFIG:Debug,RelWithDebInfo>,$<COMPILE_LANGUAGE:CUDA>>:-G>")
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${CMAKE_PROJECT_NAME})
25 changes: 25 additions & 0 deletions cuda-gl-check/run_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

CURRENT_DIR=$(pwd)
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

while true; do
read -p "Do you want to re-build? (y/n): " yn
case $yn in
[Yy]* )
cd $SCRIPT_DIR; # cd to where script is located

trash build;
mkdir build && cd build;
cmake ..;
make -j$(nproc --all);

cd $CURRENT_DIR; # cd to stored original directory
break;;
[Nn]* )
break;;
* ) echo "Invalid input. Please answer 'y' or 'n'.";;
esac
done

XDG_SESSION_TYPE=x11 $SCRIPT_DIR/build/bin/cuda-gl-check
2 changes: 1 addition & 1 deletion cuda-gl-check/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
int main(int argc, char* argv[]) {
// TODO: Change this line to use your name!
m_yourName = "TODO: YOUR NAME HERE";
m_yourName = "Amy Liu";

if (init(argc, argv)) {
mainLoop();
Expand Down
3 changes: 3 additions & 0 deletions cuda-introduction/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
output
log.txt
17 changes: 17 additions & 0 deletions cuda-introduction/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/source/**"
],
"defines": [],
"compilerPath": "/usr/local/cuda/bin/nvcc",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64",
"configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4
}
7 changes: 7 additions & 0 deletions cuda-introduction/.vscode/extension.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"nvidia.nsight-vscode-edition",
"ms-vscode.cpptools",
"ms-vscode.makefile-tools"
]
}
13 changes: 13 additions & 0 deletions cuda-introduction/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "CUDA C++: Launch",
"preLaunchTask": "CMake: build",
"type": "cuda-gdb",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"logFile": "${workspaceFolder}/log.txt",
}
]
}
63 changes: 63 additions & 0 deletions cuda-introduction/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"files.associations": {
"cpp": "cuda-cpp",
"hpp": "cuda-cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "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",
"format": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"queue": "cpp",
"ranges": "cpp",
"span": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"text_encoding": "cpp",
"typeinfo": "cpp",
"variant": "cpp"
}
}
16 changes: 16 additions & 0 deletions cuda-introduction/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cmake",
"label": "CMake: build",
"command": "build",
"targets": [
"${command:cmake.buildTargetName}"
],
"group": "build",
"problemMatcher": ["$nvcc"],
"detail": "CMake template build task"
},
]
}
7 changes: 6 additions & 1 deletion cuda-introduction/source/common.cu
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ unsigned divup(unsigned size, unsigned div)
{
// TODO: implement a 1 line function to return the divup operation.
// Note: You only need to use addition, subtraction, and division operations.
return 0;
return (size + div - 1) / div;
}

void clearHostAndDeviceArray(float *res, float *dev_res, unsigned size, const int value)
Expand All @@ -26,6 +26,11 @@ bool compareReferenceAndResult(const float *ref, const float *res, unsigned size
bool passed = true;
for (unsigned i = 0; i < size; i++)
{
#if 0
// print thread info regardless of fail or not
std::cout << "ID: " << i << " \t Res: " << res[i] << " \t Ref: " << ref[i] << std::endl;
#endif

// LOOK: Check if floating point values are equal within an epsilon as returns can vary slightly between CPU and GPU
if (std::fabs(res[i] - ref[i]) > epsilon)
{
Expand Down
Loading