Giter VIP home page Giter VIP logo

npcuda-example's Introduction

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 2.7
  • 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!

npcuda-example's People

Contributors

rmcgibbo avatar bwohlberg avatar proteneer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.