Repository navigation
Conversation
…he runtime vxc puts vx_cancel_off before each call of a Drop impl's drop, and vx_cancel_on after it. Only the runtime reads the state that they set: in a wait, cancelled(), within, a tasks block, a task and the failure of a task. The drop of a Vec, a String or a BigInt only frees memory, so it cannot see that state. The solver written in Vx runs such drops in each step, and the two calls took more time than the drops. The new MLIR pass vx-remove-unseen-drop-scopes reads the whole module. A function can reach the runtime when it calls a function with no body in the module. The C functions of the heap and vx_string_drop, which only free or allocate memory, are the exception. A call through a function value, inline assembly, and an op of a dialect that the pass does not know count too. Each caller of such a function can reach the runtime as well. The pass then removes each pair of the two calls in one block when no op between them can reach the runtime. It runs after convert-vx-to-standard and before inlining, at each -O level. This is an analysis of the call graph that only changes the generated code, as W3 of waiting_tasks_channels_and_task_errors.md does. Each drop gets the same deadline and the same cancel state as before. Part of #4583
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #4583.
What changes
vxc puts
vx_cancel_offbefore each call of aDropimpl'sdrop, andvx_cancel_onafter it. Between them, cancellation is off and the drop's deadline holds (F6 and F6a indocs/discussions/waiting_tasks_channels_and_task_errors.md). Only the runtime reads that state: in a wait,cancelled(),within, atasksblock, a task and the failure of a task. Thedropof aVec, aStringor aBigIntonly frees memory, so it cannot see that state. The solver written in Vx runs such drops in each step, and the two calls took more time than the drops.A new MLIR pass,
vx-remove-unseen-drop-scopes(src/dialect/DropScopes.cpp). It reads the whole module and finds each function that can reach the runtime. Such a function has one of these in its body:malloc,calloc,realloc,aligned_alloc,freeandvx_string_dropdo not count, because they only allocate or free memory.vxorgpuThe pass then removes
vx_cancel_offand thevx_cancel_onafter it, in one block, when no op between them can reach the runtime. A pair in two blocks stays.Where it runs. After
convert-vx-to-standard, which turns the heap ops into calls ofmallocandfree. Before inlining, while eachdropis still a call between the two. At each-Olevel, in both pipelines (src/driver.rsandsrc/codegen/mod.rs).The rule. This is an analysis of the call graph that only changes the generated code, as W3 of the same document does. The
drops that it changes cannot see the calls, so eachdropbehaves as before. A paragraph in F6a says so. The call ofwait_limitstays, because it can print or have another effect. At-O2, LLVM removes it when it only returns a number.In the runner of the solver below, the calls of
vx_cancel_offwent from 1233 to 4. The 4 that stay are inFile::openandread_file. Each is around adropthat calls the runtime to close a file, unmap a file or free a C string.Measurements
The solver written in Vx, on the same 340 queries as #4598:
ifstatements or 12matchstatements in a rowtests/solver/queries/that are linearA program built from
run_corpus.vxruns them all, one after the other. I built it twice withvxc -O2: with the vxc ofmainand with the vxc of this PR. I linked each with two runtimes built withcargo build --release: the runtime ofmain, and the runtime of #4598. The answers are the same in each run.caffeinate -dimsstd::algo::smtofmainat 414bb29Total time of each group, in ms: the median of 5 runs, with the fastest and the slowest run.
mainmainmainmainWith this PR, the runtime of #4598 makes no difference to the solver, because its drops no longer make the two calls. #4598 still makes each
dropthat keeps the calls cheaper.Each of the 340 queries is faster with this PR. Per query,
maintakes this long, in times the time with this PR and the runtime of #4598:The slowest nonlinear query took 1408 ms with
main, and takes 550 ms with this PR. Neither this solver nor z3 finds an answer to it. The next 4 are fromllama2.vx. Each took about 205 ms withmain, and takes about 79 ms with this PR.Limits
dropin a package compiled on its own keeps them.Commands
Tests
tests/optimizations/pass/a_drop_keeps_its_cancel_calls_only_when_it_can_reach_the_runtime.mlrruns the pass withvx-opton one pair around each kind of code.tests/frontend/pass/a_drop_that_cannot_wait_needs_no_cancel_calls.vxruns it on the MLIR of a program. Thedropof aVec<u64>and thedropof aStringlose the calls. Thedrops that sleep, drop a value that sleeps, callcancelled(), call a function value or start a task keep them.I broke the pass in 9 ways, one at a time, and each made a test fail:
.mlrtest that failed.vxtest, at thedropof aNap.vxtest, at thedropof aCallsvxopmallocandfreereach the runtime.vxtest, at thedropof aVec<u64>vx_string_dropreaches the runtimedropof aString.vxtest, at thedropof aStringvx_cancel_offandvx_cancel_onreach the runtimedropthat drops such a fieldscf.ifdropthat sleeps.vxtest, and 3 tests of drops that wait intests/backend/pass/