-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmake torchao_ops_mps_linear_fp_act_xbit_weight (#1304)
Summary: Pull Request resolved: #1304 Move from setup.py to cmake for building custom torchao mps ops Differential Revision: D66120124
- Loading branch information
1 parent
b714026
commit a3bb86d
Showing
7 changed files
with
122 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
cmake_minimum_required(VERSION 3.19) | ||
|
||
project(torchao_ops_mps_linear_fp_act_xbit_weight) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED YES) | ||
|
||
if (NOT CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE Release) | ||
endif() | ||
|
||
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") | ||
if (NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") | ||
message(FATAL_ERROR "Unified Memory requires Apple Silicon arquitecture") | ||
endif() | ||
else() | ||
message(FATAL_ERROR "Torchao experimental mps ops can only be built on macOS/iOS") | ||
endif() | ||
|
||
find_package(Torch REQUIRED) | ||
|
||
if(NOT TORCHAO_INCLUDE_DIRS) | ||
set(TORCHAO_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) | ||
endif() | ||
message(STATUS "TORCHAO_INCLUDE_DIRS: ${TORCHAO_INCLUDE_DIRS}") | ||
|
||
include_directories(${TORCHAO_INCLUDE_DIRS}) | ||
include_directories(${CMAKE_INSTALL_PREFIX}/include) | ||
add_library(torchao_ops_mps_linear_fp_act_xbit_weight_aten SHARED aten/register.mm) | ||
|
||
target_include_directories(torchao_ops_mps_linear_fp_act_xbit_weight_aten PRIVATE "${TORCH_INCLUDE_DIRS}") | ||
target_link_libraries(torchao_ops_mps_linear_fp_act_xbit_weight_aten PRIVATE "${TORCH_LIBRARIES}") | ||
target_compile_definitions(torchao_ops_mps_linear_fp_act_xbit_weight_aten PRIVATE USE_ATEN=1) | ||
|
||
# Enable Metal support | ||
find_library(METAL_LIB Metal) | ||
find_library(FOUNDATION_LIB Foundation) | ||
target_link_libraries(torchao_ops_mps_linear_fp_act_xbit_weight_aten PRIVATE ${METAL_LIB} ${FOUNDATION_LIB}) | ||
|
||
install( | ||
TARGETS torchao_ops_mps_linear_fp_act_xbit_weight_aten | ||
EXPORT _targets | ||
DESTINATION lib | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash -eu | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
cd "$(dirname "$BASH_SOURCE")" | ||
|
||
export CMAKE_PREFIX_PATH=$(python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())') | ||
echo "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}" | ||
export CMAKE_OUT=$(python -c "import sys; print(sys.prefix)")/torchao_mps/cmake-out | ||
echo "CMAKE_OUT: ${CMAKE_OUT}" | ||
|
||
export INCLUDE_PATH=${CMAKE_OUT}/include | ||
mkdir -p ${INCLUDE_PATH}/torchao/experimental/kernels/mps/src/ | ||
export GENERATED_METAL_SHADER_LIB=${INCLUDE_PATH}/torchao/experimental/kernels/mps/src/metal_shader_lib.h | ||
python ../../kernels/mps/codegen/gen_metal_shader_lib.py ${GENERATED_METAL_SHADER_LIB} | ||
echo "GENERATED_METAL_SHADER_LIB: ${GENERATED_METAL_SHADER_LIB}" | ||
|
||
cmake -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} \ | ||
-DCMAKE_INSTALL_PREFIX=${CMAKE_OUT} \ | ||
-S . \ | ||
-B ${CMAKE_OUT} | ||
cmake --build ${CMAKE_OUT} -j 16 --target install --config Release |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters