-
-
Notifications
You must be signed in to change notification settings - Fork 189
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
Fixing linking Sundials as an external library #2861
Conversation
@WardBrian, can you check to see if this works? Also, where can I add more documentation for this? It'd be a shame if it just stayed in this PR. |
Re: documentation For the rest of the PR: I don't like how this is inconsistent with how we currently support external versions of TBB. We use different style names there, (e.g. TBB_INC=/path/to/include/
TBB_LIB=/path/to/lib/ (e.g., without the There is also (as far as I know) no reason to not have |
I can confirm that the changes do work, if I set up my make/local as described, I can build and run $ ldd test/unit/math/rev/functor/algebra_solver_fp_test
...
libsundials_cvodes.so.6 => /home/brian/miniconda3/envs/libtest/lib/libsundials_cvodes.so.6 (0x00007f1c8eec7000)
libsundials_kinsol.so.6 => /home/brian/miniconda3/envs/libtest/lib/libsundials_kinsol.so.6 (0x00007f1c8ee8b000) So it's just naming/convenience issues to resolve |
Cool. I'll work on the doc inside CmdStan as you suggested. Thanks for making comments; responses below.
Heard, but I think the consistent thing to do is to go the other way to use The makefiles are currently inconsistent and
I get it, but for Sundials this pattern won't work exactly. For an additional complication, do we want users to control which libraries to link against? The usage suggested will also make the makefile more complicated (in ways that's not true with other libraries); let's take small steps first and get it working with the existing variables and keep simplifying as we go along. I haven't introduced any new variables with this PR. (I'm going to leave TBB-related comments out of this PR thread, but I do think it deserves reworking.)
Yes, that we should be able to do. I'd need to really double-check whether the linker commands are ok going that way. There is a little disconnect that would exist between |
I'm looking at
Is there a way to add the flags to LDFLAGS and LDLIBS conditionally? Yes, but it's a bit complicated and not sure it's worth the effort of adding something like that inside the makefile. I'd lean towards just always linking with Sundials if we wanted to go that way. (I'd say we separate out changing behavior to a separate PR anyway.) |
I'm also happy if TBB naming changes, I just like if they match. Re the second issue, I believe we'd be able to link conditionally still using a change similar to what @andrjohns did here for #2659. |
Thanks for making the last set of comments; it helped me think about renaming The conditional linking is a little harder to d, so I'll leave that for a different PR. Some things we could think about:
|
Wrong thread but this should get your attention, but if there's a math meeting can you send me the link? I have a few questions and I'll be keeping up to date on this library again.
Thanks guys...
From: Daniel Lee ***@***.***>
Sent: Thursday, January 19, 2023 9:54 AM
To: stan-dev/math ***@***.***>
Cc: Subscribed ***@***.***>
Subject: Re: [stan-dev/math] Fixing linking Sundials as an external library (PR #2861)
EXTERNAL
Thanks for making the last set of comments; it helped me think about renaming LIBSUNDIALS to SUNDIALS_TARGETS so it's more consistent with the other libraries.
The conditional linking is a little harder to d, so I'll leave that for a different PR. Some things we could think about:
* do we need conditional linking of Sundials? People have asked us for this on and off, but by the time it gets to any of the interfaces, it's always linked in. It helps a little with the linking speed, but it is a conditional build that we may or may not really need to worry about.
* If we set the LDLIBS to always carry around the sundials libraries without having the libraries built, then we run into a linker error (at least on clang++). ld: library not found for -lsundials_cvodes. clang: error: linker command failed with exit code 1 (use -v to see invocation) So by the time we include the library in the linker flags, even if it's not being used, it has to exist.
* Optional include of the Sundials linker arguments... we could do this in the Math library, but I think it complicates things donwstream. In the Math repo, we only need to link it against the tests that need it. We can add target-specific updates to those variables. But for CmdStan, it would need to take that step proactively and we'd have to put in a little additional logic downstream. (It's just a little bit of logic, but it's still something.)
-
Reply to this email directly, view it on GitHub<https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fstan-dev%2Fmath%2Fpull%2F2861%23issuecomment-1397100100&data=05%7C01%7Candre.zapico%40sas.com%7Cb1ba5ff48ef04d69f8c608dafa2cf365%7Cb1c14d5c362545b3a4309552373a0c2f%7C0%7C0%7C638097368214893811%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=vyja%2FR4NyBPIB45FZjQF3kMJhtbGAuYoj5wru0c%2F8VU%3D&reserved=0>, or unsubscribe<https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FACY543FG34CNF4DOXULKWKDWTFIPHANCNFSM6AAAAAATW5VXPM&data=05%7C01%7Candre.zapico%40sas.com%7Cb1ba5ff48ef04d69f8c608dafa2cf365%7Cb1c14d5c362545b3a4309552373a0c2f%7C0%7C0%7C638097368214893811%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=oqNCfH%2Bj2MmrfeLVW6ayfHBGZhZd%2B%2FgPYanblce%2FTRM%3D&reserved=0>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.******@***.***>>
|
No worries! Sorry!! I should have canceled today; I’m on my way to meet
Brian Ward to talk about testing.
That said, let me send you an invite and let’s chat now. I’m in a coffee
shop so it might be a little loud.
…On Thu, Jan 19, 2023 at 10:08 AM Andre Zapico ***@***.***> wrote:
Wrong thread but this should get your attention, but if there's a math
meeting can you send me the link? I have a few questions and I'll be
keeping up to date on this library again.
Thanks guys...
From: Daniel Lee ***@***.***>
Sent: Thursday, January 19, 2023 9:54 AM
To: stan-dev/math ***@***.***>
Cc: Subscribed ***@***.***>
Subject: Re: [stan-dev/math] Fixing linking Sundials as an external
library (PR #2861)
EXTERNAL
Thanks for making the last set of comments; it helped me think about
renaming LIBSUNDIALS to SUNDIALS_TARGETS so it's more consistent with the
other libraries.
The conditional linking is a little harder to d, so I'll leave that for a
different PR. Some things we could think about:
* do we need conditional linking of Sundials? People have asked us for
this on and off, but by the time it gets to any of the interfaces, it's
always linked in. It helps a little with the linking speed, but it is a
conditional build that we may or may not really need to worry about.
* If we set the LDLIBS to always carry around the sundials libraries
without having the libraries built, then we run into a linker error (at
least on clang++). ld: library not found for -lsundials_cvodes. clang:
error: linker command failed with exit code 1 (use -v to see invocation) So
by the time we include the library in the linker flags, even if it's not
being used, it has to exist.
* Optional include of the Sundials linker arguments... we could do this in
the Math library, but I think it complicates things donwstream. In the Math
repo, we only need to link it against the tests that need it. We can add
target-specific updates to those variables. But for CmdStan, it would need
to take that step proactively and we'd have to put in a little additional
logic downstream. (It's just a little bit of logic, but it's still
something.)
-
Reply to this email directly, view it on GitHub<
https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fstan-dev%2Fmath%2Fpull%2F2861%23issuecomment-1397100100&data=05%7C01%7Candre.zapico%40sas.com%7Cb1ba5ff48ef04d69f8c608dafa2cf365%7Cb1c14d5c362545b3a4309552373a0c2f%7C0%7C0%7C638097368214893811%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=vyja%2FR4NyBPIB45FZjQF3kMJhtbGAuYoj5wru0c%2F8VU%3D&reserved=0>,
or unsubscribe<
https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FACY543FG34CNF4DOXULKWKDWTFIPHANCNFSM6AAAAAATW5VXPM&data=05%7C01%7Candre.zapico%40sas.com%7Cb1ba5ff48ef04d69f8c608dafa2cf365%7Cb1c14d5c362545b3a4309552373a0c2f%7C0%7C0%7C638097368214893811%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=oqNCfH%2Bj2MmrfeLVW6ayfHBGZhZd%2B%2FgPYanblce%2FTRM%3D&reserved=0
>.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.******@***.***>>
—
Reply to this email directly, view it on GitHub
<#2861 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADH6F3PLG7L6D2RZ5OJHTLWTFKIRANCNFSM6AAAAAATW5VXPM>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Correct, I realized this same thing here. This is worth it, in my opinion, to avoid any user who wants to do this always having to paste the same thing into their No reason that necessarily needs to be done in one PR, though. This is already an improvement over what we currently have |
@WardBrian, that's exactly how I feel about this change. It's a step in the right direction and it'll allow us to get to the point where we can use the linker flags properly... hopefully soon. |
6c540ff
to
c74667f
Compare
The latest test run failed during clean up of the expression tests with error |
thanks. I'll track it down. |
c74667f
to
ab84dfd
Compare
Is it expected that the downstream tests will fail? Do we need to also have a PR against stan or cmdstan? (I assume not, #2834 suggests it is possible to make similar changes and have all tests still passing) |
No, it shouldn't need a downstream PR.... but let me check. It's possible that something was relying on one of the renamed variables. In which case, I'll do a safer PR that we can stage. |
ok... found Here's how it'll be staged:
This won't change anything user-facing... users can't set |
@WardBrian, the last commit allowed this to be used without having to change downstream repos. It was a one-liner. Mind taking a look whenever you get a chance? Thanks! |
Summary
This PR allows the user to link against a locally installed Sundials. To do this, their
make/local
should include 4 things:INC_SUNDIALS
is what needs to be provided to the c++ compiler for includes. So it should look like-I <path-to-sundials-source>
LDFLAGS_SUNDIALS
should be the linker flags for sundials. This should look like-L <path-to-sundials-libraries>
LDLIBS_SUNDIALS
is the linker instruction to include sundials libraries. This should look like-lsundials_cvodes -lsundials_idas -lsundials_kinsol -lsundials_nvecserial
(this works withLDFLAGS_SUNDIALS
to pick the right libraries)SUNDIALS_TARGETS
should be set to empty so the Stan Math library stops trying to build them.Full example (using brew to install sundials):
Edit: changed
LIBSUNDIALS
toSUNDIALS_TARGETS
. This is non-breaking... we could never set this from the outside anyway.Tests
Our tests should pick up whether this works.
Side Effects
None. This should be backwards compatible and only allows for additional functionality.
Release notes
Allows Sundials to be linked to separately installed version.
Checklist
Copyright holder: Daniel Lee
The copyright holder is typically you or your assignee, such as a university or company. By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
- Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
- Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
the basic tests are passing
./runTests.py test/unit
)make test-headers
)make test-math-dependencies
)make doxygen
)make cpplint
)the code is written in idiomatic C++ and changes are documented in the doxygen
the new changes are tested