diff --git a/CMakeLists.txt b/CMakeLists.txt index d3cd5cbd83..47c7556c76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ # A minimum CMake version of 3.21+ is needed to support the required C and C++ # standard versions -cmake_minimum_required(VERSION 3.25 FATAL_ERROR) +cmake_minimum_required(VERSION 3.21 FATAL_ERROR) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") @@ -105,6 +105,7 @@ 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) option(FBGEMM_BUILD_FBGEMM_GPU "Build fbgemm_gpu library" OFF) +option(DISABLE_FBGEMM_AUTOVEC "Disable FBGEMM Autovec" OFF) if(FBGEMM_BUILD_TESTS) enable_testing() @@ -422,3 +423,11 @@ endif() if(FBGEMM_BUILD_FBGEMM_GPU) add_subdirectory(fbgemm_gpu) endif() + +if(HAVE_GNU_F2H_IEEE) + add_definitions(-DHAVE_GNU_F2H_IEEE) +endif() + +if(DISABLE_FBGEMM_AUTOVEC) + add_definitions(-DDISABLE_FBGEMM_AUTOVEC) +endif() diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt index 44b6b408ca..71ef1db8a7 100644 --- a/bench/CMakeLists.txt +++ b/bench/CMakeLists.txt @@ -4,7 +4,7 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. -cmake_minimum_required(VERSION 3.25 FATAL_ERROR) +cmake_minimum_required(VERSION 3.21 FATAL_ERROR) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/cmake/modules/FindGnuH2fIeee.cmake b/cmake/modules/FindGnuH2fIeee.cmake new file mode 100644 index 0000000000..09c2abdd26 --- /dev/null +++ b/cmake/modules/FindGnuH2fIeee.cmake @@ -0,0 +1,21 @@ +# 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. + + +################################################################################ +# Finds and sets GNU_FH2_IEEE compilation flags +################################################################################ + +INCLUDE(CheckCXXSourceCompiles) + +CHECK_CXX_SOURCE_COMPILES(" + #include + int main() { + float f = 1.0f; + uint16_t h = __gnu_f2h_ieee(f); + return 0; + } +" HAVE_GNU_F2H_IEEE) diff --git a/fbgemm_gpu/CMakeLists.txt b/fbgemm_gpu/CMakeLists.txt index 3eba104b26..dbe2f1e6ae 100644 --- a/fbgemm_gpu/CMakeLists.txt +++ b/fbgemm_gpu/CMakeLists.txt @@ -8,7 +8,7 @@ # CMake Prelude ################################################################################ -cmake_minimum_required(VERSION 3.25 FATAL_ERROR) +cmake_minimum_required(VERSION 3.21 FATAL_ERROR) set(CMAKEMODULES ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules) set(FBGEMM_GPU ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/fbgemm_gpu/cmake/Fbgemm.cmake b/fbgemm_gpu/cmake/Fbgemm.cmake index d4964a8801..e1894f8bac 100644 --- a/fbgemm_gpu/cmake/Fbgemm.cmake +++ b/fbgemm_gpu/cmake/Fbgemm.cmake @@ -10,7 +10,6 @@ set(fbgemm_sources_normal "${FBGEMM}/src/EmbeddingSpMDM.cc" - "${FBGEMM}/src/EmbeddingSpMDMAutovec.cc" "${FBGEMM}/src/EmbeddingSpMDMNBit.cc" "${FBGEMM}/src/QuantUtils.cc" "${FBGEMM}/src/RefImplementations.cc" @@ -18,6 +17,10 @@ set(fbgemm_sources_normal "${FBGEMM}/src/SparseAdagrad.cc" "${FBGEMM}/src/Utils.cc") +if(NOT DISABLE_FBGEMM_AUTOVEC) + list(APPEND fbgemm_sources_normal "${FBGEMM}/src/EmbeddingSpMDMAutovec.cc") +endif() + set(fbgemm_sources_avx2 "${FBGEMM}/src/EmbeddingSpMDMAvx2.cc" "${FBGEMM}/src/QuantUtilsAvx2.cc") diff --git a/include/fbgemm/FloatConversion.h b/include/fbgemm/FloatConversion.h index 838769711c..0a8fdd6527 100644 --- a/include/fbgemm/FloatConversion.h +++ b/include/fbgemm/FloatConversion.h @@ -287,7 +287,7 @@ inline float cpu_half2float_ref(const float16 h) { // Same as the previous function, but use the built-in fp16 to fp32 // conversion provided by the compiler inline float cpu_half2float(const float16 h) { -#ifdef HAS_NATIVE_FP16_TYPE +#if defined(HAS_NATIVE_FP16_TYPE) && defined(HAVE_GNU_F2H_IEEE) __fp16 h_fp16; std::memcpy(&h_fp16, &h, sizeof(__fp16)); return h_fp16; @@ -297,7 +297,7 @@ inline float cpu_half2float(const float16 h) { } inline float16 cpu_float2half(const float f) { -#ifdef HAS_NATIVE_FP16_TYPE +#if defined(HAS_NATIVE_FP16_TYPE) && defined(HAVE_GNU_F2H_IEEE) __fp16 h = f; float16 res; std::memcpy(&res, &h, sizeof(__fp16)); diff --git a/src/EmbeddingSpMDMAutovec.h b/src/EmbeddingSpMDMAutovec.h index d054fb0049..0f590552fc 100644 --- a/src/EmbeddingSpMDMAutovec.h +++ b/src/EmbeddingSpMDMAutovec.h @@ -14,7 +14,9 @@ #include "fbgemm/FbgemmEmbedding.h" +#ifndef DISABLE_FBGEMM_AUTOVEC #define FBGEMM_AUTOVEC_AVAILABLE +#endif namespace fbgemm { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 403cc54df5..1ddb2882a9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,7 +4,7 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. -cmake_minimum_required(VERSION 3.25 FATAL_ERROR) +cmake_minimum_required(VERSION 3.21 FATAL_ERROR) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_EXTENSIONS OFF)