85 lines
2.7 KiB
Ruby
85 lines
2.7 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.9.0",
|
|
revision: "d69c22dd61a2f006dcfe1e3ea8468a3ecaf931aa"
|
|
license "BSD-3-Clause"
|
|
|
|
livecheck do
|
|
url :stable
|
|
strategy :github_latest
|
|
end
|
|
|
|
bottle do
|
|
sha256 cellar: :any, big_sur: "a51bfd1cc532abeabea070676f04ef4650fd087371307fabc8ffac3a7b212d30"
|
|
sha256 cellar: :any, catalina: "ca0ddb068dd09872cfe9f7bcfdb264fd01a61347dba7660eecab45840535ad53"
|
|
sha256 cellar: :any, mojave: "3e9191a6c5dcc80856aded5542387830bfcf6c6047790775b51e901324e37494"
|
|
sha256 cellar: :any_skip_relocation, x86_64_linux: "a507806bd616df3fc75cedc1024c399bac2b7f2235b6baab5499e053da5a3afb"
|
|
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/a0/a4/d63f2d7597e1a4b55aa3b4d6c5b029991d3b824b5bd331af8d4ab1ed687d/PyYAML-5.4.1.tar.gz"
|
|
sha256 "607774cbba28732bfa802b54baa7484215f530991055bb562efbed5b2f20a45e"
|
|
end
|
|
|
|
resource "typing-extensions" do
|
|
url "https://files.pythonhosted.org/packages/aa/55/62e2d4934c282a60b4243a950c9dbfa01ae7cac0e8d6c0b5315b87432c81/typing_extensions-3.10.0.0.tar.gz"
|
|
sha256 "50b6f157849174217d0656f99dc82fe932884fb250826c18350e159ec6cdf342"
|
|
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
|
|
-Dpybind11_PREFER_third_party=OFF
|
|
-DUSE_CUDA=OFF
|
|
-DUSE_METAL=OFF
|
|
-DUSE_MKLDNN=OFF
|
|
-DUSE_NNPACK=OFF
|
|
-DUSE_OPENMP=OFF
|
|
-DUSE_SYSTEM_EIGEN_INSTALL=ON
|
|
]
|
|
|
|
mkdir "build" do
|
|
system "cmake", "..", *std_cmake_args, *args
|
|
|
|
# Avoid references to Homebrew shims
|
|
inreplace "caffe2/core/macros.h", %r{#{HOMEBREW_SHIMS_PATH}/[^/]+/super/#{Regexp.escape(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
|