Skip to content

Fix build against nanoflann >= 1.10 and SYCL+GCC libomp linkage - #2151

Draft
MGRAFF2006 wants to merge 2 commits into
alicevision:developfrom
MGRAFF2006:fix/nanoflann-1.10-and-sycl-gcc-libomp
Draft

Fix build against nanoflann >= 1.10 and SYCL+GCC libomp linkage#2151
MGRAFF2006 wants to merge 2 commits into
alicevision:developfrom
MGRAFF2006:fix/nanoflann-1.10-and-sycl-gcc-libomp

Conversation

@MGRAFF2006

Copy link
Copy Markdown

Description

Two small, independent build fixes needed to compile AliceVision (develop) against current toolchains/dependencies. Both are isolated and behavior-preserving.

1. fix(deps): expose IndexType in custom nanoflann result sets

nanoflann 1.10.0 casts the accessor to typename RESULTSET::IndexType in KDTreeBaseClass::searchLevel():

if (!result_set.addPoint(
        static_cast<typename RESULTSET::DistanceType>(dist),
        static_cast<typename RESULTSET::IndexType>(accessor)))   // <-- requires IndexType typedef

Two custom result-set classes only carried IndexType as a template parameter and did not publish it as a member typedef, so building against nanoflann ≥ 1.10 fails with:

error: no type named 'IndexType' in 'class aliceVision::fuseCut::SmallerPixSizeInRadius<double, long unsigned int>'
error: no type named 'IndexType' in 'class BestPointInRadius<double, long unsigned int>'

Fix: rename the template parameter to _IndexType and expose using IndexType = _IndexType; (mirroring the existing DistanceType typedef added for nanoflann 1.7). No behavior change.

Affected files:

  • src/aliceVision/fuseCut/Kdtree.hpp (SmallerPixSizeInRadius)
  • src/software/convert/main_importE57.cpp (BestPointInRadius)

2. fix(cmake): link libomp by full path for SYCL libraries built with GCC

When AliceVision is built with GCC but the SYCL depthmap sources are compiled by AdaptiveCpp/clang (-fopenmp), the resulting aliceVision_depthMap_sycl library depends on LLVM's OpenMP runtime (libomp, __kmpc_* symbols). The existing target_link_options(... "-lomp") does not reliably propagate to GCC-linked consumers, so linking executables fails:

libaliceVision_depthMap_sycl.so: undefined reference to `__kmpc_fork_call'
libaliceVision_depthMap_sycl.so: undefined reference to `__kmpc_push_num_threads'
libaliceVision_depthMap_sycl.so: undefined reference to `__kmpc_global_thread_num'

Fix: resolve libomp to a full path (searching the AdaptiveCpp/ROCm LLVM lib dirs via AdaptiveCpp_DIR / ROCM_PATH when available) and link it with target_link_libraries(... PUBLIC ...) so it propagates transitively. Falls back to -lomp if not found.

Affected file:

  • src/cmake/Helpers.cmake

Testing

Built develop end-to-end on Arch Linux (GCC 16, nanoflann 1.10.1, AdaptiveCpp 25.10 + ROCm 7.2, SYCL depthmap backend) — full build now completes and produces working aliceVision_* binaries including aliceVision_depthMapEstimation.

Notes

Marking as draft for maintainer review; happy to adjust the libomp discovery logic if there's a preferred pattern already used elsewhere in the CMake.

nanoflann 1.10.0 casts the accessor to typename RESULTSET::IndexType in
searchLevel(), so a result set class must publicly expose an IndexType
typedef. The custom result sets SmallerPixSizeInRadius (fuseCut) and
BestPointInRadius (importE57) only carried IndexType as a template
parameter; publish it as a member typedef so AliceVision builds against
nanoflann >= 1.10.
When AliceVision is compiled with GCC but the SYCL depthmap sources are
compiled by AdaptiveCpp/clang (-fopenmp), the resulting library depends on
LLVM's OpenMP runtime (libomp: __kmpc_* symbols). A bare '-lomp' link
option does not reliably propagate to GCC-linked consumers, causing
undefined references to __kmpc_fork_call / __kmpc_global_thread_num when
linking executables (e.g. aliceVision_depthMapEstimation).

Resolve libomp to a full path (searching the AdaptiveCpp/ROCm LLVM lib
dirs when known) and link it explicitly via target_link_libraries so it
propagates transitively; keep '-lomp' as a fallback.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates nanoflann-related classes in Kdtree.hpp and main_importE57.cpp to support nanoflann 1.10.0 by exposing the IndexType typedef. It also enhances the CMake build system to locate and explicitly link LLVM's OpenMP runtime (libomp) when compiling with GCC and SYCL. The review feedback suggests avoiding reserved C++ identifiers starting with an underscore and an uppercase letter, utilizing the exposed IndexType directly in member function signatures, and properly initializing the CMake hints list to prevent empty string entries from affecting find_library.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +50 to +57
template<typename _DistanceType, typename _IndexType = size_t>
class SmallerPixSizeInRadius
{
public:
// Necessary since nanoflann 1.7.0: https://github.com/jlblancoc/nanoflann/commit/9c84c4c32c2bfa7077cc8873dd3b5bcbb557da90
using DistanceType = _DistanceType;
// Necessary since nanoflann 1.10.0: result sets must expose an IndexType typedef
using IndexType = _IndexType;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In C++, identifiers starting with an underscore followed by an uppercase letter (such as _DistanceType and _IndexType) are reserved for the implementation in any scope. To avoid potential collisions with compiler internals or standard library headers, it is highly recommended to use standard names like DistanceT and IndexT for template parameters.

Suggested change
template<typename _DistanceType, typename _IndexType = size_t>
class SmallerPixSizeInRadius
{
public:
// Necessary since nanoflann 1.7.0: https://github.com/jlblancoc/nanoflann/commit/9c84c4c32c2bfa7077cc8873dd3b5bcbb557da90
using DistanceType = _DistanceType;
// Necessary since nanoflann 1.10.0: result sets must expose an IndexType typedef
using IndexType = _IndexType;
template<typename DistanceT, typename IndexT = size_t>
class SmallerPixSizeInRadius
{
public:
// Necessary since nanoflann 1.7.0: https://github.com/jlblancoc/nanoflann/commit/9c84c4c32c2bfa7077cc8873dd3b5bcbb557da90
using DistanceType = DistanceT;
// Necessary since nanoflann 1.10.0: result sets must expose an IndexType typedef
using IndexType = IndexT;

* @return true if the search should be continued, false if the results are sufficient
*/
inline bool addPoint(DistanceType dist, IndexType index)
inline bool addPoint(DistanceType dist, _IndexType index)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since IndexType is now a public member typedef of the class, we can use it directly in the member function signature instead of the template parameter _IndexType. This is cleaner and avoids using reserved names with leading underscores.

Suggested change
inline bool addPoint(DistanceType dist, _IndexType index)
inline bool addPoint(DistanceType dist, IndexType index)

Comment on lines +64 to +71
template<typename _DistanceType, typename _IndexType = size_t>
class BestPointInRadius
{
public:
// Necessary since nanoflann 1.7.0: https://github.com/jlblancoc/nanoflann/commit/9c84c4c32c2bfa7077cc8873dd3b5bcbb557da90
using DistanceType = _DistanceType;
// Necessary since nanoflann 1.10.0: result sets must expose an IndexType typedef
using IndexType = _IndexType;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In C++, identifiers starting with an underscore followed by an uppercase letter (such as _DistanceType and _IndexType) are reserved for the implementation in any scope. To avoid potential collisions with compiler internals or standard library headers, it is highly recommended to use standard names like DistanceT and IndexT for template parameters.

template<typename DistanceT, typename IndexT = size_t>
class BestPointInRadius
{
  public:
    // Necessary since nanoflann 1.7.0: https://github.com/jlblancoc/nanoflann/commit/9c84c4c32c2bfa7077cc8873dd3b5bcbb557da90
    using DistanceType = DistanceT;
    // Necessary since nanoflann 1.10.0: result sets must expose an IndexType typedef
    using IndexType = IndexT;

* @return true if the search should be continued, false if the results are sufficient
*/
inline bool addPoint(DistanceType dist, IndexType index)
inline bool addPoint(DistanceType dist, _IndexType index)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since IndexType is now a public member typedef of the class, we can use it directly in the member function signature instead of the template parameter _IndexType. This is cleaner and avoids using reserved names with leading underscores.

    inline bool addPoint(DistanceType dist, IndexType index)

Comment thread src/cmake/Helpers.cmake
# final link time. Resolve libomp to a full path (searching the
# AdaptiveCpp/ROCm LLVM lib dirs when known) and link it explicitly so it
# propagates to consumers; fall back to "-lomp" if it cannot be located.
set(_acpp_omp_hints "")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In CMake, set(VAR "") initializes the variable as a list containing a single empty string element "". When you later append elements using list(APPEND VAR ...), the list will start with an empty string, which can cause issues with commands like find_library that interpret empty strings as paths (often resolving to the current working directory). Using set(_acpp_omp_hints) properly initializes it as an empty list.

          set(_acpp_omp_hints)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant