GithubHelp home page GithubHelp logo

amypad / cuvec Goto Github PK

View Code? Open in Web Editor NEW
78.0 4.0 2.0 730 KB

Unifying Python/C++/CUDA memory: Python buffered array ↔️ `std::vector` ↔️ CUDA managed memory

Home Page: https://amypad.github.io/CuVec/

License: Other

CMake 13.90% Python 42.66% Cuda 37.77% SWIG 3.38% Makefile 2.30%
c cuda python array vector buffer cpython cpython-extensions cpython-api cpp

cuvec's Introduction

CuVec

Unifying Python/C++/CUDA memory: Python buffered array ↔ C++11 std::vector ↔ CUDA managed memory.

Version Downloads Py-Versions DOI Licence Coverage

Table of contents

Why

Data should be manipulated using the existing functionality and design paradigms of each programming language. Python code should be Pythonic. CUDA code should be... CUDActic? C code should be... er, Clean.

However, in practice converting between data formats across languages can be a pain.

Other libraries which expose functionality to convert/pass data formats between these different language spaces tend to be bloated, unnecessarily complex, and relatively unmaintainable. By comparison, cuvec uses the latest functionality of Python, C/C++11, and CUDA to keep its code (and yours) as succinct as possible. "Native" containers are exposed so your code follows the conventions of your language. Want something which works like a numpy.ndarray? Not a problem. Want to convert it to a std::vector? Or perhaps a raw float * to use in a CUDA kernel? Trivial.

  • Less boilerplate code (fewer bugs, easier debugging, and faster prototyping)
  • Fewer memory copies (faster execution)
  • Lower memory usage (do more with less hardware)

Non objectives

Anything to do with mathematical functionality. The aim is to expose functionality, not (re)create it.

Even something as simple as setting element values is left to the user and/or pre-existing features - for example:

  • Python: arr[:] = value
  • NumPy: arr.fill(value)
  • CuPy: cupy.asarray(arr).fill(value)
  • C++: std::fill(vec.begin(), vec.end(), value)
  • C & CUDA: memset(vec.data(), value, sizeof(T) * vec.size())

Install

Requirements:

  • Python 3.7 or greater (e.g. via Anaconda or Miniconda, or via python3-dev)
  • (optional) CUDA SDK/Toolkit (including drivers for an NVIDIA GPU)
    • note that if the CUDA SDK/Toolkit is installed after CuVec, then CuVec must be re-installed to enable CUDA support
pip install cuvec

Usage

See the usage documentation and quick examples of how to upgrade a Python ↔ C++ ↔ CUDA interface.

See also NumCu, a minimal stand-alone Python package built using CuVec.

External Projects

For integration into Python, C++, CUDA, CMake, pybind11, and general SWIG projects, see the external project documentation. Full and explicit example modules using the CPython API, pybind11 API, and SWIG are also provided.

Contributing

See CONTRIBUTING.md.

Licence

Licence DOI

Copyright:

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.