From 0bef65320ed985b5f605c566eb40ea778b8493ad Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sat, 23 Jan 2021 16:14:55 +0000 Subject: [PATCH 1/3] consistent name capitalisation --- .github/workflows/test.yml | 2 +- .zenodo.json | 2 +- README.rst | 16 ++++++++-------- cuvec/CMakeLists.txt | 2 +- setup.cfg | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e838755..27155e5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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') diff --git a/.zenodo.json b/.zenodo.json index bfc278d..e8c9856 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -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", diff --git a/README.rst b/README.rst index 7923fb6..7db4737 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -cuvec +CuVec ===== Unifying Python/C++/CUDA memory: Python buffered array <-> C++11 ``std::vector`` <-> CUDA managed memory. @@ -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: @@ -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 diff --git a/cuvec/CMakeLists.txt b/cuvec/CMakeLists.txt index ab096b7..4dda903 100644 --- a/cuvec/CMakeLists.txt +++ b/cuvec/CMakeLists.txt @@ -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) diff --git a/setup.cfg b/setup.cfg index 9acac53..d0c8434 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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=casper.dcl@physics.org keywords=Python, C, C++, buffer, vector, array, CUDA, CPython, extensions, API From d36692301f2bdf11d285782802f50ddfaa4307c2 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sun, 24 Jan 2021 17:40:22 +0000 Subject: [PATCH 2/3] fix potential name clashes wih namespaces --- cuvec/include/cuvec.cuh | 8 +++++--- cuvec/include/pycuvec.cuh | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cuvec/include/cuvec.cuh b/cuvec/include/cuvec.cuh index e94a566..e630e8a 100644 --- a/cuvec/include/cuvec.cuh +++ b/cuvec/include/cuvec.cuh @@ -11,12 +11,14 @@ #include // std::bad_alloc #include // 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 struct CuAlloc { typedef T value_type; @@ -33,7 +35,7 @@ template 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; @@ -43,8 +45,8 @@ template 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: diff --git a/cuvec/include/pycuvec.cuh b/cuvec/include/pycuvec.cuh index 47591b8..15f62f4 100644 --- a/cuvec/include/pycuvec.cuh +++ b/cuvec/include/pycuvec.cuh @@ -17,6 +17,7 @@ #include // typeid #include // std::vector +namespace cuvec { template struct PyType { static const char *format() { return typeid(T).name(); } }; @@ -61,6 +62,7 @@ template <> struct PyType { template <> struct PyType { static const char *format() { return "d"; } }; +} // namespace cuvec /** classes */ /// class PyCuVec @@ -107,7 +109,7 @@ template static void PyCuVec_dealloc(PyCuVec *self) { /// __name__ template const std::string PyCuVec_t_str() { std::stringstream s; - s << "Vector_" << PyType::format(); + s << "Vector_" << cuvec::PyType::format(); return s.str(); } /// __str__ @@ -135,7 +137,7 @@ template 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::format(); + view->format = (char *)cuvec::PyType::format(); view->ndim = self->shape.size(); view->shape = self->shape.data(); view->strides = self->strides.data(); From 335d3cd80a377e78570f5b8908a0b60ae9f196ba Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sun, 24 Jan 2021 21:13:42 +0000 Subject: [PATCH 3/3] fix asarray not copying on CuVec views --- cuvec/helpers.py | 2 +- tests/test_helpers.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cuvec/helpers.py b/cuvec/helpers.py index 8a2f2ee..0c8a526 100644 --- a/cuvec/helpers.py +++ b/cuvec/helpers.py @@ -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 diff --git a/tests/test_helpers.py b/tests/test_helpers.py index c08818e..ae6f399 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -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