56 lines
2.0 KiB
Ruby
56 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.18.tar.gz"
|
|
sha256 "64fecead54f11797bd17170ffa2bf4b3289bc8720cd2b0541375785bb97b7e2c"
|
|
license "Apache-2.0" => { with: "LLVM-exception" }
|
|
head "https://github.com/wsmoses/Enzyme.git", branch: "main"
|
|
|
|
bottle do
|
|
sha256 cellar: :any, arm64_big_sur: "3528734cc826147e6286875ccac597a64df539ad749f06894e4b7a7b621ddf4f"
|
|
sha256 cellar: :any, big_sur: "80e2fb5b9143784c8208967af69bd5f3ff27f71cd6a1dca629ca805f416c02dd"
|
|
sha256 cellar: :any, catalina: "e9f0808a68ed91cac12f80f1cb5053f9b93acc1dc00dc220299d8a2e89f17814"
|
|
sha256 cellar: :any, mojave: "f10713e873f16fb5afb670312d88cf3f606d0e482d998ffd2bc3a3218797eeb4"
|
|
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"]
|
|
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.major}")}",
|
|
"-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
|