Skip to content

Commit

Permalink
Change the default release build optimization level of gcc to O2 (int…
Browse files Browse the repository at this point in the history
…el#231)

* The default release build optimization level of gcc is O3. IPEX explicitly appends the O2 to the CXX flags which results in optimization level conflict. This patch explicitly changes the default release build optimization level to O2.

* Add abi flags to the c++ extension library

* Refine code style
  • Loading branch information
EikanWang authored Oct 12, 2021
1 parent 587694e commit 526c821
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "${RPATH_VALUE}/lib/:${RPATH_VALUE}/")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${IPEX_INSTALL_LIBDIR})
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")

set(DPCPP_ROOT "${PROJECT_SOURCE_DIR}/torch_ipex/csrc")
set(DPCPP_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party")
Expand Down
8 changes: 3 additions & 5 deletions cmake/CPU.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ ENDIF()
# Define build type
IF(CMAKE_BUILD_TYPE MATCHES Debug)
message("Debug build.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -D_DEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_DEBUG")
ELSEIF(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
message("RelWithDebInfo build")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -g -DNDEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")
ELSE()
message("Release build.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")
ENDIF()

IF("${IPEX_DISP_OP}" STREQUAL "1")
Expand Down Expand Up @@ -156,8 +156,6 @@ include_directories(${DPCPP_THIRD_PARTY_ROOT}/llga/third_party/oneDNN/include)
# include_directories(${PROJECT_SOURCE_DIR}/build/third_party/mkl-dnn/include)
# include_directories(${DPCPP_THIRD_PARTY_ROOT}/mkl-dnn/include)



# Set installed PyTorch dir
if(DEFINED PYTORCH_INSTALL_DIR)
include_directories(${PYTORCH_INSTALL_DIR}/include)
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,15 @@ def run(self):
Path(output_lib_path).mkdir(parents=True, exist_ok=True)

cmake_args = [
'-DCMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=' + str(int(torch._C._GLIBCXX_USE_CXX11_ABI)),
'-DCMAKE_BUILD_TYPE=' + get_build_type(),
'-DPYTORCH_INSTALL_DIR=' + pytorch_install_dir,
'-DPYTHON_EXECUTABLE=' + sys.executable,
'-DIPEX_INSTALL_LIBDIR=' + os.path.abspath(output_lib_path),
'-DCMAKE_INSTALL_PREFIX=' + os.path.abspath(output_lib_path),
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + os.path.abspath(output_lib_path),
'-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=' + os.path.abspath(output_lib_path),
'-DIPEX_INSTALL_LIBDIR=' + os.path.abspath(output_lib_path),
'-DPYTHON_INCLUDE_DIR=' + python_include_dir,
'-DPYTHON_EXECUTABLE=' + sys.executable,
'-DPYTORCH_INSTALL_DIR=' + pytorch_install_dir,
'-DPYTORCH_INCLUDE_DIRS=' + pytorch_install_dir + "/include",
'-DPYTORCH_LIBRARY_DIRS=' + pytorch_install_dir + "/lib"]

Expand Down

0 comments on commit 526c821

Please sign in to comment.