forked from pytorch/FBGEMM
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor CMakeLists.txt (pytorch#2501)
Summary: - Refactor CMakeLists.txt to support building experimental targets - Add example folder to demonstrate building an experimental target Pull Request resolved: pytorch#2501 Reviewed By: spcyppt Differential Revision: D56265492 Pulled By: q10 fbshipit-source-id: c1b3778d78fda528bbe79b29ee2b44e7e1411a1c
- Loading branch information
1 parent
3f4f98f
commit a2fdc90
Showing
21 changed files
with
382 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules/Utilities.cmake) | ||
|
||
|
||
################################################################################ | ||
# CUDA Setup | ||
################################################################################ | ||
|
||
# Set NVML_LIB_PATH if provided, or detect the default lib path | ||
if(NOT NVML_LIB_PATH) | ||
set(DEFAULT_NVML_LIB_PATH | ||
"${CUDA_TOOLKIT_ROOT_DIR}/lib64/stubs/libnvidia-ml.so") | ||
|
||
if(EXISTS ${DEFAULT_NVML_LIB_PATH}) | ||
message(STATUS "Setting NVML_LIB_PATH: \ | ||
${CUDA_TOOLKIT_ROOT_DIR}/lib64/stubs/libnvidia-ml.so") | ||
set(NVML_LIB_PATH "${CUDA_TOOLKIT_ROOT_DIR}/lib64/stubs/libnvidia-ml.so") | ||
endif() | ||
endif() | ||
|
||
if(NVML_LIB_PATH) | ||
message(STATUS "Found NVML_LIB_PATH: ${NVML_LIB_PATH}") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules/Utilities.cmake) | ||
|
||
|
||
################################################################################ | ||
# CMake C++ Setup | ||
################################################################################ | ||
|
||
# SET THE C AND C++ VERSIONS HERE | ||
set(C_VERSION 17) | ||
set(CXX_VERSION 20) | ||
|
||
# Set the default C++ standard to CXX_VERSION if CMAKE_CXX_STANDARD is not | ||
# supplied by CMake command invocation. | ||
# Individual targets can have this value overridden; see | ||
# https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD.html | ||
# https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html | ||
# https://cmake.org/cmake/help/latest/prop_tgt/HIP_STANDARD.html | ||
if(NOT CMAKE_CXX_STANDARD) | ||
set(CMAKE_CXX_STANDARD ${CXX_VERSION}) | ||
set(CMAKE_HIP_STANDARD ${CXX_VERSION}) | ||
set(CXX_STANDARD ${CXX_VERSION}) | ||
set(HIP_STANDARD ${CXX_VERSION}) | ||
endif() | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(HIP_STANDARD_REQUIRED ON) | ||
|
||
# Set the default C standard to C_VERSION if CMAKE_C_STANDARD is not supplied | ||
# by CMake command invocation. | ||
# Individual targets can have this value overridden; see | ||
# https://cmake.org/cmake/help/latest/variable/CMAKE_C_STANDARD.html | ||
# https://cmake.org/cmake/help/latest/prop_tgt/C_STANDARD.html | ||
if(NOT CMAKE_C_STANDARD) | ||
set(C_STANDARD ${C_VERSION}) | ||
set(CMAKE_C_STANDARD ${C_VERSION}) | ||
endif() | ||
set(CMAKE_C_EXTENSIONS OFF) | ||
set(CMAKE_C_STANDARD_REQUIRED ON) | ||
|
||
if(DEFINED GLIBCXX_USE_CXX11_ABI) | ||
if(${GLIBCXX_USE_CXX11_ABI} EQUAL 1) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=1") | ||
else() | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0") | ||
endif() | ||
endif() | ||
|
||
BLOCK_PRINT( | ||
"Default C compiler flags" | ||
"(values may be overridden by CMAKE_CXX_STANDARD and CXX_STANDARD):" | ||
"" | ||
"${CMAKE_C_FLAGS}" | ||
) | ||
|
||
BLOCK_PRINT( | ||
"Default C++ compiler flags" | ||
"(values may be overridden by CMAKE_CXX_STANDARD and CXX_STANDARD):" | ||
"" | ||
"${CMAKE_CXX_FLAGS}" | ||
) | ||
|
||
# Strip all symbols from the .SO file after building | ||
add_link_options($<$<CONFIG:RELEASE>:-s>) | ||
|
||
# Set flags for AVX2 | ||
set(AVX2_FLAGS "-mavx2;-mf16c;-mfma;-fopenmp") | ||
if(NOT FBGEMM_CPU_ONLY AND WSL_MODE) | ||
# NVCC in WSL complains about unknown -mavx options | ||
# https://github.com/pytorch/FBGEMM/issues/2135 | ||
set(AVX2_FLAGS "-Xcompiler;-mavx;-Xcompiler;-mavx2;-Xcompiler;-mf16c;-Xcompiler;-mfma;-fopenmp") | ||
endif() | ||
|
||
# Set flags for AVX512 | ||
set(AVX512_FLAGS "-mavx2;-mf16c;-mfma;-mavx512f;-mavx512bw;-mavx512dq;-mavx512vl;-fopenmp") | ||
if(NOT FBGEMM_CPU_ONLY AND WSL_MODE) | ||
set(AVX512_FLAGS "-Xcompiler;-mavx2;-Xcompiler;-mf16c;-Xcompiler;-mfma;-Xcompiler;-mavx512f;-Xcompiler;-mavx512bw;-Xcompiler;-mavx512dq;-Xcompiler;-mavx512vl;-fopenmp") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules/Utilities.cmake) | ||
|
||
|
||
################################################################################ | ||
# PyTorch Dependencies Setup | ||
################################################################################ | ||
|
||
find_package(Torch REQUIRED) | ||
|
||
# | ||
# Toch Cuda Extensions are normally compiled with the flags below. However we | ||
# disabled -D__CUDA_NO_HALF_CONVERSIONS__ here as it caused "error: no suitable | ||
# constructor exists to convert from "int" to "__half" errors in | ||
# gen_embedding_forward_quantized_split_[un]weighted_codegen_cuda.cu | ||
# | ||
|
||
set(TORCH_CUDA_OPTIONS | ||
--expt-relaxed-constexpr -D__CUDA_NO_HALF_OPERATORS__ | ||
# -D__CUDA_NO_HALF_CONVERSIONS__ | ||
-D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules/Utilities.cmake) | ||
|
||
|
||
################################################################################ | ||
# ROCm and HIPify Setup | ||
################################################################################ | ||
|
||
if(USE_ROCM) | ||
# Load CMake modules | ||
list(APPEND CMAKE_MODULE_PATH | ||
"${PROJECT_SOURCE_DIR}/cmake" | ||
"${THIRDPARTY}/hipify_torch/cmake") | ||
include(Hip) | ||
include(Hipify) | ||
|
||
# Configure compiler for HIP | ||
list(APPEND HIP_HCC_FLAGS | ||
" \"-Wno-#pragma-messages\" " | ||
" \"-Wno-#warnings\" " | ||
-Wno-cuda-compat | ||
-Wno-deprecated-declarations | ||
-Wno-format | ||
-Wno-ignored-attributes | ||
-Wno-unused-result) | ||
|
||
BLOCK_PRINT( | ||
"HIP found: ${HIP_FOUND}" | ||
"HIPCC compiler flags:" | ||
"" | ||
"${HIP_HCC_FLAGS}" | ||
) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
################################################################################ | ||
# Utility Functions | ||
################################################################################ | ||
|
||
function(BLOCK_PRINT) | ||
message("") | ||
message("") | ||
message("================================================================================") | ||
foreach(ARG IN LISTS ARGN) | ||
message("${ARG}") | ||
endforeach() | ||
message("================================================================================") | ||
message("") | ||
endfunction() |
Oops, something went wrong.