Skip to content

Commit

Permalink
Set -O3 when building python wheels in opt mode.
Browse files Browse the repository at this point in the history
See sgkit-dev/vcf-zarr-publication#161

The default bazel -c opt build mode is -O2, vs. the default cmake Release
optimization mode of -O3.  It turns out that gcc doesn't unroll the underlying
blosc loop at -O3, so this sets the level to -O3 when building wheels.

PiperOrigin-RevId: 698176524
Change-Id: Iea9c47e1cb96d40169d2b28af93cf53b33e6991c
  • Loading branch information
laramiel authored and copybara-github committed Nov 20, 2024
1 parent f462942 commit 758b6e1
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,23 +234,31 @@ def run(self):
bazelisk = os.getenv('TENSORSTORE_BAZELISK', 'bazelisk.py')
# Controlled via `setup.py build_ext --debug` flag.
default_compilation_mode = 'dbg' if self.debug else 'opt'
compilation_mode = os.getenv(
'TENSORSTORE_BAZEL_COMPILATION_MODE', default_compilation_mode
)
startup_options = shlex.split(
os.getenv('TENSORSTORE_BAZEL_STARTUP_OPTIONS', '')
)
build_options = shlex.split(
os.getenv('TENSORSTORE_BAZEL_BUILD_OPTIONS', '')
)

# Build with a specific compilation mode.
# When in opt mode also set -O3 optimizations to override bazel -O2.
compilation_mode = os.getenv(
'TENSORSTORE_BAZEL_COMPILATION_MODE', default_compilation_mode
)
build_flags = ['build', '-c', compilation_mode]
if compilation_mode == 'opt':
if 'win32' in sys.platform:
# Assumes MSVC compiler.
build_flags.append('--copt=/Ox')
else:
build_flags.append('--copt=-O3')

build_command = (
[sys.executable, '-u', bazelisk]
+ startup_options
+ build_flags
+ [
'build',
'-c',
compilation_mode,
'//python/tensorstore:_tensorstore__shared_objects',
'--verbose_failures',
# Bazel does not seem to download these files by default when
Expand Down

0 comments on commit 758b6e1

Please sign in to comment.