[fbgemm] create a new port (#16346)

* [fbgemm] create a new port

* [fbgemm] patch for latest asmjit

* [fbgemm] fix wrong install for Windows

* update baseline and port SHA

* [fbgemm] make PythonInterp required

* [fbgemm] check  PythonInterp in portfile.cmake

* [fbgemm] use Python instead of PythonInterp

* [fbgemm] use vcpkg_find_acquire_program for python3

* [fbgemm] update patches

* remove /MT /MD customization
* remove deprecated warnings for asmjit

* [fbgemm] update "supports"

* uwp can't be supported with cpuinfo link failure
* x86 SIMD may become available in future update

* [fbgemm] apply PR feedback

* [fbgemm] update to latest code

* removed asmjit related patch files

* [fbgemm] update version files
This commit is contained in:
Park DongHa 2021-03-20 02:03:17 +09:00 committed by GitHub
parent 96403d0903
commit a47284e8f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 199 additions and 0 deletions

View File

@ -0,0 +1,146 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6f19a16..3c758d2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,7 +6,6 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(GNUInstallDirs)
# function to extract filelists from defs.bzl file
-find_package(PythonInterp)
function(get_filelist name outputvar)
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c
@@ -19,9 +18,6 @@ endfunction()
project(fbgemm VERSION 0.1 LANGUAGES CXX C)
-set(FBGEMM_LIBRARY_TYPE "default" CACHE STRING
- "Type of library (shared, static, or default) to build")
-set_property(CACHE FBGEMM_LIBRARY_TYPE PROPERTY STRINGS default static shared)
option(FBGEMM_BUILD_TESTS "Build fbgemm unit tests" ON)
option(FBGEMM_BUILD_BENCHMARKS "Build fbgemm benchmarks" ON)
option(FBGEMM_BUILD_DOCS "Build fbgemm documentation" OFF)
@@ -101,18 +97,11 @@ set_target_properties(fbgemm_generic fbgemm_avx2 fbgemm_avx512 PROPERTIES
#2) MSVC uses /MD in default cxx compiling flags,
#need to change it to /MT in static case
if(MSVC)
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4267 /wd4305 /wd4309")
- if(FBGEMM_LIBRARY_TYPE STREQUAL "static")
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4267 /wd4305 /wd4309 /wd4703")
+ if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(fbgemm_generic PRIVATE ASMJIT_STATIC)
target_compile_definitions(fbgemm_avx2 PRIVATE ASMJIT_STATIC)
target_compile_definitions(fbgemm_avx512 PRIVATE ASMJIT_STATIC)
- foreach(flag_var
- CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
- CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
- if(${flag_var} MATCHES "/MD")
- string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
- endif(${flag_var} MATCHES "/MD")
- endforeach(flag_var)
endif()
target_compile_options(fbgemm_avx2 PRIVATE "/arch:AVX2")
target_compile_options(fbgemm_avx512 PRIVATE "/arch:AVX512")
@@ -145,7 +134,8 @@ message(WARNING "CMAKE_CXX_FLAGS_DEBUG is ${CMAKE_CXX_FLAGS_DEBUG}")
message(WARNING "CMAKE_CXX_FLAGS_RELEASE is ${CMAKE_CXX_FLAGS_RELEASE}")
message(WARNING "==========")
-if(NOT TARGET asmjit)
+find_package(asmjit CONFIG REQUIRED) # target 'asmjit::asmjit'
+if(FALSE)
#Download asmjit from github if ASMJIT_SRC_DIR is not specified.
if(NOT DEFINED ASMJIT_SRC_DIR)
set(ASMJIT_SRC_DIR "${FBGEMM_SOURCE_DIR}/third_party/asmjit"
@@ -164,7 +154,8 @@ if(NOT TARGET asmjit)
set_property(TARGET asmjit PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()
-if(NOT TARGET cpuinfo)
+find_package(cpuinfo CONFIG REQUIRED) # target 'cpuinfo::cpuinfo'
+if(FALSE)
#Download cpuinfo from github if CPUINFO_SOURCE_DIR is not specified.
if(NOT DEFINED CPUINFO_SOURCE_DIR)
set(CPUINFO_SOURCE_DIR "${FBGEMM_SOURCE_DIR}/third_party/cpuinfo"
@@ -185,49 +176,38 @@ endif()
target_include_directories(fbgemm_generic BEFORE
PUBLIC $<BUILD_INTERFACE:${FBGEMM_SOURCE_DIR}>
PUBLIC $<BUILD_INTERFACE:${FBGEMM_SOURCE_DIR}/include>
- PRIVATE "${ASMJIT_SRC_DIR}/src"
- PRIVATE "${CPUINFO_SOURCE_DIR}/include")
+)
+target_link_libraries(fbgemm_generic PUBLIC asmjit::asmjit cpuinfo::cpuinfo)
target_include_directories(fbgemm_avx2 BEFORE
PUBLIC $<BUILD_INTERFACE:${FBGEMM_SOURCE_DIR}>
PUBLIC $<BUILD_INTERFACE:${FBGEMM_SOURCE_DIR}/include>
- PRIVATE "${ASMJIT_SRC_DIR}/src"
- PRIVATE "${CPUINFO_SOURCE_DIR}/include")
+)
+target_link_libraries(fbgemm_avx2 PUBLIC asmjit::asmjit cpuinfo::cpuinfo)
target_include_directories(fbgemm_avx512 BEFORE
PUBLIC $<BUILD_INTERFACE:${FBGEMM_SOURCE_DIR}>
PUBLIC $<BUILD_INTERFACE:${FBGEMM_SOURCE_DIR}/include>
- PRIVATE "${ASMJIT_SRC_DIR}/src"
- PRIVATE "${CPUINFO_SOURCE_DIR}/include")
-
-if(FBGEMM_LIBRARY_TYPE STREQUAL "default")
- add_library(fbgemm
- $<TARGET_OBJECTS:fbgemm_generic>
- $<TARGET_OBJECTS:fbgemm_avx2>
- $<TARGET_OBJECTS:fbgemm_avx512>)
-elseif(FBGEMM_LIBRARY_TYPE STREQUAL "shared")
- add_library(fbgemm SHARED
- $<TARGET_OBJECTS:fbgemm_generic>
- $<TARGET_OBJECTS:fbgemm_avx2>
- $<TARGET_OBJECTS:fbgemm_avx512>)
+)
+target_link_libraries(fbgemm_avx512 PUBLIC asmjit::asmjit cpuinfo::cpuinfo)
+
+add_library(fbgemm
+ $<TARGET_OBJECTS:fbgemm_generic>
+ $<TARGET_OBJECTS:fbgemm_avx2>
+ $<TARGET_OBJECTS:fbgemm_avx512>)
+if(BUILD_SHARED_LIBS)
set_property(TARGET fbgemm_generic PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET fbgemm_avx2 PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET fbgemm_avx512 PROPERTY POSITION_INDEPENDENT_CODE ON)
set_target_properties(fbgemm PROPERTIES
CXX_VISIBILITY_PRESET hidden)
-elseif(FBGEMM_LIBRARY_TYPE STREQUAL "static")
- add_library(fbgemm STATIC
- $<TARGET_OBJECTS:fbgemm_generic>
- $<TARGET_OBJECTS:fbgemm_avx2>
- $<TARGET_OBJECTS:fbgemm_avx512>)
+else()
#MSVC need to define FBGEMM_STATIC for fbgemm_generic also to
#avoid generating _dllimport functions.
target_compile_definitions(fbgemm_generic PRIVATE FBGEMM_STATIC)
target_compile_definitions(fbgemm_avx2 PRIVATE FBGEMM_STATIC)
target_compile_definitions(fbgemm_avx512 PRIVATE FBGEMM_STATIC)
target_compile_definitions(fbgemm PRIVATE FBGEMM_STATIC)
-else()
- message(FATAL_ERROR "Unsupported library type ${FBGEMM_LIBRARY_TYPE}")
endif()
if(USE_SANITIZER)
@@ -239,9 +219,7 @@ target_include_directories(fbgemm BEFORE
PUBLIC $<BUILD_INTERFACE:${FBGEMM_SOURCE_DIR}>
PUBLIC $<BUILD_INTERFACE:${FBGEMM_SOURCE_DIR}/include>)
-target_link_libraries(fbgemm $<BUILD_INTERFACE:asmjit>
- $<BUILD_INTERFACE:cpuinfo>)
-add_dependencies(fbgemm asmjit cpuinfo)
+target_link_libraries(fbgemm PUBLIC asmjit::asmjit cpuinfo::cpuinfo)
install(TARGETS fbgemm EXPORT fbgemmLibraryConfig
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
@@ -254,7 +232,7 @@ install(FILES ${FBGEMM_PUBLIC_HEADERS}
install(EXPORT fbgemmLibraryConfig DESTINATION share/cmake/fbgemm
FILE fbgemmLibraryConfig.cmake)
-if(MSVC)
+if(FALSE)
if(FBGEMM_LIBRARY_TYPE STREQUAL "shared")
install(
FILES $<TARGET_PDB_FILE:fbgemm> $<TARGET_PDB_FILE:asmjit>

View File

@ -0,0 +1,29 @@
vcpkg_fail_port_install(ON_ARCH "x86" ON_TARGET "uwp")
# The project's CMakeLists.txt uses Python to select source files. Check if it is available in advance.
vcpkg_find_acquire_program(PYTHON3)
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO pytorch/fbgemm
REF 51bc2ecc7086980fd9e6190163b04486cd37ac2a
SHA512 43e59ff25ec9365061be6a8db7ec592f096e74897e338dd3e17401f2188986cf3b7e26f82f7c1e2adf34496fb32cb4b50d40731bee3bf9fa5b1f2ac92a09e671
PATCHES
fix-cmakelists.patch
)
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS
-DUSE_SANITIZER=OFF
-DFBGEMM_BUILD_TESTS=OFF
-DFBGEMM_BUILD_BENCHMARKS=OFF
-DPYTHON_EXECUTABLE=${PYTHON3} # inject the path instead of find_package(Python)
)
vcpkg_install_cmake()
vcpkg_copy_pdbs()
vcpkg_fixup_cmake_targets(CONFIG_PATH share/cmake/${PORT})
file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)

11
ports/fbgemm/vcpkg.json Normal file
View File

@ -0,0 +1,11 @@
{
"name": "fbgemm",
"version-date": "2021-03-18",
"description": "FB (Facebook) + GEMM (General Matrix-Matrix Multiplication)",
"homepage": "https://code.fb.com/ml-applications/fbgemm/",
"supports": "!(x86 | uwp)",
"dependencies": [
"asmjit",
"cpuinfo"
]
}

View File

@ -1904,6 +1904,10 @@
"baseline": "2.0.1",
"port-version": 0
},
"fbgemm": {
"baseline": "2021-03-18",
"port-version": 0
},
"fbthrift": {
"baseline": "2020.10.19.00",
"port-version": 0

9
versions/f-/fbgemm.json Normal file
View File

@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "7a439c159752233f767113ecf1a484065e223458",
"version-date": "2021-03-18",
"port-version": 0
}
]
}