57 lines
2.0 KiB
Ruby
57 lines
2.0 KiB
Ruby
class Enzyme < Formula
|
|
desc "High-performance automatic differentiation of LLVM"
|
|
homepage "https://enzyme.mit.edu"
|
|
url "https://github.com/wsmoses/Enzyme/archive/v0.0.9.tar.gz"
|
|
sha256 "c6f906747f1d32f92c70f6f9e0b8d94f38fc43fdb8633db09281b360b97a1421"
|
|
license "Apache-2.0" => { with: "LLVM-exception" }
|
|
head "https://github.com/wsmoses/Enzyme.git", branch: "main"
|
|
|
|
bottle do
|
|
sha256 arm64_big_sur: "f33b0cf71958fcf10357dc8dc005c9bd5123e8538ef122536d0bbd8a4f2369bd"
|
|
sha256 big_sur: "400c0178774a87c3a357ada0fe613691ead64c2bd04c6535349be6fd55c16f0d"
|
|
sha256 catalina: "bfb97f1714c1686b8eb7f57aeec89ed9f3e9160ee72b14c81b9b9d3045f4f3de"
|
|
sha256 mojave: "1ab282a86c3910ee2c1b6432016efae90ef92562f1c5ad84d422eaf0c5cb8210"
|
|
end
|
|
|
|
depends_on "cmake" => :build
|
|
depends_on "llvm"
|
|
|
|
def install
|
|
mkdir "build" do
|
|
system "cmake", "../enzyme", *std_cmake_args, "-DLLVM_DIR=#{Formula["llvm"].opt_lib}/cmake/llvm"
|
|
system "make"
|
|
system "make", "install"
|
|
end
|
|
end
|
|
|
|
test do
|
|
(testpath/"test.c").write <<~EOS
|
|
#include <stdio.h>
|
|
extern double __enzyme_autodiff(void*, double);
|
|
double square(double x) {
|
|
return x * x;
|
|
}
|
|
double dsquare(double x) {
|
|
return __enzyme_autodiff(square, x);
|
|
}
|
|
int main() {
|
|
double i = 21.0;
|
|
printf("square(%.0f)=%.0f, dsquare(%.0f)=%.0f\\n", i, square(i), i, dsquare(i));
|
|
}
|
|
EOS
|
|
|
|
llvm = Formula["llvm"]
|
|
llvm_version = llvm.version.major
|
|
opt = llvm.opt_bin/"opt"
|
|
ENV["CC"] = llvm.opt_bin/"clang"
|
|
|
|
system ENV.cc, testpath/"test.c", "-S", "-emit-llvm", "-o", "input.ll", "-O2",
|
|
"-fno-vectorize", "-fno-slp-vectorize", "-fno-unroll-loops"
|
|
system opt, "input.ll", "-load=#{opt_lib}/#{shared_library("LLVMEnzyme-#{llvm_version}")}",
|
|
"-enzyme", "-o", "output.ll", "-S"
|
|
system ENV.cc, "output.ll", "-O3", "-o", "test"
|
|
|
|
assert_equal "square(21)=441, dsquare(21)=42\n", shell_output("./test")
|
|
end
|
|
end
|