Skip to content

Commit

Permalink
bump version, merge pull request #2 from AMYPAD/devel
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl authored Jan 24, 2021
2 parents dac6aca + 335d3cd commit 2e0e86f
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: cuvec ${{ github.ref }} beta
release_name: CuVec ${{ github.ref }} beta
body_path: _CHANGES.md
draft: true
- if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
Expand Down
2 changes: 1 addition & 1 deletion .zenodo.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title": "cuvec: Unifying Python/C++/CUDA memory",
"title": "CuVec: Unifying Python/C++/CUDA memory",
"keywords": ["Python", "C", "C++", "buffer", "vector", "array", "CUDA", "CPython", "extensions", "API"],
"creators": [
{"name": "da Costa-Luis, Casper O.", "orcid": "0000-0002-7211-1557",
Expand Down
16 changes: 8 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cuvec
CuVec
=====

Unifying Python/C++/CUDA memory: Python buffered array <-> C++11 ``std::vector`` <-> CUDA managed memory.
Expand Down Expand Up @@ -157,7 +157,7 @@ Install in "development/editable" mode including dev/test dependencies:

.. code:: sh
git clone https://github.com/AMYPAD/cuvec && cd cuvec
git clone https://github.com/AMYPAD/CuVec && cd CuVec
pip install -e .[dev]
Alternatively, if ``cmake`` and a generator (such as ``make`` or ``ninja``) are available, then ``setup.py build`` and ``develop`` can be explicitly called; optionally with extra ``cmake`` and generator arguments:
Expand Down Expand Up @@ -185,14 +185,14 @@ Copyright 2021
.. |DOI| image:: https://zenodo.org/badge/DOI/10.5281/zenodo.4446211.svg
:target: https://doi.org/10.5281/zenodo.4446211
.. |Licence| image:: https://img.shields.io/pypi/l/cuvec.svg?label=licence
:target: https://github.com/AMYPAD/cuvec/blob/master/LICENCE
.. |Tests| image:: https://img.shields.io/github/workflow/status/AMYPAD/cuvec/Test?logo=GitHub
:target: https://github.com/AMYPAD/cuvec/actions
:target: https://github.com/AMYPAD/CuVec/blob/master/LICENCE
.. |Tests| image:: https://img.shields.io/github/workflow/status/AMYPAD/CuVec/Test?logo=GitHub
:target: https://github.com/AMYPAD/CuVec/actions
.. |Downloads| image:: https://img.shields.io/pypi/dm/cuvec.svg?logo=pypi&logoColor=white&label=PyPI%20downloads
:target: https://pypi.org/project/cuvec
.. |Coverage| image:: https://codecov.io/gh/AMYPAD/cuvec/branch/master/graph/badge.svg
:target: https://codecov.io/gh/AMYPAD/cuvec
.. |Coverage| image:: https://codecov.io/gh/AMYPAD/CuVec/branch/master/graph/badge.svg
:target: https://codecov.io/gh/AMYPAD/CuVec
.. |Version| image:: https://img.shields.io/pypi/v/cuvec.svg?logo=python&logoColor=white
:target: https://github.com/AMYPAD/cuvec/releases
:target: https://github.com/AMYPAD/CuVec/releases
.. |Py-Versions| image:: https://img.shields.io/pypi/pyversions/cuvec.svg?logo=python&logoColor=white
:target: https://pypi.org/project/cuvec
2 changes: 1 addition & 1 deletion cuvec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ option(CUVEC_DEBUG "Print out CUDA malloc & free operations" OFF)
if(CUVEC_DEBUG)
add_compile_definitions(CUVEC_DEBUG)
endif(CUVEC_DEBUG)
message(STATUS "cuvec debugging: ${CUVEC_DEBUG}")
message(STATUS "CuVec debugging: ${CUVEC_DEBUG}")

set(${CMAKE_PROJECT_NAME}_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/include/") # / suffix important
install(DIRECTORY "${${CMAKE_PROJECT_NAME}_INCLUDE_DIRS}" DESTINATION ${CMAKE_PROJECT_NAME}/include)
Expand Down
2 changes: 1 addition & 1 deletion cuvec/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __new__(cls, arr):
obj = np.asarray(arr).view(cls)
obj.cuvec = arr
return obj
if isinstance(arr, CuVec):
if isinstance(arr, CuVec) and hasattr(arr, 'cuvec'):
log.debug("new view")
obj = np.asarray(arr).view(cls)
obj.cuvec = arr.cuvec
Expand Down
8 changes: 5 additions & 3 deletions cuvec/include/cuvec.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
#include <new> // std::bad_alloc
#include <vector> // std::vector

namespace cuvec {
void HandleError(cudaError_t err, const char *file, int line) {
if (err != cudaSuccess) {
fprintf(stderr, "%s in %s at line %d\n", cudaGetErrorString(err), file, line);
exit(EXIT_FAILURE);
}
}
} // namespace cuvec

template <class T> struct CuAlloc {
typedef T value_type;
Expand All @@ -33,7 +35,7 @@ template <class T> struct CuAlloc {

T *p;
// p = (T *)malloc(n * sizeof(T));
HandleError(cudaMallocManaged(&p, n * sizeof(T)), __FILE__, __LINE__);
cuvec::HandleError(cudaMallocManaged((void **)&p, n * sizeof(T)), __FILE__, __LINE__);
if (p) {
report(p, n);
return p;
Expand All @@ -43,8 +45,8 @@ template <class T> struct CuAlloc {
}

void deallocate(T *p, std::size_t n) noexcept {
report(p, n, 0);
HandleError(cudaFree(p), __FILE__, __LINE__); // free(p);
report(p, n, false);
cuvec::HandleError(cudaFree((void *)p), __FILE__, __LINE__); // free(p);
}

private:
Expand Down
6 changes: 4 additions & 2 deletions cuvec/include/pycuvec.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <typeinfo> // typeid
#include <vector> // std::vector

namespace cuvec {
template <typename T> struct PyType {
static const char *format() { return typeid(T).name(); }
};
Expand Down Expand Up @@ -61,6 +62,7 @@ template <> struct PyType<float> {
template <> struct PyType<double> {
static const char *format() { return "d"; }
};
} // namespace cuvec

/** classes */
/// class PyCuVec<T>
Expand Down Expand Up @@ -107,7 +109,7 @@ template <class T> static void PyCuVec_dealloc(PyCuVec<T> *self) {
/// __name__
template <class T> const std::string PyCuVec_t_str() {
std::stringstream s;
s << "Vector_" << PyType<T>::format();
s << "Vector_" << cuvec::PyType<T>::format();
return s.str();
}
/// __str__
Expand Down Expand Up @@ -135,7 +137,7 @@ template <class T> static int PyCuVec_getbuffer(PyObject *obj, Py_buffer *view,
view->len = self->vec.size() * sizeof(T);
view->readonly = 0;
view->itemsize = sizeof(T);
view->format = (char *)PyType<T>::format();
view->format = (char *)cuvec::PyType<T>::format();
view->ndim = self->shape.size();
view->shape = self->shape.data();
view->strides = self->strides.data();
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ long_description=file: README.rst
long_description_content_type=text/x-rst
license=MPL 2.0
license_file=LICENCE
url=https://github.com/AMYPAD/cuvec
url=https://github.com/AMYPAD/CuVec
project_urls=
Changelog=https://github.com/AMYPAD/cuvec/releases
Documentation=https://github.com/AMYPAD/cuvec#cuvec
Changelog=https://github.com/AMYPAD/CuVec/releases
Documentation=https://github.com/AMYPAD/CuVec#CuVec
author=Casper da Costa-Luis
author_email[email protected]
keywords=Python, C, C++, buffer, vector, array, CUDA, CPython, extensions, API
Expand Down
8 changes: 8 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,11 @@ def test_asarray():
assert y.cuvec != v.cuvec
assert (y == v).all()
assert np.asarray(y.cuvec).data == np.asarray(v.cuvec).data
z = cu.asarray(v[:])
assert z.cuvec != v.cuvec
assert (z == v[:]).all()
assert np.asarray(z.cuvec).data == np.asarray(v.cuvec).data
s = cu.asarray(v[1:])
assert s.cuvec != v.cuvec
assert (s == v[1:]).all()
assert np.asarray(s.cuvec).data != np.asarray(v.cuvec).data

0 comments on commit 2e0e86f

Please sign in to comment.