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

add option to use mpi imported targets #482

Merged
merged 7 commits into from
Apr 16, 2021
Merged

Conversation

cyrush
Copy link
Member

@cyrush cyrush commented Apr 14, 2021

Adds an option to use the modern imported targets provided by FindMPI.

This solves an issue with BLT related to transitive mpi deps and -pthreads vs cuda.

The issue:

  • You build a TPL that doesn't have cuda support. In that case, BLT does not (cannot) apply any of the cuda pthreads protection logic. (As far as I know we can't use generator exprs that involve non-enabled languages)
  • You now use this TPL in a lib or application that does need CUDA support. The flags that are tied to MPI are already baked in to the first lib, so nvcc sees pthreads and gives up.

Using the targets imported by FindMPI solves this issue, b/c those targets expand to include the proper guards when FindMPI is called.

I don't know the exact point at where it changed, but pthreads is added by FindMPI in newer versions of CMake. It does not happen in CMake 3.14. We may eventually want to make this the default when newer CMake is used.

TODO:

LINK_FLAGS ${_mpi_link_flags}
EXPORTABLE ${BLT_EXPORT_THIRDPARTY})

if(BLT_USE_MPI_IMPORTED_TARGETS)
Copy link
Member

Choose a reason for hiding this comment

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

imported is a bit overloaded in this context.

Copy link
Member

Choose a reason for hiding this comment

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

maybe "BLT_USE_CMAKE_MPI_TARGETS"?

Copy link
Member Author

Choose a reason for hiding this comment

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

the other MPI options are all have the BLT_MPI prefix, like BLT_MPI_COMPILE_FLAGS

how about:
BLT_MPI_USE_FINDMPI_CMAKE_TARGETS

Copy link
Member

@white238 white238 Apr 15, 2021

Choose a reason for hiding this comment

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

That works.. after this is proven to solve you problem, we should handle the overriding case where the user provides includes/link flags/etc.

Either by erroring out or overriding the target's properties

Copy link
Member Author

Choose a reason for hiding this comment

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

or
BLT_MPI_USE_FIND_MPI_CMAKE_TARGETS

Copy link
Member

Choose a reason for hiding this comment

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

BLT_USE_FIND_MPI_TARGETS?

@cyrush
Copy link
Member Author

cyrush commented Apr 15, 2021

@white238 pushed docs, error checks and improvements. I also verified this does resolve the issue.
Let me know if I should make more tweaks.

#
# TODO: should this be BLT_ENABLE_FIND_MPI?
#
if(ENABLE_FIND_MPI)
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove line 34 if you want to add this?

Yea this was a very early option. It should be prefixed but I've been hesitant to change it due to legacy. But honestly no one uses that I know anymore. The main use case was BGQ.

Copy link
Member Author

Choose a reason for hiding this comment

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

removed line 34 and the TODO

COMPILE_FLAGS ${_mpi_compile_flags}
LINK_FLAGS ${_mpi_link_flags}
EXPORTABLE ${BLT_EXPORT_THIRDPARTY})
endif()
Copy link
Member

Choose a reason for hiding this comment

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

Add a new line here please.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -86,6 +86,11 @@ Test. ``test_2.cpp`` provides an example driver for MPI with GoogleTest.
BLT also has the variable ``ENABLE_FIND_MPI`` which turns off all CMake's ``FindMPI``
logic and then uses the MPI wrapper directly when you provide them as the default
compilers.

BLT also provides ``BLT_USE_FIND_MPI_TARGETS`` that will directly use the
``MPI::MPI_C`` and ``MPI::MPI_CXX`` targets provided by CMake's ``FindMPI``.
Copy link
Member

Choose a reason for hiding this comment

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

Please add that it those targets are able to be referenced under the unified name of mpi

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

two backticks

Copy link
Member Author

Choose a reason for hiding this comment

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

two backticks times two.

Copy link
Member

@kennyweiss kennyweiss left a comment

Choose a reason for hiding this comment

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

Looks good @cyrush

Please also update the RELEASE_NOTES

@@ -33,6 +33,29 @@ set(_mpi_link_flags )

message(STATUS "Enable FindMPI: ${ENABLE_FIND_MPI}")

#
# TODO: should this be BLT_ENABLE_FIND_MPI?
Copy link
Member

Choose a reason for hiding this comment

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

TODO: should this be BLT_ENABLE_FIND_MPI?

I agree that we should convert it to BLT_ENABLE_FIND_MPI and deprecate ENABLE_FIND_MPI, e.g. via a loud warning at first.

Perhaps we should do the same for many/most blt ENABLE_ variables at the same time?

Copy link
Member

Choose a reason for hiding this comment

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

It would be a good time to do it since we just did the 0.4.0 release.

Copy link
Member Author

@cyrush cyrush Apr 16, 2021

Choose a reason for hiding this comment

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

Added: #483 to track this name change, won't do in this PR




if(NOT ENABLE_FIND_MPI AND BLT_USE_FIND_MPI_TARGETS)
Copy link
Member

Choose a reason for hiding this comment

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

Seems like we could handle this better by converting BLT_USE_FIND_MPI_TARGETS to a cmake_dependent_option

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried cmake_dependent_option. It will just flip BLT_USE_FIND_MPI_TARGETS to OFF, when ENABLE_FIND_MPI is OFF. I think an explicit error is a better approach here -- better to error when things aren't consistent than to drive on to surprise town.

if (BLT_MPI_COMPILE_FLAGS)
if(BLT_USE_FIND_MPI_TARGETS)
Copy link
Member

Choose a reason for hiding this comment

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

Can you please convert this to a foreach() ?
That way it is easier to see that it is the same logic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Each error case here provides a detailed unique error message. It's not just the var names that are different, so var indirection in a for loop won't get you the same result.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking at the full section in the file -- the logic seems easy to parse. I feel a cmake for loop would not improve the readability. If you have an idea of how it could work, lets explore in a future PR.

@cyrush cyrush merged commit 68c98b7 into develop Apr 16, 2021
@cyrush cyrush deleted the task/2021_04_find_mpi_fixes branch April 16, 2021 20:06
cyrush added a commit that referenced this pull request Apr 22, 2021
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.

3 participants