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

Allow launcher_extra to split quoted values #444

Merged
merged 6 commits into from Oct 19, 2022

Conversation

bryevdv
Copy link
Contributor

@bryevdv bryevdv commented Oct 18, 2022

This PR makes the driver automatically split --launcher-extra values on whitespace internally, Doing so allows for simpler invocations with quoted strings like this:

legate --launcher-extra="-H =g0002,g0003"

rather than having to manually split across multiple --launcher-extra arguments as is currently required:

legate --launcher-extra="-H" --launcher-extra="g0002,g0003"

cc @lightsighter

@bryevdv bryevdv added the category:improvement PR introduces an improvement and will be classified as such in release notes label Oct 18, 2022
@manopapad
Copy link
Contributor

manopapad commented Oct 18, 2022

What if I want to pass to the launcher an argument that contains spaces? Say I want the final result to be something like:

mpirun -f "some dirname with spaces/a.txt" legate-prog.py

@bryevdv
Copy link
Contributor Author

bryevdv commented Oct 18, 2022

What if I want to pass to the launcher an argument that contains spaces? Say I want the final result to be something like:

Ah, I misunderstood your comment in chat... Yah that's a fly in the ointment. I am sure there are ways to accommodate this possibility but I'm not sure we'd want to inflict them on users. Do any of these sound appealing?

  • require quoted quotes legate --launcher-extra="-f 'some dir/foo.txt'"
  • another cmdline opt: legate --launcher-extra="-f" --launcher-extra-nosplit="some dir/foo.txt"
  • env var WAR? FOO="some dir/foo.txt" then --launcher-extra="-f $FOO"

? that said are we sure that it even works now/before without extra quoting? I would expect

legate --launcher-extra="-f" --launcher-extra="some dir/foo.txt"

to render as

mpirun -f some dir/foo.txt

which would not work?

If extra quoting is already necessary to make things work then we could try to make this PR more careful to not split quoted values

@manopapad
Copy link
Contributor

require quoted quotes

Of the alternatives, this is the most palatable. I would be a little weary of writing a "quoted expression" parser from scratch, as there's a bunch of silly edge cases that we would need to handle, e.g.:

--launcher-extra "a b \"c \\" d\" e"

which should produce these final arguments: a, b, c " d , and e.

So it would be great if there's an existing "quoted expression" parser we can use, e.g. something in the standard library, or invoking a sub-shell.

that said are we sure that it even works now/before without extra quoting?

Yes, it works today (in verbose mode you even quote the arguments!)

~/cunumeric> ~/quickstart/run.sh 1 prog.py --dry-run --launcher-extra="-f" --launcher-extra="some dir/f.txt"
Redirecting stdout, stderr and logs to /Users/mpapadakis/Sites/local/2022/10/18/140237
Did not detect a supported cluster, assuming local-node run.
Command: legate --launcher mpirun --numamem 8192 --omps 1 --ompthreads 4 --cpus 1 --sysmem 256 --verbose --log-to-file --nodes 1 --ranks-per-node 1 prog.py --dry-run --launcher-extra=-f --launcher-extra=some dir/f.txt --logdir /Users/mpapadakis/Sites/local/2022/10/18/140237

--- Legion Python Configuration ------------------------------------------------

Legate paths:
  legate_dir       : /Users/mpapadakis/legate.core
  legate_build_dir : /Users/mpapadakis/legate.core/_skbuild/macosx--x86_64-3.8/cmake-build
  bind_sh_path     : /Users/mpapadakis/legate.core/bind.sh
  legate_lib_path  : /Users/mpapadakis/legate.core/build/lib

Legion paths:
  legion_bin_path       : /Users/mpapadakis/legate.core/_skbuild/macosx--x86_64-3.8/cmake-build/_deps/legion-build/bin
  legion_lib_path       : /Users/mpapadakis/legate.core/_skbuild/macosx--x86_64-3.8/cmake-build/_deps/legion-build/lib
  realm_defines_h       : /Users/mpapadakis/legate.core/_skbuild/macosx--x86_64-3.8/cmake-build/_deps/legion-build/runtime/realm_defines.h
  legion_defines_h      : /Users/mpapadakis/legate.core/_skbuild/macosx--x86_64-3.8/cmake-build/_deps/legion-build/runtime/legion_defines.h
  legion_spy_py         : /Users/mpapadakis/legion/tools/legion_spy.py
  legion_prof_py        : /Users/mpapadakis/legion/tools/legion_prof.py
  legion_python         : /Users/mpapadakis/legate.core/_skbuild/macosx--x86_64-3.8/cmake-build/_deps/legion-build/bin/legion_python
  legion_module         : /Users/mpapadakis/legion/bindings/python/build/lib
  legion_jupyter_module : /Users/mpapadakis/legion/jupyter_notebook

Command:
  mpirun -n 1 --npernode 1 --bind-to none --mca mpi_warn_on_fork 0 -x CONDA_SHLVL -x CONDA_PROMPT_MODIFIER -x CONDA_EXE -x CONDA_TOOLCHAIN_BUILD -x CONDA_TOOLCHAIN_HOST -x LEGION_DIR -x CONDA_PREFIX_1 -x PATH -x CONDA_PREFIX -x CONDA_PYTHON_EXE -x CONDA_DEFAULT_ENV -x CMAKE_PREFIX_PATH -x PYTHONDONTWRITEBYTECODE -x PYTHONPATH -x NCCL_LAUNCH_MODE -x GASNET_MPI_THREAD -x DYLD_LIBRARY_PATH -x LEGATE_NEED_OPENMP -x LEGATE_MAX_DIM -x LEGATE_MAX_FIELDS -x REALM_BACKTRACE -f 'some dir/f.txt' /Users/mpapadakis/legate.core/_skbuild/macosx--x86_64-3.8/cmake-build/_deps/legion-build/bin/legion_python -ll:py 1 -lg:local 0 -ll:ocpu 1 -ll:othr 4 -ll:onuma 1 -ll:util 2 -ll:csize 256 -ll:nsize 8192 -level openmp=5 -logfile /Users/mpapadakis/Sites/local/2022/10/18/140237/legate_%.log -lg:eager_alloc_percentage 50 prog.py

@bryevdv
Copy link
Contributor Author

bryevdv commented Oct 18, 2022

I would be a little weary of writing a "quoted expression" parser from scratch

I would have to be back in undergrad CS to even dream of it :)

I think stdlib shlex.split might do what we want out of the box, though.

@bryevdv
Copy link
Contributor Author

bryevdv commented Oct 18, 2022

@manopapad see the test in f201fdc I believe that is what we want.

@bryevdv
Copy link
Contributor Author

bryevdv commented Oct 18, 2022

@manopapad FYI I think the quickstart run.sh must be quoting internally or something?

legate --verbose --dry-run --launcher=mpirun --launcher-extra="-f" --launcher-extra="some dir/f.txt" 

yields for me:

... -x REALM_BACKTRACE -f some dir/f.txt /home/bryan/work/legate.core/_skbuild/linu....

@bryevdv
Copy link
Contributor Author

bryevdv commented Oct 18, 2022

Yikes, despite my test, the actual output is wrong:

legate --verbose --dry-run --launcher=mpirun --launcher-extra="-f 'some dir/f.txt'" 

yields

-x REALM_BACKTRACE -f ''"'"'some dir/f.txt'"'"'' /home/bryan/work/legate.co

🙄

@bryevdv
Copy link
Contributor Author

bryevdv commented Oct 18, 2022

OK, we were already calling shlex.quote near the end, so the posix=False was not necessary and resulted in over-quoting. I think its finally good:

legate --verbose --dry-run --launcher=mpirun --launcher-extra="-f 'some dir/f.txt'" --color

then

... -x REALM_BACKTRACE -f 'some dir/f.txt' /home/bryan/work/legate.core ...

@manopapad
Copy link
Contributor

Actually, can we do the same for nsys_extra? It has the exact same constraints as launcher_extra.

Also, can we note on the documentation for these two arguments that we split on whitespace, and the user will need to internally quote if they want to pass an argument that is meant to contain spaces?

@manopapad
Copy link
Contributor

Otherwise works great!

~/legate.core> ~/quickstart/run.sh 1 prog.py --dry-run --launcher-extra="a b \"c \\\" d\" e"
Redirecting stdout, stderr and logs to /Users/mpapadakis/Sites/local/2022/10/18/165802
...
Command:
  mpirun -n 1 --npernode 1 --bind-to none --mca mpi_warn_on_fork 0 -x CONDA_SHLVL -x CONDA_PROMPT_MODIFIER -x CONDA_EXE -x CONDA_TOOLCHAIN_BUILD -x CONDA_TOOLCHAIN_HOST -x LEGION_DIR -x CONDA_PREFIX_1 -x PATH -x CONDA_PREFIX -x CONDA_PYTHON_EXE -x CONDA_DEFAULT_ENV -x CMAKE_PREFIX_PATH -x PYTHONDONTWRITEBYTECODE -x PYTHONPATH -x NCCL_LAUNCH_MODE -x GASNET_MPI_THREAD -x DYLD_LIBRARY_PATH -x LEGATE_NEED_OPENMP -x LEGATE_MAX_DIM -x LEGATE_MAX_FIELDS -x REALM_BACKTRACE a b 'c " d' e /Users/mpapadakis/legate.core/_skbuild/macosx--x86_64-3.8/cmake-build/_deps/legion-build/bin/legion_python -ll:py 1 -lg:local 0 -ll:ocpu 1 -ll:othr 4 -ll:onuma 1 -ll:util 2 -ll:csize 256 -ll:nsize 8192 -level openmp=5 -logfile /Users/mpapadakis/Sites/local/2022/10/18/165802/legate_%.log -lg:eager_alloc_percentage 50 prog.py

@bryevdv
Copy link
Contributor Author

bryevdv commented Oct 19, 2022

@manopapad done in b47b864

@bryevdv bryevdv merged commit 90fb1ee into nv-legate:branch-22.12 Oct 19, 2022
@bryevdv bryevdv deleted the bv/launcher-extra-ux branch October 19, 2022 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:improvement PR introduces an improvement and will be classified as such in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants