From b778776532bd12041a1a8c6f584ff41fba041c4c Mon Sep 17 00:00:00 2001 From: Griffin Bassman Date: Mon, 3 Jun 2024 12:55:04 -0400 Subject: [PATCH] add to vw_core --- CMakeLists.txt | 1 + vowpalwabbit/core/CMakeLists.txt | 4 ++++ vowpalwabbit/core/src/reductions/gd.cc | 1 + 3 files changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b373508f90..2b367e7eb20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,6 +178,7 @@ option(VW_BUILD_VW_C_WRAPPER "Enable building the c_wrapper project" ON) option(vw_BUILD_NET_CORE "Build .NET Core targets" OFF) option(vw_BUILD_NET_FRAMEWORK "Build .NET Framework targets" OFF) option(VW_BUILD_WASM "Add WASM target" OFF) +option(STD_INV_SQRT "Use standard library inverse square root" OFF) if(VW_INSTALL AND NOT VW_ZLIB_SYS_DEP) message(WARNING "Installing with a vendored version of zlib is not recommended. Use VW_ZLIB_SYS_DEP to use a system dependency or specify VW_INSTALL=OFF to silence this warning.") diff --git a/vowpalwabbit/core/CMakeLists.txt b/vowpalwabbit/core/CMakeLists.txt index db03a2ed0b7..e6107a988fd 100644 --- a/vowpalwabbit/core/CMakeLists.txt +++ b/vowpalwabbit/core/CMakeLists.txt @@ -440,6 +440,10 @@ if (MSVC_IDE) target_sources(vw_core PRIVATE $ ) endif() +if(STD_INV_SQRT) + target_compile_definitions(vw_core PUBLIC STD_INV_SQRT) +endif() + # Clang-cl on Windows has issues with our usage of SIMD types. Turn it off explicitly for Windows + clang-cl to mitigate. # See issue # if(WIN32 AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") diff --git a/vowpalwabbit/core/src/reductions/gd.cc b/vowpalwabbit/core/src/reductions/gd.cc index 852448606b7..a97c6521984 100644 --- a/vowpalwabbit/core/src/reductions/gd.cc +++ b/vowpalwabbit/core/src/reductions/gd.cc @@ -153,6 +153,7 @@ VW_WARNING_STATE_POP static inline float inv_sqrt(float x) { + return 1.f / std::sqrt(x); #if defined(STD_INV_SQRT) return 1.f / std::sqrt(x); #endif