Skip to content

Commit

Permalink
add dist/inplace python build scripts and improve rapids-generate-scr…
Browse files Browse the repository at this point in the history
…ipts performance
  • Loading branch information
cwharris committed Sep 18, 2023
1 parent f77f7c7 commit bbc9ce1
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 68 deletions.
2 changes: 1 addition & 1 deletion features/src/rapids-build-utils/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "NVIDIA RAPIDS devcontainer build utilities",
"id": "rapids-build-utils",
"version": "23.10.11",
"version": "23.10.12",
"description": "A feature to install the RAPIDS devcontainer build utilities",
"containerEnv": {
"BASH_ENV": "/etc/bash.bash_env"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ TMPL=/opt/rapids-build-utils/bin/tmpl;
TMP_SCRIPT_DIR=/tmp/rapids-build-utils
mkdir -p $TMP_SCRIPT_DIR

remove_script_for_pattern() {
clean_scripts() {
set -euo pipefail;
local pattern="${1}";
for x in $(find $TMP_SCRIPT_DIR -printf '%f\n' | grep -oP "$pattern"); do
(sudo rm "$TMP_SCRIPT_DIR/$x" >/dev/null 2>&1 || true);
(sudo update-alternatives --remove-all $x >/dev/null 2>&1 || true);
for x in $(find $TMP_SCRIPT_DIR -maxdepth 1 -type f -printf '%f\n'); do
(sudo update-alternatives --remove-all $x > /dev/null 2>&1);
done
sudo rm -rf "$TMP_SCRIPT_DIR";
mkdir -p $TMP_SCRIPT_DIR
}

generate_script() {
local bin="${1:-}";
if test -n "$bin" && ! test -f "$TMP_SCRIPT_DIR/${bin}"; then
(
cat - \
| envsubst '$NAME
$SRC_PATH
Expand All @@ -37,12 +38,16 @@ generate_script() {
sudo update-alternatives --install \
"/usr/bin/${bin}" "${bin}" "$TMP_SCRIPT_DIR/${bin}" 0 \
>/dev/null 2>&1;
) & true;

echo "$!"
fi
}

generate_all_script_impl() {
local bin="$SCRIPT-all";
if test -n "$bin" && ! test -f "$TMP_SCRIPT_DIR/${bin}"; then
(
cat - \
| envsubst '$NAMES
$SCRIPT' \
Expand All @@ -53,6 +58,9 @@ generate_all_script_impl() {
sudo update-alternatives --install \
"/usr/bin/${bin}" "${bin}" "$TMP_SCRIPT_DIR/${bin}" 0 \
>/dev/null 2>&1;
) & true;

echo "$!"
fi
}

Expand Down Expand Up @@ -96,6 +104,11 @@ generate_python_scripts() {
| generate_script "${script_name}-${PY_LIB}-python";
) || true;
done
for script_name in "inplace" "dist"; do (
cat ${TMPL}/python-build-${script_name}.tmpl.sh \
| generate_script "build-${PY_LIB}-python-${script_name}";
) || true;
done
cat ${TMPL}/python-wheel.tmpl.sh \
| generate_script "build-${PY_LIB}-wheel";
}
Expand Down Expand Up @@ -271,9 +284,10 @@ if test -n "${rapids_build_utils_debug:-}"; then
PS4="+ ${BASH_SOURCE[0]}:\${LINENO} "; set -x;
fi

(remove_script_for_pattern '^clone-[A-Za-z\-_]*$');
(remove_script_for_pattern '^clean-[A-Za-z\-_]*$');
(remove_script_for_pattern '^build-[A-Za-z\-_]*$');
(remove_script_for_pattern '^configure-[A-Za-z\-_]*$');
(clean_scripts);

(generate_scripts "$@");
for pid in $(generate_scripts "$@"); do
while [[ -e "/proc/$pid" ]]; do
sleep 0.1
done
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#! /usr/bin/env bash

build_${PY_LIB}_python_dist() {

echo "python dist builds not yet implemented";
exit 1;
}

if test -n "${rapids_build_utils_debug:-}"; then
PS4="+ ${BASH_SOURCE[0]}:\${LINENO} "; set -x;
fi

build_${PY_LIB}_python_dist "$@";
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#! /usr/bin/env bash

build_${PY_LIB}_python_inplace() {

set -euo pipefail;

if [[ ! -d ~/${PY_SRC} ]]; then
exit 1;
fi

local verbose="";
local parallel="";

eval "$( \
devcontainer-utils-parse-args --names '
a|archs |
j|parallel |
v|verbose |
m|max-device-obj-memory-usage |
' - <<< "$@" \
| xargs -r -d'\n' -I% echo -n local %\; \
)";

verbose="${v:-${verbose:-}}";
parallel="${j:-${parallel:-${JOBS:-${PARALLEL_LEVEL:-$(nproc --ignore=2)}}}}";

local cmake_args=();

if test -n "${verbose}"; then
cmake_args+=("--log-level=VERBOSE");
fi

cmake_args+=(${CMAKE_ARGS:-});
cmake_args+=(${CPP_DEPS});
cmake_args+=(${CPP_ARGS});
cmake_args+=(${__rest__[@]});

local ninja_args=();
if test -n "${verbose}"; then
ninja_args+=("-v");
fi
if test -n "${parallel}"; then
if [ "${parallel:-}" = "true" ]; then
parallel="";
fi
ninja_args+=("-j${parallel}");
fi

local pip_args=();
if test -n "${verbose}"; then
pip_args+=("-vv");
fi
pip_args+=("--no-build-isolation");
pip_args+=("--no-deps");
pip_args+=("--editable");
pip_args+=(~/"${PY_SRC}");
cmake_args+=("-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON");

trap "rm -rf ~/'${PY_SRC}/$(echo "${PY_LIB}" | tr '-' '_').egg-info'" EXIT;

time \
CMAKE_GENERATOR="Ninja" \
CMAKE_ARGS="${cmake_args[@]}" \
SKBUILD_BUILD_OPTIONS="${ninja_args[@]}" \
SETUPTOOLS_ENABLE_FEATURES="legacy-editable" \
python -m pip install ${pip_args[@]} \
;
}

if test -n "${rapids_build_utils_debug:-}"; then
PS4="+ ${BASH_SOURCE[0]}:\${LINENO} "; set -x;
fi

build_${PY_LIB}_python_inplace "$@";
Original file line number Diff line number Diff line change
@@ -1,74 +1,27 @@
#! /usr/bin/env bash

build_${PY_LIB}_python() {

set -euo pipefail;

if [[ ! -d ~/${PY_SRC} ]]; then
exit 1;
fi

local verbose="";
local parallel="";
build_${PY_LIB}_python_dist() {

# pull out the --rapids-dist or --rapids-inplace args (if any)
eval "$( \
devcontainer-utils-parse-args --names '
a|archs |
j|parallel |
v|verbose |
m|max-device-obj-memory-usage |
rapids-dist |
rapids-inplace |
' - <<< "$@" \
| xargs -r -d'\n' -I% echo -n local %\; \
)";

verbose="${v:-${verbose:-}}";
parallel="${j:-${parallel:-${JOBS:-${PARALLEL_LEVEL:-$(nproc --ignore=2)}}}}";
# check if rapids_dist is set.

local cmake_args=();

if test -n "${verbose}"; then
cmake_args+=("--log-level=VERBOSE");
if [[ ! -z ${rapids_dist+x} ]]; then
build-${PY_LIB}-python-dist ${__rest__[@]};
else
build-${PY_LIB}-python-inplace ${__rest__[@]};
fi

cmake_args+=(${CMAKE_ARGS:-});
cmake_args+=(${CPP_DEPS});
cmake_args+=(${CPP_ARGS});
cmake_args+=(${__rest__[@]});

local ninja_args=();
if test -n "${verbose}"; then
ninja_args+=("-v");
fi
if test -n "${parallel}"; then
if [ "${parallel:-}" = "true" ]; then
parallel="";
fi
ninja_args+=("-j${parallel}");
fi

local pip_args=();
if test -n "${verbose}"; then
pip_args+=("-vv");
fi
pip_args+=("--no-build-isolation");
pip_args+=("--no-deps");
pip_args+=("--editable");
pip_args+=(~/"${PY_SRC}");
cmake_args+=("-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON");

trap "rm -rf ~/'${PY_SRC}/$(echo "${PY_LIB}" | tr '-' '_').egg-info'" EXIT;

time \
CMAKE_GENERATOR="Ninja" \
CMAKE_ARGS="${cmake_args[@]}" \
SKBUILD_BUILD_OPTIONS="${ninja_args[@]}" \
SETUPTOOLS_ENABLE_FEATURES="legacy-editable" \
python -m pip install ${pip_args[@]} \
;
}

if test -n "${rapids_build_utils_debug:-}"; then
PS4="+ ${BASH_SOURCE[0]}:\${LINENO} "; set -x;
fi

build_${PY_LIB}_python "$@";
build_${PY_LIB}_python_dist "$@";

0 comments on commit bbc9ce1

Please sign in to comment.