Commit 4148de2f0b5c15b909824bfa0de8ba67b0956b32
1 parent
97c9bd44
added NVIDIA kernel compatible build environment
Showing
11 changed files
with
35 additions
and
141 deletions
CMakeLists.txt
| ... | ... | @@ -108,7 +108,6 @@ endif() |
| 108 | 108 | if(UNIX) |
| 109 | 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 | 110 | set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib ${_qt5Core_install_prefix}/lib) |
| 111 | - set(CUDA_NVCC_FLAGS "") # put NVCC compiler flags here | |
| 112 | 111 | if(NOT APPLE) |
| 113 | 112 | if(${CMAKE_CXX_COMPILER} STREQUAL "/opt/intel/bin/icpc") |
| 114 | 113 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-intel -wd2196") | ... | ... |
app/br/CMakeLists.txt
openbr/CMakeLists.txt
| ... | ... | @@ -8,7 +8,12 @@ set(SRC openbr.cpp |
| 8 | 8 | universal_template.cpp) |
| 9 | 9 | aux_source_directory(core BR_CORE) |
| 10 | 10 | include(plugins/plugins.cmake) |
| 11 | -include(cuda-plugins/cuda-plugins.cmake) | |
| 11 | + | |
| 12 | +# CUDA shit | |
| 13 | +FIND_PACKAGE(CUDA REQUIRED) | |
| 14 | +SET(CUDA_SEPARABLE_COMPILATION ON) | |
| 15 | +SET(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -arch=sm_20;--compiler-options "-fPIC") | |
| 16 | +SET(CUDA_VERBOSE_BUILD ON) | |
| 12 | 17 | |
| 13 | 18 | # Janus API |
| 14 | 19 | option(BR_WITH_JANUS "Build IARPA Janus related applications." ON) |
| ... | ... | @@ -29,25 +34,18 @@ if(NOT BR_EMBEDDED) |
| 29 | 34 | install(FILES ${HEADERS} DESTINATION include/openbr/gui) |
| 30 | 35 | endif() |
| 31 | 36 | |
| 32 | -# normal BR library declaration | |
| 33 | -add_library(openbr SHARED ${SRC} ${BR_CORE} ${BR_JANUS} ${BR_GUI} ${BR_ICONS} ${BR_THIRDPARTY_SRC} ${BR_RESOURCES} ${NATURALSTRINGCOMPARE_SRC}) | |
| 37 | +# normal BR library declaration - added openbr-cuda library | |
| 38 | +message(STATUS "BR_THIRDPARTY_SRC") | |
| 39 | +message(STATUS ${BR_THIRDPARTY_SRC}) | |
| 40 | +cuda_add_library(openbr SHARED ${SRC} ${BR_CORE} ${BR_JANUS} ${BR_GUI} ${BR_ICONS} ${BR_THIRDPARTY_SRC} ${BR_RESOURCES} ${NATURALSTRINGCOMPARE_SRC}) | |
| 34 | 41 | qt5_use_modules(openbr ${QT_DEPENDENCIES}) |
| 35 | 42 | set_target_properties(openbr PROPERTIES |
| 36 | 43 | DEFINE_SYMBOL BR_LIBRARY |
| 37 | 44 | VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH} |
| 38 | 45 | SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}) |
| 39 | -target_link_libraries(openbr ${BR_THIRDPARTY_LIBS}) | |
| 46 | +target_link_libraries(openbr ${BR_THIRDPARTY_LIBS} ${CUDA_LIBRARIES}) | |
| 40 | 47 | add_cppcheck(openbr) |
| 41 | 48 | |
| 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 | - | |
| 51 | 49 | # Janus implementation |
| 52 | 50 | if(BR_WITH_JANUS) |
| 53 | 51 | set(JANUS_BUILD_PP5_WRAPPER ${BR_WITH_PP5} CACHE BOOL "Build Janus implementation using PittPatt 5") | ... | ... |
openbr/cuda-plugins/cglg/customthreshold.cu deleted
| 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/cuda-plugins/cuda-plugins.cmake deleted
| 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}) |
openbr/cuda-plugins/cglg/copyfrom.cpp renamed to openbr/plugins/cuda/copyfrom.cpp
openbr/cuda-plugins/cglg/copyto.cpp renamed to openbr/plugins/cuda/copyto.cpp
openbr/cuda-plugins/cglg/passthrough.cpp renamed to openbr/plugins/cuda/passthrough.cpp
| 1 | -#include <opencv2/imgproc/imgproc.hpp> | |
| 2 | - | |
| 3 | 1 | #include <openbr/plugins/openbr_internal.h> |
| 4 | 2 | |
| 3 | +#include <opencv2/imgproc/imgproc.hpp> | |
| 4 | +#include <opencv2/gpu/gpu.hpp> | |
| 5 | + | |
| 5 | 6 | using namespace cv; |
| 7 | +using namespace cv::gpu; | |
| 8 | + | |
| 9 | +extern void br_cuda_device_wrapper(); | |
| 6 | 10 | |
| 7 | 11 | namespace br |
| 8 | 12 | { |
| ... | ... | @@ -13,7 +17,16 @@ namespace br |
| 13 | 17 | private: |
| 14 | 18 | void project(const Template &src, Template &dst) const |
| 15 | 19 | { |
| 16 | - dst = src; | |
| 20 | + // upload the src mat to the GPU | |
| 21 | + GpuMat srcGpuMat, dstGpuMat; | |
| 22 | + srcGpuMat.upload(src.m()); | |
| 23 | + dstGpuMat.upload(src.m()); | |
| 24 | + | |
| 25 | + br_cuda_device_wrapper(); | |
| 26 | + | |
| 27 | + dstGpuMat.download(dst.m()); | |
| 28 | + | |
| 29 | + // TODO(colin): add delete code | |
| 17 | 30 | } |
| 18 | 31 | }; |
| 19 | 32 | ... | ... |
openbr/plugins/cuda/passthrough.cu
0 → 100644
openbr/cuda-plugins/cglg/threshold.cpp renamed to openbr/plugins/cuda/threshold.cpp
openbr/plugins/plugins.cmake
| ... | ... | @@ -31,7 +31,7 @@ endforeach() |
| 31 | 31 | # Collect all source files except for excluded plugins |
| 32 | 32 | foreach(DIR ${BR_PLUGINS_DIR} ${BR_THIRDPARTY_PLUGINS_DIR}) |
| 33 | 33 | get_filename_component(DIR_NAME ${DIR} NAME) |
| 34 | - file(GLOB PLUGINS ${DIR}/*.cpp ${DIR}/*.h) | |
| 34 | + file(GLOB PLUGINS ${DIR}/*.cpp ${DIR}/*.cu ${DIR}/*.h) | |
| 35 | 35 | foreach(PLUGIN ${PLUGINS}) |
| 36 | 36 | get_filename_component(PLUGIN_NAME ${PLUGIN} NAME) |
| 37 | 37 | set(EXCLUDE FALSE) | ... | ... |