### Clang C++20 Compiler Installation and Configuration Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Complete setup for using Clang as the host compiler for FBGEMM and FBGEMM_GPU CPU/CUDA builds. Includes Conda installation of LLVM+Clang 16.0.6 with libcxx and compiler-rt, environment variable configuration for LD_LIBRARY_PATH, and NVCC flags setup for Clang compatibility. ```shell # Minimum LLVM+Clang version required for FBGEMM_GPU llvm_version=16.0.6 # NOTE: libcxx from conda-forge is outdated for linux-aarch64, so we cannot # explicitly specify the version number conda install -n ${env_name} -c conda-forge --override-channels -y \ clangxx=${llvm_version} \ libcxx \ llvm-openmp=${llvm_version} \ compiler-rt=${llvm_version} # Append $CONDA_PREFIX/lib to $LD_LIBRARY_PATH in the Conda environment ld_library_path=$(conda run -n ${env_name} printenv LD_LIBRARY_PATH) conda_prefix=$(conda run -n ${env_name} printenv CONDA_PREFIX) conda env config vars set -n ${env_name} LD_LIBRARY_PATH="${ld_library_path}:${conda_prefix}/lib" # Set NVCC_PREPEND_FLAGS in the Conda environment for Clang to work correctly as the host compiler conda env config vars set -n ${env_name} NVCC_PREPEND_FLAGS="\"-std=c++20 -Xcompiler -std=c++20 -Xcompiler -stdlib=libstdc++ -ccbin ${clangxx_path} -allow-unsupported-compiler\"" ``` -------------------------------- ### Install Library (CPU) (Shell) Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Installs the CPU-built library into the Conda environment (using GCC). ```sh # !! Run in fbgemm_gpu/ directory inside the Conda environment !! python setup.py install --build-variant=cpu ``` -------------------------------- ### ROCm Package Installation via APT Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Complete process for installing ROCm packages on bare metal systems using the AMDGPU repository. Includes optional apt prompt disabling, repository update, and installation of ROCm with hiplibsdk and rocm usecases while disabling DKMS. ```shell # [OPTIONAL] Disable apt installation prompts export DEBIAN_FRONTEND=noninteractive # Update the repo DB apt update # Download the installer wget -q https://repo.radeon.com/amdgpu-install/6.3.1/ubuntu/focal/amdgpu-install_6.3.60301-1_all.deb -O amdgpu-install.deb # Run the installer apt install ./amdgpu-install.deb # Install ROCm amdgpu-install -y --usecase=hiplibsdk,rocm --no-dkms ``` -------------------------------- ### Install Miniconda and Set Up Environment (Shell) Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Installs Miniconda for reproducible builds and sets up a Conda environment with a specified Python version. It includes upgrading pip and pyOpenSSL. ```sh export PLATFORM_NAME="$(uname -s)-$(uname -m)" # Set the Miniconda prefix directory miniconda_prefix=$HOME/miniconda # Download the Miniconda installer wget -q "https://repo.anaconda.com/miniconda/Miniconda3-latest-${PLATFORM_NAME}.sh" -O miniconda.sh # Run the installer bash miniconda.sh -b -p "$miniconda_prefix" -u # Load the shortcuts . ~/.bashrc # Run updates conda update -n base -c conda-forge -y conda ``` ```sh env_name= python_version=3.13 # Create the environment conda create -y -n ${env_name} -c conda-forge python="${python_version}" # Upgrade PIP and pyOpenSSL package conda run -n ${env_name} pip install --upgrade pip conda run -n ${env_name} python -m pip install pyOpenSSL>22.1.0 ``` -------------------------------- ### Verify NVIDIA Driver Installation with nvidia-smi (Shell) Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/InstallationInstructions.rst This command verifies that the NVIDIA drivers are correctly installed and reports the driver version, CUDA version, GPU details, and running processes using the GPU. It is a crucial step before setting up the CUDA environment for FBGEMM_GPU. ```sh nvidia-smi ``` -------------------------------- ### Install FBGEMM GPU Library and Files (CMake) Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/experimental/gen_ai/CMakeLists.txt Installs the built FBGEMM GPU shared library and associated Python files or directories. It uses `add_to_package` for the library and `install` commands for directories, with conditional installation for the `fb/gen_ai` directory. ```cmake ################################################################################ # Install Shared Library and Python Files ################################################################################ add_to_package( DESTINATION fbgemm_gpu/experimental/gen_ai TARGETS ${FBGEMM_GENAI_LIB_NAME}) install( DIRECTORY bench DESTINATION fbgemm_gpu/experimental/gen_ai) install( DIRECTORY gen_ai DESTINATION fbgemm_gpu/experimental) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/fb/gen_ai) install( DIRECTORY fb/gen_ai DESTINATION fbgemm_gpu/experimental) endif() ``` -------------------------------- ### Conditional Build Targets Setup Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/CMakeLists.txt Configures build targets based on FBGEMM_BUILD_TARGET and FBGEMM_BUILD_VARIANT, with fatal errors for unsupported combos like CPU+GENAI or non-CUDA+HSTU. Adds subdirectories for experimental gen_ai, example, gemm, hstu, and includes FbgemmGpu.cmake for default target. Inputs are build variables; outputs added build components. ```cmake ################################################################################ # Build Targets ################################################################################ if(FBGEMM_BUILD_TARGET STREQUAL BUILD_TARGET_GENAI) if(FBGEMM_BUILD_VARIANT STREQUAL BUILD_VARIANT_CPU) message(FATAL_ERROR "Unsupported (target, variant) combination: (${FBGEMM_BUILD_TARGET}, ${FBGEMM_BUILD_VARIANT})") endif() if(FBGEMM_BUILD_VARIANT STREQUAL BUILD_VARIANT_CUDA) # Add experimental packaging example add_subdirectory(experimental/example) endif() # Build FBGEMM GenAI add_subdirectory(experimental/gen_ai) # Add Triton GEMM kernels add_subdirectory(experimental/gemm) elseif(FBGEMM_BUILD_TARGET STREQUAL BUILD_TARGET_HSTU) if(NOT FBGEMM_BUILD_VARIANT STREQUAL BUILD_VARIANT_CUDA) message(FATAL_ERROR "Unsupported (target, variant) combination: (${FBGEMM_BUILD_TARGET}, ${FBGEMM_BUILD_VARIANT})") endif() # Build HSTU kernels add_subdirectory(experimental/hstu) elseif(FBGEMM_BUILD_TARGET STREQUAL BUILD_TARGET_DEFAULT) # Build FBGEMM_GPU include(FbgemmGpu.cmake) endif() ``` -------------------------------- ### Verify PyTorch Installation via Python Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Performs basic verification checks on the installed PyTorch package. The first command checks if the distributed module can be imported, and the second prints the installed PyTorch version. These are essential steps to confirm a successful installation. ```python conda run -n ${env_name} python -c "import torch.distributed" conda run -n ${env_name} python -c "import torch; print(torch.__version__)" ``` -------------------------------- ### Install FBGEMM Simplicial Attention Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/experimental/simplicial_attention/README.md Clones and installs the FBGEMM repository with experimental simplicial attention modules. This provides the core implementation and dependencies required for running attention kernels. ```bash git clone https://github.com/pytorch/FBGEMM.git cd fbgemm/fbgemm_gpu/experimental/simplicial_attention pip install -e . ``` -------------------------------- ### Install FBGEMM Dependencies (Shell) Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Installs the required dependencies for building and testing FBGEMM using pip. This ensures all necessary packages are available. ```sh cd fbgemm_${FBGEMM_VERSION}/fbgemm_gpu pip install -r requirements.txt ``` -------------------------------- ### Install Build Tools with Conda Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm/development/BuildInstructions.rst Installs essential build tools like bazel, cmake, doxygen, make, ninja, and openblas into a specified Conda environment. 'bazel' is for Bazel builds, and 'ninja' is for Windows builds. ```sh conda install -n ${env_name} -c conda-forge --override-channels -y \ bazel \ cmake \ doxygen \ make \ ninja \ openblas ``` -------------------------------- ### MIOpen Dependency Installation Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Installation of MIOpen (AMD's machine learning acceleration library) which is required as a dependency for the ROCm variant of FBGEMM_GPU. Includes hipify-clang for hipification support. ```shell apt install hipify-clang miopen-hip miopen-hip-dev ``` -------------------------------- ### Install PyTorch-Triton via PIP Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Installs the PyTorch-Triton package, necessary for the experimental FBGEMM_GPU Triton-GEMM module. This command installs a specific version (e.g., 3.0.0+dedb7bdf33) using a nightly index URL. Ensure the version SHA matches the one pinned in the PyTorch repository. ```sh conda run -n ${env_name} pip install --pre pytorch-triton==3.0.0+dedb7bdf33 --index-url https://download.pytorch.org/whl/nightly/ ``` -------------------------------- ### Verify CUDA Installation Files (Shell) Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Finds and verifies the presence of key CUDA installation files within the Conda environment's prefix, including cuda_runtime.h, libnvidia-ml.so, and libnccl.so* ```sh conda_prefix=$(conda run -n ${env_name} printenv CONDA_PREFIX) find "${conda_prefix}" -name cuda_runtime.h find "${conda_prefix}" -name libnvidia-ml.so find "${conda_prefix}" -name libnccl.so* ``` -------------------------------- ### Install library and Python files Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/experimental/hstu/CMakeLists.txt Adds the built library to the package and installs Python files to the specified destination directory. ```CMake add_to_package( DESTINATION fbgemm_gpu/experimental/hstu TARGETS fbgemm_gpu_experimental_hstu) install( DIRECTORY hstu DESTINATION fbgemm_gpu/experimental) ``` -------------------------------- ### Install documentation dependencies with Conda and pip Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/general/documentation/Overview.rst Sets up the documentation toolchain by installing Sphinx Python packages via pip and Doxygen documentation generator with graphviz and make via conda. Must be run inside the Conda environment from the fbgemm_gpu/docs directory. These dependencies are required before building the documentation. ```sh # !! Run inside the Conda environment !!\n\n# From the /fbgemm_gpu/ directory\ncd docs\n\n# Install Sphinx and other Python packages\npip install -r requirements.txt\n\n# Install Doxygen and and other tools\nconda install -c conda-forge --override-channels -y \\n doxygen \\n graphviz \\n make ``` -------------------------------- ### Build documentation with make Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/general/documentation/Overview.rst Generates C++ documentation via Doxygen, Python documentation via Sphinx, and assembles them into a unified documentation site. This command cleans previous builds before generating new documentation. Execute this after installing all required dependencies. ```sh # Generate the C++ documentation, the Python documentation, and assemble\n# together\nmake clean doxygen html ``` -------------------------------- ### ROCm Docker Container Setup Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Instructions for running FBGEMM_GPU in a Docker container with ROCm support. Uses the minimal ROCm Docker image to reduce container size while maintaining necessary functionality for building and running FBGEMM_GPU. ```shell # Run for ROCm 6.3 docker run -it --entrypoint "/bin/bash" rocm/rocm-terminal:6.3 ``` -------------------------------- ### Shell: Install FBGEMM GPU Library Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/experimental/gen_ai/README.md Provides commands to install the FBGEMM GPU library, including options for the full library with specific CUDA versions or a GenAI-only package. Ensure compatibility with your CUDA toolkit. ```bash # Full FBGEMM library pip install fbgemm-gpu==1.4.0 pip install fbgemm-gpu==1.4.0 --index-url https://download.pytorch.org/whl/cu126 # FBGEMM library with GenAI operator only pip install fbgemm-gpu-genai ``` -------------------------------- ### Install FBGEMM GenAI Test Requirements Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_genai/development/TestInstructions.rst Installs required Python packages for FBGEMM GenAI testing using pip. Must be executed from the fbgemm_gpu directory inside a Conda environment after the FBGEMM GenAI package has been built or installed. Uses requirements_genai.txt file to specify dependencies. ```sh # !! Run inside the Conda environment !! # From the fbgemm_gpu/ directory python -m pip install -r requirements_genai.txt ``` -------------------------------- ### Install FBGEMM HSTU with CUDA Architecture Targeting Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/experimental/hstu/README.md Bash installation commands for FBGEMM HSTU with specific CUDA architecture compilation. Supports targeting Ampere (8.0), Hopper (9.0), or both GPU architectures. Requires navigating to fbgemm_gpu directory and uses PyTorch's setup.py with custom build targets. ```bash cd fbgemm_gpu/ # Install HSTU-Ampere python setup.py install --build-target=hstu -DTORCH_CUDA_ARCH_LIST="8.0" # Install HSTU-Hopper python setup.py install --build-target=hstu -DTORCH_CUDA_ARCH_LIST="9.0" # Install both python setup.py install --build-target=hstu -DTORCH_CUDA_ARCH_LIST="8.0 9.0" # If you don't add -DTORCH_CUDA_ARCH_LIST, the default is "8.0 9.0". ``` -------------------------------- ### Create FBGEMM Library Target and Install - CMake Source: https://github.com/pytorch/fbgemm/blob/main/CMakeLists.txt Creates the main FBGEMM library target by combining all configured optimization targets (Neon, SVE, Autovec) with the generic implementation. Configures public header installation and CMake package export configuration. Library type is configurable via FBGEMM_LIBRARY_TYPE variable. Includes installation rules for headers and CMake config files for downstream dependency resolution. ```cmake cpp_library( PREFIX fbgemm TYPE ${FBGEMM_LIBRARY_TYPE} DEPS fbgemm_generic ${fbgemm_targets} ) get_filelist("get_fbgemm_public_headers()" FBGEMM_PUBLIC_HEADERS) install( FILES ${FBGEMM_PUBLIC_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/fbgemm") install( EXPORT fbgemmLibraryConfig DESTINATION share/cmake/fbgemm FILE fbgemmLibraryConfig.cmake) ``` -------------------------------- ### GCC C++20 Compiler Installation via Conda Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Installation of GCC compiler version 10.4.0 with sysroot support through Conda. Ensures C++20 compatibility and GLIBCXX version compatibility with older systems. Includes version pinning for consistent builds across different systems. ```shell # Set GCC to 10.4.0 to keep compatibility with older versions of GLIBCXX # # A newer versions of GCC also works, but will need to be accompanied by an # appropriate updated version of the sysroot_linux package. gcc_version=10.4.0 conda install -n ${env_name} -c conda-forge --override-channels -y \ gxx_linux-64=${gcc_version} \ sysroot_linux-64=2.17 ``` -------------------------------- ### Install PyTorch Nightly (CPU) via PIP Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Installs the latest nightly build of the CPU-only variant of PyTorch using pip within a Conda environment. This command specifies the index URL for nightly CPU wheels, ensuring a deterministic installation. It's recommended for reliable CPU-only builds. ```sh conda run -n ${env_name} pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu/ ``` -------------------------------- ### Install FBGEMM with CUDA Build Variant Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_genai/development/BuildInstructions.rst Installs the FBGEMM library with a CUDA build variant. Requires specifying build targets, variant, and paths for NVML and NCCL libraries. The CUDA architecture list is also configured. ```shell python setup.py install \ --build-target=genai \ --build-variant=cuda \ --nvml_lib_path=${NVML_LIB_PATH} \ --nccl_lib_path=${NCCL_LIB_PATH} \ -DTORCH_CUDA_ARCH_LIST="${cuda_arch_list}" ``` -------------------------------- ### Build Wheel Artifact (CUDA) (Shell) Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst This script builds the wheel artifact for a CUDA build, with optional settings for CUDA installation paths, CUB directory, host compiler compatibility, and verbose NVCC logs. ```sh # !! Run in fbgemm_gpu/ directory inside the Conda environment !! # [OPTIONAL] Specify the CUDA installation paths # This may be required if CMake is unable to find nvcc export CUDACXX=/path/to/nvcc export CUDA_BIN_PATH=/path/to/cuda/installation # [OPTIONAL] Provide the CUB installation directory (applicable only to CUDA versions prior to 11.1) export CUB_DIR=/path/to/cub # [OPTIONAL] Allow NVCC to use host compilers that are newer than what NVCC officially supports vcc_prepend_flags=( -allow-unsupported-compiler ) # [OPTIONAL] If clang is the host compiler, set NVCC to use libstdc++ since libc++ is not supported vcc_prepend_flags+=( -Xcompiler -stdlib=libstdc++ -ccbin "/path/to/clang++" ) # [OPTIONAL] Set NVCC_PREPEND_FLAGS as needed export NVCC_PREPEND_FLAGS="${nvcc_prepend_flags[@]}" # [OPTIONAL] Enable verbose NVCC logs export NVCC_VERBOSE=1 # Specify cuDNN header and library paths ``` -------------------------------- ### Install PyTorch Release Candidate via Conda Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Installs the latest release candidate (test) version of PyTorch using Conda. This command targets the 'pytorch-test' channel to retrieve the RC build for the specified Conda environment. Ensure the environment is correctly named '${env_name}'. ```sh conda install -n ${env_name} -y pytorch -c pytorch-test ``` -------------------------------- ### Sphinx: Reference Documentation Sections Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/general/documentation/Sphinx.rst Demonstrates how to create and reference documentation sections using Sphinx's :ref: directive. An anchor starting with an underscore is required, followed by an empty line before the section header. ```rst .. _docs.example.reference: Example Section Header ---------------------- NOTES: #. The reference anchor must start with an underscore, i.e. ``_``. #. !! There must be an empty line between the anchor and its target !! Referencing the section :ref:`docs.example.reference` from another page in the docs. Referencing the section with :ref:`custom text ` from another page in the docs. Note that the prefix underscore is not needed when referencing the anchor. ``` -------------------------------- ### Clone FBGEMM Repo and Install GenAI Requirements Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_genai/development/BuildInstructions.rst This script clones the FBGEMM repository with submodules for a specific version and installs the necessary Python packages for GenAI builds using pip. It assumes execution within an activated Conda environment. ```sh # !! Run inside the Conda environment !! # Select a version tag FBGEMM_VERSION=v1.4.0 # Clone the repo along with its submodules git clone --recursive -b ${FBGEMM_VERSION} https://github.com/pytorch/FBGEMM.git fbgemm_${FBGEMM_VERSION} # Install additional required packages for building and testing cd fbgemm_${FBGEMM_VERSION}/fbgemm_gpu pip install -r requirements_genai.txt ``` -------------------------------- ### Run FBGEMM GenAI Benchmarks Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_genai/development/TestInstructions.rst Executes FBGEMM GenAI benchmark suite by running Python benchmark scripts. Must be run from the bench subdirectory inside a Conda environment. The example demonstrates running quantize benchmarks specifically using the quantize_bench.py script. ```sh # !! Run inside the Conda environment !! # From the fbgemm_gpu/experimental/gen_ai/bench/ directory cd bench python quantize_bench.py ``` -------------------------------- ### Setup OpenMP Flags Source: https://github.com/pytorch/fbgemm/blob/main/CMakeLists.txt Finds the OpenMP library using `find_package(OpenMP)`. It then prints a status message indicating whether OpenMP was found and its include directories. If OpenMP is not supported, a warning message is issued to the user. ```cmake find_package(OpenMP) if(OpenMP_FOUND) message(STATUS "OpenMP found: OpenMP_C_INCLUDE_DIRS = ${OpenMP_C_INCLUDE_DIRS}") else() message(WARNING "OpenMP is not supported by the compiler") endif() ``` -------------------------------- ### Find and Configure GoogleTest Package with CMake Source: https://github.com/pytorch/fbgemm/blob/main/test/CMakeLists.txt Locates the GTest package and, if unavailable, downloads and builds Googletest from source. It also configures optional sanitizer warnings and reports OpenMP library status. ensures test dependencies are available before building. ```CMake find_package(GTest)\n\nif(NOT GTest_FOUND)\n # Download Googletest framework from github if\n # GOOGLETEST_SOURCE_DIR is not specified.\n set(INSTALL_GTEST OFF)\n\n if(NOT DEFINED GOOGLETEST_SOURCE_DIR)\n set(GOOGLETEST_SOURCE_DIR "${FBGEMM_SOURCE_DIR}/external/googletest"\n CACHE STRING "googletest source directory from submodules")\n endif()\n\n #build Googletest framework\n set(TEMP_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})\n set(BUILD_SHARED_LIBS OFF)\n add_subdirectory("${GOOGLETEST_SOURCE_DIR}" "FBGEMM_BINARY_DIR}/googletest")\n # Recover the build shared libs option.\n set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS})\nendif()\n\nif(FBGEMM_USE_SANITIZER)\n message(WARNING "USING SANITIZER IN TEST")\nendif()\n\nif(${OpenMP_FOUND})\n message(STATUS "OpenMP_LIBRARIES= ${OpenMP_CXX_LIBRARIES}")\nendif() ``` -------------------------------- ### Serve documentation locally with sphinx-serve Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/general/documentation/Overview.rst Launches a local web server to view the generated documentation after a successful build. The server serves files from the build directory and provides a browser-accessible preview. Run this command following documentation generation. ```sh sphinx-serve -b build ``` -------------------------------- ### Build FBGEMM on Windows with CMake and Ninja Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm/development/BuildInstructions.rst This snippet outlines the process for building FBGEMM on Windows using CMake and Ninja. It includes setting up the Visual Studio environment variables, creating a build directory, configuring CMake with specific options, and finally building the project with Ninja. Note the use of 'cl.exe' for C and C++ compilers. ```powershell # Specify the target architecture to bc x64 call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64 # Create a build directory mkdir %BUILD_DIR% cd %BUILD_DIR% cmake -G Ninja -DFBGEMM_BUILD_BENCHMARKS=OFF -DFBGEMM_LIBRARY_TYPE=${{ matrix.library-type }} -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" .. ninja -v all ``` -------------------------------- ### Access Netlify deployment preview URLs Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/general/documentation/Overview.rst Template URL for accessing documentation preview deployments on Netlify. Replace {PR NUMBER} with the actual pull request number to view the preview site automatically built for each PR. Enables verification of documentation changes before merging. ```sh https://deploy-preview-{PR NUMBER}--pytorch-fbgemm-docs.netlify.app/ ``` -------------------------------- ### Initialize FBGEMM GPU Build with Project and Dependencies Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/CMakeLists.txt Kicks off the FBGEMM_GPU build by including compiler setups, printing build settings, declaring the CMake project, and setting up dependencies. Depends on multiple modules like CxxCompilerSetup, PyTorchSetup, etc. Inputs are build variants and related variables, outputs the project declaration. Limited to supported languages (CXX, CUDA). ```CMake # FBGEMM_GPU C++ Setup - must be set AFTER FBGEMM_BUILD_VARIANT declaration but # BEFORE project declaration include(${CMAKEMODULES}/CxxCompilerSetup.cmake) if(SKBUILD) BLOCK_PRINT("The project is built using scikit-build") endif() BLOCK_PRINT( "Build Settings" "" "FBGEMM_BUILD_TARGET : ${FBGEMM_BUILD_TARGET}" "FBGEMM_BUILD_VARIANT : ${FBGEMM_BUILD_VARIANT}" "" "NVCC_VERBOSE : ${NVCC_VERBOSE}" "CUDNN_INCLUDE_DIR : ${CUDNN_INCLUDE_DIR}" "CUDNN_LIBRARY : ${CUDNN_LIBRARY}" "NVML_LIB_PATH : ${NVML_LIB_PATH}" "TORCH_CUDA_ARCH_LIST : ${TORCH_CUDA_ARCH_LIST}" "" "HIP_ROOT_DIR : ${HIP_ROOT_DIR}" "HIPCC_VERBOSE : ${HIPCC_VERBOSE}" "AMDGPU_TARGETS : ${AMDGPU_TARGETS}" "PYTORCH_ROCM_ARCH : ${PYTORCH_ROCM_ARCH}") set(project_languages CXX) if(FBGEMM_BUILD_VARIANT STREQUAL BUILD_VARIANT_CUDA) list(APPEND project_languages CUDA) endif() # Declare CMake project project( fbgemm_gpu VERSION 1.4.0 LANGUAGES ${project_languages}) # AVX Flags Setup - must be set AFTER project declaration include(${CMAKEMODULES}/FindAVX.cmake) # PyTorch Dependencies Setup include(${CMAKEMODULES}/PyTorchSetup.cmake) # CUDA Setup include(${CMAKEMODULES}/CudaSetup.cmake) # ROCm and HIPify Setup include(${CMAKEMODULES}/RocmSetup.cmake) # Load gpu_cpp_library() include(${CMAKEMODULES}/GpuCppLibrary.cmake) ``` -------------------------------- ### Install PyTorch Nightly via Conda Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Installs the latest nightly build of PyTorch within a specified Conda environment. It uses the 'pytorch-nightly' channel for installation. Note that nightly builds may sometimes default to the CPU variant if CUDA is not yet detected or installed. ```sh conda install -n ${env_name} -y pytorch -c pytorch-nightly ``` -------------------------------- ### Install FBGEMM Build Dependencies via Conda Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Installs essential build tools and libraries for FBGEMM using Conda. This command installs packages like ninja, cmake, numpy, and scikit-build within a specified Conda environment, using the conda-forge channel and overriding existing channels. The '-y' flag automatically confirms the installations. ```sh conda install -n ${env_name} -c conda-forge --override-channels -y \ click \ cmake \ hypothesis \ jinja2 \ make \ ncurses \ ninja \ numpy \ scikit-build \ tbb \ wheel ``` -------------------------------- ### Install PyTorch Nightly ROCm Variant via PIP Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Installs the latest nightly build of the ROCm variant of PyTorch using pip. This command uses the dedicated index URL for ROCm 6.3 nightly builds. This installation method is currently the primary channel for ROCm builds. ```sh conda run -n ${env_name} pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/rocm6.3/ ``` -------------------------------- ### Define Custom Target for All Blackwell FMHA Examples with CMake Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/experimental/gen_ai/src/attention/cuda/cutlass_blackwell_fmha/CMakeLists.txt Creates a custom CMake target named '77_blackwell_fmha_all' that depends on the compilation of all generated Blackwell FMHA examples. This target simplifies the build process by allowing users to build all relevant examples with a single command. ```cmake add_custom_target(77_blackwell_fmha_all DEPENDS 77_blackwell_fmha_fp8 77_blackwell_fmha_fp16 77_blackwell_fmha_gen_fp8 77_blackwell_fmha_gen_fp16 77_blackwell_mla_2sm_fp8 77_blackwell_mla_2sm_fp16 77_blackwell_mla_2sm_cpasync_fp8 77_blackwell_mla_2sm_cpasync_fp16 77_blackwell_fmha_bwd_fp8 77_blackwell_fmha_bwd_fp16 77_blackwell_mla_fwd_fp8 77_blackwell_mla_fwd_fp16 ) ``` -------------------------------- ### Install Specific PyTorch CUDA Version via PIP Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Installs a specific version of PyTorch with CUDA support (e.g., 2.6.0+cu126) using pip. This command allows precise version and CUDA toolkit version selection via the index URL. This is crucial for matching PyTorch builds with installed CUDA versions. ```sh conda run -n ${env_name} pip install torch==2.6.0+cu126 --index-url https://download.pytorch.org/whl/cu126/ ``` -------------------------------- ### Run CUDA Docker Image (Shell) Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Pulls and runs a pre-built Docker image for CUDA development, specifically for Ubuntu 22.04 and CUDA 12.6, setting up the entrypoint to bash. ```sh # Run for Ubuntu 22.04, CUDA 12.6 docker run -it --entrypoint "/bin/bash" nvidia/cuda:12.6.0-devel-ubuntu22.04 ``` -------------------------------- ### Install PyTorch Test (RC) CUDA Variant via PIP Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Installs the latest release candidate (test) version of PyTorch with CUDA support using pip. This command uses a specific index URL for CUDA 12.6 test builds. Ensure your system has compatible CUDA drivers installed prior to running this command. ```sh conda run -n ${env_name} pip install --pre torch --index-url https://download.pytorch.org/whl/test/cu126/ ``` -------------------------------- ### Lint documentation with Sphinx Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/general/documentation/Overview.rst Runs the documentation build process with linting enabled to check for reStructuredText syntax errors, broken references, and style issues. Note that linting may cause documentation assembly issues and should be run separately from regular builds. Set the SPHINX_LINT environment variable to enable this mode. ```sh SPHINX_LINT=1 make clean doxygen html ``` -------------------------------- ### Configure and Build FBGEMM GenAI with CUDA Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_genai/development/BuildInstructions.rst This script configures environment variables for CUDA builds of FBGEMM GenAI, including paths for CUDA, cuDNN, NVML, and NCCL. It then invokes `setup.py` to build the CUDA wheel artifact, targeting specific GPU architectures. ```sh # !! Run in fbgemm_gpu/ directory inside the Conda environment !! # [OPTIONAL] Specify the CUDA installation paths # This may be required if CMake is unable to find nvcc export CUDACXX=/path/to/nvcc export CUDA_BIN_PATH=/path/to/cuda/installation # [OPTIONAL] Provide the CUB installation directory (applicable only to CUDA versions prior to 11.1) export CUB_DIR=/path/to/cub # [OPTIONAL] Allow NVCC to use host compilers that are newer than what NVCC officially supports nvcc_prepend_flags=( -allow-unsupported-compiler ) # [OPTIONAL] If clang is the host compiler, set NVCC to use libstdc++ since libc++ is not supported nvcc_prepend_flags+= -Xcompiler -stdlib=libstdc++ -ccbin "/path/to/clang++" # [OPTIONAL] Set NVCC_PREPEND_FLAGS as needed export NVCC_PREPEND_FLAGS="${nvcc_prepend_flags[@]}" # [OPTIONAL] Enable verbose NVCC logs export NVCC_VERBOSE=1 # Specify cuDNN header and library paths export CUDNN_INCLUDE_DIR=/path/to/cudnn/include export CUDNN_LIBRARY=/path/to/cudnn/lib # Specify NVML filepath export NVML_LIB_PATH=/path/to/libnvidia-ml.so # Specify NCCL filepath export NCCL_LIB_PATH=/path/to/libnccl.so.2 # Build for SM70/80 (V100/A100 GPU); update as needed # If not specified, only the CUDA architecture supported by current system will be targeted # If not specified and no CUDA device is present either, all CUDA architectures will be targeted cuda_arch_list=7.0;8.0 # Unset TORCH_CUDA_ARCH_LIST if it exists, bc it takes precedence over # -DTORCH_CUDA_ARCH_LIST during the invocation of setup.py unset TORCH_CUDA_ARCH_LIST # Build the wheel artifact only python setup.py bdist_wheel \ --build-target=genai \ --build-variant=cuda \ --python-tag="${python_tag}" \ --plat-name="${python_plat_name}" \ --nvml_lib_path=${NVML_LIB_PATH} \ --nccl_lib_path=${NCCL_LIB_PATH} \ -DTORCH_CUDA_ARCH_LIST="${cuda_arch_list}" # Build and install the library into the Conda environment ``` -------------------------------- ### Install CUDA Package via Conda (Shell) Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Installs the full CUDA package, including NVML, into a specified Conda environment using a specific CUDA version from the nvidia channel. ```sh # See https://anaconda.org/nvidia/cuda for all available versions of CUDA cuda_version=12.4.1 # Install the full CUDA package conda install -n ${env_name} -y cuda -c "nvidia/label/cuda-${cuda_version}" ``` -------------------------------- ### Install FBGEMM with ROCm Build Variant Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_genai/development/BuildInstructions.rst Installs the FBGEMM library with a ROCm build variant into the Conda environment. Requires ROCM_PATH and PYTORCH_ROCM_ARCH to be set. This command configures ROCm-specific build flags. ```shell python setup.py install \ --build-target=genai \ --build-variant=rocm \ -DAMDGPU_TARGETS="${PYTORCH_ROCM_ARCH}" \ -DHIP_ROOT_DIR="${ROCM_PATH}" \ -DCMAKE_C_FLAGS="-DTORCH_USE_HIP_DSA" \ -DCMAKE_CXX_FLAGS="-DTORCH_USE_HIP_DSA" ``` -------------------------------- ### GLIBC and GLIBCXX Version Compatibility Check Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Commands to inspect supported GLIBC and GLIBCXX library versions in libstdc++.so.6. Useful for verifying binary compatibility across different systems and ensuring compiled libraries will work on target deployment platforms. ```shell libcxx_path=/path/to/libstdc++.so.6 # Print supported for GLIBC versions objdump -TC "${libcxx_path}" | grep GLIBC_ | sed 's/.*GLIBC_\([.0-9]*\).*/GLIBC_\1/g' | sort -Vu | cat # Print supported for GLIBCXX versions objdump -TC "${libcxx_path}" | grep GLIBCXX_ | sed 's/.*GLIBCXX_\([.0-9]*\).*/GLIBCXX_\1/g' | sort -Vu | cat ``` -------------------------------- ### Verify CUDA CMake Macros Header Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Checks for the presence of the 'cuda_cmake_macros.h' file within the Conda environment's installation directory. This file is a key indicator that the CUDA variant of PyTorch has been correctly installed. The command searches recursively from the Conda prefix. ```sh conda_prefix=$(conda run -n ${env_name} printenv CONDA_PREFIX) find "${conda_prefix}" -name cuda_cmake_macros.h ``` -------------------------------- ### Define Source Include Directories for FBGEMM GPU Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/CMakeLists.txt Sets the include directories for FBGEMM and FBGEMM_GPU sources, along with PyTorch and third-party libraries. No direct inputs, outputs the list of include paths. Depends on predefined variables like FBGEMM and TORCH_INCLUDE_DIRS. Assumes directory structures exist. ```CMake set(fbgemm_sources_include_directories # FBGEMM ${FBGEMM}/include # FBGEMM_GPU ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/../include # PyTorch ${TORCH_INCLUDE_DIRS} # Third-party ${THIRDPARTY}/asmjit/src ${THIRDPARTY}/cpuinfo/include ${THIRDPARTY}/cutlass/include ${THIRDPARTY}/cutlass/tools/util/include ${THIRDPARTY}/composable_kernel/include ${THIRDPARTY}/composable_kernel/library/include ${THIRDPARTY}/json/include ${NCCL_INCLUDE_DIRS}) ``` -------------------------------- ### Install Specific PyTorch Version via Conda Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Installs a specific version of PyTorch (e.g., 2.0.0) using Conda. This command allows for precise version control by specifying the version number and channel. It's recommended to use this method for reproducible builds. ```sh conda install -n ${env_name} -y pytorch==2.0.0 -c pytorch ``` -------------------------------- ### Install Triton TLX Backend Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/experimental/simplicial_attention/README.md Installs the stable TLX branch of Triton that provides base functionality for 2-Simplicial Attention kernels. The stable branch offers compatibility but may not achieve optimal performance due to PTX compiler optimization issues. ```bash git clone -b tlx https://github.com/facebookexperimental/triton.git cd triton pip install -e . --no-build-isolation ``` -------------------------------- ### Build with Clang (CPU) (Shell) Source: https://github.com/pytorch/fbgemm/blob/main/fbgemm_gpu/docs/src/fbgemm_gpu/development/BuildInstructions.rst Builds with Clang instead of GCC, appending `--cxxprefix=$CONDA_PREFIX` to the build command. ```sh # !! Run in fbgemm_gpu/ directory inside the Conda environment !! python setup.py bdist_wheel --build-variant=cpu --python-tag="${python_tag}" --plat-name="${python_plat_name}" --cxxprefix=$CONDA_PREFIX # Build and install the library into the Conda environment (Clang) python setup.py install --build-variant=cpu --cxxprefix=$CONDA_PREFIX ```