@@ -6,6 +6,8 @@ set(GPU_RUNTIME "CUDA" CACHE STRING "HIP or CUDA or MPS")
66set (OPENCV_DIR "OPENCV_DIR-NOTFOUND" CACHE PATH "Path to the OPENCV installation directory" )
77set (OPENSPLAT_MAX_CUDA_COMPATIBILITY OFF CACHE BOOL "Build for maximum CUDA device compatibility" )
88set (OPENSPLAT_BUILD_VISUALIZER OFF CACHE BOOL "Build visualizer application" )
9+ set (OPENSPLAT_USE_FAST_MATH OFF CACHE BOOL "Enable fast math optimizations for GPU kernels (-use_fast_math / -ffast-math)" )
10+
911set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} )
1012
1113# Read version
@@ -38,6 +40,10 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
3840endif ()
3941# Suppress warning #20012-D (nvcc and glm)
4042set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -diag-suppress=20012)
43+ if (OPENSPLAT_USE_FAST_MATH)
44+ message (STATUS "Fast math optimizations enabled for CUDA" )
45+ set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --use_fast_math)
46+ endif ()
4147
4248include (FetchContent)
4349FetchContent_Declare(nlohmann_json
@@ -129,6 +135,10 @@ elseif(GPU_RUNTIME STREQUAL "HIP")
129135 endif ()
130136 set (CMAKE_MODULE_PATH "${HIP_PATH} /cmake" ${CMAKE_MODULE_PATH} )
131137 find_package (HIP REQUIRED)
138+ if (OPENSPLAT_USE_FAST_MATH)
139+ message (STATUS "Fast math optimizations enabled for HIP" )
140+ set (CMAKE_HIP_FLAGS ${CMAKE_HIP_FLAGS} -ffast-math)
141+ endif ()
132142
133143 file (GLOB_RECURSE GSPLAT_GPU_SRC LIST_DIRECTORIES False rasterizer/gsplat/*.cu)
134144 set_source_files_properties (${GSPLAT_GPU_SRC} PROPERTIES LANGUAGE HIP)
@@ -146,6 +156,11 @@ elseif(GPU_RUNTIME STREQUAL "MPS")
146156 message (STATUS "Metal framework found" )
147157
148158 set (XC_FLAGS -O3)
159+ if (OPENSPLAT_USE_FAST_MATH)
160+ message (STATUS "Fast math optimizations enabled for Metal" )
161+
162+ set (XC_FLAGS ${XC_FLAGS} -ffast-math)
163+ endif ()
149164 set (USE_MPS ON CACHE BOOL "Use MPS for GPU acceleration" )
150165else ()
151166 set (GPU_RUNTIME "CPU" )
0 commit comments