Skip to content

cpp/purify/config.in.h: Add #cmakedefine PURIFY_ONNXRT #360

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

Closed

Conversation

bernhardkaindl
Copy link

@bernhardkaindl bernhardkaindl commented Oct 13, 2024

@tkoskela @20DM:

To enable onnxrt (onnxruntime) supporting the compiled C++ code, PURIFY_ONNXRT must be defined at the preprocessor level:

https://github.com/astro-informatics/purify/blob/development/cpp/purify/algorithm_factory.h#L27
https://github.com/astro-informatics/purify/blob/development/cpp/purify/algorithm_factory.h#L204
(these are the only places that I found)

This string is found in bin/purify if the ONNXRT code is not compiled:
https://github.com/astro-informatics/purify/blob/development/cpp/purify/algorithm_factory.h#L210

On the cmake level, it is set here:
https://github.com/astro-informatics/purify/blob/development/cmake_files/dependencies.cmake#L37

But it needs to be conditinally defined in config.h(.in) to reach the C++ level (actual compilation):

//! Whether PURIFY is running with onnxrt (onnxruntime)
#cmakedefine PURIFY_ONNXRT

Without this, even with cmake -Donnxrt=ON, strings bin/purify | grep onnxrt will find a string that is compiled only when PURIFY_ONNXRT is not set by config.h (and it is not if this cmakedefine is not set).

PS: I noticed this in an extended review of spack/spack#46839

PPS: With this, PURIFY_ONNXRT is set, onnxrt code gets included in the build, but compilation with gcc-13.1.0 fails with these errors:

In file included from /home/bkaindl/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-13.1.0/sopt-4.2.0-5spnatotqxu442pewzbqqxmz7wsurmr6/include/sopt/tf_g_proximal.h:8,
                 from /home/bkaindl/spack/.stage/spack-stage-purify-4.2.0-c7wp4nh7gjtj4boaiucjlzq2ljlf2vjl/spack-src/cpp/purify/algorithm_factory.h:28,
                 from /home/bkaindl/spack/.stage/spack-stage-purify-4.2.0-c7wp4nh7gjtj4boaiucjlzq2ljlf2vjl/spack-src/cpp/tests/algo_factory.cc:12:
/home/bkaindl/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-13.1.0/sopt-4.2.0-5spnatotqxu442pewzbqqxmz7wsurmr6/include/sopt/ort_session.h: In instantiation of 'sopt::Vector<SCALAR> sopt::ORTsession::compute(sopt::Vector<SCALAR>&, const std::vector<long int>&) const [with T = std::complex<double>; sopt::Vector<SCALAR> = Eigen::Matrix<std::complex<double>, -1, 1>]':
/home/bkaindl/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-13.1.0/sopt-4.2.0-5spnatotqxu442pewzbqqxmz7wsurmr6/include/sopt/tf_g_proximal.h:78:31:   required from 'void sopt::algorithm::TFGProximal<SCALAR>::call_model(t_Vector&, const t_Vector&) const [with SCALAR = std::complex<double>; t_Vector = Eigen::Matrix<std::complex<double>, -1, 1>]'
/home/bkaindl/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-13.1.0/sopt-4.2.0-5spnatotqxu442pewzbqqxmz7wsurmr6/include/sopt/tf_g_proximal.h:56:15:   required from 'sopt::algorithm::TFGProximal<SCALAR>::t_Proximal sopt::algorithm::TFGProximal<SCALAR>::proximal_function() const [with SCALAR = std::complex<double>; t_Proximal = std::function<void(Eigen::Matrix<std::complex<double>, -1, 1>&, double, const Eigen::Matrix<std::complex<double>, -1, 1>&)>]'
/home/bkaindl/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-13.1.0/sopt-4.2.0-5spnatotqxu442pewzbqqxmz7wsurmr6/include/sopt/tf_g_proximal.h:54:14:   required from here
/home/bkaindl/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-13.1.0/sopt-4.2.0-5spnatotqxu442pewzbqqxmz7wsurmr6/include/sopt/ort_session.h:81:21: error: cannot convert 'const std::complex<double>' to '__gnu_cxx::__alloc_traits<std::allocator<float>, float>::value_type' {aka 'float'} in assignment
   81 |       flat_input[i] = input[i];
In file included from /home/bkaindl/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-13.1.0/sopt-4.2.0-5spnatotqxu442pewzbqqxmz7wsurmr6/include/sopt/tf_g_proximal.h:8,
                 from /home/bkaindl/spack/.stage/spack-stage-purify-4.2.0-c7wp4nh7gjtj4boaiucjlzq2ljlf2vjl/spack-src/cpp/purify/algorithm_factory.h:28,
                 from /home/bkaindl/spack/.stage/spack-stage-purify-4.2.0-c7wp4nh7gjtj4boaiucjlzq2ljlf2vjl/spack-src/cpp/tests/mpi_algo_factory.cc:19:
/home/bkaindl/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-13.1.0/sopt-4.2.0-5spnatotqxu442pewzbqqxmz7wsurmr6/include/sopt/ort_session.h: In instantiation of 'sopt::Vector<SCALAR> sopt::ORTsession::compute(sopt::Vector<SCALAR>&, const std::vector<long int>&) const [with T = std::complex<double>; sopt::Vector<SCALAR> = Eigen::Matrix<std::complex<double>, -1, 1>]':
/home/bkaindl/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-13.1.0/sopt-4.2.0-5spnatotqxu442pewzbqqxmz7wsurmr6/include/sopt/tf_g_proximal.h:78:31:   required from 'void sopt::algorithm::TFGProximal<SCALAR>::call_model(t_Vector&, const t_Vector&) const [with SCALAR = std::complex<double>; t_Vector = Eigen::Matrix<std::complex<double>, -1, 1>]'
/home/bkaindl/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-13.1.0/sopt-4.2.0-5spnatotqxu442pewzbqqxmz7wsurmr6/include/sopt/tf_g_proximal.h:56:15:   required from 'sopt::algorithm::TFGProximal<SCALAR>::t_Proximal sopt::algorithm::TFGProximal<SCALAR>::proximal_function() const [with SCALAR = std::complex<double>; t_Proximal = std::function<void(Eigen::Matrix<std::complex<double>, -1, 1>&, double, const Eigen::Matrix<std::complex<double>, -1, 1>&)>]'
/home/bkaindl/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-13.1.0/sopt-4.2.0-5spnatotqxu442pewzbqqxmz7wsurmr6/include/sopt/tf_g_proximal.h:54:14:   required from here
/home/bkaindl/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-13.1.0/sopt-4.2.0-5spnatotqxu442pewzbqqxmz7wsurmr6/include/sopt/ort_session.h:81:21: error: cannot convert 'const std::complex<double>' to '__gnu_cxx::__alloc_traits<std::allocator<float>, float>::value_type' {aka 'float'} in assignment
   81 |       flat_input[i] = input[i];
In file included from /home/bkaindl/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-13.1.0/sopt-4.2.0-5spnatotqxu442pewzbqqxmz7wsurmr6/include/sopt/tf_g_proximal.h:8,
                 from /home/bkaindl/spack/.stage/spack-stage-purify-4.2.0-c7wp4nh7gjtj4boaiucjlzq2ljlf2vjl/spack-src/cpp/purify/algorithm_factory.h:28,
                 from /home/bkaindl/spack/.stage/spack-stage-purify-4.2.0-c7wp4nh7gjtj4boaiucjlzq2ljlf2vjl/spack-src/cpp/main.cc:8:
/home/bkaindl/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-13.1.0/sopt-4.2.0-5spnatotqxu442pewzbqqxmz7wsurmr6/include/sopt/ort_session.h: In instantiation of 'sopt::Vector<SCALAR> sopt::ORTsession::compute(sopt::Vector<SCALAR>&, const std::vector<long int>&) const [with T = std::complex<double>; sopt::Vector<SCALAR> = Eigen::Matrix<std::complex<double>, -1, 1>]':
/home/bkaindl/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-13.1.0/sopt-4.2.0-5spnatotqxu442pewzbqqxmz7wsurmr6/include/sopt/tf_g_proximal.h:78:31:   required from 'void sopt::algorithm::TFGProximal<SCALAR>::call_model(t_Vector&, const t_Vector&) const [with SCALAR = std::complex<double>; t_Vector = Eigen::Matrix<std::complex<double>, -1, 1>]'
/home/bkaindl/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-13.1.0/sopt-4.2.0-5spnatotqxu442pewzbqqxmz7wsurmr6/include/sopt/tf_g_proximal.h:56:15:   required from 'sopt::algorithm::TFGProximal<SCALAR>::t_Proximal sopt::algorithm::TFGProximal<SCALAR>::proximal_function() const [with SCALAR = std::complex<double>; t_Proximal = std::function<void(Eigen::Matrix<std::complex<double>, -1, 1>&, double, const Eigen::Matrix<std::complex<double>, -1, 1>&)>]'
/home/bkaindl/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-13.1.0/sopt-4.2.0-5spnatotqxu442pewzbqqxmz7wsurmr6/include/sopt/tf_g_proximal.h:54:14:   required from here
/home/bkaindl/spack/opt/spack/linux-ubuntu22.04-skylake/gcc-13.1.0/sopt-4.2.0-5spnatotqxu442pewzbqqxmz7wsurmr6/include/sopt/ort_session.h:81:21: error: cannot convert 'const std::complex<double>' to '__gnu_cxx::__alloc_traits<std::allocator<float>, float>::value_type' {aka 'float'} in assignment
   81 |       flat_input[i] = input[i];

This used py-onnxruntime@1.18.2 and sopt@4.2.0

To enable onnxrt (onnxruntime) supporting the compiled C++ code, PURIFY_ONNXRT must be defined at the preprocessor level.

On the cmake level, it is set here:
https://github.com/astro-informatics/purify/blob/development/cmake_files/dependencies.cmake#L37

But it needs to be conditinally defined in config.h(.in) to reach the C++ level (actual compilation):

//! Whether PURIFY is running with onnxrt (onnxruntime)
#cmakedefine PURIFY_ONNXRT

Without this, even with `cmake -Donnxrt=ON`, strings bin/purify | grep onnxrt will find a string that is compiled only when PURIFY_ONNXRT is not set by config.h (and it is not if this cmakedefine is not set).
Copy link
Contributor

@tkoskela tkoskela left a comment

Choose a reason for hiding this comment

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

Thank you for the sugestion, it looks good to me!

It looks like the double to float conversion error you ran into has already been fixed in the development branch astro-informatics/sopt@e0aab12. I'll update the purify onnx variant once we've got a new release.

@tkoskela
Copy link
Contributor

Going to close this as the change is also already in #343

@tkoskela tkoskela closed this Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants