This project provides examples of how to integrate CUDA with PostgreSQL. It includes the following: a vector addition extension computed on the GPU, a Set Returning Function (SRF) that computes the maximum number of each time interval using a parallel reduction algorithm on the GPU, and an implementation of a CUDA kernel that computes the heart rate of a resident based on their bed sensor data. The heart rate estimation kernel results are the ones presented in the submitted paper. The project also includes a Python script that can be used to reproduce the results of the paper by inserting dummy data into the database and running the heart rate estimation function over different time intervals. Lastly, the project includes a script that can be used to generate a plot of the results of the heart rate estimation function over different time intervals.
- Python 3.6 or higher installation instructions
- Valid installation of PostgreSQL (version 10 or higher)
- Having a superuser role in PostgreSQL (i.e.
postgresuser in Linux has superuser role by default). - Development libraries and headers for C language backend for PostgreSQL
sudo apt install postgresql-server-dev-XXwhereXXis the version of PostgreSQL
- CUDA Toolkit (version 10.1 or higher)
git clone https://github.com/MU-HPDI/postgres-extensions-with-cuda.git
cd postgres-extensions-with-cuda- Make sure that the PostgreSQL server is running.
- Check valid GPU devices:
nvidia-smiExample output:
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.161.03 Driver Version: 470.161.03 CUDA Version: 11.4 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce ... Off | 00000000:0A:00.0 Off | N/A |
| 0% 37C P8 2W / 225W | 159MiB / 7981MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 1229 G /usr/lib/xorg/Xorg 36MiB |
| 0 N/A N/A 1475 G /usr/bin/gnome-shell 9MiB |
| 0 N/A N/A 159183 C ...ied 127.0.0.1(60178) idle 109MiB |
+-----------------------------------------------------------------------------+
- Check the include PostgreSQL directory:
pg_config --includedir-server - Change the
PG_SERVER_DIRvariable in theMakefilefile to the directory returned if wanting to use a different version of PostgreSQL. (pg_config --includedir-serverreturns the directory for the latest version of the installed PostgreSQL.) - Create a build directory:
mkdir build - Set the required environment variables in a
.envfile from the.env.examplefile. - Insert dummy data into the database:
make insert - Run the project:
make clean extension
Once the project is running, you can execute the following functions:
This function returns the sum of two integer vectors.
SELECT vector_addition_cuda(ARRAY[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ARRAY[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);This function returns the maximum number of each time interval using a parallel reduction algorithm on the GPU.
SELECT * FROM max_reduction_cuda('2023-04-08 22:00:00'::TIMESTAMP, '2023-04-09 22:00:00'::TIMESTAMP);This function returns the heart rate of a resident based on their bed sensor data.
SELECT * FROM heart_rate_estimation('bed_data', '2021-05-29 00:00:00'::TIMESTAMP, '2021-06-07 00:00:00'::TIMESTAMP, 100, 'GPU', '1.0');The following environment variables are required to run the project:
PGUSER: The PostgreSQL usernamePGPASSWORD: The PostgreSQL passwordPGHOST: The PostgreSQL server host namePGPORT: The PostgreSQL server port numberPGDATABASE: The PostgreSQL database name
The following steps can be used to reproduce the results of this project (i.e. Fig. 5 from the paper). In this step, we are going to get the heart rate estimation over different time intervals using the GPU and CPU (1 to 1800 minutes of bed sensor data). The experiemnt can take a minute to run and generate the plot. The following steps assume that the project has been installed and all data has been inserted into the database. (See the Repository Installation and Usage sections for more details.):
- Run the following command:
make plotNote: If the plot is already generated, you need to change the experiment_version variable in the scripts/plots.py file to perform a new experiment.
This project is licensed under the MIT License. See the LICENSE file for details.
