Skip to content

Commit 0485fcf

Browse files
q10facebook-github-bot
authored andcommitted
Update setup.py to account for targets and variants (#4023)
Summary: X-link: facebookresearch/FBGEMM#1116 Pull Request resolved: #4023 Reviewed By: jwfromm Differential Revision: D73744468 Pulled By: q10 fbshipit-source-id: 131d6e5a1645b458fe3b8ace98184cea86ce3b1e
1 parent 219132e commit 0485fcf

File tree

8 files changed

+184
-136
lines changed

8 files changed

+184
-136
lines changed

.github/scripts/fbgemm_gpu_build.bash

+7-8
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ __configure_fbgemm_gpu_build_cpu () {
141141
# Update the package name and build args depending on if CUDA is specified
142142
echo "[BUILD] Setting CPU-only build args ..."
143143
build_args=(
144-
--package_variant=cpu
144+
--build-variant=cpu
145145
)
146146
}
147147

148148
__configure_fbgemm_gpu_build_docs () {
149149
# Update the package name and build args depending on if CUDA is specified
150150
echo "[BUILD] Setting CPU-only (docs) build args ..."
151151
build_args=(
152-
--package_variant=docs
152+
--build-variant=docs
153153
)
154154
}
155155

@@ -206,7 +206,7 @@ __configure_fbgemm_gpu_build_rocm () {
206206
# https://rocm.docs.amd.com/en/docs-6.1.1/reference/rocmcc.html
207207
echo "[BUILD] Setting ROCm build args ..."
208208
build_args=(
209-
--package_variant=rocm
209+
--build-variant=rocm
210210
# HIP_ROOT_DIR now required for HIP to be correctly detected by CMake
211211
-DHIP_ROOT_DIR=/opt/rocm
212212
# ROCm CMake complains about missing AMDGPU_TARGETS, so we explicitly set this
@@ -284,7 +284,7 @@ __configure_fbgemm_gpu_build_cuda () {
284284

285285
echo "[BUILD] Setting CUDA build args ..."
286286
build_args=(
287-
--package_variant=cuda
287+
--build-variant=cuda
288288
--nvml_lib_path="${nvml_lib_path}"
289289
--nccl_lib_path="${nccl_lib_path}"
290290
# Pass to PyTorch CMake
@@ -303,10 +303,9 @@ __configure_fbgemm_gpu_build_genai () {
303303

304304
__configure_fbgemm_gpu_build_cuda "$fbgemm_variant_targets" || return 1
305305

306-
# Replace the package_variant flag, since GenAI is also a CUDA-type build
307-
for i in "${!build_args[@]}"; do
308-
build_args[i]="${build_args[i]/--package_variant=cuda/--package_variant=genai}"
309-
done
306+
build_args+=(
307+
--build-target=genai
308+
)
310309
}
311310

312311
# shellcheck disable=SC2120

.github/scripts/fbgemm_gpu_install.bash

+10-7
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ __install_fetch_version_and_variant_info () {
3939

4040
echo "[CHECK] Printing out the FBGEMM-GPU version ..."
4141
# shellcheck disable=SC2086,SC2155
42-
installed_fbgemm_gpu_version=$(conda run ${env_prefix} python -c "import fbgemm_gpu; print(fbgemm_gpu.__version__)")
42+
installed_fbgemm_target=$(conda run ${env_prefix} python -c "import fbgemm_gpu; print(fbgemm_gpu.__target__)")
4343
# shellcheck disable=SC2086,SC2155
44-
installed_fbgemm_gpu_variant=$(conda run ${env_prefix} python -c "import fbgemm_gpu; print(fbgemm_gpu.__variant__)")
44+
installed_fbgemm_variant=$(conda run ${env_prefix} python -c "import fbgemm_gpu; print(fbgemm_gpu.__variant__)")
45+
# shellcheck disable=SC2086,SC2155
46+
installed_fbgemm_version=$(conda run ${env_prefix} python -c "import fbgemm_gpu; print(fbgemm_gpu.__version__)")
4547
echo "################################################################################"
46-
echo "[CHECK] The installed VERSION of FBGEMM_GPU is: ${installed_fbgemm_gpu_version}"
47-
echo "[CHECK] The installed VARIANT of FBGEMM_GPU is: ${installed_fbgemm_gpu_variant}"
48+
echo "[CHECK] The installed FBGEMM TARGET is: ${installed_fbgemm_target}"
49+
echo "[CHECK] The installed FBGEMM VARIANT is: ${installed_fbgemm_variant}"
50+
echo "[CHECK] The installed FBGEMM VERSION is: ${installed_fbgemm_version}"
4851
echo "################################################################################"
4952
echo ""
5053
}
@@ -53,7 +56,7 @@ __install_check_subpackages () {
5356
# shellcheck disable=SC2086,SC2155
5457
local fbgemm_gpu_packages=$(conda run ${env_prefix} python -c "import fbgemm_gpu; print(dir(fbgemm_gpu))")
5558

56-
if [ "$installed_fbgemm_gpu_variant" == "cuda" ] || [ "$installed_fbgemm_gpu_variant" == "genai" ]; then
59+
if [ "$installed_fbgemm_target" == "genai" ]; then
5760
# shellcheck disable=SC2086,SC2155
5861
local experimental_packages=$(conda run ${env_prefix} python -c "import fbgemm_gpu.experimental; print(dir(fbgemm_gpu.experimental))")
5962
fi
@@ -74,7 +77,7 @@ __install_check_subpackages () {
7477
"fbgemm_gpu.tbe.cache"
7578
)
7679

77-
if [ "$installed_fbgemm_gpu_variant" != "genai" ]; then
80+
if [ "$installed_fbgemm_target" != "genai" ]; then
7881
subpackages+=(
7982
"fbgemm_gpu.split_embedding_codegen_lookup_invokers"
8083
"fbgemm_gpu.tbe.ssd"
@@ -89,7 +92,7 @@ __install_check_subpackages () {
8992

9093
__install_check_operator_registrations () {
9194
echo "[INSTALL] Check for operator registrations ..."
92-
if [ "$installed_fbgemm_gpu_variant" == "genai" ]; then
95+
if [ "$installed_fbgemm_target" == "genai" ]; then
9396
local test_operators=(
9497
"torch.ops.fbgemm.nccl_init"
9598
"torch.ops.fbgemm.gqa_attn_splitk"

.github/scripts/fbgemm_gpu_test.bash

+20-30
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,16 @@ __setup_fbgemm_gpu_test () {
154154

155155
# Configure the environment for ignored test suites for each FBGEMM_GPU
156156
# variant
157-
if [ "$fbgemm_gpu_variant" == "cpu" ]; then
157+
if [ "$fbgemm_build_variant" == "cpu" ]; then
158158
echo "[TEST] Configuring for CPU-based testing ..."
159159
__configure_fbgemm_gpu_test_cpu
160160

161-
elif [ "$fbgemm_gpu_variant" == "rocm" ]; then
161+
elif [ "$fbgemm_build_variant" == "rocm" ]; then
162162
echo "[TEST] Configuring for ROCm-based testing ..."
163163
__configure_fbgemm_gpu_test_rocm
164164

165165
else
166-
echo "[TEST] FBGEMM_GPU variant is ${fbgemm_gpu_variant}; configuring for CUDA-based testing ..."
166+
echo "[TEST] FBGEMM_GPU variant is ${fbgemm_build_variant}; configuring for CUDA-based testing ..."
167167
__configure_fbgemm_gpu_test_cuda
168168
fi
169169

@@ -189,9 +189,6 @@ __setup_fbgemm_gpu_test () {
189189

190190
echo "[TEST] Checking imports ..."
191191
(test_python_import_package "${env_name}" fbgemm_gpu) || return 1
192-
if [ "$fbgemm_gpu_variant" != "genai" ]; then
193-
(test_python_import_package "${env_name}" fbgemm_gpu.split_embedding_codegen_lookup_invokers) || return 1
194-
fi
195192

196193
# Set the feature flags to enable experimental features as needed
197194
__set_feature_flags
@@ -251,21 +248,19 @@ __run_fbgemm_gpu_tests_in_directory () {
251248
__determine_test_directories () {
252249
target_directories=()
253250

254-
if [ "$fbgemm_gpu_variant" != "genai" ]; then
255-
target_directories+=(
256-
fbgemm_gpu/test
257-
)
258-
fi
259-
260-
if [ "$fbgemm_gpu_variant" == "genai" ]; then
251+
if [ "$fbgemm_build_target" == "genai" ]; then
261252
target_directories+=(
262253
fbgemm_gpu/experimental/example/test
263254
fbgemm_gpu/experimental/gemm/test
264255
fbgemm_gpu/experimental/gen_ai/test
265256
)
257+
else
258+
target_directories+=(
259+
fbgemm_gpu/test
260+
)
266261
fi
267262

268-
echo "[TEST] Determined the testing directories:"
263+
echo "[TEST] Determined the test directories:"
269264
for test_dir in "${target_directories[@]}"; do
270265
echo "$test_dir"
271266
done
@@ -274,14 +269,10 @@ __determine_test_directories () {
274269

275270
test_all_fbgemm_gpu_modules () {
276271
env_name="$1"
277-
fbgemm_gpu_variant="$2"
278272
if [ "$env_name" == "" ]; then
279-
echo "Usage: ${FUNCNAME[0]} ENV_NAME [FBGEMM_GPU_VARIANT]"
273+
echo "Usage: ${FUNCNAME[0]} ENV_NAME"
280274
echo "Example(s):"
281275
echo " ${FUNCNAME[0]} build_env # Test all FBGEMM_GPU modules applicable to to the installed variant"
282-
echo " ${FUNCNAME[0]} build_env cpu # Test all FBGEMM_GPU modules applicable to CPU"
283-
echo " ${FUNCNAME[0]} build_env cuda # Test all FBGEMM_GPU modules applicable to CUDA"
284-
echo " ${FUNCNAME[0]} build_env rocm # Test all FBGEMM_GPU modules applicable to ROCm"
285276
return 1
286277
else
287278
echo "################################################################################"
@@ -295,14 +286,13 @@ test_all_fbgemm_gpu_modules () {
295286
# shellcheck disable=SC2155
296287
local env_prefix=$(env_name_or_prefix "${env_name}")
297288

298-
# Determine the FBGEMM_GPU varaiant if needed
299-
if [ "$fbgemm_gpu_variant" == "" ]; then
300-
echo "[TEST] FBGEMM_GPU variant not explicitly provided by user; will automatically determine from the FBGEMM_GPU installation ..."
301-
# shellcheck disable=SC2086
302-
fbgemm_gpu_variant=$(conda run ${env_prefix} python -c "import fbgemm_gpu; print(fbgemm_gpu.__variant__)")
303-
echo "[TEST] Determined FBGEMM_GPU variant from installation: ${fbgemm_gpu_variant}"
304-
echo "[TEST] Will be running tests specific to this variant ..."
305-
fi
289+
# Determine the FBGEMM build target and variant
290+
# shellcheck disable=SC2086
291+
fbgemm_build_target=$(conda run ${env_prefix} python -c "import fbgemm_gpu; print(fbgemm_gpu.__target__)")
292+
# shellcheck disable=SC2086
293+
fbgemm_build_variant=$(conda run ${env_prefix} python -c "import fbgemm_gpu; print(fbgemm_gpu.__variant__)")
294+
echo "[TEST] Determined FBGEMM_GPU (target : variant) from installation: (${fbgemm_build_target} : ${fbgemm_build_variant})"
295+
echo "[TEST] Will be running tests specific to this target and variant ..."
306296

307297
# Determine the test directories to include for testing
308298
__determine_test_directories
@@ -312,9 +302,9 @@ test_all_fbgemm_gpu_modules () {
312302

313303
# Iterate through the test directories and run bulk tests
314304
for test_dir in "${target_directories[@]}"; do
315-
cd "${test_dir}" || return 1
316-
__run_fbgemm_gpu_tests_in_directory "${env_name}" "${fbgemm_gpu_variant}" || return 1
317-
cd - || return 1
305+
cd "${test_dir}" || return 1
306+
__run_fbgemm_gpu_tests_in_directory "${env_name}" || return 1
307+
cd - || return 1
318308
done
319309
}
320310

.github/scripts/nova_postscript.bash

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fi
6666

6767
$CONDA_RUN python3 -c "import torch; print('cuda.is_available() ', torch.cuda.is_available()); print ('device_count() ',torch.cuda.device_count());"
6868
cd "${FBGEMM_REPO}" || { echo "[NOVA] Failed to cd to ${FBGEMM_REPO} from $(pwd)"; };
69-
test_all_fbgemm_gpu_modules "${BUILD_ENV_NAME}" "${fbgemm_variant}"
69+
test_all_fbgemm_gpu_modules "${BUILD_ENV_NAME}"
7070
end_time=$(date +%s)
7171
runtime=$((end_time-start_time))
7272
start_time=${end_time}

fbgemm_gpu/docs/src/fbgemm_genai/development/BuildInstructions.rst

+49-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ toolchains have been properly installed.
147147
148148
# Build the wheel artifact only
149149
python setup.py bdist_wheel \
150-
--package_variant=genai \
150+
--build-target=genai \
151+
--build-variant=cuda \
151152
--python-tag="${python_tag}" \
152153
--plat-name="${python_plat_name}" \
153154
--nvml_lib_path=${NVML_LIB_PATH} \
@@ -156,11 +157,57 @@ toolchains have been properly installed.
156157
157158
# Build and install the library into the Conda environment
158159
python setup.py install \
159-
--package_variant=genai \
160+
--build-target=genai \
161+
--build-variant=cuda \
160162
--nvml_lib_path=${NVML_LIB_PATH} \
161163
--nccl_lib_path=${NCCL_LIB_PATH} \
162164
-DTORCH_CUDA_ARCH_LIST="${cuda_arch_list}"
163165
166+
.. _fbgemm-gpu.build.process.rocm:
167+
168+
ROCm Build
169+
----------
170+
171+
For ROCm builds, ``ROCM_PATH`` and ``PYTORCH_ROCM_ARCH`` need to be specified.
172+
The presence of a ROCm device, however, is not required for building
173+
the package.
174+
175+
Similar to CUDA builds, building with Clang + ``libstdc++`` can be enabled by
176+
appending ``--cxxprefix=$CONDA_PREFIX`` to the build command, presuming the
177+
toolchains have been properly installed.
178+
179+
.. code:: sh
180+
181+
# !! Run in fbgemm_gpu/ directory inside the Conda environment !!
182+
183+
export ROCM_PATH=/path/to/rocm
184+
185+
# [OPTIONAL] Enable verbose HIPCC logs
186+
export HIPCC_VERBOSE=1
187+
188+
# Build for the target architecture of the ROCm device installed on the machine (e.g. 'gfx908,gfx90a,gfx942')
189+
# See https://rocm.docs.amd.com/en/latest/reference/gpu-arch-specs.html for list
190+
export PYTORCH_ROCM_ARCH=$(${ROCM_PATH}/bin/rocminfo | grep -o -m 1 'gfx.*')
191+
192+
# Build the wheel artifact only
193+
python setup.py bdist_wheel \
194+
--build-target=genai \
195+
--build-variant=rocm \
196+
--python-tag="${python_tag}" \
197+
--plat-name="${python_plat_name}" \
198+
-DAMDGPU_TARGETS="${PYTORCH_ROCM_ARCH}" \
199+
-DHIP_ROOT_DIR="${ROCM_PATH}" \
200+
-DCMAKE_C_FLAGS="-DTORCH_USE_HIP_DSA" \
201+
-DCMAKE_CXX_FLAGS="-DTORCH_USE_HIP_DSA"
202+
203+
# Build and install the library into the Conda environment
204+
python setup.py install \
205+
--build-target=genai \
206+
--build-variant=rocm \
207+
-DAMDGPU_TARGETS="${PYTORCH_ROCM_ARCH}" \
208+
-DHIP_ROOT_DIR="${ROCM_PATH}" \
209+
-DCMAKE_C_FLAGS="-DTORCH_USE_HIP_DSA" \
210+
-DCMAKE_CXX_FLAGS="-DTORCH_USE_HIP_DSA"
164211
165212
Post-Build Checks (For Developers)
166213
----------------------------------

fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst

+9-9
Original file line numberDiff line numberDiff line change
@@ -542,16 +542,16 @@ For CPU-only builds, the ``--cpu_only`` flag needs to be specified.
542542
543543
# Build the wheel artifact only
544544
python setup.py bdist_wheel \
545-
--package_variant=cpu \
545+
--build-variant=cpu \
546546
--python-tag="${python_tag}" \
547547
--plat-name="${python_plat_name}"
548548
549549
# Build and install the library into the Conda environment (GCC)
550550
python setup.py install \
551-
--package_variant=cpu
551+
--build-variant=cpu
552552
553553
# NOTE: To build the package as part of generating the documentation, use
554-
# `--package_variant=docs` flag instead!
554+
# `--build-variant=docs` flag instead!
555555
556556
To build using Clang + ``libstdc++`` instead of GCC, simply append the
557557
``--cxxprefix`` flag:
@@ -562,14 +562,14 @@ To build using Clang + ``libstdc++`` instead of GCC, simply append the
562562
563563
# Build the wheel artifact only
564564
python setup.py bdist_wheel \
565-
--package_variant=cpu \
565+
--build-variant=cpu \
566566
--python-tag="${python_tag}" \
567567
--plat-name="${python_plat_name}" \
568568
--cxxprefix=$CONDA_PREFIX
569569
570570
# Build and install the library into the Conda environment (Clang)
571571
python setup.py install \
572-
--package_variant=cpu
572+
--build-variant=cpu
573573
--cxxprefix=$CONDA_PREFIX
574574
575575
Note that this presumes the Clang toolchain is properly installed along with the
@@ -642,7 +642,7 @@ toolchains have been properly installed.
642642
643643
# Build the wheel artifact only
644644
python setup.py bdist_wheel \
645-
--package_variant=cuda \
645+
--build-variant=cuda \
646646
--python-tag="${python_tag}" \
647647
--plat-name="${python_plat_name}" \
648648
--nvml_lib_path=${NVML_LIB_PATH} \
@@ -651,7 +651,7 @@ toolchains have been properly installed.
651651
652652
# Build and install the library into the Conda environment
653653
python setup.py install \
654-
--package_variant=cuda \
654+
--build-variant=cuda \
655655
--nvml_lib_path=${NVML_LIB_PATH} \
656656
--nccl_lib_path=${NCCL_LIB_PATH} \
657657
-DTORCH_CUDA_ARCH_LIST="${cuda_arch_list}"
@@ -684,7 +684,7 @@ presuming the toolchains have been properly installed.
684684
685685
# Build the wheel artifact only
686686
python setup.py bdist_wheel \
687-
--package_variant=rocm \
687+
--build-variant=rocm \
688688
--python-tag="${python_tag}" \
689689
--plat-name="${python_plat_name}" \
690690
-DAMDGPU_TARGETS="${PYTORCH_ROCM_ARCH}" \
@@ -694,7 +694,7 @@ presuming the toolchains have been properly installed.
694694
695695
# Build and install the library into the Conda environment
696696
python setup.py install \
697-
--package_variant=rocm \
697+
--build-variant=rocm \
698698
-DAMDGPU_TARGETS="${PYTORCH_ROCM_ARCH}" \
699699
-DHIP_ROOT_DIR="${ROCM_PATH}" \
700700
-DCMAKE_C_FLAGS="-DTORCH_USE_HIP_DSA" \

0 commit comments

Comments
 (0)