Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force the alignment of SoA and AoS Particles #4375

Merged
merged 4 commits into from
Mar 26, 2025

Conversation

WeiqunZhang
Copy link
Member

@WeiqunZhang WeiqunZhang commented Mar 14, 2025

This fixes build issues on 32-bit Linux. This should not affect 64 bits machines.

Fix #4371

@WeiqunZhang WeiqunZhang requested a review from ax3l March 14, 2025 05:02
@WeiqunZhang WeiqunZhang linked an issue Mar 14, 2025 that may be closed by this pull request
@ax3l ax3l self-assigned this Mar 14, 2025
@ax3l ax3l added the bug label Mar 14, 2025
@WeiqunZhang WeiqunZhang changed the title Force the alignment of SoAParticle to 8 Force the alignment of SoA and AoS Particles Mar 14, 2025
@ax3l
Copy link
Member

ax3l commented Mar 15, 2025

@WeiqunZhang I see still the same error with this patch in BLAST-ImpactX/impactx-wheels#3

@ax3l
Copy link
Member

ax3l commented Mar 15, 2025

Oh, I think I tested the first version. Will restart with the latest changes now.

@ax3l
Copy link
Member

ax3l commented Mar 15, 2025

Ok, improvement. Now only the legacy data type (AoS + SoA) has the same alignment issue, too, e.g., for amrex::Particle<2, 1> in void amrex::ParticleContainer_impl

    [ 60%] Building CXX object _deps/fetchedpyamrex-build/CMakeFiles/pyAMReX_3d.dir/src/Particle/ParticleContainer_FHDeX.cpp.o
    cd /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpyamrex-build && /opt/rh/devtoolset-10/root/usr/bin/c++ -DAMREX_SPACEDIM=3 -DpyAMReX_3d_EXPORTS -I/project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpyamrex-src/src -I/usr/local/share/amrex/C_scripts -isystem /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpybind11-src/include -isystem /opt/python/cp39-cp39/include/python3.9 -Wall -Wextra -Wpedantic -Wshadow -Woverloaded-virtual -Wunreachable-code -O3 -DNDEBUG -std=c++17 -fPIC -fvisibility=hidden -pthread -flto -fno-fat-lto-objects -MD -MT _deps/fetchedpyamrex-build/CMakeFiles/pyAMReX_3d.dir/src/Particle/ParticleContainer_FHDeX.cpp.o -MF CMakeFiles/pyAMReX_3d.dir/src/Particle/ParticleContainer_FHDeX.cpp.o.d -o CMakeFiles/pyAMReX_3d.dir/src/Particle/ParticleContainer_FHDeX.cpp.o -c /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpyamrex-src/src/Particle/ParticleContainer_FHDeX.cpp
    In file included from /usr/local/include/AMReX_ParticleContainer.H:1542,
                     from /usr/local/include/AMReX_Particles.H:5,
                     from /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpyamrex-src/src/Particle/ParticleContainer.H:20,
                     from /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpyamrex-src/src/Particle/ParticleContainer.cpp:6:
    /usr/local/include/AMReX_ParticleContainerI.H: In instantiation of ‘void amrex::ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::Initialize() [with T_ParticleType = amrex::Particle<2, 1>; int T_NArrayReal = 3; int T_NArrayInt = 1; Allocator = amrex::PinnedArenaAllocator; T_CellAssignor = amrex::DefaultAssignor]’:
    /usr/local/include/AMReX_ParticleContainer.H:204:9:   required from ‘amrex::ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::ParticleContainer_impl() [with T_ParticleType = amrex::Particle<2, 1>; int T_NArrayReal = 3; int T_NArrayInt = 1; Allocator = amrex::PinnedArenaAllocator; T_CellAssignor = amrex::DefaultAssignor]’
    /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpybind11-src/include/pybind11/detail/init.h:76:12:   required from ‘Class* pybind11::detail::initimpl::construct_or_initialize(Args&& ...) [with Class = amrex::ParticleContainer_impl<amrex::Particle<2, 1>, 3, 1, amrex::PinnedArenaAllocator, amrex::DefaultAssignor>; Args = {}; typename std::enable_if<std::is_constructible<_Tp, _Args>::value, int>::type <anonymous> = 0]’
    /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpybind11-src/include/pybind11/detail/init.h:208:70:   required from ‘static void pybind11::detail::initimpl::constructor<Args>::execute(Class&, const Extra& ...) [with Class = pybind11::class_<amrex::ParticleContainer_impl<amrex::Particle<2, 1>, 3, 1, amrex::PinnedArenaAllocator, amrex::DefaultAssignor> >; Extra = {}; typename std::enable_if<(! Class::has_alias), int>::type <anonymous> = 0; Args = {}]’
    /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpybind11-src/include/pybind11/pybind11.h:1659:21:   required from ‘pybind11::class_<type_, options>& pybind11::class_<type_, options>::def(const pybind11::detail::initimpl::constructor<Args ...>&, const Extra& ...) [with Args = {}; Extra = {}; type_ = amrex::ParticleContainer_impl<amrex::Particle<2, 1>, 3, 1, amrex::PinnedArenaAllocator, amrex::DefaultAssignor>; options = {}]’
    /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpyamrex-src/src/Particle/ParticleContainer.H:178:13:   required from ‘void make_ParticleContainer_and_Iterators(pybind11::module&, std::string) [with T_ParticleType = amrex::Particle<2, 1>; int T_NArrayReal = 3; int T_NArrayInt = 1; Allocator = amrex::PinnedArenaAllocator; pybind11::module = pybind11::module_; std::string = std::basic_string<char>]’
    /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpyamrex-src/src/Particle/ParticleContainer.H:513:41:   required from ‘void make_ParticleContainer_and_Iterators(pybind11::module&) [with T_ParticleType = amrex::Particle<2, 1>; int T_NArrayReal = 3; int T_NArrayInt = 1; pybind11::module = pybind11::module_]’
    /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpyamrex-src/src/Particle/ParticleContainer.cpp:57:65:   required from here
    /usr/local/include/AMReX_ParticleContainerI.H:77:61: error: static assertion failed: sizeof ParticleType is not a multiple of sizeof RealType
       77 |         static_assert(sizeof(ParticleType)%sizeof(RealType) == 0,
          |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
    /usr/local/include/AMReX_ParticleContainerI.H: In instantiation of ‘void amrex::ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::Initialize() [with T_ParticleType = amrex::Particle<2, 1>; int T_NArrayReal = 3; int T_NArrayInt = 1; Allocator = std::allocator; T_CellAssignor = amrex::DefaultAssignor]’:
    /usr/local/include/AMReX_ParticleContainer.H:204:9:   required from ‘amrex::ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::ParticleContainer_impl() [with T_ParticleType = amrex::Particle<2, 1>; int T_NArrayReal = 3; int T_NArrayInt = 1; Allocator = std::allocator; T_CellAssignor = amrex::DefaultAssignor]’
    /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpybind11-src/include/pybind11/detail/init.h:76:12:   required from ‘Class* pybind11::detail::initimpl::construct_or_initialize(Args&& ...) [with Class = amrex::ParticleContainer_impl<amrex::Particle<2, 1>, 3, 1, std::allocator, amrex::DefaultAssignor>; Args = {}; typename std::enable_if<std::is_constructible<_Tp, _Args>::value, int>::type <anonymous> = 0]’
    /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpybind11-src/include/pybind11/detail/init.h:208:70:   required from ‘static void pybind11::detail::initimpl::constructor<Args>::execute(Class&, const Extra& ...) [with Class = pybind11::class_<amrex::ParticleContainer_impl<amrex::Particle<2, 1>, 3, 1, std::allocator, amrex::DefaultAssignor> >; Extra = {}; typename std::enable_if<(! Class::has_alias), int>::type <anonymous> = 0; Args = {}]’
    /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpybind11-src/include/pybind11/pybind11.h:1659:21:   required from ‘pybind11::class_<type_, options>& pybind11::class_<type_, options>::def(const pybind11::detail::initimpl::constructor<Args ...>&, const Extra& ...) [with Args = {}; Extra = {}; type_ = amrex::ParticleContainer_impl<amrex::Particle<2, 1>, 3, 1, std::allocator, amrex::DefaultAssignor>; options = {}]’
    /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpyamrex-src/src/Particle/ParticleContainer.H:178:13:   required from ‘void make_ParticleContainer_and_Iterators(pybind11::module&, std::string) [with T_ParticleType = amrex::Particle<2, 1>; int T_NArrayReal = 3; int T_NArrayInt = 1; Allocator = std::allocator; pybind11::module = pybind11::module_; std::string = std::basic_string<char>]’
    /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpyamrex-src/src/Particle/ParticleContainer.H:531:37:   required from ‘void make_ParticleContainer_and_Iterators(pybind11::module&) [with T_ParticleType = amrex::Particle<2, 1>; int T_NArrayReal = 3; int T_NArrayInt = 1; pybind11::module = pybind11::module_]’
    /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpyamrex-src/src/Particle/ParticleContainer.cpp:57:65:   required from here
    /usr/local/include/AMReX_ParticleContainerI.H:77:61: error: static assertion failed: sizeof ParticleType is not a multiple of sizeof RealType
    /usr/local/include/AMReX_ParticleContainerI.H: In instantiation of ‘void amrex::ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::Initialize() [with T_ParticleType = amrex::Particle<2, 1>; int T_NArrayReal = 3; int T_NArrayInt = 1; Allocator = amrex::ArenaAllocator; T_CellAssignor = amrex::DefaultAssignor]’:
    /usr/local/include/AMReX_ParticleContainer.H:204:9:   required from ‘amrex::ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::ParticleContainer_impl() [with T_ParticleType = amrex::Particle<2, 1>; int T_NArrayReal = 3; int T_NArrayInt = 1; Allocator = amrex::ArenaAllocator; T_CellAssignor = amrex::DefaultAssignor]’
    /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpybind11-src/include/pybind11/detail/init.h:76:12:   required from ‘Class* pybind11::detail::initimpl::construct_or_initialize(Args&& ...) [with Class = amrex::ParticleContainer_impl<amrex::Particle<2, 1>, 3, 1, amrex::ArenaAllocator, amrex::DefaultAssignor>; Args = {}; typename std::enable_if<std::is_constructible<_Tp, _Args>::value, int>::type <anonymous> = 0]’
    /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpybind11-src/include/pybind11/detail/init.h:208:70:   required from ‘static void pybind11::detail::initimpl::constructor<Args>::execute(Class&, const Extra& ...) [with Class = pybind11::class_<amrex::ParticleContainer_impl<amrex::Particle<2, 1>, 3, 1, amrex::ArenaAllocator, amrex::DefaultAssignor> >; Extra = {}; typename std::enable_if<(! Class::has_alias), int>::type <anonymous> = 0; Args = {}]’
    /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpybind11-src/include/pybind11/pybind11.h:1659:21:   required from ‘pybind11::class_<type_, options>& pybind11::class_<type_, options>::def(const pybind11::detail::initimpl::constructor<Args ...>&, const Extra& ...) [with Args = {}; Extra = {}; type_ = amrex::ParticleContainer_impl<amrex::Particle<2, 1>, 3, 1, amrex::ArenaAllocator, amrex::DefaultAssignor>; options = {}]’
    /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpyamrex-src/src/Particle/ParticleContainer.H:178:13:   required from ‘void make_ParticleContainer_and_Iterators(pybind11::module&, std::string) [with T_ParticleType = amrex::Particle<2, 1>; int T_NArrayReal = 3; int T_NArrayInt = 1; Allocator = amrex::ArenaAllocator; pybind11::module = pybind11::module_; std::string = std::basic_string<char>]’
    /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpyamrex-src/src/Particle/ParticleContainer.H:533:35:   required from ‘void make_ParticleContainer_and_Iterators(pybind11::module&) [with T_ParticleType = amrex::Particle<2, 1>; int T_NArrayReal = 3; int T_NArrayInt = 1; pybind11::module = pybind11::module_]’
    /project/build/temp.linux-i686-cpython-39/Release/_deps/fetchedpyamrex-src/src/Particle/ParticleContainer.cpp:57:65:   required from here
    /usr/local/include/AMReX_ParticleContainerI.H:77:61: error: static assertion failed: sizeof ParticleType is not a multiple of sizeof RealType

@ax3l
Copy link
Member

ax3l commented Mar 15, 2025

Oh wait, that was patched here as well. So does not work just yet it seems.

@ax3l ax3l force-pushed the fix_particle_alignment branch 13 times, most recently from c92653a to 0d3c5ba Compare March 21, 2025 07:06
@ax3l
Copy link
Member

ax3l commented Mar 21, 2025

Added a CI runner that shows the issue (and fixed a few more musl issues in #4385 on the way).

Status is still:

/home/runner/work/amrex/amrex/Src/Particle/AMReX_ParticleContainerI.H:77:61: error: static assertion failed: sizeof ParticleType is not a multiple of sizeof RealType
   77 |         static_assert(sizeof(ParticleType)%sizeof(RealType) == 0,
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
/home/runner/work/amrex/amrex/Src/Particle/AMReX_ParticleContainerI.H:77:61: note: the comparison reduces to '(4 == 0)'

If you have more ideas, you can push them here and see if the AlpineLinux runner passes.

@WeiqunZhang WeiqunZhang force-pushed the fix_particle_alignment branch from 0732f06 to ae329ec Compare March 24, 2025 23:34
@WeiqunZhang
Copy link
Member Author

There might be a compiler bug that does not treat multiple alignas statements correctly. It is supposed to use the strictest one, but it might be using the last one. If I only use one, the Particle CI tests pass.

This fixes build issues on 32-bit Linux. This should not affect 64 bits
machines.
@WeiqunZhang WeiqunZhang force-pushed the fix_particle_alignment branch from ae329ec to 7e14c64 Compare March 24, 2025 23:53
@WeiqunZhang WeiqunZhang requested a review from atmyers March 24, 2025 23:53
@WeiqunZhang WeiqunZhang force-pushed the fix_particle_alignment branch from 7e14c64 to 8a05f84 Compare March 24, 2025 23:56
@atmyers atmyers merged commit 546cc5e into AMReX-Codes:development Mar 26, 2025
75 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiling for 32bit Linux
3 participants