Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py-numpy: rework blas/lapack #2365

Merged
merged 2 commits into from
Jan 26, 2017
Merged

Conversation

davydden
Copy link
Member

@davydden davydden commented Nov 18, 2016

another part of #2361 plus a lots of extras.

tested py-numpy@1.11.2 by calling

spack activate py-numpy; spack load python;

followed by (see https://github.com/Homebrew/homebrew-python/blob/master/numpy.rb#L123-L126)

python -c 'import numpy as np; t = np.ones((3,3),int); assert t.sum() == 9; assert np.dot(t,t).sum() == 27; np.show_config()'

on...

macOS Sierra + clang:

  • spack install py-numpy+blas+lapack ^openblas
lapack_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/Users/davydden/spack/opt/spack/darwin-sierra-x86_64/clang-8.0.0-apple/openblas-0.2.19-7qdxwznmqzlbqtusssagtxkypivod6ct/lib']
    define_macros = [('HAVE_CBLAS', None)]
    language = c
blas_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/Users/davydden/spack/opt/spack/darwin-sierra-x86_64/clang-8.0.0-apple/openblas-0.2.19-7qdxwznmqzlbqtusssagtxkypivod6ct/lib']
    define_macros = [('HAVE_CBLAS', None)]
    language = c
openblas_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/Users/davydden/spack/opt/spack/darwin-sierra-x86_64/clang-8.0.0-apple/openblas-0.2.19-7qdxwznmqzlbqtusssagtxkypivod6ct/lib']
    define_macros = [('HAVE_CBLAS', None)]
    language = c
openblas_lapack_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/Users/davydden/spack/opt/spack/darwin-sierra-x86_64/clang-8.0.0-apple/openblas-0.2.19-7qdxwznmqzlbqtusssagtxkypivod6ct/lib']
    define_macros = [('HAVE_CBLAS', None)]
    language = c
blas_mkl_info:
  NOT AVAILABLE

Ubuntu 16.04 + GCC5.4:

  • spack install py-numpy+blas+lapack ^openblas
lapack_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/home/davydden/spack/opt/spack/linux-ubuntu16-x86_64/gcc-5.4.0/openblas-0.2.19-ehpxgz2j74uc7pbca5lnufmna4is3oqs/lib']
    define_macros = [('HAVE_CBLAS', None)]
    language = c
blas_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/home/davydden/spack/opt/spack/linux-ubuntu16-x86_64/gcc-5.4.0/openblas-0.2.19-ehpxgz2j74uc7pbca5lnufmna4is3oqs/lib']
    define_macros = [('HAVE_CBLAS', None)]
    language = c
openblas_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/home/davydden/spack/opt/spack/linux-ubuntu16-x86_64/gcc-5.4.0/openblas-0.2.19-ehpxgz2j74uc7pbca5lnufmna4is3oqs/lib']
    define_macros = [('HAVE_CBLAS', None)]
    language = c
openblas_lapack_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/home/davydden/spack/opt/spack/linux-ubuntu16-x86_64/gcc-5.4.0/openblas-0.2.19-ehpxgz2j74uc7pbca5lnufmna4is3oqs/lib']
    define_macros = [('HAVE_CBLAS', None)]
    language = c
blas_mkl_info:
  NOT AVAILABLE
  • spack install py-numpy+blas+lapack ^atlas (mix threaded and non-threaded libs due to upstream)
atlas_3_10_blas_threads_info:
    libraries = ['satlas', 'tatlas']
    library_dirs = ['/home/davydden/spack/opt/spack/linux-ubuntu16-x86_64/gcc-5.4.0/atlas-3.10.2-5jtibobvt7nlwd3zyviionsn7v4z2npd/lib']
    define_macros = [('HAVE_CBLAS', None), ('ATLAS_INFO', '"\\"3.10.2\\""')]
    language = c
lapack_opt_info:
    libraries = ['tatlas', 'satlas', 'tatlas']
    library_dirs = ['/home/davydden/spack/opt/spack/linux-ubuntu16-x86_64/gcc-5.4.0/atlas-3.10.2-5jtibobvt7nlwd3zyviionsn7v4z2npd/lib']
    define_macros = [('ATLAS_INFO', '"\\"3.10.2\\""')]
    language = f77
blas_opt_info:
    libraries = ['satlas', 'tatlas']
    library_dirs = ['/home/davydden/spack/opt/spack/linux-ubuntu16-x86_64/gcc-5.4.0/atlas-3.10.2-5jtibobvt7nlwd3zyviionsn7v4z2npd/lib']
    define_macros = [('HAVE_CBLAS', None), ('ATLAS_INFO', '"\\"3.10.2\\""')]
    language = c
openblas_info:
  NOT AVAILABLE
openblas_lapack_info:
  NOT AVAILABLE
atlas_3_10_threads_info:
    libraries = ['tatlas', 'satlas', 'tatlas']
    library_dirs = ['/home/davydden/spack/opt/spack/linux-ubuntu16-x86_64/gcc-5.4.0/atlas-3.10.2-5jtibobvt7nlwd3zyviionsn7v4z2npd/lib']
    define_macros = [('ATLAS_INFO', '"\\"3.10.2\\""')]
    language = f77
lapack_mkl_info:
  NOT AVAILABLE
blas_mkl_info:
  NOT AVAILABLE
  • spack install py-numpy+blas+lapack ^mkl (not working due to upstream)
lapack_info:
  NOT AVAILABLE
lapack_opt_info:
  NOT AVAILABLE
openblas_lapack_info:
  NOT AVAILABLE
blas_info:
  NOT AVAILABLE
atlas_3_10_blas_threads_info:
  NOT AVAILABLE
atlas_threads_info:
  NOT AVAILABLE
blas_src_info:
  NOT AVAILABLE
atlas_3_10_threads_info:
  NOT AVAILABLE
atlas_blas_info:
  NOT AVAILABLE
atlas_3_10_blas_info:
  NOT AVAILABLE
lapack_src_info:
  NOT AVAILABLE
atlas_blas_threads_info:
  NOT AVAILABLE
openblas_info:
  NOT AVAILABLE
blas_mkl_info:
  NOT AVAILABLE
blas_opt_info:
  NOT AVAILABLE
atlas_info:
  NOT AVAILABLE
atlas_3_10_info:
  NOT AVAILABLE
lapack_mkl_info:
  NOT AVAILABLE

@glennpj ping.

@davydden davydden added the WIP label Nov 18, 2016
@davydden davydden force-pushed the pkg/py_numpy_default_all branch 2 times, most recently from 7d215e7 to 290deb4 Compare November 20, 2016 17:49
@davydden davydden changed the title py-numpy: fix blas/lapack section title py-numpy: rework blas/lapack Nov 20, 2016
@davydden
Copy link
Member Author

there appears to be a bug in numpy which leads to simultaneous usage of both single-threaded and multi-threaded Atlas (evident from above) numpy/numpy#8294 , but i don't think we can do much about it at this point.

@davydden davydden added ready and removed WIP labels Nov 21, 2016
@davydden
Copy link
Member Author

@tgamblin @alalazo @adamjstewart ping.

@glennpj
Copy link
Contributor

glennpj commented Nov 29, 2016

This does not work for MKL so the 'ready' label should be removed.

@glennpj
Copy link
Contributor

glennpj commented Nov 29, 2016

Here is a snippet from the build log:

blas_opt_info:
blas_mkl_info:
  libraries mkl_intel_lp64,mkl_core,mkl_gnu_thread,pthread,m,dl not found in ['/home/gjohnson/spack/opt/spack/linux-centos7-x86_64/gcc-4.8.5/mkl-11.3.3.210-gkyo32sq4snk3r3z2qdxkac5lgtnlh7p', '/home/gjohnson/spack/opt/spack/linux-centos7-x86_64/gcc-4.8.5/mkl-11.3.3.210-gkyo32sq4snk3r3z2qdxkac5lgtnlh7p/include', '/home/gjohnson/spack/opt/spack/linux-centos7-x86_64/gcc-4.8.5/mkl-11.3.3.210-gkyo32sq4snk3r3z2qdxkac5lgtnlh7p/lib', '/home/gjohnson/spack/opt/spack/linux-centos7-x86_64/gcc-4.8.5/mkl-11.3.3.210-gkyo32sq4snk3r3z2qdxkac5lgtnlh7p/lib/intel64']
  NOT AVAILABLE

@davydden
Copy link
Member Author

@glennpj

This does not work for MKL so the 'ready' label should be removed.

I fixed the error you reported, but numpy still does not pick up mkl properly. Frankly, i am not intended to fix it within this PR as I believe it is a problem with numpy's config system. It already fails to work properly even with a single Atlas lib, see numpy/numpy#8294. The authors are considering re-implementing the config:

After going through the whole set of site.cfg issues, I'm almost tempted to leave that as is for backwards compat and create a new .cfg config file with sane behavior. There are so many corner cases and people with workarounds for current behavior that it'll be very hard to fix otherwise.

Thereby, the PR will stay with ready attached. You may want to open issue upstream to help debugging the current or (hopefully) upcoming build system with MKL.

@davydden
Copy link
Member Author

@tgamblin @becker33 ping.

@glennpj
Copy link
Contributor

glennpj commented Nov 29, 2016

@davydden If you do not intend to have MKL working with this PR then you should raise an error if ^mkl is in the spec.

@glennpj
Copy link
Contributor

glennpj commented Nov 29, 2016

I have to say that I disagree with the way MKL is being handled in Spack. Building numpy with MKL is possible using the mkl_rt library and this is documented by Intel, see PR #2361. One could make an argument that a lot of config/build systems are broken upstream. I thought one of the tenets of Spack was to work with build systems as they are and have spack provide convenience but not impose structure. The path here will have Spack without an MKL linked numpy/scipy for an indefinite amount of time.

@tgamblin
Copy link
Member

@davydden: I actually agree with @glennpj on this one. If the PR breaks existing support for mkl, I think it's broken. Having numpy work with MKL is important to a lot of users. I haven't looked at the details yet, but is it not possible to get that working?

@tgamblin
Copy link
Member

FWIW, testing get with %intel ^mkl will probably be one if he first combinatorial cases we add to package testing in CI.

@alalazo
Copy link
Member

alalazo commented Nov 29, 2016

@glennpj @tgamblin

I have to say that I disagree with the way MKL is being handled in Spack. Building numpy with MKL is possible using the mkl_rt library and this is documented by Intel, see PR #2361. One could make an argument that a lot of config/build systems are broken upstream. I thought one of the tenets of Spack was to work with build systems as they are and have spack provide convenience but not impose structure.

I think I removed mkl_rt from intel-parallel-studio in #1682 . As far as I understand mkl_rt is just an handle to defer the choice of the ABI + threading-layer at run-time, and it is potentially dangerous in the sense that the actual libraries that you use depend on having specific environment variables set. This just to give an idea why it was removed there in favor of a set of libraries which are consistent with the variants of intel-parallel-studio.

There's one thing that is not clear to me from the discussion above: is using mkl_rt necessary for py-numpy (because it won't link in any other way) or are we just missing the correct way of passing a consistent linking line? In the former case I'll try to think of a way to re-add it in #1875 while I am polishing the PR.

@tgamblin
Copy link
Member

tgamblin commented Nov 29, 2016

@alalazo: thanks!

There's one thing that is not clear to me from the discussion above: is using mkl_rt necessary for py-numpy (because it won't link in any other way) or are we just missing the correct way of passing a consistent linking line?

I actually don't know the answer to this -- @glennpj do you?

@davydden
Copy link
Member Author

@glennpj :

Building numpy with MKL is possible using the mkl_rt library and this is documented by Intel

yes, it is possible, but as @alalazo pointed out

mkl_rt is just an handle to defer the choice of the ABI + threading-layer at run-time, and it is potentially dangerous in the sense that the actual libraries that you use depend on having specific environment variables set.

One could make an argument that a lot of config/build systems are broken upstream.

I don't feel like Spack should give away the security of using one-blas-lapack-everywhere only to make numpy work with MKL. That's the whole point of Spack and graph of packages and conretization.

@tgamblin:

If the PR breaks existing support for mkl

it does not, MKL was not working, and still does not work.

@alalazo:

is using mkl_rt necessary for py-numpy (because it won't link in any other way) or are we just missing the correct way of passing a consistent linking line? In the former case I'll try to think of a way to re-add it in #1875 while I am polishing the PR.

i would not add it to MKL anyhow. I think it is dangerous and should be avoided by all means. The fact that some packages are broken (clearly numpy is an example), does not mean that we need to change default library lists for MKL. One can always hard-code mkl_rt here irrespectfully of what is actually returned as Blas/Lapack from MKL, but it is only needed because numpy is broken upstream. Again, there is nothing wrong in NOT using mkl_rt, and packages should support it.
Keep in mind that numpy does not respect input libs for Atlas either (see numpy/numpy#8294), but it does not mean that we should change the list of Blas/Lapack libraries provided by it.

p.s. either way, i do not plan to do anything with this PR, so feel free to merge it and then someone can take it further with numpy+mkl business.

@alalazo
Copy link
Member

alalazo commented Nov 29, 2016

The fact that some packages are broken (clearly numpy is an example), does not mean that we need to change default library lists for MKL.

I don't mean to change the current default behavior. The changes in #1875 allow to say something like:

mkl_rt = spec['mkl:rt'].libs

and you'll get the mkl_rt library directly from the package that provides it and only if you ask explicitly.

Now: I would do it only if necessary to compile numpy with mkl and I still prefer a change in py-numpy to get this working. But I also think that having a numpy that compiles against mkl is a must at least for v1.0.

@davydden
Copy link
Member Author

Now: I would do it only if necessary to compile numpy with mkl and I still prefer a change in py-numpy to get this working. But I also think that having a numpy that compiles against mkl is a must at least for v1.0.

Sound good to me!

Ps. Just to expand my answer why mkl_rt should be avoided by all means: imagine you build a DAG of packages where (I) one package need 32bit integers in Blas/Lapack (ii) another needs 64 (iii) yet another needs threading (iv) yet another needs serial version. As soon as you use mkl_rt, Spack would happily conferize the whole graph, whereas users of packages may get hard-to-debug segmentation faults. I think one of the key advantage of Spack is that it guarantees that one and only one version of a package is used in DAG (be it complex/real valued, 32/64 bit, threaded or not, etc) and everything is RPATH'ed.

@davydden
Copy link
Member Author

@alalazo : I added mkl_rt here, on a second thought i would say you don't need to do anything in #1875 with it.

@davydden
Copy link
Member Author

@glennpj @tgamblin PR updated with mkl_rt.

'^atlas' in spec):
f.write('libraries=%s\n' % names)
f.write('library_dirs=%s\n' % dirs)

if not ((platform.system() == "Darwin") and
(platform.mac_ver()[0] == '10.12')):
f.write('rpath=%s\n' % ':'.join(lapackblas.directories))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

His the rpath properly taken into account if it is in the section [all/default] when you use openblas, mkl or atlas.
Or should it be placed in all the sections separately ? It was added for #719 so should be easy to check.

If it works fine in the [all/default] section you can also factorize the library_dirs that is the same for all of them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

library_dirs do NOT work in ALL (although it's advertised it should), i checked that. I will check if rpath needs to be in each section separately...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nrichart after looking at #719 AFAICT it works fine because I actually do activate numpy and then do import and run a simple test (see OP). In other words, it works as expected.

@davydden
Copy link
Member Author

davydden commented Dec 7, 2016

@tgamblin @becker33 ping.

@davydden
Copy link
Member Author

@tgamblin @becker33 ping-ping.

@davydden
Copy link
Member Author

@tgamblin @becker33 ping-ping-ping.

@tgamblin
Copy link
Member

tgamblin commented Jan 23, 2017

@davydden: Sorry for the delay -- can you rebase?

including a workaround for MKL due to
limited config system of numpy
@davydden
Copy link
Member Author

@tgamblin i rebased, hopefully the tester will be happy.

@davydden
Copy link
Member Author

@tgamblin the tester is happy with py-numpy, this can be merged unless you have further comments

@tgamblin tgamblin merged commit d324d13 into spack:develop Jan 26, 2017
diaena pushed a commit to diaena/spack that referenced this pull request May 26, 2017
* py-numpy: fix blas/lapack section title

* py-numpy: rework BLAS/LAPACK

including a workaround for MKL due to
limited config system of numpy
@davydden davydden deleted the pkg/py_numpy_default_all branch May 28, 2017 20:55
amklinv pushed a commit that referenced this pull request Jul 17, 2017
* py-numpy: fix blas/lapack section title

* py-numpy: rework BLAS/LAPACK

including a workaround for MKL due to
limited config system of numpy
healther pushed a commit to electronicvisions/spack that referenced this pull request Jul 26, 2017
* py-numpy: fix blas/lapack section title

* py-numpy: rework BLAS/LAPACK

including a workaround for MKL due to
limited config system of numpy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants