Skip to content

Commit

Permalink
Merge pull request #59 from erwincoumans/master
Browse files Browse the repository at this point in the history
cuda_laikago_codegen, running 2048 Laikago's in real-time!
  • Loading branch information
erwincoumans authored Dec 18, 2020
2 parents c558902 + 697a8d4 commit 36087a2
Show file tree
Hide file tree
Showing 38 changed files with 1,756 additions and 222 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
[submodule "third_party/CppAD"]
path = third_party/CppAD
url = https://github.com/coin-or/CppAD.git
ignore = all
[submodule "third_party/CppADCodeGen"]
path = third_party/CppADCodeGen
url = https://github.com/eric-heiden/CppADCodeGen.git
ignore = all
[submodule "third_party/glog"]
path = third_party/glog
url = https://github.com/google/glog.git
ignore = all
[submodule "third_party/ceres-solver"]
path = third_party/ceres-solver
url = https://github.com/ceres-solver/ceres-solver
ignore = all
[submodule "third_party/gflags"]
path = third_party/gflags
url = https://github.com/gflags/gflags.git
ignore = all
[submodule "third_party/bullet3"]
path = third_party/bullet3
url = https://github.com/bulletphysics/bullet3
ignore = all
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
endif()



if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
cmake_policy(SET CMP0017 NEW)
Expand Down
2 changes: 1 addition & 1 deletion build_libs_unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ cd $ROOT
mkdir build_cmake
cd build_cmake

cmake -DBullet_DIR=$ROOT/third_party/bullet3/build_cmake -Dgflags_DIR=$ROOT/third_party/gflags/build_cmake -Dglog_DIR=$ROOT/third_party/glog/build_cmake -DEigen3_DIR=$ROOT/third_party/eigen3/build_cmake -DCeres_DIR=$ROOT/third_party/ceres-solver/build_cmake/local_install/lib/cmake/Ceres -DUSE_CPPAD=ON ..
cmake -DBullet_DIR=$ROOT/third_party/bullet3/build_cmake -Dgflags_DIR=$ROOT/third_party/gflags/build_cmake -Dglog_DIR=$ROOT/third_party/glog/build_cmake -DEigen3_DIR=$ROOT/third_party/eigen3/build_cmake -DCeres_DIR=$ROOT/third_party/ceres-solver/build_cmake/local_install/lib/cmake/Ceres -DUSE_CPPAD=ON -DUSE_CERES=ON ..
make -j4

11 changes: 8 additions & 3 deletions build_libs_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ popd
cd %ROOT%


pushd third_party\cppadcodegen
git apply ..\patches\CppADCodeGen.diff
popd
cd %ROOT%

pushd third_party\gflags
mkdir build_cmake
cd build_cmake
Expand Down Expand Up @@ -86,7 +91,7 @@ del third_party\gflags\build_cmake\local_install\lib\*.lib
mkdir build_cmake
cd build_cmake

cmake -DCMAKE_CXX_FLAGS="/MP" -DUSE_MSVC_RUNTIME_LIBRARY_DLL=ON -DBullet_DIR=%ROOT%\third_party\bullet3\build_cmake -Dgflags_DIR=%ROOT%\third_party\gflags\build_cmake -Dglog_DIR=%ROOT%\third_party\glog\build_cmake -DEigen3_DIR=%ROOT%\third_party\eigen3\build_cmake -DCeres_DIR=%ROOT%\third_party\ceres-solver\build_cmake\local_install\cmake -DUSE_CPPAD=ON ..
cmake -DCMAKE_CXX_FLAGS="/MP" -DUSE_CERES=ON -DUSE_MSVC_RUNTIME_LIBRARY_DLL=ON -DBullet_DIR=%ROOT%\third_party\bullet3\build_cmake -Dgflags_DIR=%ROOT%\third_party\gflags\build_cmake -Dglog_DIR=%ROOT%\third_party\glog\build_cmake -DEigen3_DIR=%ROOT%\third_party\eigen3\build_cmake -DCeres_DIR=%ROOT%\third_party\ceres-solver\build_cmake\local_install\cmake -DUSE_CPPAD=ON ..

cmake --build . --target INSTALL --config Release
start DIFF_PHYSICS.sln
rem cmake --build . --target INSTALL --config Release
rem start DIFF_PHYSICS.sln
27 changes: 27 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ if (Eigen3_FOUND)
add_executable(pendulum_example_eigen_gui pendulum_example_gui.cpp ${TDS_HDRS})
target_link_libraries(pendulum_example_eigen_gui opengl_window Eigen3::Eigen ${CMAKE_DL_LIBS})
target_include_directories(pendulum_example_eigen_gui PRIVATE ../src)

add_executable(laikago_opengl_eigen_example laikago_opengl_example.cpp ../third_party/stb_image/stb_image.cpp ../third_party/tinyobjloader/tiny_obj_loader.cc ${TDS_HDRS})
target_link_libraries(laikago_opengl_eigen_example Eigen3::Eigen tinyxml2 opengl_window ${CMAKE_DL_LIBS})
target_include_directories(laikago_opengl_eigen_example PRIVATE ../third_party/tinyobjloader)
target_include_directories(laikago_opengl_eigen_example PRIVATE ../third_party ../src)

add_executable(laikago_opengl_tiny_example laikago_opengl_example.cpp ../third_party/stb_image/stb_image.cpp ../third_party/tinyobjloader/tiny_obj_loader.cc ${TDS_HDRS})
target_link_libraries(laikago_opengl_tiny_example Eigen3::Eigen tinyxml2 opengl_window ${CMAKE_DL_LIBS})
target_include_directories(laikago_opengl_tiny_example PRIVATE ../third_party/tinyobjloader)
target_include_directories(laikago_opengl_tiny_example PRIVATE ../third_party ../src)
target_compile_definitions(laikago_opengl_tiny_example PRIVATE USE_TINY )

endif()

add_executable(billiard_opt_example_gui billiard_opt_example_gui.cpp ${TDS_HDRS})
Expand Down Expand Up @@ -42,6 +54,21 @@ IF(USE_CPPAD)
if (USE_STAN)
target_link_libraries(cuda_codegen PRIVATE ${STAN_LIBRARIES})
endif(USE_STAN)

add_executable(cuda_laikago_codegen cuda_laikago_codegen.cpp ${TDS_HDRS})
target_compile_definitions(cuda_laikago_codegen PRIVATE -DUSE_CPPAD)
target_link_libraries(
cuda_laikago_codegen
PRIVATE
${CMAKE_DL_LIBS}
opengl_window
tinyxml2
Eigen3::Eigen
differentiation
)
if (USE_STAN)
target_link_libraries(cuda_laikago_codegen PRIVATE ${STAN_LIBRARIES})
endif(USE_STAN)
ENDIF(USE_CPPAD)

IF(USE_CERES)
Expand Down
4 changes: 2 additions & 2 deletions examples/ceres_estimation_real.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void visualize_trajectory(const std::vector<std::vector<T>> &states,
std::vector<int> mbvisuals;
if (visualizer->canSubmitCommand())
{
for (int i = 0; i < mb->size(); i++)
for (int i = 0; i < mb->num_links(); i++)
{
int sphereId = visualizer->loadURDF("sphere_small.urdf");
mbvisuals.push_back(sphereId);
Expand All @@ -135,7 +135,7 @@ void visualize_trajectory(const std::vector<std::vector<T>> &states,
std::chrono::duration<double>(Utils::getDouble(dt * 20.)));
// sync transforms
int visual_index = 0;
for (std::size_t l = 0; l < mb->size(); l++)
for (std::size_t l = 0; l < mb->num_links(); l++)
{
int sphereId = mbvisuals[visual_index++];
typename Algebra::Quaternion rot;
Expand Down
13 changes: 7 additions & 6 deletions examples/cuda_codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct ContactSimulation {

int input_dim() const { return system->dof() + system->dof_qd(); }
int state_dim() const {
return system->dof() + system->dof_qd() + system->size() * 3;
return system->dof() + system->dof_qd() + system->num_links() * 3;
}
int output_dim() const { return num_timesteps * state_dim(); }

Expand Down Expand Up @@ -166,7 +166,7 @@ int main(int argc, char* argv[]) {
int sphere_shape = app.register_graphics_unit_sphere_shape(SPHERE_LOD_LOW);
// typedef tds::Conversion<DiffAlgebra, tds::TinyAlgebraf> Conversion;
std::vector<int> visuals;
for (int i = 0; i < num_total_threads * simulation.system->size(); ++i) {
for (int i = 0; i < num_total_threads * simulation.system->num_links(); ++i) {
TinyVector3f pos(0, 0, 0);
TinyQuaternionf orn(0, 0, 0, 1);
TinyVector3f color(0.5, 0.6, 1);
Expand All @@ -186,7 +186,8 @@ int main(int argc, char* argv[]) {
const int link_pos_id_offset =
simulation.system->dof() + simulation.system->dof_qd();
const int square_id = (int)std::sqrt((double)num_total_threads);
const float radius = 1.f;
//sim_spacing is the visual distance between independent parallel simulations
const float sim_spacing = 5.f;
for (int run = 0; run < 40; ++run) {
for (int i = 0; i < num_total_threads; ++i) {
inputs[i] = std::vector<Scalar>(simulation.input_dim(), Scalar(0));
Expand All @@ -212,14 +213,14 @@ int main(int argc, char* argv[]) {
int visual_id = 0;
for (int i = 0; i < num_total_threads; ++i) {
TinyVector3f prev_pos(0, 0, 0);
for (std::size_t l = 0; l < simulation.system->size(); ++l) {
for (std::size_t l = 0; l < simulation.system->num_links(); ++l) {
int sphereId = visuals[visual_id++];
TinyVector3f pos;
pos[0] = outputs[i][link_pos_id_offset + l * 3 + 0];
pos[1] = outputs[i][link_pos_id_offset + l * 3 + 1];
pos[2] = outputs[i][link_pos_id_offset + l * 3 + 2];
pos[0] += radius * (i % square_id) - square_id * radius / 2;
pos[1] += radius * (i / square_id) - square_id * radius / 2;
pos[0] += sim_spacing * (i % square_id) - square_id * sim_spacing / 2;
pos[1] += sim_spacing * (i / square_id) - square_id * sim_spacing / 2;
TinyQuaternionf orn(0, 0, 0, 1);
if (l > 0) {
//app.m_renderer->draw_line(prev_pos, pos, line_color, line_width);
Expand Down
Loading

0 comments on commit 36087a2

Please sign in to comment.