-
Notifications
You must be signed in to change notification settings - Fork 77
Introduce backwards compatible infrastructure for parallelism #1708
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
base: master
Are you sure you want to change the base?
Conversation
In order to maintain backwards compatibility, we need to provide stubs for functionality needed for parallelism when no libraries provide this. Also, to keep possibly diverging parts to a minimum, the utilities for parallelism are kept in a separate module.
This works async in Ocaml4 and truly parallel in OCaml5
fix printing issue by using BatFormat in messages.ml
This is a high level abstraction AND a backward compat. wrapper
Possibly, this could be needed elsewhere, where state is involved
Make stack DLS and initialize for each domain Actually implemented by Felix Krayer
522315f
to
80cac2a
Compare
80cac2a
to
3f7d226
Compare
Turns out introducing domain_shims breaks GobView. The application than outputs
on the console and hangs indefinitely. |
Do you know where this call happens? Is it something we can safely stub to just return unit or somehow avoid these calls when in Gobview mode? |
I guess we either need to turn the gobview job into an unlocked one, or provide a different lockfile for the gobview job somehow? |
let pp_print_option ?(none = fun _ () -> ()) pp_v ppf = function | ||
| None -> none ppf () | ||
| Some v -> pp_v ppf v | ||
in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this about? Isn't it just a copy of what's in Stdlib.Format
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The module now uses BatFormat
, which does not define the method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But why BatFormat
? The standard library version from OCaml 5 should be safe: it's been reimplemented to use DLS properly. Batteries as no domains-specific fixes.
src/util/timing/goblint_timing.ml
Outdated
let enabled_dls = Domain.DLS.new_key (fun () -> false) | ||
let options_dls = Domain.DLS.new_key (fun () -> dummy_options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary for these to be domain-local? These are more like global options than state.
#1550 mentions that maybe only current
needs to be domain-local.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Felix himself has introduced all of them in 62422e9
As far as can see enabled_dls
is rather tracking if it is active in a given moment (set via start
and stop
), and making it a reference makes the solver crash at the end. Options however are global options and can be made into refs.
9e1614d reflects this now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as can see
enabled_dls
is rather tracking if it is active in a given moment (set via start and stop), and making it a reference makes the solver crash at the end.
But we only ever call start
at the very beginning of Goblint and never even call stop
. So I don't understand why there would be any issue. start
also modifies options
and that's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, making them into refs did cause issues, so I will need to investigate this further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 8 out of 25 changed files in this pull request and generated 1 comment.
Files not reviewed (17)
- dune-project: Language not supported
- goblint.opam: Language not supported
- goblint.opam.locked: Language not supported
- src/cdomain/value/cdomains/mutexAttrDomain.ml: Language not supported
- src/cdomain/value/dune: Language not supported
- src/common/util/messages.ml: Language not supported
- src/config/options.schema.json: Language not supported
- src/dune: Language not supported
- src/goblint_lib.ml: Language not supported
- src/lifters/wideningTokenLifter.ml: Language not supported
- src/solver/dune: Language not supported
- src/util/parallel/domainsafeLazy.ml: Language not supported
- src/util/parallel/domainsafeLazy.mli: Language not supported
- src/util/parallel/dune: Language not supported
- src/util/parallel/gobMutex.domainslib.ml: Language not supported
- src/util/parallel/gobMutex.no-domainslib.ml: Language not supported
- src/util/parallel/threadpool.domainslib.ml: Language not supported
Comments suppressed due to low confidence (1)
.github/workflows/unlocked.yml:255
- [nitpick] Consider using consistent capitalization for 'GobView' across workflow configurations to align with the documentation.
gobview:
Looks like the Copilot reviews won't be too useful for us right now since it doesn't want to review .ml files. |
(name goblint_parallel) | ||
(public_name goblint.parallel) | ||
(libraries | ||
batteries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is batteries used here?
(select threadpool.ml from | ||
(domainslib -> threadpool.domainslib.ml) | ||
(-> threadpool.no-domainslib.ml) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) | |
) |
@@ -0,0 +1,6 @@ | |||
(** Lazy type which protects against concurrent calls of 'force'. *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(** Lazy type which protects against concurrent calls of 'force'. *) | |
(** Lazy type which protects against concurrent calls of {!force}. *) |
src/util/parallel/domainsafeLazy.ml
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're taking the mutex implementation from domain-local-await, why not the lazy? https://github.com/ocaml-multicore/domain-local-await?tab=readme-ov-file#example-concurrency-safe-lazy (pending the licence question below)
In particular, that one seems to properly handle exceptions, whereas the one here would royally break: the mutex wouldn't be unlocked even and any future attempts to lock it will block forever.
(select gobMutex.ml from | ||
(domainslib -> gobMutex.domainslib.ml) | ||
( -> gobMutex.no-domainslib.ml) | ||
) | ||
(select threadpool.ml from | ||
(domainslib -> threadpool.domainslib.ml) | ||
(-> threadpool.no-domainslib.ml) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a good idea to have .mli
files for these as well (not dependent on domainlib presence).
let create n = () | ||
|
||
let add_work pool f = | ||
let promise = Domain.spawn f in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dummy implementation is supposed to be OCaml 4 compatible, so it can't use Domain
at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Domain is provided by domain_shims
, which is already included here. It acts as Domain
on Ocaml5 and provides async parallelism on OCaml4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
domain_shims implements Domain
via Thread
though, so it still allows interleaved execution (but not parallel execution). Even for that, output needs to be done under a real mutex, not a dummy one.
If the non-parallel mutex is a dummy, then the non-parallel thread pool probably should be even stupider: just run in the same thread entirely.
This contains the rather harmless parts. As discussed, all variations of modules have been implemented using
domain_shims
and the select stanza in dune.ppx_optcomp
is not involved anymore.The PR is rather large, but can be reviewed commit-by-commit.