[MPS] Fix build regressions introduced by #92868 (#101036)

https://github.com/pytorch/pytorch/pull/92868 introduced  `OBJC` and `OBJCXX` language dialects, but fails to propagate some important flags, like OpenMP include path(if found),  `-fno-objc-arc` and `-Wno-unguarded-availability-new` suppression.

This PR remedies that and fixes https://github.com/pytorch/pytorch/issues/100925

<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at 62677d4</samp>

This pull request improves the support for MPSGraph on Apple platforms by fixing some CMake flags for parallelism and memory management. It modifies `cmake/Dependencies.cmake` and `CMakeLists.txt` accordingly.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/101036
Approved by: https://github.com/atalman, https://github.com/huydhn
This commit is contained in:
Nikita Shulga
2023-05-10 04:15:41 +00:00
committed by PyTorch MergeBot
parent b004c0b3c6
commit 30cecc0e11
2 changed files with 6 additions and 3 deletions

View File

@ -971,11 +971,11 @@ endif()
if(APPLE)
if(USE_MPS)
string(APPEND CMAKE_OBJCXX_FLAGS " -DUSE_MPS")
string(APPEND CMAKE_CXX_FLAGS " -DUSE_MPS -fno-objc-arc")
string(APPEND CMAKE_OBJCXX_FLAGS " -DUSE_MPS -fno-objc-arc")
string(APPEND CMAKE_CXX_FLAGS " -DUSE_MPS")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -weak_framework Foundation -weak_framework MetalPerformanceShaders -weak_framework MetalPerformanceShadersGraph -weak_framework Metal")
# To suppress MPSGraph availability warnings
append_cxx_flag_if_supported("-Wno-unguarded-availability-new" CMAKE_CXX_FLAGS)
append_cxx_flag_if_supported("-Wno-unguarded-availability-new" CMAKE_OBJCXX_FLAGS)
endif()
append_cxx_flag_if_supported("-Wno-unused-private-field" CMAKE_CXX_FLAGS)
append_cxx_flag_if_supported("-Wno-missing-braces" CMAKE_CXX_FLAGS)

View File

@ -1176,6 +1176,9 @@ if(USE_OPENMP AND NOT TARGET caffe2::openmp)
include(${CMAKE_CURRENT_LIST_DIR}/Modules/FindOpenMP.cmake)
if(OPENMP_FOUND)
message(STATUS "Adding OpenMP CXX_FLAGS: " ${OpenMP_CXX_FLAGS})
if(APPLE AND USE_MPS)
string(APPEND CMAKE_OBJCXX_FLAGS " ${OpenMP_CXX_FLAGS}")
endif()
if(OpenMP_CXX_LIBRARIES)
message(STATUS "Will link against OpenMP libraries: ${OpenMP_CXX_LIBRARIES}")
endif()