robotology / osqp-eigen

Simple Eigen-C++ wrapper for OSQP library
https://robotology.github.io/osqp-eigen/
BSD 3-Clause "New" or "Revised" License
381 stars 112 forks source link

Using OSQP-Eigen with OSQP CUDA #148

Open JTylerBoylan opened 10 months ago

JTylerBoylan commented 10 months ago

I got OSQP-Eigen to build and solve when I build OSQP with its normal linear algebra library, but when I build OSQP with it's CUDA library instead, I get a compilation error for OSQP-Eigen.

Compilation Error:

/usr/bin/ld: CMakeFiles/main.dir/src/main.cpp.o: in function `bool OsqpEigen::SparseMatrixHelper::createOsqpSparseMatrix<Eigen::SparseMatrix<float, 0, int> >(Eigen::SparseCompressedBase<Eigen::SparseMatrix<float, 0, int> > const&, OSQPCscMatrix*&)':
/usr/local/include/OsqpEigen/SparseMatrixHelper.tpp:42: undefined reference to `csc_spalloc'
/usr/bin/ld: /usr/local/lib/libOsqpEigen.so.0.8.1: undefined reference to `csc_spfree'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/main.dir/build.make:99: main] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Dockerfile:

FROM nvidia/cuda:12.2.0-devel-ubuntu22.04

RUN apt-get update -y

RUN apt-get install -y cmake git

RUN apt-get install -y libeigen3-dev

RUN git clone https://github.com/osqp/osqp
RUN cd osqp && mkdir build
RUN cd osqp/build && cmake -G "Unix Makefiles" .. -DOSQP_ALGEBRA_BACKEND=cuda
# RUN cd osqp/build && cmake -G "Unix Makefiles" ..
# Does not fail when using above ^
RUN cd osqp/build && cmake --build . --target install

RUN git clone https://github.com/robotology/osqp-eigen
RUN cd osqp-eigen && mkdir build
RUN cd osqp-eigen/build && cmake ..
RUN cd osqp-eigen/build && make && make install

CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)
project(my_project)

set(CMAKE_BUILD_TYPE RelWithDebInfo)

find_package(OsqpEigen REQUIRED)
find_package(Eigen3)

include_directories(SYSTEM ${EIGEN3_INCLUDE_DIR})

include_directories(include)

# Add the executable
add_executable(main src/main.cpp)
target_include_directories(main PUBLIC include)
target_link_libraries(main PUBLIC stdc++ stdc++fs m OsqpEigen::OsqpEigen)
traversaro commented 10 months ago

Thanks a lot for the issue. Just to understand, with the exact version of osqp (not some other version), just changing OSQP_ALGEBRA_BACKEND to builtin (or mkl, if you know how to install that) everything works?

JTylerBoylan commented 10 months ago

Correct, using OSQP_ALGEBRA_BACKEND=builtin works (as well as using double types for my matrices), but cuda does not. The CUDA backend requires the use of floats instead of doubles. I have not tried mkl.