• Stars
    star
    143
  • Rank 257,007 (Top 6 %)
  • Language
    C
  • License
    BSD 2-Clause "Sim...
  • Created about 12 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Example python (numpy) -- CUDA installable package with a C-extension library

npcuda-example

This is an example of a simple Python C++ extension which uses CUDA and is compiled via nvcc. The idea is to use this coda as an example or template from which to build your own CUDA-accelerated Python extensions.

The extension is a single C++ class which manages the GPU memory and provides methods to call operations on the GPU data. This C++ class is wrapped via swig or cython -- effectively exporting this class into python land.

swig vs cython

swig

Swig is a widely used code generator for exposing C and C++ libraries in high level dynamically typed languages. In principle, it involves minimal code rewriting. You just have to write swig interface files that instruct swig on how to do the translation.

In practice, swig and numpy don't work together that well. The numpy interface relies on a bunch of magical macros that are extremely difficult to debug.

!!cython!!

Cython is sweet. It's basically python, with optional static type declarations and the ability to call c functions directly. Take a look at wrapper.pyx. It looks like python, but it gets translated into C, and then compiled into a shared object file which you import from python (look at the test.py file)

Cython is the way to go.

difference from PyCUDA

The point of this project is not to enable you to access the CUDA API in python, to write cuda code in strings and have them be dynamically compiled, or anything like that.

Instead, the goal is to demonstrate some of the biolerplate and tricks needed to make a CPython extension module that uses CUDA compiled with setuptools/distutils just like your standard C exension modules.

authors

  • Robert McGibbon
  • Yutong Zhao

installation

Requirements:

  • python
  • python setuptools, numpy
  • nvcc. I'm using version 4.2
  • nose (for testing)
  • swig for the swig wrapping method. I've tested with version 1.3.40
  • cython for the cython wrapping method. I've tested with version 0.16

To install, cd into your directory of choice -- either swig or cython. Then, just run $ python setup.py install. To see if everything is working, run $ nosetests

Silence is golden!

More Repositories

1

slidedeck

Beautiful HTML5 slides in markdown. A easy-to-use fork of the google-io-2012 slide deck
CSS
316
star
2

jupyter-emacskeys

Emacs keybindings for Jupyter notebook
Python
88
star
3

python-appveyor-conda-example

Demo project for building and shipping Python conda packages with Appveyor CI and Travis CI
PowerShell
66
star
4

reftagger

Parse and tag unstructured academic citations.
Python
46
star
5

pyhmc

Hamiltonain Monte Carlo in Python
Python
35
star
6

logsumexp

Fast SSE logsumexp for python/numpy
C
29
star
7

figshare

Command line client for figshare
Python
19
star
8

pyvdwsurface

Molecular (Van der Waals) surface.
C++
18
star
9

sphinxcontrib-autodoc_doxygen

Sphinx / Doxygen bridge
Python
15
star
10

covar

Compute shrinkage estimates of the covariance matrix
Python
14
star
11

sphinxcontrib-lunrsearch

Instant search for Sphinx
Python
12
star
12

mydra

Python
12
star
13

openmm-webbuilder

JS/HTML5 webapp for setting up custom GPU-accelerated OpenMM molecular dynamics simulations.
JavaScript
12
star
14

async-priority-channel

Rust
11
star
15

mullermsm

Markov State Models on the Muller potential: a MSMBuilder Tutorial
Python
11
star
16

r-rmcgibbo

Python
9
star
17

resp2

RESP plugin for PSI4
C++
9
star
18

openmm-cookbook

A collection of code snippets for doing molecular simulations with OpenMM.
9
star
19

msmaccelerator2

Adaptive Sampling Markov State Model Driven Molecular Dynamics
Python
8
star
20

Jarvis

C++
8
star
21

execgraph

Parallel execution of shell commands with DAG dependencies
Rust
7
star
22

openmm-cmd

OpenMM Command Line Application
Python
7
star
23

qchem-utils

Utilities for working with Q-Chem
Python
7
star
24

information

Some information theory stuff -- transfer entropy, etc.
Python
7
star
25

nixpkgs-hammering-action

Python
5
star
26

projector

Interactive plotting of MD projections + molecular viewer with HTML5 and WebGL
JavaScript
4
star
27

conda-hint

Hint generation for conda resolver.
Python
4
star
28

history

An enhanced history(1) for bash
Rust
4
star
29

pypatchelf

Patchelf utility, packaged for python/pip
Python
4
star
30

simtk.unit

Python Units
Python
4
star
31

ropen

Rust
3
star
32

hpcutils

Command line utilities for working remotely on HPC clusters.
Python
2
star
33

msmbuilder3

Work on progress for next iteration of MSMBuilder
Python
2
star
34

doccheck

Check that docstrings satisfy Numpy format
Python
2
star
35

sudoku

Haskell Sudoku Solver
Haskell
2
star
36

post-build-postgres

Nix post-build-hook to upload to postgresql
Rust
2
star
37

cache-dash-h

cache the help text for your dog-slow scripts
C++
2
star
38

mutations

Notes (and code) on efficiently simulating mutants with MSMs
Python
2
star
39

okbot

Respond to OkCupid messages with tweets.
Python
2
star
40

fsync

Use your local GUI editor for remote development over SSH
Shell
2
star
41

opt-k

Likelihood framework for choosing the optimal number of states in a Markov State Model
TeX
2
star
42

idle-trigger

Trigger a command when the CPUs are idle
Rust
2
star
43

circular_dichroism

prediction of cd spectra from structures
Python
2
star
44

metric-learning

metric learning stuff
Python
2
star
45

minimsmbuilder

Python
2
star
46

hdf5pickle

Fast persistence of Python objects to HDF5 files
Python
2
star
47

nixpkgs-hammering-action-example

See https://github.com/rmcgibbo/nixpkgs-hammering-action
Nix
2
star
48

GPURMSD

Yutong's GPU accelerated RMSD code
C++
1
star
49

precedenceConstrainedKnapsack

Precedence constrained knapsack problem solver
C++
1
star
50

cargo-remote

cargo subcommand to compile rust projects remotely
Rust
1
star
51

python-flake-utils

Nix
1
star
52

ipython_parallel_profiles

profiles for IPython.parallel
Python
1
star
53

bibtex-resolver

Python
1
star
54

holmes_rubin

Holmes-Rubin EM Estimator for Continuous-Time Markov processes
Python
1
star
55

arduino

Personal arduino projects
Processing
1
star
56

tungsten

Parallel Markov State Model Acceleraed Molecular Dynamics
C++
1
star
57

rmcgibbo-config

My config files (bashrcs, etc) to be synced across machines
Emacs Lisp
1
star
58

zmq-objc-framework

Objective-C binding for ZeroMQ. Fork of https://github.com/jeremy-w/objc-zmq
Shell
1
star
59

cctools-3.4.2-fork

Fork of cctools (workqueue) for MSMAccelerator
C
1
star
60

bagofwaves

Python
1
star
61

rmcgibbo.org

professional website
CSS
1
star
62

wavekernel

C++
1
star
63

oom-enospc-notify

Detect OOM and ENOSPC errors with BPF
Python
1
star
64

kmeansrmsd

C
1
star
65

openmm-pulling

Pulling Simulation and Smoothing
Python
1
star
66

openmm-builder

A graphical interface for building (and now running!) OpenMM scripts
Python
1
star
67

toy-systems

Python
1
star
68

nebterpolator

Interpolator for generating smooth paths from an ab-intio MD trajectory for NEB calculations.
Python
1
star
69

openmm-debpackaging

Shell
1
star
70

adaptive-group-testing

https://en.wikipedia.org/wiki/Group_testing#Generalised_binary-splitting_algorithm
Python
1
star
71

neb

OpenMM Nudged Elastic Band (NEB) Plugin. Currently only supports steepest descent optimization -- needs a little to switch to a quasti-newton optimizer.
Python
1
star
72

nix-unsafePlugins

This is unsafe. Don't use it.
C++
1
star
73

gh-util

Github command line utilities
Python
1
star
74

numpy-mypy

Python
1
star