homebrew-core/Formula/openblas.rb

78 lines
2.8 KiB
Ruby

class Openblas < Formula
desc "Optimized BLAS library"
homepage "https://www.openblas.net/"
url "https://github.com/xianyi/OpenBLAS/archive/v0.3.20.tar.gz"
sha256 "8495c9affc536253648e942908e88e097f2ec7753ede55aca52e5dead3029e3c"
license "BSD-3-Clause"
head "https://github.com/xianyi/OpenBLAS.git", branch: "develop"
livecheck do
url :stable
strategy :github_latest
end
bottle do
sha256 cellar: :any, arm64_monterey: "e6dc1cbdb470a50abd39392d92639e0b8ccec8480790ec1bc35e7e70511f39e9"
sha256 cellar: :any, arm64_big_sur: "a08b76f9d53d35fa5ec0484c07a097f0275c6697c790da4b33c930d56b10bf16"
sha256 cellar: :any, monterey: "64e8434a833240ece09df09d86ba8c835d9b10c0e22e05aa8bfb6e97014f8d6f"
sha256 cellar: :any, big_sur: "00becc271a08671bd1d59f9567fd37ddfe72bdb518d268e4452550e6ab3b9e3b"
sha256 cellar: :any, catalina: "0de72c027ce82230482ebbc01afbfc12a5bed294b195769959cfc2e6f0befca8"
sha256 cellar: :any_skip_relocation, x86_64_linux: "db54160b4ed4032d9714336ea39d2e000ff24df7706d868b9a0ac054acb5a006"
end
keg_only :shadowed_by_macos, "macOS provides BLAS in Accelerate.framework"
depends_on "gcc" # for gfortran
fails_with :clang
def install
ENV.runtime_cpu_detection
ENV.deparallelize # build is parallel by default, but setting -j confuses it
ENV["DYNAMIC_ARCH"] = "1"
ENV["USE_OPENMP"] = "1"
# Force a large NUM_THREADS to support larger Macs than the VMs that build the bottles
ENV["NUM_THREADS"] = "56"
ENV["TARGET"] = case Hardware.oldest_cpu
when :arm_vortex_tempest
"VORTEX"
else
Hardware.oldest_cpu.upcase.to_s
end
# Must call in two steps
system "make", "CC=#{ENV.cc}", "FC=gfortran", "libs", "netlib", "shared"
system "make", "PREFIX=#{prefix}", "install"
lib.install_symlink shared_library("libopenblas") => shared_library("libblas")
lib.install_symlink shared_library("libopenblas") => shared_library("liblapack")
end
test do
(testpath/"test.c").write <<~EOS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "cblas.h"
int main(void) {
int i;
double A[6] = {1.0, 2.0, 1.0, -3.0, 4.0, -1.0};
double B[6] = {1.0, 2.0, 1.0, -3.0, 4.0, -1.0};
double C[9] = {.5, .5, .5, .5, .5, .5, .5, .5, .5};
cblas_dgemm(CblasColMajor, CblasNoTrans, CblasTrans,
3, 3, 2, 1, A, 3, B, 3, 2, C, 3);
for (i = 0; i < 9; i++)
printf("%lf ", C[i]);
printf("\\n");
if (fabs(C[0]-11) > 1.e-5) abort();
if (fabs(C[4]-21) > 1.e-5) abort();
return 0;
}
EOS
system ENV.cc, "test.c", "-I#{include}", "-L#{lib}", "-lopenblas",
"-o", "test"
system "./test"
end
end