Skip to content

Commit

Permalink
Fixed decltype problem with nvcc compiler. The fix should not influen…
Browse files Browse the repository at this point in the history
…ce any runtime behavior. Moved lvr2_mesh_builder to lvr2_mesh_tool since the executable is named like this.
  • Loading branch information
amock committed May 21, 2024
1 parent c3569a2 commit a780b03
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 6 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ option(BUILD_TOOLS "Build tools including lvr2_reconstruct" ON)
option(BUILD_TOOLS_EXPERIMENTAL "Build experimental tools" OFF)
option(WITH_DRACO "Build libraries with draco enabled" OFF)

## Compile as C++17
add_compile_options(-std=c++17)
set(CMAKE_CXX_STANDARD 17)

# DEFAULT RELEASE
if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
Expand Down Expand Up @@ -613,7 +616,7 @@ add_subdirectory(src/liblvr2)
if(BUILD_TOOLS)
add_subdirectory(src/tools/lvr2_reconstruct)
add_subdirectory(src/tools/lvr2_mesh_reducer)
add_subdirectory(src/tools/lvr2_hdf5_mesh_builder)
add_subdirectory(src/tools/lvr2_hdf5_mesh_tool)
endif(BUILD_TOOLS)

if(BUILD_TOOLS_EXPERIMENTAL)
Expand Down
5 changes: 3 additions & 2 deletions include/lvr2/geometry/BaseVector.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <cmath>
#include "Normal.hpp"
#include "lvr2/util/Panic.hpp"
#include "lvr2/util/TypeTraits.hpp"

namespace lvr2
{
Expand Down Expand Up @@ -258,7 +259,7 @@ BaseVector<CoordT> BaseVector<CoordT>::average(const CollectionT& vecs)
for (auto v: vecs)
{
static_assert(
std::is_same<decltype(v), BaseVector<CoordT>>::value,
arg_has_type<BaseVector<CoordT> >(v),
"Collection has to contain Vectors"
);
acc += v;
Expand All @@ -276,7 +277,7 @@ BaseVector<CoordT> BaseVector<CoordT>::centroid(const CollectionT& points)
for (auto p: points)
{
static_assert(
std::is_same<decltype(p), BaseVector<CoordT>>::value,
arg_has_type<BaseVector<CoordT> >(p),
"Type mismatch in centroid calculation."
);
acc += p;
Expand Down
3 changes: 2 additions & 1 deletion include/lvr2/geometry/Normal.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@


#include "lvr2/util/Panic.hpp"
#include "lvr2/util/TypeTraits.hpp"


namespace lvr2
Expand Down Expand Up @@ -66,7 +67,7 @@ Normal<CoordType>& Normal<CoordType>::average(const CollectionT& normals)
for (auto n: normals)
{
static_assert(
std::is_same<decltype(n), Normal<CoordType>>::value,
arg_has_type<Normal<CoordType> >(n),
"Collection has to contain Vectors"
);
acc += n.asVector();
Expand Down
48 changes: 48 additions & 0 deletions include/lvr2/util/TypeTraits.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef LVR2_UTIL_TYPE_TRAITS_HPP
#define LVR2_UTIL_TYPE_TRAITS_HPP

#include <type_traits>

namespace lvr2 {

/**
* @brief This type trait was necessary to
*
* Usage:
*
* @code
* auto v = vector[0];
*
* static_assert(
* arg_has_type<Vector<float> >(v),
* "Error: Type mismatch"
* );
*
* @endcode
*
* Why?
* The following code snipped was compiling in .cpp files but not in .cu
* - Ubuntu 20, GCC 9.4.0, NVCC 12.4
*
* @code
* auto v = vector[0];
*
* static_assert(
* std::is_same<decltype(v), BaseVector<float> >::value,
* "Error: Type mismatch"
* );
* @endcode
*
* Since cuda code sometimes includes BaseVector.hpp all cuda libraries wont compile.
* Problem was that `decltype` in .cu file is not working as expected
*
*/
template<typename T, typename AutoType>
static constexpr bool arg_has_type(const AutoType& t1)
{
return std::is_same<T, AutoType>::value;
}

} // namespace lvr2

#endif // LVR2_UTIL_TYPE_TRAITS_HPP
8 changes: 6 additions & 2 deletions src/liblvr2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ endif( NOT MSVC)
#####################################################################################

if(CUDA_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CUDA_SEPARABLE_COMPILATION ON)

# List of CUDA kernel code sources
set(LVR2_CUDA_SRC
Expand All @@ -214,6 +215,8 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif(VTK_FOUND)

message(STATUS "Building static LVR CUDA library")


cuda_add_library(lvr2cuda_static STATIC ${LVR2_CUDA_SRC})
target_link_libraries(lvr2cuda_static lvr2_static)

Expand All @@ -225,6 +228,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
cuda_add_library(lvr2cuda SHARED ${LVR2_CUDA_CPP_SRC} ${LVR2_CUDA_SRC})

target_link_libraries(lvr2cuda lvr2)
add_dependencies(lvr2cuda lvr2)

install(
TARGETS lvr2cuda_static lvr2cuda
Expand All @@ -233,5 +237,5 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

endif()
endif(CUDA_FOUND)

File renamed without changes.
File renamed without changes.

0 comments on commit a780b03

Please sign in to comment.