Commit 97c9bd44344e57c5c5c343d0104859828f0f440b
1 parent
d4022e85
modified build environment to build CUDA programs
Showing
8 changed files
with
134 additions
and
0 deletions
CMakeLists.txt
| @@ -108,6 +108,7 @@ endif() | @@ -108,6 +108,7 @@ endif() | ||
| 108 | if(UNIX) | 108 | if(UNIX) |
| 109 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-strict-overflow -Wno-comment -Wno-unknown-pragmas -fvisibility=hidden -fno-omit-frame-pointer") | 109 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-strict-overflow -Wno-comment -Wno-unknown-pragmas -fvisibility=hidden -fno-omit-frame-pointer") |
| 110 | set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib ${_qt5Core_install_prefix}/lib) | 110 | set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib ${_qt5Core_install_prefix}/lib) |
| 111 | + set(CUDA_NVCC_FLAGS "") # put NVCC compiler flags here | ||
| 111 | if(NOT APPLE) | 112 | if(NOT APPLE) |
| 112 | if(${CMAKE_CXX_COMPILER} STREQUAL "/opt/intel/bin/icpc") | 113 | if(${CMAKE_CXX_COMPILER} STREQUAL "/opt/intel/bin/icpc") |
| 113 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-intel -wd2196") | 114 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-intel -wd2196") |
openbr/CMakeLists.txt
| @@ -8,6 +8,7 @@ set(SRC openbr.cpp | @@ -8,6 +8,7 @@ set(SRC openbr.cpp | ||
| 8 | universal_template.cpp) | 8 | universal_template.cpp) |
| 9 | aux_source_directory(core BR_CORE) | 9 | aux_source_directory(core BR_CORE) |
| 10 | include(plugins/plugins.cmake) | 10 | include(plugins/plugins.cmake) |
| 11 | +include(cuda-plugins/cuda-plugins.cmake) | ||
| 11 | 12 | ||
| 12 | # Janus API | 13 | # Janus API |
| 13 | option(BR_WITH_JANUS "Build IARPA Janus related applications." ON) | 14 | option(BR_WITH_JANUS "Build IARPA Janus related applications." ON) |
| @@ -28,6 +29,7 @@ if(NOT BR_EMBEDDED) | @@ -28,6 +29,7 @@ if(NOT BR_EMBEDDED) | ||
| 28 | install(FILES ${HEADERS} DESTINATION include/openbr/gui) | 29 | install(FILES ${HEADERS} DESTINATION include/openbr/gui) |
| 29 | endif() | 30 | endif() |
| 30 | 31 | ||
| 32 | +# normal BR library declaration | ||
| 31 | add_library(openbr SHARED ${SRC} ${BR_CORE} ${BR_JANUS} ${BR_GUI} ${BR_ICONS} ${BR_THIRDPARTY_SRC} ${BR_RESOURCES} ${NATURALSTRINGCOMPARE_SRC}) | 33 | add_library(openbr SHARED ${SRC} ${BR_CORE} ${BR_JANUS} ${BR_GUI} ${BR_ICONS} ${BR_THIRDPARTY_SRC} ${BR_RESOURCES} ${NATURALSTRINGCOMPARE_SRC}) |
| 32 | qt5_use_modules(openbr ${QT_DEPENDENCIES}) | 34 | qt5_use_modules(openbr ${QT_DEPENDENCIES}) |
| 33 | set_target_properties(openbr PROPERTIES | 35 | set_target_properties(openbr PROPERTIES |
| @@ -37,6 +39,15 @@ set_target_properties(openbr PROPERTIES | @@ -37,6 +39,15 @@ set_target_properties(openbr PROPERTIES | ||
| 37 | target_link_libraries(openbr ${BR_THIRDPARTY_LIBS}) | 39 | target_link_libraries(openbr ${BR_THIRDPARTY_LIBS}) |
| 38 | add_cppcheck(openbr) | 40 | add_cppcheck(openbr) |
| 39 | 41 | ||
| 42 | +# CUDA portion of BR | ||
| 43 | + | ||
| 44 | +cuda_add_library(openbr-cuda SHARED ${BR_THIRDPARTY_CUDA_SRC}) | ||
| 45 | +qt5_use_modules(openbr-cuda ${QT_DEPENDENCIES}) | ||
| 46 | +set_target_properties(openbr-cuda PROPERTIES | ||
| 47 | + DEFINE_SYMBOL BR_CUDA_LIBRARY | ||
| 48 | + VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH} | ||
| 49 | + SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}) | ||
| 50 | + | ||
| 40 | # Janus implementation | 51 | # Janus implementation |
| 41 | if(BR_WITH_JANUS) | 52 | if(BR_WITH_JANUS) |
| 42 | set(JANUS_BUILD_PP5_WRAPPER ${BR_WITH_PP5} CACHE BOOL "Build Janus implementation using PittPatt 5") | 53 | set(JANUS_BUILD_PP5_WRAPPER ${BR_WITH_PP5} CACHE BOOL "Build Janus implementation using PittPatt 5") |
openbr/plugins/cuda/copyfrom.cpp renamed to openbr/cuda-plugins/cglg/copyfrom.cpp
openbr/plugins/cuda/copyto.cpp renamed to openbr/cuda-plugins/cglg/copyto.cpp
openbr/cuda-plugins/cglg/customthreshold.cu
0 → 100644
| 1 | +/* | ||
| 2 | +#include <iostream> | ||
| 3 | + | ||
| 4 | +// external opencv CUDA interface | ||
| 5 | +#include <opencv2/opencv.hpp> | ||
| 6 | +#include <opencv2/gpu/gpu.hpp> | ||
| 7 | + | ||
| 8 | +// internal CUDA stuff | ||
| 9 | +#include <opencv2/core/cuda/common.hpp> | ||
| 10 | +#include <opencv2/core/cuda/emulation.hpp> | ||
| 11 | +#include <opencv2/core/cuda/transform.hpp> | ||
| 12 | +#include <opencv2/core/cuda/functional.hpp> | ||
| 13 | +#include <opencv2/core/cuda/utility.hpp> | ||
| 14 | + | ||
| 15 | +#include <openbr/plugins/openbr_internal.h> | ||
| 16 | + | ||
| 17 | +using namespace std; | ||
| 18 | + | ||
| 19 | +using namespace cv; | ||
| 20 | +using namespace cv::gpu; | ||
| 21 | +using namespace cv::cuda; | ||
| 22 | +using namespace cv::cuda::device; | ||
| 23 | + | ||
| 24 | +namespace br | ||
| 25 | +{ | ||
| 26 | + class CUDACustomThresholdTransform : public UntrainableTransform | ||
| 27 | + { | ||
| 28 | + Q_OBJECT | ||
| 29 | + | ||
| 30 | +private: | ||
| 31 | + void project(const Template &src, Template &dst) const | ||
| 32 | + { | ||
| 33 | + // get the mat to send to the GPU | ||
| 34 | + GpuMat gpuMat_src, gpuMat_dst; | ||
| 35 | + | ||
| 36 | + try | ||
| 37 | + { | ||
| 38 | + // copy the contents to the GPU | ||
| 39 | + gpuMat_src.upload(src.m()); | ||
| 40 | + | ||
| 41 | + threshold(gpuMat_src, gpuMat_dst, 128.0, 255.0, CV_THRESH_BINARY); | ||
| 42 | + | ||
| 43 | + gpuMat_dst.download(dst.m()); | ||
| 44 | + } | ||
| 45 | + catch(const cv::Exception& ex) | ||
| 46 | + { | ||
| 47 | + cout << "Error: " << ex.what() << endl; | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + }; | ||
| 51 | + | ||
| 52 | + BR_REGISTER(Transform, CUDACustomThresholdTransform); | ||
| 53 | + | ||
| 54 | + namespace cuda { namespace customthreshold { | ||
| 55 | + texture<uchar, cudaTextureType2D, cudaReadModeElementType> tex_src(false, cudaFilterModePoint, cudaAddressModeClamp); | ||
| 56 | + struct SrcTex { | ||
| 57 | + __host__ SrcTex(int _xoff, int _yoff) : xoff(_xoff), yoff(_yoff) {} | ||
| 58 | + __device__ __forceinline__ int operator ()(int y, int x) const { | ||
| 59 | + return tex2D(tex_src, x + xoff, y + yoff); | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + __global__ void testKernel(const SrcTex src) { | ||
| 63 | + const int x = blockIdx.x * blockDim.x + threadIdx.x; | ||
| 64 | + const int y = blockIdx.y * blockDim.y + threadIdx.y; | ||
| 65 | + | ||
| 66 | + src(x, y) = 1;sajfflksajlkfjdsalkfjsadjflkdsaf | ||
| 67 | + } | ||
| 68 | + } | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | +#include "cglg/customthreshold.moc" | ||
| 72 | +*/ |
openbr/plugins/cuda/passthrough.cpp renamed to openbr/cuda-plugins/cglg/passthrough.cpp
openbr/plugins/cuda/threshold.cpp renamed to openbr/cuda-plugins/cglg/threshold.cpp
openbr/cuda-plugins/cuda-plugins.cmake
0 → 100644
| 1 | +# Optional Appendable CMake Variables: | ||
| 2 | +# BR_THIRDPARTY_CUDA_PLUGINS - Additional plugins | ||
| 3 | +# BR_THIRDPARTY_CUDA_PLUGINS_DIR - Additional folder(s) of plugins | ||
| 4 | +# BR_EXCLUDED_CUDA_PLUGINS - Plugins that should not be built | ||
| 5 | +# BR_THIRDPARTY_SRC - Additional source code needed by a plugin | ||
| 6 | +# BR_THIRDPARTY_LIBS - Additional libaries needed by a plugin | ||
| 7 | + | ||
| 8 | +# Also look for CMake modules in the thirdparty plugins folder(s) | ||
| 9 | +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${BR_THIRDPARTY_CUDA_PLUGINS_DIR}) | ||
| 10 | + | ||
| 11 | +# Gather all of the plugin subdirectories | ||
| 12 | +file(GLOB SUBFILES cuda-plugins/*) | ||
| 13 | +foreach(FILE ${SUBFILES}) | ||
| 14 | + if(IS_DIRECTORY ${FILE}) | ||
| 15 | + set(BR_CUDA_PLUGINS_DIR ${BR_CUDA_PLUGINS_DIR} ${FILE}) | ||
| 16 | + endif() | ||
| 17 | +endforeach() | ||
| 18 | +set(BR_CUDA_PLUGINS_DIR ${BR_CUDA_PLUGINS_DIR} cuda-plugins/) # Remove this when finished with reorg | ||
| 19 | + | ||
| 20 | +# Exclude pertinent plugins based on .cmake files | ||
| 21 | +mark_as_advanced(BR_EXCLUDED_CUDA_PLUGINS) | ||
| 22 | +foreach(DIR cuda-plugins/cmake ${BR_THIRDPARTY_CUDA_PLUGINS_DIR}) | ||
| 23 | + file(GLOB CMAKE_FILES ${DIR}/*.cmake) | ||
| 24 | + foreach(CMAKE_FILE ${CMAKE_FILES}) | ||
| 25 | + if (NOT ${CMAKE_FILE} MATCHES "Find.*cmake") | ||
| 26 | + include(${CMAKE_FILE}) | ||
| 27 | + endif() | ||
| 28 | + endforeach() | ||
| 29 | +endforeach() | ||
| 30 | + | ||
| 31 | +# Collect all source files except for excluded plugins | ||
| 32 | +foreach(DIR ${BR_CUDA_PLUGINS_DIR} ${BR_THIRDPARTY_CUDA_PLUGINS_DIR}) | ||
| 33 | + get_filename_component(DIR_NAME ${DIR} NAME) | ||
| 34 | + file(GLOB CUDA_PLUGINS ${DIR}/*.cu ${DIR}/*.cpp ${DIR}/*.h) | ||
| 35 | + foreach(CUDA_PLUGIN ${CUDA_PLUGINS}) | ||
| 36 | + get_filename_component(CUDA_PLUGIN_NAME ${CUDA_PLUGIN} NAME) | ||
| 37 | + set(EXCLUDE FALSE) | ||
| 38 | + foreach(EXCLUDED_CUDA_PLUGIN ${BR_EXCLUDED_CUDA_PLUGINS}) | ||
| 39 | + get_filename_component(EXCLUDED_CUDA_PLUGIN_NAME ${EXCLUDED_CUDA_PLUGIN} NAME) | ||
| 40 | + if (${CUDA_PLUGIN_NAME} STREQUAL ${EXCLUDED_CUDA_PLUGIN_NAME}) | ||
| 41 | + set(EXCLUDE TRUE) | ||
| 42 | + endif() | ||
| 43 | + endforeach() | ||
| 44 | + if(NOT ${EXCLUDE}) | ||
| 45 | + set(BR_THIRDPARTY_CUDA_PLUGINS ${BR_THIRDPARTY_CUDA_PLUGINS} ${CUDA_PLUGIN}) | ||
| 46 | + endif() | ||
| 47 | + endforeach() | ||
| 48 | +endforeach() | ||
| 49 | + | ||
| 50 | +set(BR_THIRDPARTY_CUDA_SRC ${BR_THIRDPARTY_CUDA_SRC} ${BR_THIRDPARTY_CUDA_PLUGINS}) |