Skip to content
Snippets Groups Projects
Commit a04d7e04 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Refactor cuda init code

parent f124b911
No related branches found
No related tags found
No related merge requests found
Pipeline #13652 passed
......@@ -175,7 +175,7 @@ check_include_file_cxx("opencv2/cudastereo.hpp" HAVE_OPENCVCUDA)
find_program(CPPCHECK_FOUND cppcheck)
if (CPPCHECK_FOUND)
message(STATUS "Found cppcheck: will perform source checks")
set(CMAKE_CXX_CPPCHECK "cppcheck" "-D__align__(A)" "-DCUDARTAPI" "--enable=warning,performance,portability,style" "--inline-suppr" "--std=c++11" "--suppress=*:*catch.hpp" "--suppress=*:*elas*" "--suppress=*:*nanogui*" "--suppress=*:*json.hpp" "--quiet")
set(CMAKE_CXX_CPPCHECK "cppcheck" "-D__align__(A)" "-DCUDARTAPI" "--enable=warning,performance,style" "--inline-suppr" "--std=c++11" "--suppress=*:*catch.hpp" "--suppress=*:*elas*" "--suppress=*:*nanogui*" "--suppress=*:*json.hpp" "--quiet")
endif()
# include_directories(${PROJECT_SOURCE_DIR}/common/cpp/include)
......
......@@ -21,7 +21,7 @@ target_include_directories(ftlcommon PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE src)
target_link_libraries(ftlcommon Threads::Threads ${OS_LIBS} ${OpenCV_LIBS} ${PCL_LIBRARIES} ${URIPARSER_LIBRARIES})
target_link_libraries(ftlcommon Threads::Threads ${OS_LIBS} ${OpenCV_LIBS} ${PCL_LIBRARIES} ${URIPARSER_LIBRARIES} ${CUDA_LIBRARIES})
add_subdirectory(test)
......@@ -22,6 +22,12 @@
namespace ftl {
namespace cuda {
bool initialise();
bool hasCompute(int major, int minor);
int deviceCount();
/**
* Represent a CUDA texture object. Instances of this class can be used on both
* host and device. A texture object base cannot be constructed directly, it
......@@ -142,6 +148,7 @@ TextureObject<T>::TextureObject(const cv::cuda::GpuMat &d) {
resDesc.res.pitch2D.height = d.rows;
cudaTextureDesc texDesc;
// cppcheck-suppress memsetClassFloat
memset(&texDesc, 0, sizeof(texDesc));
texDesc.readMode = cudaReadModeElementType;
......@@ -175,6 +182,7 @@ TextureObject<T>::TextureObject(const cv::cuda::PtrStepSz<T> &d) {
resDesc.res.pitch2D.height = d.rows;
cudaTextureDesc texDesc;
// cppcheck-suppress memsetClassFloat
memset(&texDesc, 0, sizeof(texDesc));
texDesc.readMode = cudaReadModeElementType;
......@@ -207,6 +215,7 @@ TextureObject<T>::TextureObject(T *ptr, int pitch, int width, int height) {
resDesc.res.pitch2D.height = height;
cudaTextureDesc texDesc;
// cppcheck-suppress memsetClassFloat
memset(&texDesc, 0, sizeof(texDesc));
texDesc.readMode = cudaReadModeElementType;
......@@ -240,6 +249,7 @@ TextureObject<T>::TextureObject(size_t width, size_t height) {
resDesc.res.pitch2D.height = height;
cudaTextureDesc texDesc;
// cppcheck-suppress memsetClassFloat
memset(&texDesc, 0, sizeof(texDesc));
texDesc.readMode = cudaReadModeElementType;
cudaCreateTextureObject(&tex, &resDesc, &texDesc, NULL);
......
......@@ -20,6 +20,7 @@
#include <ftl/uri.hpp>
#include <ftl/threads.hpp>
#include <ftl/timer.hpp>
#include <ftl/cuda_common.hpp>
#include <fstream>
#include <string>
......@@ -519,6 +520,9 @@ Configurable *ftl::config::configure(int argc, char **argv, const std::string &r
// Some global settings
ftl::timer::setInterval(1000 / rootcfg->value("fps",20));
// Check CUDA
ftl::cuda::initialise();
int pool_size = rootcfg->value("thread_pool_factor", 2.0f)*std::thread::hardware_concurrency();
if (pool_size != ftl::pool.size()) ftl::pool.resize(pool_size);
......
......@@ -2,6 +2,40 @@
using ftl::cuda::TextureObjectBase;
static int dev_count = 0;
static std::vector<cudaDeviceProp> properties;
bool ftl::cuda::initialise() {
// Do an initial CUDA check
cudaSafeCall(cudaGetDeviceCount(&dev_count));
CHECK_GE(dev_count, 1) << "No CUDA devices found";
LOG(INFO) << "CUDA Devices (" << dev_count << "):";
properties.resize(dev_count);
for (int i=0; i<dev_count; i++) {
cudaSafeCall(cudaGetDeviceProperties(&properties[i], i));
LOG(INFO) << " - " << properties[i].name;
}
return true;
}
bool ftl::cuda::hasCompute(int major, int minor) {
int dev = -1;
cudaSafeCall(cudaGetDevice(&dev));
if (dev > 0) {
return properties[dev].major > major ||
(properties[dev].major == major && properties[dev].minor >= minor);
}
return false;
}
int ftl::cuda::deviceCount() {
return dev_count;
}
TextureObjectBase::~TextureObjectBase() {
free();
}
......
......@@ -7,12 +7,13 @@ add_executable(configurable_unit
../src/configuration.cpp
../src/loguru.cpp
../src/ctpl_stl.cpp
../src/cuda_common.cpp
./configurable_unit.cpp
)
target_include_directories(configurable_unit PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_link_libraries(configurable_unit
${URIPARSER_LIBRARIES}
Threads::Threads ${OS_LIBS})
Threads::Threads ${OS_LIBS} ${OpenCV_LIBS} ${CUDA_LIBRARIES})
### URI ########################################################################
add_executable(uri_unit
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment