Skip to content

Commit

Permalink
bump version, merge pull request #6 from AMYPAD/devel
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl authored Feb 3, 2021
2 parents 51e1f92 + e2b2cbd commit fead5e6
Show file tree
Hide file tree
Showing 18 changed files with 800 additions and 324 deletions.
11 changes: 10 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,19 @@ C++/CUDA Projects
python -c "import cuvec; print(cuvec.include_path)"
For reference, see ``cuvec.example_mod``'s source code: `example_mod.cu <https://github.com/AMYPAD/CuVec/blob/master/cuvec/src/example_mod/example_mod.cu>`_.

SWIG Projects
-------------

Using the include path from above, simply ``%include "cuvec.i"`` in a SWIG interface file.

For reference, see ``cuvec.example_swig``'s source code: `example_swig.i <https://github.com/AMYPAD/CuVec/blob/master/cuvec/src/example_swig/example_swig.i>`_ and `example_swig.cu <https://github.com/AMYPAD/CuVec/blob/master/cuvec/src/example_swig/example_swig.cu>`_.

CMake Projects
--------------

This is likely unnecessary (see above).
This is likely unnecessary (see above for simpler ``#include`` instructions).

The raw C++/CUDA libraries may be included in external projects using ``cmake``.
Simply build the project and use ``find_package(AMYPADcuvec)``.
Expand Down
10 changes: 9 additions & 1 deletion cuvec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ find_package(CUDAToolkit REQUIRED)
if(SKBUILD)
find_package(PythonExtensions REQUIRED)
set(LIB_TYPE "MODULE")

find_package(SWIG 3.0 COMPONENTS python)
if(SWIG_FOUND)
include(${SWIG_USE_FILE})
set(${CMAKE_PROJECT_NAME}_SWIG_SRC "${CMAKE_CURRENT_LIST_DIR}/include/${CMAKE_PROJECT_NAME}.i")
set_source_files_properties("${${CMAKE_PROJECT_NAME}_SWIG_SRC}" PROPERTIES CPLUSPLUS ON)
endif()
else()
set(LIB_TYPE "SHARED")
endif()
Expand Down Expand Up @@ -43,7 +50,7 @@ add_library(AMYPAD::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${${CMAKE_PROJECT_NAME}_INCLUDE_DIRS}>"
"$<INSTALL_INTERFACE:${CMAKE_PROJECT_NAME}/include>")
target_link_libraries(${PROJECT_NAME} ${Python3_LIBRARIES} ${CUDA_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${Python3_LIBRARIES} CUDA::cudart_static)

if(SKBUILD)
python_extension_module(${PROJECT_NAME})
Expand All @@ -61,6 +68,7 @@ install(EXPORT ${PROJECT_NAME}Targets FILE AMYPAD${PROJECT_NAME}Targets.cmake
NAMESPACE AMYPAD:: DESTINATION ${CMAKE_PROJECT_NAME}/cmake)

add_subdirectory(src/example_mod)
add_subdirectory(src/example_swig)

# install project

Expand Down
3 changes: 1 addition & 2 deletions cuvec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
from warnings import warn
warn(str(err), UserWarning)
else:
from .helpers import CuVec, asarray, copy, zeros
from .pycuvec import cu_copy, cu_zeros, typecodes, vec_types
from .pycuvec import CuVec, asarray, copy, cu_copy, cu_zeros, typecodes, vec_types, zeros

# for use in `cmake -DCMAKE_PREFIX_PATH=...`
cmake_prefix = Path(resource_filename(__name__, "cmake")).resolve()
Expand Down
90 changes: 0 additions & 90 deletions cuvec/helpers.py

This file was deleted.

3 changes: 2 additions & 1 deletion cuvec/include/cuvec.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
#ifndef _CUVEC_H_
#define _CUVEC_H_

#include "cuda_runtime.h"
#include <cstdio> // fprintf
#include <cstdlib> // std::size_t
#include <limits> // std::numeric_limits
#include <new> // std::bad_alloc
#include <vector> // std::vector

namespace cuvec {
void HandleError(cudaError_t err, const char *file, int line) {
static 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);
Expand Down
40 changes: 40 additions & 0 deletions cuvec/include/cuvec.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* SWIG template header wrapping `CuVec<T>`. Provides:
* CuVec(T)
* for external use via `%include "cuvec.i"`.
* Note that `CuVec(T)` is `%define`d to be `CuVec<T>`, which in turn is
* defined in "cuvec.cuh"
*/
%include "std_vector.i"

%{
#include "cuvec.cuh" // CuAlloc
#include "cuda_fp16.h" // __half

template<class T> size_t data(CuVec<T> &vec) {
return (size_t) vec.data();
};
%}

/// `%define X Y` rather than `using X = Y;`
/// due to https://github.com/swig/swig/issues/1058
%define CuVec(T) std::vector<T, CuAlloc<T>> %enddef

template<class T> size_t data(CuVec(T) &vec);

%define MKCUVEC(T, typechar)
%template(CuVec_ ## typechar) CuVec(T);
%template(CuVec_ ## typechar ## _data) data<T>;
%enddef
MKCUVEC(signed char, b)
MKCUVEC(unsigned char, B)
MKCUVEC(char, c)
MKCUVEC(short, h)
MKCUVEC(unsigned short, H)
MKCUVEC(int, i)
MKCUVEC(unsigned int, I)
MKCUVEC(long long, q)
MKCUVEC(unsigned long long, Q)
MKCUVEC(__half, e)
MKCUVEC(float, f)
MKCUVEC(double, d)
Loading

0 comments on commit fead5e6

Please sign in to comment.