Correct the default Bazel vector instructions options#782
Conversation
The documented way that `bazel build`, `bazel test`, and similar commands behave without options like `--config=avx` is that the AVX, SSE, and other optimization options are not applied. However, this was not what was happening: the default ended up applying them. The previous changes to `.bazelrc` and `dev_tools/test_libs.sh` that I did in PR #758 and other recent PRs not fully address this. The changes here invert the way `--build_tag_filters` and `--test_tag_filters` are used: they are set to filter out things tagged with `avx` and `sse` by default in `.bazelrc`, and options like `--config=sse` add the things back. To make this work, `dev_tools/test_libs.sh` has to be updated as well.
6daef69 to
3f35e62
Compare
The documented way that `bazel build`, `bazel test`, and similar commands behave without options like `--config=avx` is that the AVX, SSE, and other optimization options are not applied. However, this was not what was happening: the default ended up applying them. The previous changes to `.bazelrc` and `dev_tools/test_libs.sh` that I did in PR #758 and other recent PRs not fully address this. The changes here invert the way `--build_tag_filters` and `--test_tag_filters` are used: they are set to filter out things tagged with `avx` and `sse` by default in `.bazelrc`, and options like `--config=sse` add the things back. To make this work, `dev_tools/test_libs.sh` has to be updated as well.
3f35e62 to
0ce15cf
Compare
| [[ "$features" == *avx2* ]] && filters+=",avx" | ||
| [[ "$features" == *sse* ]] && filters+=",sse" |
There was a problem hiding this comment.
This runs into the same problem as in #710 - the shell has the -e option so the script will exit here if any of avx2 or sse features were missing. To have a positive condition, you need to rewrite this as
if [[ "$features" == *avx2* ]]; then
filters+=",avx"
fi
...There was a problem hiding this comment.
So, I tested the following, and it does not exit early. Do you have an environment where it doesn't work this way?
#!/usr/bin/env bash
set -eo pipefail -o errtrace
declare foo=""
declare bar="original"
foo="something"
[[ "$foo" == *notthere* ]] && bar="new string"
echo $barThere was a problem hiding this comment.
I stand corrected - per bash set -e doc for the && and || lists it is only the last command that counts for errexit. I got confused, because on my Debian box it indeed exits early in an interactive session. This happens because interactive bash runs some fancy prompt functions which try to restore the exit status of the last command and that triggers errexit.
With your snippet (and the same system bashrc) this can be reproduced with
bash -i <snippet.bash
TLDR - it is OK as is.
There was a problem hiding this comment.
Wow, that's unobvious. Thanks for the info!
pavoljuhas
left a comment
There was a problem hiding this comment.
test_libs.sh may exit too early, please correct.
It's not clear if it's essential to use =, but it seems more likely to avoid some argument-splitting issues, so let's use that consistently.
On lines 48-49: if the first bazel build invocation succeeds, then the second is pointless because it's _more_ likely to succeed than the first. If the first invocation fails, we won't get to the second one anyway.
The documented way that
bazel build,bazel test, and similar commands behave without options like--config=avxis that the AVX, SSE, and other optimization options are not applied. However, this was not what was happening: the default ended up applying them even if--config=sseetc. were not used. Evidently, the previous changes to.bazelrcanddev_tools/test_libs.shthat I did in PR #758 and other recent PRs not correct this.The changes here invert the way
--build_tag_filtersand--test_tag_filtersare used: they are set to filter out things tagged withavxandsseby default in.bazelrc, and options like--config=sseadd the things back.To make this work,
dev_tools/test_libs.shhas to be updated as well.