Skip to content

Commit

Permalink
Remove global includes and use target include for GPU/CUDA (PointClou…
Browse files Browse the repository at this point in the history
…dLibrary#6010)

* Change to use target_include_directories.
Rearranged files between gpu_utils and gpu_containers, to break cyclic includes.

* Remove unncessary .cpp file.

* Revert moving of files.

* Copy error function to safe_call.

Added deprecated headers for notice to users.

* Revert include paths.

* Add missing include

* Added empty cu file.

* Add include to gpu people.
  • Loading branch information
larshg authored Aug 22, 2024
1 parent bfd615a commit 13d437b
Show file tree
Hide file tree
Showing 36 changed files with 318 additions and 288 deletions.
1 change: 0 additions & 1 deletion cuda/apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ if(NOT VTK_FOUND)
else()
set(DEFAULT TRUE)
set(REASON)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
endif()

PCL_SUBSYS_OPTION(build "${SUBSYS_NAME}" "${SUBSYS_DESC}" ${DEFAULT} "${REASON}")
Expand Down
1 change: 0 additions & 1 deletion cuda/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ set(common_incs
include/pcl/cuda/common/point_type_rgb.h
)

include_directories(./include)
set(LIB_NAME "pcl_${SUBSYS_NAME}")
set(EXT_DEPS CUDA)
PCL_MAKE_PKGCONFIG(${LIB_NAME} COMPONENT ${SUBSYS_NAME} DESC "${SUBSYS_DESC}"
Expand Down
1 change: 0 additions & 1 deletion cuda/features/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ set(incs
)

set(LIB_NAME "pcl_${SUBSYS_NAME}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
PCL_CUDA_ADD_LIBRARY(${LIB_NAME} COMPONENT ${SUBSYS_NAME} SOURCES ${srcs} ${incs})
target_link_libraries(${LIB_NAME} pcl_common)

Expand Down
1 change: 0 additions & 1 deletion cuda/io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ set(incs
)

set(LIB_NAME "pcl_${SUBSYS_NAME}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
PCL_CUDA_ADD_LIBRARY(${LIB_NAME} COMPONENT ${SUBSYS_NAME} SOURCES ${srcs} ${incs})
target_link_libraries(${LIB_NAME} pcl_common)

Expand Down
1 change: 0 additions & 1 deletion cuda/sample_consensus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ set(incs
)

set(LIB_NAME "pcl_${SUBSYS_NAME}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
PCL_CUDA_ADD_LIBRARY(${LIB_NAME} COMPONENT ${SUBSYS_NAME} SOURCES ${srcs} ${incs})
target_link_libraries("${LIB_NAME}" pcl_cuda_features)

Expand Down
1 change: 0 additions & 1 deletion cuda/segmentation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ set(srcs
)

set(LIB_NAME "pcl_${SUBSYS_NAME}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
PCL_CUDA_ADD_LIBRARY(${LIB_NAME} COMPONENT ${SUBSYS_NAME} SOURCES ${srcs} ${incs})
target_link_libraries(${LIB_NAME} pcl_common)

Expand Down
9 changes: 3 additions & 6 deletions gpu/containers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(SUBSYS_NAME gpu_containers)
set(SUBSYS_PATH gpu/containers)
set(SUBSYS_DESC "Containers with reference counting for GPU memory. This module can be compiled without Cuda Toolkit.")
set(SUBSYS_DEPS common)
set(SUBSYS_DEPS common gpu_utils)

PCL_SUBSYS_OPTION(build "${SUBSYS_NAME}" "${SUBSYS_DESC}" ON)
PCL_SUBSYS_DEPEND(build NAME ${SUBSYS_NAME} DEPS ${SUBSYS_DEPS})
Expand All @@ -12,19 +12,16 @@ if(NOT build)
return()
endif()

file(GLOB srcs src/*.cpp src/*.hpp)
file(GLOB srcs src/*.cpp src/*.cu src/*.hpp)
file(GLOB incs include/pcl/gpu/containers/*.h)
file(GLOB incs_impl include/pcl/gpu/containers/impl/*.hpp)

source_group("Header Files\\impl" FILES ${incs_impl})
list(APPEND incs ${incs_impl})

get_filename_component(UTILS_INC "${CMAKE_CURRENT_SOURCE_DIR}/../utils/include" REALPATH)

set(LIB_NAME "pcl_${SUBSYS_NAME}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include" ${UTILS_INC})
PCL_CUDA_ADD_LIBRARY(${LIB_NAME} COMPONENT ${SUBSYS_NAME} SOURCES ${srcs} ${incs})
target_link_libraries(${LIB_NAME} pcl_common)
target_link_libraries(${LIB_NAME} pcl_common pcl_gpu_utils)

#Ensures that CUDA is added and the project can compile as it uses cuda calls.
set_source_files_properties(src/device_memory.cpp PROPERTIES LANGUAGE CUDA)
Expand Down
154 changes: 154 additions & 0 deletions gpu/containers/include/pcl/gpu/containers/impl/repacks.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* Software License Agreement (BSD License)
*
* Copyright (c) 2011, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Anatoly Baskeheev, Itseez Ltd, (myname.mysurname@mycompany.com)
*/

#ifndef __PCL_GPU_UTILS_REPACKS_HPP__
#define __PCL_GPU_UTILS_REPACKS_HPP__

#include <pcl/gpu/containers/device_array.h>
#include <pcl/pcl_macros.h>
#include <pcl/point_types.h>

namespace pcl {
namespace gpu {
///////////////////////////////////////
/// This is an experimental code ///
///////////////////////////////////////

const int NoCP = 0xFFFFFFFF;

/** \brief Returns field copy operation code. */
inline int
cp(int from, int to)
{
return ((to & 0xF) << 4) + (from & 0xF);
}

/* Combines several field copy operations to one int (called rule) */
inline int
rule(int cp1, int cp2 = NoCP, int cp3 = NoCP, int cp4 = NoCP)
{
return (cp1 & 0xFF) + ((cp2 & 0xFF) << 8) + ((cp3 & 0xFF) << 16) +
((cp4 & 0xFF) << 24);
}

/* Combines performs all field copy operations in given rule array (can be 0, 1, or 16
* copies) */
void
copyFieldsImpl(
int in_size, int out_size, int rules[4], int size, const void* input, void* output);

template <typename PointIn, typename PointOut>
void
copyFieldsEx(const DeviceArray<PointIn>& src,
DeviceArray<PointOut>& dst,
int rule1,
int rule2 = NoCP,
int rule3 = NoCP,
int rule4 = NoCP)
{
int rules[4] = {rule1, rule2, rule3, rule4};
dst.create(src.size());
copyFieldsImpl(sizeof(PointIn) / sizeof(int),
sizeof(PointOut) / sizeof(int),
rules,
(int)src.size(),
src.ptr(),
dst.ptr());
}

void
copyFields(const DeviceArray<PointXYZ>& src, DeviceArray<PointNormal>& dst)
{
// PointXYZ.x (0) -> PointNormal.x (0)
// PointXYZ.y (1) -> PointNormal.y (1)
// PointXYZ.z (2) -> PointNormal.z (2)
copyFieldsEx(src, dst, rule(cp(0, 0), cp(1, 1), cp(2, 2)));
};

void
copyFields(const DeviceArray<Normal>& src, DeviceArray<PointNormal>& dst)
{
// PointXYZ.normal_x (0) -> PointNormal.normal_x (4)
// PointXYZ.normal_y (1) -> PointNormal.normal_y (5)
// PointXYZ.normal_z (2) -> PointNormal.normal_z (6)
// PointXYZ.curvature (4) -> PointNormal.curvature (8)
copyFieldsEx(src, dst, rule(cp(0, 4), cp(1, 5), cp(2, 6), cp(4, 8)));
};

void
copyFields(const DeviceArray<PointXYZRGBL>& src, DeviceArray<PointXYZ>& dst)
{
// PointXYZRGBL.x (0) -> PointXYZ.x (0)
// PointXYZRGBL.y (1) -> PointXYZ.y (1)
// PointXYZRGBL.z (2) -> PointXYZ.z (2)
copyFieldsEx(src, dst, rule(cp(0, 0), cp(1, 1), cp(2, 2)));
};

void
copyFields(const DeviceArray<PointXYZRGB>& src, DeviceArray<PointXYZ>& dst)
{
// PointXYZRGB.x (0) -> PointXYZ.x (0)
// PointXYZRGB.y (1) -> PointXYZ.y (1)
// PointXYZRGB.z (2) -> PointXYZ.z (2)
copyFieldsEx(src, dst, rule(cp(0, 0), cp(1, 1), cp(2, 2)));
};

void
copyFields(const DeviceArray<PointXYZRGBA>& src, DeviceArray<PointXYZ>& dst)
{
// PointXYZRGBA.x (0) -> PointXYZ.x (0)
// PointXYZRGBA.y (1) -> PointXYZ.y (1)
// PointXYZRGBA.z (2) -> PointXYZ.z (2)
copyFieldsEx(src, dst, rule(cp(0, 0), cp(1, 1), cp(2, 2)));
};

void
copyFieldsZ(const DeviceArray<PointXYZ>& src, DeviceArray<float>& dst)
{
// PointXYZRGBL.z (2) -> float (1)
copyFieldsEx(src, dst, rule(cp(2, 0)));
};

void
copyFieldsZ(const DeviceArray<PointXYZRGB>& src, DeviceArray<float>& dst)
{
// PointXYZRGBL.z (2) -> float (1)
copyFieldsEx(src, dst, rule(cp(2, 0)));
};
} // namespace gpu
} // namespace pcl

#endif /* __PCL_GPU_UTILS_REPACKS_HPP__ */
93 changes: 93 additions & 0 deletions gpu/containers/include/pcl/gpu/containers/impl/texture_binder.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Software License Agreement (BSD License)
*
* Copyright (c) 2011, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Anatoly Baskeheev, Itseez Ltd, (myname.mysurname@mycompany.com)
*/

#ifndef PCL_GPU_UTILS_TEXTURE_BINDER_HPP_
#define PCL_GPU_UTILS_TEXTURE_BINDER_HPP_

#include <pcl/gpu/containers/device_array.h>
#include <pcl/gpu/utils/safe_call.hpp>

namespace pcl {
namespace gpu {
class TextureBinder {
public:
template <class T, enum cudaTextureReadMode readMode>
TextureBinder(const DeviceArray2D<T>& arr, const struct texture<T, 2, readMode>& tex)
: texref(&tex)
{
cudaChannelFormatDesc desc = cudaCreateChannelDesc<T>();
cudaSafeCall(
cudaBindTexture2D(0, tex, arr.ptr(), desc, arr.cols(), arr.rows(), arr.step()));
}

template <class T, enum cudaTextureReadMode readMode>
TextureBinder(const DeviceArray<T>& arr, const struct texture<T, 1, readMode>& tex)
: texref(&tex)
{
cudaChannelFormatDesc desc = cudaCreateChannelDesc<T>();
cudaSafeCall(cudaBindTexture(0, tex, arr.ptr(), desc, arr.sizeBytes()));
}

template <class T, enum cudaTextureReadMode readMode>
TextureBinder(const PtrStepSz<T>& arr, const struct texture<T, 2, readMode>& tex)
: texref(&tex)
{
cudaChannelFormatDesc desc = cudaCreateChannelDesc<T>();
cudaSafeCall(
cudaBindTexture2D(0, tex, arr.data, desc, arr.cols, arr.rows, arr.step));
}

template <class T, enum cudaTextureReadMode readMode>
TextureBinder(const PtrSz<T>& arr, const struct texture<T, 1, readMode>& tex)
: texref(&tex)
{
cudaChannelFormatDesc desc = cudaCreateChannelDesc<T>();
cudaSafeCall(cudaBindTexture(0, tex, arr.data, desc, arr.size * arr.elemSize()));
}

~TextureBinder() { cudaSafeCall(cudaUnbindTexture(texref)); }

private:
const struct textureReference* texref;
};
} // namespace gpu

namespace device {
using pcl::gpu::TextureBinder;
}
} // namespace pcl

#endif /* PCL_GPU_UTILS_TEXTURE_BINDER_HPP_*/
6 changes: 3 additions & 3 deletions gpu/utils/src/repacks.cu → gpu/containers/src/repacks.cu
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "internal.hpp"
#include <pcl/gpu/utils/safe_call.hpp>
#include <pcl/pcl_exports.h>

#include <algorithm>
#include "pcl/gpu/utils/safe_call.hpp"
#include "pcl/pcl_exports.h"

namespace pcl
{
Expand Down
1 change: 0 additions & 1 deletion gpu/features/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ file(GLOB srcs_utils src/utils/*.hpp)
source_group("Source Files\\utils" FILES ${srcs_utils})

set(LIB_NAME "pcl_${SUBSYS_NAME}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/src")
PCL_CUDA_ADD_LIBRARY(${LIB_NAME} COMPONENT ${SUBSYS_NAME} SOURCES ${srcs} ${incs} ${cuda} ${srcs_utils} ${dev_incs})
target_link_libraries("${LIB_NAME}" pcl_gpu_utils pcl_gpu_containers pcl_gpu_octree)

Expand Down
20 changes: 1 addition & 19 deletions gpu/features/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,8 @@ if(NOT BUILD_TESTS)
return()
endif()

include_directories(
"${PCL_SOURCE_DIR}/test/gtest-1.6.0/include"
"${PCL_SOURCE_DIR}/test/gtest-1.6.0"
)

set(pcl_gtest_sources "${PCL_SOURCE_DIR}/test/gtest-1.6.0/src/gtest-all.cc")

set(the_test_target test_gpu_features)

get_filename_component(DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(INC1 "${DIR}/../../../io/include" REALPATH)
get_filename_component(INC2 "${DIR}/../../../features/include" REALPATH)
get_filename_component(INC3 "${DIR}/../../../kdtree/include" REALPATH)
get_filename_component(INC4 "${DIR}/../../../visualization/include" REALPATH)
get_filename_component(INC5 "${DIR}/../../../common/include" REALPATH)
get_filename_component(INC6 "${DIR}/../../../search/include" REALPATH)
get_filename_component(INC7 "${DIR}/../../../octree/include" REALPATH)


file(GLOB test_src *.cpp *.hpp)
list(APPEND test_src ${pcl_gtest_sources})
include_directories("${INC1}" "${INC2}" "${INC3}" "${INC4}" "${INC5}" "${INC6}" "${INC7}")
include_directories(SYSTEM ${VTK_INCLUDE_DIRS})

6 changes: 3 additions & 3 deletions gpu/kinfu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(SUBSYS_NAME gpu_kinfu)
set(SUBSYS_PATH gpu/kinfu)
set(SUBSYS_DESC "Kinect Fusion implementation")
set(SUBSYS_DEPS common io gpu_containers geometry search)
set(SUBSYS_DEPS common io gpu_utils gpu_containers geometry search)
if(${CUDA_VERSION_STRING} VERSION_GREATER_EQUAL "12.0")
set(DEFAULT FALSE)
set(REASON "Kinfu uses textures which was removed in CUDA 12")
Expand All @@ -26,10 +26,10 @@ source_group("Source Files\\cuda" FILES ${cuda})
source_group("Source Files" FILES ${srcs})

set(LIB_NAME "pcl_${SUBSYS_NAME}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/src")

PCL_CUDA_ADD_LIBRARY(${LIB_NAME} COMPONENT ${SUBSYS_NAME} SOURCES ${srcs} ${incs} ${cuda})
target_link_libraries(${LIB_NAME} pcl_gpu_containers)
target_link_libraries(${LIB_NAME} pcl_gpu_utils pcl_gpu_containers)
target_include_directories(${LIB_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)

target_compile_options(${LIB_NAME} PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--ftz=true;--prec-div=false;--prec-sqrt=false>)

Expand Down
Loading

0 comments on commit 13d437b

Please sign in to comment.