92 lines
3.1 KiB
Ruby
92 lines
3.1 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.12.0",
|
|
revision: "67ece03c8cd632cce9523cd96efde6f2d1cc8121"
|
|
license "BSD-3-Clause"
|
|
revision 1
|
|
|
|
livecheck do
|
|
url :stable
|
|
regex(/^v?(\d+(?:\.\d+)+)$/i)
|
|
end
|
|
|
|
bottle do
|
|
sha256 cellar: :any, arm64_monterey: "686f303c779745ed5783ef13c7960d16f843d3d0c7e7f30abebb4713d98c32ab"
|
|
sha256 cellar: :any, arm64_big_sur: "4a4634af0fc675988c9f92ff5ddadeaa4b200795c9348695bbc81147122e7874"
|
|
sha256 cellar: :any, monterey: "271abaa70085d2b71236f310efb69627a7c3e21e3fd2a132fb9505bbc6a2686e"
|
|
sha256 cellar: :any, big_sur: "1330a22befa5c55dfa06213cd5d1cdfeb1ef791643b415370e006008a8e8c32e"
|
|
sha256 cellar: :any, catalina: "937c5e220841d09a46d3ed3dd982c7d1459fe609c020f5c476f6d375919dea16"
|
|
sha256 cellar: :any_skip_relocation, x86_64_linux: "dfbca1c50824431e00e6fa0dc2bd979a06739fe8b479b15a053a84bba5011a7b"
|
|
end
|
|
|
|
depends_on "cmake" => :build
|
|
depends_on "python@3.10" => :build
|
|
depends_on "eigen"
|
|
depends_on "libyaml"
|
|
depends_on "protobuf"
|
|
depends_on "pybind11"
|
|
|
|
on_macos do
|
|
depends_on "libomp"
|
|
end
|
|
|
|
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/fe/71/1df93bd59163c8084d812d166c907639646e8aac72886d563851b966bf18/typing_extensions-4.2.0.tar.gz"
|
|
sha256 "f1c24655a0da0d1b67f07e17a5e6b2a105894e6824b92096378bb3668ef02376"
|
|
end
|
|
|
|
def install
|
|
venv = virtualenv_create(buildpath/"venv", Formula["python@3.10"].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=ON
|
|
-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 "cmake", "--build", ".", "--target", "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
|