|
| 1 | +# BSD 2-Clause License |
| 2 | +# |
| 3 | +# Copyright (c) 2024, Hewlett Packard Enterprise |
| 4 | +# All rights reserved. |
| 5 | +# |
| 6 | +# Redistribution and use in source and binary forms, with or without |
| 7 | +# modification, are permitted provided that the following conditions are met: |
| 8 | +# |
| 9 | +# 1. Redistributions of source code must retain the above copyright notice, this |
| 10 | +# list of conditions and the following disclaimer. |
| 11 | +# |
| 12 | +# 2. Redistributions in binary form must reproduce the above copyright notice, |
| 13 | +# this list of conditions and the following disclaimer in the documentation |
| 14 | +# and/or other materials provided with the distribution. |
| 15 | +# |
| 16 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 20 | +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 21 | +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 22 | +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 23 | +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | + |
| 27 | +PYTORCH_VERSION=2.0.1 |
| 28 | +OSX_ARCHITECTURE=arm64 |
| 29 | + |
| 30 | +TORCH_TARGET = libtorch-macos-$(OSX_ARCHITECTURE)-$(PYTORCH_VERSION).zip |
| 31 | +TORCH_BUILD = $(PWD)/build/libtorch |
| 32 | +TORCH_INSTALL = $(PWD)/install/libtorch |
| 33 | + |
| 34 | +TORCH_CMAKE_OPTIONS = |
| 35 | +TORCH_CMAKE_OPTIONS += -DCMAKE_OSX_ARCHITECTURES=$(OSX_ARCHITECTURE) |
| 36 | +TORCH_CMAKE_OPTIONS += -DUSE_MKL=OFF -DUSE_MKLDNN=OFF -DUSE_ITT=OFF |
| 37 | +TORCH_CMAKE_OPTIONS += -DUSE_QNNPACK=OFF -DUSE_KINETO=OFF |
| 38 | + |
| 39 | +.PHONY: help |
| 40 | +help: |
| 41 | + @grep "^# help\:" Makefile | grep -v grep | sed 's/\# help\: //' | sed 's/\# help\://' |
| 42 | + |
| 43 | +ifneq ($(shell uname), Darwin) |
| 44 | + $(error This tool requires Mac OSX) |
| 45 | +endif |
| 46 | + |
| 47 | +# help: |
| 48 | +# help: ----Overview---- |
| 49 | +# help: This makefile can be used to builds ML backends for use on arm64. Generally |
| 50 | +# help: all that needs to be done to accomplish this is |
| 51 | +# help: |
| 52 | +# help: pip install -r pytorch/requirements.txt |
| 53 | +# help: make torch |
| 54 | +# help: |
| 55 | +# help: ----Meta targets---- |
| 56 | +# help: clean -- Cleans all build and install directories |
| 57 | +.PHONY: clean |
| 58 | +clean: clean_torch |
| 59 | + |
| 60 | +# help: |
| 61 | +# help: ----Build Targets---- |
| 62 | +# help: torch -- Builds libtorch |
| 63 | +# help: |
| 64 | +.PHONY: torch |
| 65 | +torch: $(TORCH_TARGET) |
| 66 | + |
| 67 | +# Checkout a specific version of Torch and update all of the torch submodules |
| 68 | +.PHONY: checkout_torch |
| 69 | +checkout_torch: |
| 70 | + cd pytorch && git checkout v$(PYTORCH_VERSION) && \ |
| 71 | + git submodule foreach --recursive git reset --hard && \ |
| 72 | + git submodule update --init --recursive |
| 73 | + |
| 74 | +$(TORCH_BUILD) $(TORCH_INSTALL): |
| 75 | + mkdir -p $@ |
| 76 | + |
| 77 | +.PHONY: build_torch |
| 78 | +build_torch: $(TORCH_BUILD) $(TORCH_INSTALL) checkout_torch |
| 79 | + cd $< && \ |
| 80 | + cmake -DCMAKE_INSTALL_PREFIX=$(TORCH_INSTALL) $(TORCH_CMAKE_OPTIONS) ../../pytorch && \ |
| 81 | + make install -j 6 |
| 82 | + |
| 83 | +$(TORCH_TARGET): build_torch |
| 84 | + cd install && zip -r ../$@ libtorch |
| 85 | + |
| 86 | +.PHONY: clean_torch |
| 87 | +clean_torch: |
| 88 | + rm -rf $(TORCH_BUILD) $(TORCH_TARGET) $(TORCH_INSTALL) |
| 89 | + |
0 commit comments