CUDA Example: Refactor to Number 0

Less fiddeling in the scripts when adding more examples later on.
This commit is contained in:
Axel Huebl 2016-01-19 09:31:29 +01:00
parent 6c98c38dfa
commit 13ca58e189
5 changed files with 13 additions and 12 deletions

View File

@ -115,6 +115,8 @@ set(PYBIND11_EXAMPLES
example/example13.cpp example/example13.cpp
) )
set(PYBIND11_FIRSTEXAMPLE 1)
set(PYBIND11_LASTEXAMPLE 13)
if(${CUDA_FOUND}) if(${CUDA_FOUND})
macro(add_library_wrapper) macro(add_library_wrapper)
@ -125,7 +127,8 @@ if(${CUDA_FOUND})
add_definitions(-DPYBIND11_CUDA=1) add_definitions(-DPYBIND11_CUDA=1)
list(APPEND CUDA_NVCC_FLAGS -std=c++11) list(APPEND CUDA_NVCC_FLAGS -std=c++11)
list(APPEND CUDA_NVCC_FLAGS -arch=${CUDA_ARCH}) list(APPEND CUDA_NVCC_FLAGS -arch=${CUDA_ARCH})
set(PYBIND11_EXAMPLES ${PYBIND11_EXAMPLES} example/example14.cu) set(PYBIND11_EXAMPLES ${PYBIND11_EXAMPLES} example/example0.cu)
set(PYBIND11_FIRSTEXAMPLE 0)
else() else()
macro(add_library_wrapper) macro(add_library_wrapper)
add_library(${ARGV}) add_library(${ARGV})
@ -207,9 +210,7 @@ endif()
enable_testing() enable_testing()
set(RUN_TEST ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/example/run_test.py) set(RUN_TEST ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/example/run_test.py)
list(LENGTH PYBIND11_EXAMPLES PYBIND11_NUMEXAMPLES) foreach(i RANGE ${PYBIND11_FIRSTEXAMPLE} ${PYBIND11_LASTEXAMPLE})
math(EXPR PYBIND11_NUMEXAMPLES "${PYBIND11_NUMEXAMPLES} - 1")
foreach(i RANGE 1 ${PYBIND11_NUMEXAMPLES})
add_test(NAME example${i} COMMAND ${RUN_TEST} example${i}) add_test(NAME example${i} COMMAND ${RUN_TEST} example${i})
endforeach() endforeach()

View File

@ -10,6 +10,9 @@
#include "example.h" #include "example.h"
#if (PYBIND11_CUDA==1)
void init_ex0(py::module &);
#endif
void init_ex1(py::module &); void init_ex1(py::module &);
void init_ex2(py::module &); void init_ex2(py::module &);
void init_ex3(py::module &); void init_ex3(py::module &);
@ -23,13 +26,13 @@ void init_ex10(py::module &);
void init_ex11(py::module &); void init_ex11(py::module &);
void init_ex12(py::module &); void init_ex12(py::module &);
void init_ex13(py::module &); void init_ex13(py::module &);
#if (PYBIND11_CUDA==1)
void init_ex14(py::module &);
#endif
PYBIND11_PLUGIN(example) { PYBIND11_PLUGIN(example) {
py::module m("example", "pybind example plugin"); py::module m("example", "pybind example plugin");
#if (PYBIND11_CUDA==1)
init_ex0(m);
#endif
init_ex1(m); init_ex1(m);
init_ex2(m); init_ex2(m);
init_ex3(m); init_ex3(m);
@ -43,9 +46,6 @@ PYBIND11_PLUGIN(example) {
init_ex11(m); init_ex11(m);
init_ex12(m); init_ex12(m);
init_ex13(m); init_ex13(m);
#if (PYBIND11_CUDA==1)
init_ex14(m);
#endif
return m.ptr(); return m.ptr();
} }

View File

@ -1,5 +1,5 @@
/* /*
example/example14.cu -- CUDA acceleratred Mandelbrot example example/example0.cu -- CUDA acceleratred Mandelbrot example
Copyright (c) 2012-2016 Axel Huebl <a.huebl@hzdr.de> Copyright (c) 2012-2016 Axel Huebl <a.huebl@hzdr.de>
@ -157,6 +157,6 @@ int mandelbrot() {
namespace py = pybind11; namespace py = pybind11;
void init_ex14(py::module &m) { void init_ex0(py::module &m) {
m.def("mandelbrot", &mandelbrot, "Start mandelbrot calculation"); m.def("mandelbrot", &mandelbrot, "Start mandelbrot calculation");
} }