Skip to content

Conversation

@yungyuc
Copy link
Member

@yungyuc yungyuc commented Nov 16, 2025

Without the patch, I got build error on my local macos 26:

cd /Users/yungyuc/work/modmesh/build/clion/restdebug/cpp/modmesh && /usr/bin/c++ cpp/modmesh/CMakeFiles/modmesh_primary.dir/toggle/pymod/toggle_pymod.cpp.o -MF CMakeFiles/modmesh_primary.dir/toggle/pymod/toggle_pymod.cpp.o.d -o CMakeFiles/modmesh_primary.dir/toggle/pymod/toggle_pymod.cpp.o -c /Users/yungyuc/work/modmesh/cpp/modmesh/toggle/pymod/toggle_pymod.cpp
In file included from /Users/yungyuc/work/modmesh/cpp/modmesh/buffer/SimpleArray.cpp:29:
In file included from /Users/yungyuc/work/modmesh/cpp/modmesh/buffer/SimpleArray.hpp:33:
In file included from /Users/yungyuc/work/modmesh/cpp/modmesh/simd/simd.hpp:34:
/Users/yungyuc/work/modmesh/cpp/modmesh/simd/neon/neon.hpp:63:34: error: use of undeclared identifier 'get_recommended_alignment'
   63 |     constexpr size_t alignment = get_recommended_alignment();
      |                                  ^
/Users/yungyuc/work/modmesh/cpp/modmesh/simd/neon/neon.hpp:64:13: error: no member named 'check_alignment' in namespace 'modmesh::simd::detail'
   64 |     detail::check_alignment(start, alignment, "check_between start");
      |     ~~~~~~~~^
/Users/yungyuc/work/modmesh/cpp/modmesh/simd/neon/neon.hpp:127:38: error: use of undeclared identifier 'get_recommended_alignment'
  127 |         constexpr size_t alignment = get_recommended_alignment();
      |                                      ^
/Users/yungyuc/work/modmesh/cpp/modmesh/simd/neon/neon.hpp:128:17: error: no member named 'check_alignment' in namespace 'modmesh::simd::detail'
  128 |         detail::check_alignment(dest, alignment, "add dest");
      |         ~~~~~~~~^

It seems to come from PR #628 , but I do not know why CI did not catch it.

@KHLee529 is simd_generic.hpp a good location for the helpers? I am not sure about it.

@yungyuc yungyuc self-assigned this Nov 16, 2025
@yungyuc yungyuc added bug Something isn't working build Build system and automation labels Nov 16, 2025
@yungyuc
Copy link
Member Author

yungyuc commented Nov 16, 2025

@tigercosmos @KHLee529 this fix is still work in progress and does not yet pass CI, but I am curious why we got the build error in the code base (or is it in my environment)?

@KHLee529
Copy link
Collaborator

As what I found from simply look into code, get_recommended_alignment and check_alignment is defined in file simd.hpp which is not included by neon.hpp. This may possibly be the reason of this compile error.
The reason why CI doesn't reproduce this problem might be that NDEBUG is not defined in CI compile option though I haven't confirm this.

@KHLee529
Copy link
Collaborator

@KHLee529 is simd_generic.hpp a good location for the helpers? I am not sure about it.

As for this question, in short, I prefer putting it in simd_support.hpp or even each platform.

When I designed the SIMD library, I treated simd.hpp as the only entry point of SIMD library and the library function interfaces in it are implemented based on it's functionality, that's why there're functions like check_between. In contrast, most of the SIMD library seems to wrap the different hardwares into same operations. For example, they might provide vec_load, vec_save functions to load/save data from memory to/back from vector registers, and vec_add, vec_subtract functions to simply add two vector registers together. Maybe the neon_alias.hpp can be a analogy to them.

simd_generic.hpp is designed to prevent malfunction when no SIMD feature is supported on the target platform so we can find also check_between function without SIMD operations in it. The flow chart may look like below.

flowchart TD
    A[SIMD::check_between] --> C{detect SIMD support}
    C --> |support neon| N[neon::check_between]
    C --> |support AVX512| X[avx512::check_between]
    C --> |not support any SIMD feature| G[generic::check_between]
Loading

So simd_support.hpp that currently provides only the platform detection function plays the role as a utility library for all SIMD features, that's why I prefer putting the helper functions there. Maybe it can be renamed to simd_util.hpp

In another way of thinking, if the get_recommended_alignement functions are platform-specific features, they may also be properly located in the directories of each platform like set it to 16 in neon.hpp and 0 in simd_generic.hpp and 64 for avx512.hpp in the future.

@yungyuc @tigercosmos This is my thought to this SIMD library. Please comment or suggest your opinion.

@tigercosmos
Copy link
Collaborator

I've tested the latest master locally on Ubuntu and macOS, and I haven't encountered any compilation errors. However, I agree with @KHLee529's solution.

@yungyuc yungyuc force-pushed the bugfix/simd-helper-declaration branch from 177bdc5 to d3d3d23 Compare November 16, 2025 06:16
#endif // NDEBUG

// Get the recommended memory alignment for SIMD operations based on the detected SIMD instruction set.
inline constexpr size_t get_recommended_alignment()
Copy link
Member Author

Choose a reason for hiding this comment

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

I think get_recommended_alignment should be an implementation detail in this early stage of development. If we find it is a generally useful helper, then take it outside detail in the future.

{
#if defined(__aarch64__) || defined(__arm__)
return 16;
#elif defined(__AVX512F__)
Copy link
Member Author

Choose a reason for hiding this comment

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

The helper contains non-NEON conditionals that should be refactored in the future.

{
using namespace detail;
switch (detect_simd())
switch (detail::detect_simd())
Copy link
Member Author

Choose a reason for hiding this comment

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

We should not using namespace detail, or defeat part of the purpose of the namespace detail. I created issue #631 to get rid of the misusing.

@yungyuc
Copy link
Member Author

yungyuc commented Nov 16, 2025

Thank you, @tigercosmos @KHLee529 . I am following @KHLee529 recommendation to move the NEON-specific code to neon.hpp. More refactoring may be done as we go.

PR is ready for review. The code passed CI in my fork.

@yungyuc yungyuc changed the title Move SIMD helpers from simd.hpp to simd_generic.hpp Move NEON SIMD helpers from simd.hpp to neon.hpp Nov 16, 2025
@yungyuc yungyuc marked this pull request as ready for review November 16, 2025 06:22
return 16;
#elif defined(__AVX512F__)
return 64;
#elif defined(__AVX__) || defined(__AVX2__)
Copy link
Collaborator

Choose a reason for hiding this comment

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

if we put this function in NEON, then we don't need these lines.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's OK. The non-NEON conditional code is OK as a hint for a need for refactoring.

To make it clear, I added a comment for TODO 3 lines above.

@yungyuc yungyuc merged commit 0a4b0a4 into solvcon:master Nov 16, 2025
10 of 11 checks passed
@yungyuc
Copy link
Member Author

yungyuc commented Nov 16, 2025

macos-15 devbuild has run for more than 3 hours. Merge without waiting for it.

@yungyuc yungyuc deleted the bugfix/simd-helper-declaration branch November 16, 2025 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working build Build system and automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants