diff --git a/ci/travis/ci.sh b/ci/travis/ci.sh index 9eb785c98..8e639933a 100755 --- a/ci/travis/ci.sh +++ b/ci/travis/ci.sh @@ -104,6 +104,13 @@ upload_wheels() { fi done fi + ( + cd "${WORKSPACE_DIR}"/python + if ! python -s -c "import ray, sys; sys.exit(0 if ray._raylet.OPTIMIZED else 1)"; then + echo "ERROR: Uploading non-optimized wheels! Performance will suffer for users!" + false + fi + ) } test_core() { diff --git a/doc/source/development.rst b/doc/source/development.rst index 4c0867fd1..1b306ba70 100644 --- a/doc/source/development.rst +++ b/doc/source/development.rst @@ -23,7 +23,7 @@ changes you make to files in the Ray directory will not have any effect. If you run into **Permission Denied** errors when running ``pip install``, you can try adding ``--user``. You may also need to run something like ``sudo -chown -R $USER $HOME/anaconda3`` (substituting in the appropriate path). +chown -R "$USER" ~/anaconda3`` (substituting in the appropriate path). If you make changes to the C++ or Python files, you will need to run the build so C++ code is recompiled and/or Python files are redeployed in @@ -38,6 +38,35 @@ the following: This command is not enough to recompile all C++ unit tests. To do so, see `Testing locally`_. +Fast, Debug, and Optimized Builds +--------------------------------- + +Currently, Ray is built with optimizations, which can take a long time and +interfere with debugging. To perform fast, debug, or optimized builds, you can +run the following (via ``-c`` ``fastbuild``/``dbg``/``opt``, respectively): + +.. code-block:: shell + + bazel build -c fastbuild //:ray_pkg + +This will rebuild Ray with the appropriate options (which may take a while). +If you need to build all targets, you can use ``"//:*"`` instead of +``//:ray_pkg``. + +To make this change permanent, you can add an option such as the following +line to your user-level ``~/.bazelrc`` file (not to be confused with the +workspace-level ``.bazelrc`` file): + +.. code-block:: shell + + build --compilation_mode=fastbuild + +If you do so, remember to revert this change, unless you want it to affect +all of your development in the future. + +Using ``dbg`` instead of ``fastbuild`` generates more debug information, +which can make it easier to debug with a debugger like ``gdb``. + .. _python-develop: Developing Ray (Python Only) diff --git a/python/ray/_raylet.pxd b/python/ray/_raylet.pxd index e69b5c452..969801655 100644 --- a/python/ray/_raylet.pxd +++ b/python/ray/_raylet.pxd @@ -26,6 +26,18 @@ from ray.includes.function_descriptor cimport ( CFunctionDescriptor, ) +cdef extern from *: + """ + #if __OPTIMIZE__ && __OPTIMIZE__ == 1 + #undef __OPTIMIZE__ + int __OPTIMIZE__ = 1; + #define __OPTIMIZE__ 1 + #else + int __OPTIMIZE__ = 0; + #endif + """ + int __OPTIMIZE__ + cdef extern from "Python.h": # Note(simon): This is used to configure asyncio actor stack size. # Cython made PyThreadState an opaque types. Saying that if the user wants diff --git a/python/ray/_raylet.pyx b/python/ray/_raylet.pyx index 48df281cc..d3a65bd0b 100644 --- a/python/ray/_raylet.pyx +++ b/python/ray/_raylet.pyx @@ -109,6 +109,8 @@ include "includes/serialization.pxi" include "includes/libcoreworker.pxi" include "includes/global_state_accessor.pxi" +# Expose GCC & Clang macro to report whether C++ optimizations were enabled during compilation. +OPTIMIZED = __OPTIMIZE__ logger = logging.getLogger(__name__) diff --git a/python/ray/ray_perf.py b/python/ray/ray_perf.py index 55c3c100c..789ac5b6a 100644 --- a/python/ray/ray_perf.py +++ b/python/ray/ray_perf.py @@ -1,12 +1,15 @@ """This is the script for `ray microbenchmark`.""" import asyncio +import logging import os import time import numpy as np import multiprocessing import ray +logger = logging.getLogger(__name__) + # Only run tests matching this filter pattern. filter_pattern = os.environ.get("TESTS_TO_RUN", "") @@ -89,7 +92,21 @@ def timeit(name, fn, multiplier=1): round(np.std(stats), 2)) +def check_optimized_build(): + if not ray._raylet.OPTIMIZED: + msg = ("WARNING: Unoptimized build! " + "To benchmark an optimized build, try:\n" + "\tbazel build -c opt //:ray_pkg\n" + "You can also make this permanent by adding\n" + "\tbuild --compilation_mode=opt\n" + "to your user-wide ~/.bazelrc file. " + "(Do not add this to the project-level .bazelrc file.)") + logger.warning(msg) + + def main(): + check_optimized_build() + print("Tip: set TESTS_TO_RUN='pattern' to run a subset of benchmarks") ray.init()