Add compilation of *.f files

This commit is contained in:
Andrey Tkachenko 2020-08-28 16:32:59 +04:00
parent 8a684350e0
commit 5e612f7d47
3 changed files with 66 additions and 14 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "cblas-src"
version = "0.1.1"
version = "0.1.2"
authors = ["Andrey Tkachenko <andreytkachenko64@gmail.com>"]
edition = "2018"
build="build.rs"

View File

@ -1,14 +1,13 @@
use std::{env, fs, io};
use std::path::{Path, PathBuf};
use flate2::read::GzDecoder;
use tar::Archive;
use curl::easy::Easy;
use flate2::read::GzDecoder;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::{env, fs, io};
use tar::Archive;
const CBLAS_SRC: &str = "http://www.netlib.org/blas/blast-forum/cblas.tgz";
fn download<P: AsRef<Path>>(source_url: &str, target_file: P) -> anyhow::Result<()> {
let f = fs::File::create(&target_file)?;
let mut writer = io::BufWriter::new(f);
@ -50,12 +49,59 @@ fn main() {
extract(cblas_name, &out_path).unwrap();
}
Command::new("gfortran")
.current_dir(cblas_dir.join("src"))
.arg("-O3")
.arg("-c").arg(cblas_dir.join("src/cdotcsub.f"))
.arg("-c").arg(cblas_dir.join("src/cdotusub.f"))
.arg("-c").arg(cblas_dir.join("src/dasumsub.f"))
.arg("-c").arg(cblas_dir.join("src/ddotsub.f"))
.arg("-c").arg(cblas_dir.join("src/dnrm2sub.f"))
.arg("-c").arg(cblas_dir.join("src/dsdotsub.f"))
.arg("-c").arg(cblas_dir.join("src/dzasumsub.f"))
.arg("-c").arg(cblas_dir.join("src/dznrm2sub.f"))
.arg("-c").arg(cblas_dir.join("src/icamaxsub.f"))
.arg("-c").arg(cblas_dir.join("src/idamaxsub.f"))
.arg("-c").arg(cblas_dir.join("src/isamaxsub.f"))
.arg("-c").arg(cblas_dir.join("src/izamaxsub.f"))
.arg("-c").arg(cblas_dir.join("src/sasumsub.f"))
.arg("-c").arg(cblas_dir.join("src/scasumsub.f"))
.arg("-c").arg(cblas_dir.join("src/scnrm2sub.f"))
.arg("-c").arg(cblas_dir.join("src/sdotsub.f"))
.arg("-c").arg(cblas_dir.join("src/sdsdotsub.f"))
.arg("-c").arg(cblas_dir.join("src/snrm2sub.f"))
.arg("-c").arg(cblas_dir.join("src/zdotcsub.f"))
.arg("-c").arg(cblas_dir.join("src/zdotusub.f"))
.status()
.expect("fortran failed");
cc::Build::new()
.warnings(false)
.extra_warnings(false)
.static_flag(true)
.define("ADD_", None)
.include(cblas_dir.join("include"))
.object(cblas_dir.join("src/cdotcsub.o"))
.object(cblas_dir.join("src/cdotusub.o"))
.object(cblas_dir.join("src/dasumsub.o"))
.object(cblas_dir.join("src/ddotsub.o"))
.object(cblas_dir.join("src/dnrm2sub.o"))
.object(cblas_dir.join("src/dsdotsub.o"))
.object(cblas_dir.join("src/dzasumsub.o"))
.object(cblas_dir.join("src/dznrm2sub.o"))
.object(cblas_dir.join("src/icamaxsub.o"))
.object(cblas_dir.join("src/idamaxsub.o"))
.object(cblas_dir.join("src/isamaxsub.o"))
.object(cblas_dir.join("src/izamaxsub.o"))
.object(cblas_dir.join("src/sasumsub.o"))
.object(cblas_dir.join("src/scasumsub.o"))
.object(cblas_dir.join("src/scnrm2sub.o"))
.object(cblas_dir.join("src/sdotsub.o"))
.object(cblas_dir.join("src/sdsdotsub.o"))
.object(cblas_dir.join("src/snrm2sub.o"))
.object(cblas_dir.join("src/zdotcsub.o"))
.object(cblas_dir.join("src/zdotusub.o"))
.file(cblas_dir.join("src/cblas_caxpy.c"))
.file(cblas_dir.join("src/cblas_ccopy.c"))
.file(cblas_dir.join("src/cblas_cdotc_sub.c"))
@ -200,8 +246,6 @@ fn main() {
.file(cblas_dir.join("src/cblas_ztrmv.c"))
.file(cblas_dir.join("src/cblas_ztrsm.c"))
.file(cblas_dir.join("src/cblas_ztrsv.c"))
// TODO build fortran files aswell
.compile("libcblas");
}

View File

@ -1,3 +1,4 @@
#[cfg(test)]
mod tests {
extern crate openblas_src;
@ -12,6 +13,7 @@ mod tests {
2.0, 5.0,
3.0, 6.0,
];
let b = vec![
1.0, 5.0, 9.0,
2.0, 6.0, 10.0,
@ -25,11 +27,17 @@ mod tests {
4.0, 2.0,
];
let sdot_res = unsafe {
ddot(6, &a, 1, &a, 1)
};
unsafe {
dgemm(Layout::ColumnMajor, Transpose::None, Transpose::None,
m, n, k, 1.0, &a, m, &b, k, 1.0, &mut c, m);
}
assert_eq!(sdot_res, 91.0);
assert!(
c == vec![
40.0, 90.0,