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

Finding the artifact path on initialization improves relocatability #134

Merged
merged 2 commits into from
Feb 1, 2022

Conversation

ven-k
Copy link
Contributor

@ven-k ven-k commented Jan 27, 2022

No description provided.

@odow
Copy link
Member

odow commented Jan 27, 2022

What do you mean by relocatability?

@codecov
Copy link

codecov bot commented Jan 27, 2022

Codecov Report

Merging #134 (8a9674d) into master (a436e1a) will increase coverage by 0.09%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #134      +/-   ##
==========================================
+ Coverage   79.13%   79.22%   +0.09%     
==========================================
  Files           3        3              
  Lines         230      231       +1     
==========================================
+ Hits          182      183       +1     
  Misses         48       48              
Impacted Files Coverage Δ
src/ECOS.jl 91.66% <100.00%> (+0.75%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a436e1a...8a9674d. Read the comment docs.

@ven-k
Copy link
Contributor Author

ven-k commented Jan 28, 2022

We can create sysimages and relocatable-apps for quicker startup time. It is a precompiled library file.
But when you generate these on machine A and want to use on some other machine B, if any directory-path is hardwired say by using @__DIR__ ... the sysimage fails to execute that function.

Here, the const ecos = ECOS_jll.libecos records the artifact-path of machine A. And when you try to use the sysimage on machine B, as the artifact-path might not always match (happens when JULIA_DEPOT_PATHs are different) sysimage fails to initialize.

@odow
Copy link
Member

odow commented Jan 28, 2022

Ah, you're relocating the sysimage.

We should probably have a standard way of doing this across all the solvers then.

Is this (a non-const global) the recommended way of setting the paths?

Our other option is a const libecos = Ref{String}() which we will in __init__, and then calls can use libecos[]. We originally avoided doing this in order to maintain support for Julia 1.0, but a lot of solvers (like ECOS) have dropped 1.0 support.

@ven-k
Copy link
Contributor Author

ven-k commented Feb 1, 2022

Our other option is a const libecos = Ref{String}()

  • libecos = Ref{String}() I tried this out. But, you can't access it outside without declaring global
  • And "const" keyword can't be used inside a function
  • Declaring anywhere outside the init() will reintroduce the problem

If you are refactoring across the ecosystem, RelocatableFolders might be something you want to look at (for any @__DIR__s). I avoided that here as ecos is used in __init__. So declaring it inside it is much more convenient and also, using RelocatableFolders.@path would create a scratchspace with the entire artifact libecos.so

@odow
Copy link
Member

odow commented Feb 1, 2022

Okay, I tried

  • Our current setup
  • global ecos = ECOS_jll.libecos
  • const ecos = Ref{String}() and changing occurrences of ecos to ecos[].

There didn't seem to be any difference in performance.

From here: https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/#Non-constant-Function-Specifications

image

So even though the value is not a const, it doesn't affect performance:

julia> using ECOS

julia> @code_warntype ECOS.ECOS_ver()
Variables
  #self#::Core.Const(ECOS.ECOS_ver)

Body::Cstring
1%1 = $(Expr(:foreigncall, :(Core.tuple(:ECOS_ver, ECOS.ecos)), Cstring, svec(), 0, :(:ccall)))::Cstring
└──      return %1

@odow odow merged commit 7e903b4 into jump-dev:master Feb 1, 2022
@odow
Copy link
Member

odow commented Feb 1, 2022

Thanks @ven-k. Are you working for JuliaComputing? What are you using ECOS for?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants