A small working CUDA example powered by Python and PyCUDA. Go to main.py to view the code.
The example implements an algorithm that counts the relatively non-prime numbers
(GCD is not 1) for each number up to size=1000.
Also in the file main.cu a complete native CUDA code attached that does the same as in the python example.
- NVIDIA device
- NVIDIA driver installed (https://www.nvidia.com/en-us/drivers/)
- CUDA installed (https://developer.nvidia.com/cuda-downloads)
- Python 3.9 (or higher)
- numpy>=2.0.2
- pycuda>=2024.1.2
For running C example only, first 3 points above will be enough.
- Create a virtualenv:
python -m virtualenv .venv - Activate the virtualenv:
source ./.venv/bin/activate(or.\.venv\Scripts\activatefor Windows) - Install requirements:
pip install -r requirements.txt - Run the script:
python main.py
- Compile the code:
nvcc -arch=native main.cu -o main(ornvcc main.cu -o main.exefor Windows) - Run the exe-file:
./main(or.\main.exefor Windows)