loco-3d / crocoddyl

Crocoddyl is an optimal control library for robot control under contact sequence. Its solver is based on various efficient Differential Dynamic Programming (DDP)-like algorithms
BSD 3-Clause "New" or "Revised" License
841 stars 172 forks source link

Enabling vectorization #1166

Closed will-gerard closed 11 months ago

will-gerard commented 1 year ago

I am trying to enable vectorization to maximize performance, but haven't been successful yet, and I'm wondering if anyone can give me guidance. I see the ENABLE_VECTORIZATION option in the CMakeLists.txt file, so that is what I am using for crocoddyl, and when I configure pinocchio I provide -DCMAKE_CXX_FLAGS="-march=native", since the enable vectorization option isn't recognized. Attempting to use the resulting crocoddyl build segfaults, so I built in debug mode to use gdb, and I see the following trace:


(gdb) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=140737238532096) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=140737238532096) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=140737238532096, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00007ffff0042476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007ffff00287f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x00007ffff00896f6 in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7ffff01dbb8c "%s\n") at ../sysdeps/posix/libc_fatal.c:155
#6  0x00007ffff00a0d7c in malloc_printerr (str=str@entry=0x7ffff01de7b0 "double free or corruption (out)") at ./malloc/malloc.c:5664
#7  0x00007ffff00a2ef0 in _int_free (av=0x7ffff0219c80 <main_arena>, p=0x5555ac70e5d0, have_lock=<optimized out>) at ./malloc/malloc.c:4588
#8  0x00007ffff00a54d3 in __GI___libc_free (mem=<optimized out>) at ./malloc/malloc.c:3391
#9  0x00007ffff1266586 in crocoddyl::SolverDDP::~SolverDDP() () from /usr/local/lib/libcrocoddyl.so
#10 0x0000555555590eb6 in crocoddylSolve<float> (state_size=14, control_size=7, h_ee_goal_traj=<optimized out>, Q_vec=..., QF_vec=..., R_vec=..., EE_penalty_vec=..., state=..., actuation=..., ee_joint_frame_id=17, h_xu=0x555556706e20, timestep=0.015625, knot_points=32,
    ee_pos_size=6) at /home/a2rlab/anaconda3/envs/pinocchio/x86_64-conda-linux-gnu/include/c++/10.4.0/ext/new_allocator.h:89
#11 0x0000555555591d30 in track<float, double> (traj_steps=666, d_eePos_traj=0x7fffa3a00000, d_xu_traj=0x7fffa3a04000, d_xs=0x7fffa3a11c00, pcg_exit_tol=<optimized out>, xu_traj2d=..., eePos_traj2d=..., test_output_prefix=..., test_iter=0, goal_state_ind=0, start_state_ind=0,
    timestep=0.015625, knot_points=32, control_size=7, state_size=<optimized out>) at toplevel.cuh:711
#12 0x000055555557c79c in main () at runme.cu:151

I guess I am not enabling vectorization correctly, but I'm not sure how to proceed. The only dependency I have been building from source is pinocchio, the rest I am installing via conda. I see in the comment on 1027 that "Testing vectorization will require to compile all the dependencies (pinocchio, hpp-fcl, eigenpy, etc) with the same flags, if we want to run Python-based tests and examples," so based on this I believe my issue is in the fact that I'm using versions of dependent packages which don't have vectorization enabled. I have a couple of questions though:

I only really want the c++ in vectorized mode, so do I still need to build dependencies like eigenpy from source, and enable vectorization, in order to use vectorization in crocoddyl?

If I do need to build all the dependencies from source with vectorization enabled, do you have a list of which packages these are anywhere? Hpp-fcl is an optional dependency of pinocchio I see in the docs, so I'm just not sure where to look to figure out which packages I need to be rebuilding.

For dependent packages, which don't seem to have ENABLE_VECTORIZATION as an option in their CMakeLists.txt files, is -DCMAKE_CXX_FLAGS="-march=native" as an option to cmake the correct way to enable it?

Thank you very much in advance!

cmastalli commented 1 year ago

Hi @will-gerard,

I apologize for the late reply. We're working hard to improve Crocoddyl and our response time is limited.

I only really want the c++ in vectorized mode, so do I still need to build dependencies like eigenpy from source, and enable vectorization, in order to use vectorization in crocoddyl?

Yes, you need to do it for each project that generates a library. This won't apply for header-only libraries such as Pinocchio.

If I do need to build all the dependencies from source with vectorization enabled, do you have a list of which packages these are anywhere? Hpp-fcl is an optional dependency of pinocchio I see in the docs, so I'm just not sure where to look to figure out which packages I need to be rebuilding.

You can find the links to Crocoddyl dependencies in the Readme file. For Pinocchio dependencies, please ask this question to Pinocchio developers.

For dependent packages, which don't seem to have ENABLE_VECTORIZATION as an option in their CMakeLists.txt files, is -DCMAKE_CXX_FLAGS="-march=native" as an option to cmake the correct way to enable it?

Yes, you're correct. I have included it in Crocoddyl as makes things easier for our users, but including this cmake option goes beyond my scope. You could discuss this possibility with each project leader.

Please let me know if we can close this issue. Thanks!

will-gerard commented 10 months ago

@cmastalli I'm sorry, I thought I had responded. Thank you very much for you response and your work on this package, all set on this issue so thanks for closing.