-
Notifications
You must be signed in to change notification settings - Fork 369
cmake torchao_ops_mps_linear_fp_act_xbit_weight #1304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
facebook-github-bot
merged 1 commit into
pytorch:main
from
manuelcandales:export-D66120124
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why cmake prefix path points to site-packages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's where the cmake stuff is. I am working on a conda environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean thats where the cmake stuff is. prefix path is used for looking up packages https://cmake.org/cmake/help/latest/variable/CMAKE_PREFIX_PATH.html and other stuff