Skip to main content

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

Version Downloads Py-Versions Licence Tests Coverage

Why

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++, 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.

Non objectives

Anything to do with mathematical functionality. Even something as simple as setting element values is left to the user and/or pre-existing features - simply use numpy.ndarray.fill() (Python/Numpy), std::fill() (C++), or memset() (C/CUDA).

Install

Requirements:

pip install cuvec

Usage

Creating

Python

import cuvec
vec = cuvec.vector((1337, 42), "float32")

CPython API

#include "Python.h"
#include "pycuvec.cuh" // requires nvcc
PyObject *obj = (PyObject *)PyCuVec_zeros<float>({1337, 42});
// don't forget to Py_INCREF(obj) if returning it.

/// N.B.: convenience functions provided by "pycuvec.cuh":
// PyCuVec<T> *PyCuVec_zeros(std::vector<Py_ssize_t> shape);
// PyCuVec<T> *PyCuVec_zeros_like(PyCuVec<T> *other);
// PyCuVec<T> *PyCuVec_deepcopy(PyCuVec<T> *other);

C++/CUDA

#include "cuvec.cuh" // requires nvcc
CuVec<float> vec(1337 * 42); // like std::vector<float>

Converting

The following involve no memory copies.

CPython API to C++

/// input: `PyObject *obj` (obtained from e.g.: `PyArg_ParseTuple()`, etc)
/// output: `CuVec<type> vec`
CuVec<float> &vec = ((PyCuVec<float> *)obj)->vec; // like std::vector<float>
std::vector<Py_ssize_t> &shape = ((PyCuVec<float> *)obj)->shape;

C++ to C/CUDA

/// input: `CuVec<type> vec`
/// output: `type *arr`
float *arr = vec->data(); // pointer to `cudaMallocManaged()` data

External CMake Projects

The raw C++/CUDA libraries may be included in external projects using cmake. Simply build the project and use find_package(AMYPADcuvec).

# print installation directory (after `pip install cuvec`)...
python -c "import cuvec; print(cuvec.cmake_prefix)"

# ... or build & install directly with cmake
mkdir build && cd build
cmake ../cuvec && cmake --build . && cmake --install . --prefix /my/install/dir

At this point any external project may include cuvec as follows (Once setting -DCMAKE_PREFIX_DIR=<installation prefix from above>):

cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(myproj)
find_package(AMYPADcuvec COMPONENTS cuvec REQUIRED)
add_executable(myexe ...)
target_link_libraries(myexe PRIVATE AMYPAD::cuvec)

Licence

Licence

Copyright 2021

Release files for cuvec 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cuvec 1.0.0
File Size Uploaded
cuvec-1.0.0.tar.gz 22.0 kB Details

Release files / cuvec-1.0.0.tar.gz

Download URL cuvec-1.0.0.tar.gz
Size 22.0 kB
Tags Source
SHA-256 checksum
How to use checksums
71634e2604e29092678317d5355fe369720d3b9ad9d75a82292305f88eb312f3
BLAKE2b-256 checksum
How to use checksums
8366077fd5a9c847c6115905cd24754a4fe4aab91e09a92a62aed9c8bb03da67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

Release history Release notifications | RSS feed

6.0.1

1 release file

6.0.0

1 release file

5.0.1

1 release file

5.0.0

1 release file

4.1.1

1 release file

4.1.0

1 release file

4.0.0

1 release file

3.0.0

1 release file

2.12.0

1 release file

2.11.4

1 release file

2.11.3

1 release file

2.11.2

1 release file

2.11.1

1 release file

2.11.0

1 release file

2.10.0

1 release file

2.9.0

1 release file

2.8.0

1 release file

2.7.7

1 release file

2.7.6

1 release file

2.7.5

1 release file

2.7.4

1 release file

2.7.3

1 release file

2.7.2

1 release file

2.7.1

1 release file

2.7.0

1 release file

2.6.0

1 release file

2.5.0

1 release file

2.4.0

1 release file

2.3.1

1 release file

2.3.0

1 release file

2.2.0

1 release file

2.1.2

1 release file

2.1.1

1 release file

2.1.0

1 release file

2.0.1

1 release file

2.0.0

1 release file

This release

1.0.0 This release

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page