-
Notifications
You must be signed in to change notification settings - Fork 185
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
Differential Revision: D66120124 Pull Request resolved: #1304
- Loading branch information
1 parent
7446433
commit 7489c7d
Showing
8 changed files
with
143 additions
and
46 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 @@ | ||
cmake-out/ |
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,60 @@ | ||
# 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 architecture") | ||
endif() | ||
else() | ||
message(FATAL_ERROR "Torchao experimental mps ops can only be built on macOS/iOS") | ||
endif() | ||
|
||
find_package(Torch REQUIRED) | ||
|
||
# Generate metal_shader_lib.h by running gen_metal_shader_lib.py | ||
set(GENERATED_METAL_SHADER_LIB ${CMAKE_INSTALL_PREFIX}/include/torchao/experimental/kernels/mps/src/metal_shader_lib.h) | ||
add_custom_command( | ||
OUTPUT ${GENERATED_METAL_SHADER_LIB} | ||
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/../../kernels/mps/codegen/gen_metal_shader_lib.py ${GENERATED_METAL_SHADER_LIB} | ||
COMMENT "Generating metal_shader_lib.h using gen_metal_shader_lib.py" | ||
) | ||
add_custom_target(generated_metal_shader_lib ALL DEPENDS ${GENERATED_METAL_SHADER_LIB}) | ||
|
||
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) | ||
add_dependencies(torchao_ops_mps_linear_fp_act_xbit_weight_aten generated_metal_shader_lib) | ||
|
||
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,19 @@ | ||
#!/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=${PWD}/cmake-out | ||
echo "CMAKE_OUT: ${CMAKE_OUT}" | ||
|
||
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