Skip to content

Commit

Permalink
Add folly support (attempt 2) (#2926)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #2926

- Add folly support (attempt 2)

Reviewed By: sryap

Differential Revision: D60616299
  • Loading branch information
q10 authored and facebook-github-bot committed Aug 2, 2024
1 parent 48fd1f1 commit 566aee5
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .github/scripts/fbgemm_gpu_build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,19 @@ __configure_fbgemm_gpu_build_genai () {
done
}

__configure_folly_flags () {
echo "[BUILD] Looking up Folly library filepath ..."
# shellcheck disable=SC2155,SC2086
local conda_prefix=$(conda run ${env_prefix} printenv CONDA_PREFIX)
# shellcheck disable=SC2155,SC2086
local folly_lib_path=$(conda run ${env_prefix} find ${conda_prefix} -name "libfolly.so")

echo "[BUILD] Setting CUDA build args ..."
build_args+=(
--folly_lib_path="${folly_lib_path}"
)
}

# shellcheck disable=SC2120
__configure_fbgemm_gpu_build () {
echo "################################################################################"
Expand Down Expand Up @@ -278,6 +291,9 @@ __configure_fbgemm_gpu_build () {
__configure_fbgemm_gpu_build_clang
fi

# Add build flags to support building against Folly
__configure_folly_flags

# Set verbosity
build_args+=(
--verbose
Expand Down
23 changes: 22 additions & 1 deletion .github/scripts/utils_build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ __conda_install_gcc () {
local env_prefix=$(env_name_or_prefix "${env_name}")

# shellcheck disable=SC2155
local gcc_version=10.4.0
local gcc_version=12.4.0

echo "[INSTALL] Installing GCC (${gcc_version}, ${archname}) through Conda ..."
# shellcheck disable=SC2086
Expand Down Expand Up @@ -211,9 +211,29 @@ install_cxx_compiler () {

# Run post-install checks
__compiler_post_install_checks


# print_exec sudo ln -fs /root/miniconda/$env_name/build_docs/lib/libstdc++.so.6 /usr/lib64/libstdc++.so.6
echo $LD_LIBRARY_PATH
echo $LIBRARY_PATH

__show_glibcxx_info

echo "[INSTALL] Successfully installed C/C++ compilers"
}

__show_glibcxx_info () {
echo "[TEST] Enumerating libstdc++.so files ..."

# shellcheck disable=SC2155
local all_libcxx_libs=$(find / -type f -name 'libstdc++.so*' -print | sort)
for f in $all_libcxx_libs; do
echo "$f";
objdump -TC "$f" | grep GLIBCXX_ | sed 's/.*GLIBCXX_\([.0-9]*\).*/GLIBCXX_\1/g' | sort -Vu | cat
echo ""
done
}

install_build_tools () {
local env_name="$1"
if [ "$env_name" == "" ]; then
Expand Down Expand Up @@ -249,6 +269,7 @@ install_build_tools () {
build \
click \
cmake \
folly \
hypothesis \
jinja2 \
make \
Expand Down
7 changes: 5 additions & 2 deletions fbgemm_gpu/FbgemmGpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ set(fbgemm_sources_include_directories
${THIRDPARTY}/cutlass/include
${THIRDPARTY}/cutlass/tools/util/include
${THIRDPARTY}/json/include
${NCCL_INCLUDE_DIRS})
${NCCL_INCLUDE_DIRS}
${FOLLY_INCLUDE_DIRS})


################################################################################
Expand Down Expand Up @@ -684,7 +685,8 @@ endif()
# Add PyTorch include/
target_include_directories(fbgemm_gpu_py PRIVATE
${TORCH_INCLUDE_DIRS}
${NCCL_INCLUDE_DIRS})
${NCCL_INCLUDE_DIRS}
${FOLLY_INCLUDE_DIRS})

# Remove `lib` from the output artifact name `libfbgemm_gpu_py.so`
set_target_properties(fbgemm_gpu_py PROPERTIES PREFIX "")
Expand All @@ -693,6 +695,7 @@ set_target_properties(fbgemm_gpu_py PROPERTIES PREFIX "")
target_link_libraries(fbgemm_gpu_py
${TORCH_LIBRARIES}
${NCCL_LIBRARIES}
${FOLLY_LIBRARIES}
${CUDA_DRIVER_LIBRARIES})

# Link to NVML
Expand Down
16 changes: 16 additions & 0 deletions fbgemm_gpu/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ def from_args(cls, argv: List[str]):
default=None,
help="NCCL (libnccl.so.2) filepath. This is required for building certain targets.",
)
parser.add_argument(
"--folly_lib_path",
type=str,
default=None,
help="Folly (libfolly.so) filepath. This is required for building certain targets.",
)
parser.add_argument(
"--cxxprefix",
type=str,
Expand Down Expand Up @@ -276,6 +282,16 @@ def _get_cxx11_abi():
]
)

if self.args.folly_lib_path:
folly_root = os.path.dirname(os.path.dirname(self.args.folly_lib_path))
cxx_flags.extend([f"-L{folly_root}/lib"])
cmake_args.extend(
[
f"-DFOLLY_INCLUDE_DIRS={folly_root}/include",
f"-DFOLLY_LIBRARIES={self.args.folly_lib_path}",
]
)

if self.args.cxxprefix:
print("[SETUP.PY] Setting CMake flags ...")
path = self.args.cxxprefix
Expand Down
5 changes: 5 additions & 0 deletions fbgemm_gpu/src/metric_ops/metric_ops_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
*/

#include <ATen/core/op_registration/op_registration.h>
// #include <folly/hash/Checksum.h>
#include <torch/library.h>

#include "fbgemm_gpu/sparse_ops_utils.h"
#include "metric_ops.h"

namespace fbgemm_gpu {

// uint32_t example_folly_code(const std::vector<uint8_t>& buffer) {
// return folly::crc32c(buffer.data(), buffer.size());
// }

TORCH_LIBRARY_FRAGMENT(fbgemm, m) {
m.def(
"batch_auc(int num_tasks, Tensor indices, Tensor laebls, Tensor weights) -> Tensor");
Expand Down
6 changes: 6 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@
# Build the docs
cd docs
# print_exec uname -a
# print_exec ldd --version
# yum install sudo
ls -la /root/miniconda/envs/$BUILD_ENV/lib
# print_exec export LD_LIBRARY_PATH=/root/miniconda/envs/$BUILD_ENV/lib
print_exec export LD_PRELOAD=/root/miniconda/envs/$BUILD_ENV/lib/libstdc++.so
build_fbgemm_gpu_docs $BUILD_ENV
"""

0 comments on commit 566aee5

Please sign in to comment.