Merge pull request #845 from davydden/openblas_cleanup_unit_test
openblas: fix a bug and cleanup the unit test
This commit is contained in:
commit
87c772b117
3 changed files with 75 additions and 52 deletions
|
@ -94,43 +94,28 @@ def setup_dependent_package(self, module, dspec):
|
||||||
self.spec.lapack_shared_lib = self.spec.blas_shared_lib
|
self.spec.lapack_shared_lib = self.spec.blas_shared_lib
|
||||||
|
|
||||||
def check_install(self, spec):
|
def check_install(self, spec):
|
||||||
"Build and run a small program to test that we have Lapack symbols"
|
# TODO: Pull this out to the framework function which recieves a pair of xyz.c and xyz.output
|
||||||
print "Checking Openblas installation..."
|
print "Checking Openblas installation..."
|
||||||
checkdir = "spack-check"
|
source_file = join_path(os.path.dirname(self.module.__file__),
|
||||||
with working_dir(checkdir, create=True):
|
'test_cblas_dgemm.c')
|
||||||
source = r"""
|
output_file = join_path(os.path.dirname(self.module.__file__),
|
||||||
#include <cblas.h>
|
'test_cblas_dgemm.output')
|
||||||
#include <stdio.h>
|
|
||||||
int main(void) {
|
with open(output_file, 'r') as f:
|
||||||
int i=0;
|
expected = f.read()
|
||||||
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("%f\n", C[i]);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
expected = """\
|
|
||||||
11.000000
|
|
||||||
-9.000000
|
|
||||||
5.000000
|
|
||||||
-9.000000
|
|
||||||
21.000000
|
|
||||||
-1.000000
|
|
||||||
5.000000
|
|
||||||
-1.000000
|
|
||||||
3.000000
|
|
||||||
"""
|
|
||||||
with open("check.c", 'w') as f:
|
|
||||||
f.write(source)
|
|
||||||
cc = which('cc')
|
cc = which('cc')
|
||||||
# TODO: Automate these path and library settings
|
cc('-c', "-I%s" % join_path(spec.prefix, "include"), source_file)
|
||||||
cc('-c', "-I%s" % join_path(spec.prefix, "include"), "check.c")
|
link_flags = ["-L%s" % join_path(spec.prefix, "lib"),
|
||||||
cc('-o', "check", "check.o",
|
"-llapack",
|
||||||
"-L%s" % join_path(spec.prefix, "lib"), "-llapack", "-lblas", "-lpthread")
|
"-lblas",
|
||||||
|
"-lpthread"
|
||||||
|
]
|
||||||
|
if '+openmp' in spec:
|
||||||
|
link_flags.extend([self.compiler.openmp_flag])
|
||||||
|
cc('-o', "check", "test_cblas_dgemm.o",
|
||||||
|
*link_flags)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
check = Executable('./check')
|
check = Executable('./check')
|
||||||
output = check(return_output=True)
|
output = check(return_output=True)
|
||||||
|
@ -148,4 +133,3 @@ def check_install(self, spec):
|
||||||
print output
|
print output
|
||||||
print '-'*80
|
print '-'*80
|
||||||
raise RuntimeError("Openblas install check failed")
|
raise RuntimeError("Openblas install check failed")
|
||||||
shutil.rmtree(checkdir)
|
|
||||||
|
|
|
@ -1,13 +1,49 @@
|
||||||
#include <cblas.h>
|
#include <cblas.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
int main(void) {
|
|
||||||
int i=0;
|
double m[] = {
|
||||||
double A[6] = {1.0, 2.0, 1.0, -3.0, 4.0, -1.0};
|
3, 1, 3,
|
||||||
double B[6] = {1.0, 2.0, 1.0, -3.0, 4.0, -1.0};
|
1, 5, 9,
|
||||||
double C[9] = {.5, .5, .5, .5, .5, .5, .5, .5, .5};
|
2, 6, 5
|
||||||
cblas_dgemm(CblasColMajor, CblasNoTrans, CblasTrans,
|
};
|
||||||
3, 3, 2, 1, A, 3, B, 3, 2, C, 3);
|
|
||||||
for (i = 0; i < 9; i++)
|
double x[] = {
|
||||||
printf("%f\n", C[i]);
|
-1, 3, -3
|
||||||
return 0;
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void dgesv_(int *n, int *nrhs, double *a, int *lda,
|
||||||
|
int *ipivot, double *b, int *ldb, int *info);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
int i;
|
||||||
|
// blas:
|
||||||
|
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("%f\n", C[i]);
|
||||||
|
|
||||||
|
// lapack:
|
||||||
|
int ipiv[3];
|
||||||
|
int j;
|
||||||
|
int info;
|
||||||
|
int n = 1;
|
||||||
|
int nrhs = 1;
|
||||||
|
int lda = 3;
|
||||||
|
int ldb = 3;
|
||||||
|
dgesv_(&n,&nrhs, &m[0], &lda, ipiv, &x[0], &ldb, &info);
|
||||||
|
for (i=0; i<3; ++i)
|
||||||
|
printf("%5.1f %3d\n", x[i], ipiv[i]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,3 +7,6 @@
|
||||||
5.000000
|
5.000000
|
||||||
-1.000000
|
-1.000000
|
||||||
3.000000
|
3.000000
|
||||||
|
-0.3 1
|
||||||
|
3.0 1499101120
|
||||||
|
-3.0 32767
|
||||||
|
|
Loading…
Reference in a new issue