Skip to content

An example for building CPU/GPU agnostic code in Python and C++/CUDA

License

Notifications You must be signed in to change notification settings

mikekatz04/gpu_example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gpuexample: An example of GPU/CPU agnostic Python/C/CUDA codes

This package contains a basic setup for wrapping CPU/GPU agnostic C/C++/CUDA into CPU/GPU agnostic Python. The goal of the package is to compute a 2D array of sine waves with different amplitude, frequency, and initial phase. src/GPUExample.cu is the source C/C++/CUDA file. Its header file is include/GPUExample.hh. It is wrapped into Python with a Cython wrapper (src/gpu_example.pyx) originally inspired by this Github repository. The Python file that contains the sine wave creation is gpuexample/gpuexample.py. The file test_gpuexample.py will run the code on the CPU and, if available, on an NVIDIA GPU.

Getting Started / Installing

Below is a quick set of instructions to get you started with gpuexample.

  1. Install Anaconda if you do not have it.

  2. Create a virtual environment. Note: There is no available conda compiler for Windows.

conda create -n gpuex_env -c conda-forge gcc_linux-64 gxx_linux-64 numpy Cython scipy python=3.9
conda activate few_env
If on MACOSX, substitute `gcc_linux-64` and `gxx_linus-64` with `clang_osx-64` and `clangxx_osx-64`.
  1. If using GPUs, use pip to install cupy. If you have cuda version 9.2, for example:
pip install cupy-cuda92
  1. Clone the repository.
git clone https://github.com/mikekatz04/gpu_example.git
cd gpu_example
  1. Run install. If using GPUs, make sure CUDA is on your PATH or the CUDAHOME variable is set as an environment variable.
python setup.py install
  1. Run the test file.
python test_gpuexample.py
  1. To import gpuexample:
from gpuexample.gpuexample import pyGPUExample

Prerequisites

To install this software for use with NVIDIA GPUs (compute capability >2.0), you need the CUDA toolkit and CuPy. The CUDA toolkit must have cuda version >8.0. Be sure to properly install CuPy within the correct CUDA toolkit version. Make sure the nvcc binary is on $PATH or set it as the CUDAHOME environment variable.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Current Version: 1.0.0

Authors

  • Michael Katz

License

This project is licensed under the GNU License - see the LICENSE.md file for details.

About

An example for building CPU/GPU agnostic code in Python and C++/CUDA

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published