diff --git a/CMakeLists.txt b/CMakeLists.txt index d8047ea..1f41dc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,6 +108,7 @@ endif() if(UNIX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-strict-overflow -Wno-comment -Wno-unknown-pragmas -fvisibility=hidden -fno-omit-frame-pointer") set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib ${_qt5Core_install_prefix}/lib) + set(CUDA_NVCC_FLAGS "") # put NVCC compiler flags here if(NOT APPLE) if(${CMAKE_CXX_COMPILER} STREQUAL "/opt/intel/bin/icpc") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-intel -wd2196") diff --git a/openbr/CMakeLists.txt b/openbr/CMakeLists.txt index 6e9677c..c09d502 100644 --- a/openbr/CMakeLists.txt +++ b/openbr/CMakeLists.txt @@ -8,6 +8,7 @@ set(SRC openbr.cpp universal_template.cpp) aux_source_directory(core BR_CORE) include(plugins/plugins.cmake) +include(cuda-plugins/cuda-plugins.cmake) # Janus API option(BR_WITH_JANUS "Build IARPA Janus related applications." ON) @@ -28,6 +29,7 @@ if(NOT BR_EMBEDDED) install(FILES ${HEADERS} DESTINATION include/openbr/gui) endif() +# normal BR library declaration add_library(openbr SHARED ${SRC} ${BR_CORE} ${BR_JANUS} ${BR_GUI} ${BR_ICONS} ${BR_THIRDPARTY_SRC} ${BR_RESOURCES} ${NATURALSTRINGCOMPARE_SRC}) qt5_use_modules(openbr ${QT_DEPENDENCIES}) set_target_properties(openbr PROPERTIES @@ -37,6 +39,15 @@ set_target_properties(openbr PROPERTIES target_link_libraries(openbr ${BR_THIRDPARTY_LIBS}) add_cppcheck(openbr) +# CUDA portion of BR + +cuda_add_library(openbr-cuda SHARED ${BR_THIRDPARTY_CUDA_SRC}) +qt5_use_modules(openbr-cuda ${QT_DEPENDENCIES}) +set_target_properties(openbr-cuda PROPERTIES + DEFINE_SYMBOL BR_CUDA_LIBRARY + VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH} + SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}) + # Janus implementation if(BR_WITH_JANUS) set(JANUS_BUILD_PP5_WRAPPER ${BR_WITH_PP5} CACHE BOOL "Build Janus implementation using PittPatt 5") diff --git a/openbr/plugins/cuda/copyfrom.cpp b/openbr/cuda-plugins/cglg/copyfrom.cpp index e624aae..e624aae 100644 --- a/openbr/plugins/cuda/copyfrom.cpp +++ b/openbr/cuda-plugins/cglg/copyfrom.cpp diff --git a/openbr/plugins/cuda/copyto.cpp b/openbr/cuda-plugins/cglg/copyto.cpp index 36f683f..36f683f 100644 --- a/openbr/plugins/cuda/copyto.cpp +++ b/openbr/cuda-plugins/cglg/copyto.cpp diff --git a/openbr/cuda-plugins/cglg/customthreshold.cu b/openbr/cuda-plugins/cglg/customthreshold.cu new file mode 100644 index 0000000..b414b57 --- /dev/null +++ b/openbr/cuda-plugins/cglg/customthreshold.cu @@ -0,0 +1,72 @@ +/* +#include + +// external opencv CUDA interface +#include +#include + +// internal CUDA stuff +#include +#include +#include +#include +#include + +#include + +using namespace std; + +using namespace cv; +using namespace cv::gpu; +using namespace cv::cuda; +using namespace cv::cuda::device; + +namespace br +{ + class CUDACustomThresholdTransform : public UntrainableTransform + { + Q_OBJECT + +private: + void project(const Template &src, Template &dst) const + { + // get the mat to send to the GPU + GpuMat gpuMat_src, gpuMat_dst; + + try + { + // copy the contents to the GPU + gpuMat_src.upload(src.m()); + + threshold(gpuMat_src, gpuMat_dst, 128.0, 255.0, CV_THRESH_BINARY); + + gpuMat_dst.download(dst.m()); + } + catch(const cv::Exception& ex) + { + cout << "Error: " << ex.what() << endl; + } + } + }; + + BR_REGISTER(Transform, CUDACustomThresholdTransform); + + namespace cuda { namespace customthreshold { + texture tex_src(false, cudaFilterModePoint, cudaAddressModeClamp); + struct SrcTex { + __host__ SrcTex(int _xoff, int _yoff) : xoff(_xoff), yoff(_yoff) {} + __device__ __forceinline__ int operator ()(int y, int x) const { + return tex2D(tex_src, x + xoff, y + yoff); + } + } + __global__ void testKernel(const SrcTex src) { + const int x = blockIdx.x * blockDim.x + threadIdx.x; + const int y = blockIdx.y * blockDim.y + threadIdx.y; + + src(x, y) = 1;sajfflksajlkfjdsalkfjsadjflkdsaf + } + } +} + +#include "cglg/customthreshold.moc" +*/ diff --git a/openbr/plugins/cuda/passthrough.cpp b/openbr/cuda-plugins/cglg/passthrough.cpp index 5b1044d..5b1044d 100644 --- a/openbr/plugins/cuda/passthrough.cpp +++ b/openbr/cuda-plugins/cglg/passthrough.cpp diff --git a/openbr/plugins/cuda/threshold.cpp b/openbr/cuda-plugins/cglg/threshold.cpp index 219dccf..219dccf 100644 --- a/openbr/plugins/cuda/threshold.cpp +++ b/openbr/cuda-plugins/cglg/threshold.cpp diff --git a/openbr/cuda-plugins/cuda-plugins.cmake b/openbr/cuda-plugins/cuda-plugins.cmake new file mode 100644 index 0000000..a4bf886 --- /dev/null +++ b/openbr/cuda-plugins/cuda-plugins.cmake @@ -0,0 +1,50 @@ +# Optional Appendable CMake Variables: +# BR_THIRDPARTY_CUDA_PLUGINS - Additional plugins +# BR_THIRDPARTY_CUDA_PLUGINS_DIR - Additional folder(s) of plugins +# BR_EXCLUDED_CUDA_PLUGINS - Plugins that should not be built +# BR_THIRDPARTY_SRC - Additional source code needed by a plugin +# BR_THIRDPARTY_LIBS - Additional libaries needed by a plugin + +# Also look for CMake modules in the thirdparty plugins folder(s) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${BR_THIRDPARTY_CUDA_PLUGINS_DIR}) + +# Gather all of the plugin subdirectories +file(GLOB SUBFILES cuda-plugins/*) +foreach(FILE ${SUBFILES}) + if(IS_DIRECTORY ${FILE}) + set(BR_CUDA_PLUGINS_DIR ${BR_CUDA_PLUGINS_DIR} ${FILE}) + endif() +endforeach() +set(BR_CUDA_PLUGINS_DIR ${BR_CUDA_PLUGINS_DIR} cuda-plugins/) # Remove this when finished with reorg + +# Exclude pertinent plugins based on .cmake files +mark_as_advanced(BR_EXCLUDED_CUDA_PLUGINS) +foreach(DIR cuda-plugins/cmake ${BR_THIRDPARTY_CUDA_PLUGINS_DIR}) + file(GLOB CMAKE_FILES ${DIR}/*.cmake) + foreach(CMAKE_FILE ${CMAKE_FILES}) + if (NOT ${CMAKE_FILE} MATCHES "Find.*cmake") + include(${CMAKE_FILE}) + endif() + endforeach() +endforeach() + +# Collect all source files except for excluded plugins +foreach(DIR ${BR_CUDA_PLUGINS_DIR} ${BR_THIRDPARTY_CUDA_PLUGINS_DIR}) + get_filename_component(DIR_NAME ${DIR} NAME) + file(GLOB CUDA_PLUGINS ${DIR}/*.cu ${DIR}/*.cpp ${DIR}/*.h) + foreach(CUDA_PLUGIN ${CUDA_PLUGINS}) + get_filename_component(CUDA_PLUGIN_NAME ${CUDA_PLUGIN} NAME) + set(EXCLUDE FALSE) + foreach(EXCLUDED_CUDA_PLUGIN ${BR_EXCLUDED_CUDA_PLUGINS}) + get_filename_component(EXCLUDED_CUDA_PLUGIN_NAME ${EXCLUDED_CUDA_PLUGIN} NAME) + if (${CUDA_PLUGIN_NAME} STREQUAL ${EXCLUDED_CUDA_PLUGIN_NAME}) + set(EXCLUDE TRUE) + endif() + endforeach() + if(NOT ${EXCLUDE}) + set(BR_THIRDPARTY_CUDA_PLUGINS ${BR_THIRDPARTY_CUDA_PLUGINS} ${CUDA_PLUGIN}) + endif() + endforeach() +endforeach() + +set(BR_THIRDPARTY_CUDA_SRC ${BR_THIRDPARTY_CUDA_SRC} ${BR_THIRDPARTY_CUDA_PLUGINS})