homebrew-core/Formula/libtorch.rb

89 lines
3.0 KiB
Ruby

class Libtorch < Formula
include Language::Python::Virtualenv
desc "Tensors and dynamic neural networks"
homepage "https://pytorch.org/"
url "https://github.com/pytorch/pytorch.git",
tag: "v1.10.1",
revision: "302ee7bfb604ebef384602c56e3853efed262030"
license "BSD-3-Clause"
livecheck do
url :stable
regex(/^v?(\d+(?:\.\d+)+)$/i)
end
bottle do
sha256 cellar: :any, arm64_monterey: "c4c93596ff324b9b20d4702ae5ba39c5dc98bf11abba9bbcda34c1083081b171"
sha256 cellar: :any, arm64_big_sur: "25b7cd16fd367cbafaa341f49147dcc84de28dee5b1c6fb06cbcaf6643be1108"
sha256 cellar: :any, monterey: "6eb641d82391ce6d0b8beb0760832973f7b762c439fef1b88e6cf30fbdbda5a5"
sha256 cellar: :any, big_sur: "a2ddf9175a7f372afe253eed381e9184b14e9da7f34802c0477b6c413847bad9"
sha256 cellar: :any, catalina: "62cc4be579de6cfe41f558c10b19ccf41152d104a68f9593c7ed7754a3165e37"
sha256 cellar: :any_skip_relocation, x86_64_linux: "622f4e75fbcc99a838cd669753f0dbe3a2e241115ae63138dde47ab28877bda8"
end
depends_on "cmake" => :build
depends_on "python@3.9" => :build
depends_on "eigen"
depends_on "libomp"
depends_on "libyaml"
depends_on "protobuf"
depends_on "pybind11"
resource "PyYAML" do
url "https://files.pythonhosted.org/packages/36/2b/61d51a2c4f25ef062ae3f74576b01638bebad5e045f747ff12643df63844/PyYAML-6.0.tar.gz"
sha256 "68fb519c14306fec9720a2a5b45bc9f0c8d1b9c72adf45c37baedfcd949c35a2"
end
resource "typing-extensions" do
url "https://files.pythonhosted.org/packages/ed/12/c5079a15cf5c01d7f4252b473b00f7e68ee711be605b9f001528f0298b98/typing_extensions-3.10.0.2.tar.gz"
sha256 "49f75d16ff11f1cd258e1b988ccff82a3ca5570217d7ad8c5f48205dd99a677e"
end
def install
venv = virtualenv_create(buildpath/"venv", Formula["python@3.9"].opt_bin/"python3")
venv.pip_install resources
args = %W[
-DBUILD_CUSTOM_PROTOBUF=OFF
-DBUILD_PYTHON=OFF
-DPYTHON_EXECUTABLE=#{buildpath}/venv/bin/python
-DUSE_CUDA=OFF
-DUSE_METAL=OFF
-DUSE_MKLDNN=OFF
-DUSE_NNPACK=OFF
-DUSE_OPENMP=OFF
-DUSE_SYSTEM_EIGEN_INSTALL=ON
-DUSE_SYSTEM_PYBIND11=ON
]
# Remove when https://github.com/pytorch/pytorch/issues/67974 is addressed
args << "-DUSE_SYSTEM_BIND11=ON"
mkdir "build" do
system "cmake", "..", *std_cmake_args, *args
# Avoid references to Homebrew shims
inreplace "caffe2/core/macros.h", Superenv.shims_path/ENV.cxx, ENV.cxx
system "make"
system "make", "install"
end
end
test do
(testpath/"test.cpp").write <<~EOS
#include <torch/torch.h>
#include <iostream>
int main() {
torch::Tensor tensor = torch::rand({2, 3});
std::cout << tensor << std::endl;
}
EOS
system ENV.cxx, "-std=c++14", "test.cpp", "-o", "test",
"-I#{include}/torch/csrc/api/include",
"-L#{lib}", "-ltorch", "-ltorch_cpu", "-lc10"
system "./test"
end
end