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
BLD, ENH: Reading of extra flags from site.cfg to extend flexibility #5597
Conversation
Addition to the distutils module to be able to read in more optional arguments and flags from the site.cfg file. Currently are these additional options read: runtime_library_dirs: It allows users to set the runtime library directories so that LD_LIBRARY_PATH can be ignored. This has the same format as the library_dirs option. extra_compile_args: This allows the user to add specific compiler flags when compiling sources. There will be no formatting/checking of these additional compile flags, the compiler should complain if something is wrong. extra_link_args: This allows the user to add specific linker flags when linking the .so objects. There will be no formatting/checking of these additional compile flags, the linker should complain if something is wrong. When the config is runned it automatically prints out the read in information, thereby allowing the user to see what has been set and what has not. Tested with and without flags to check that it builds correctly.
This looks interesting. As an enhancement, should go into master only though, not 1.9.x Can you please add:
|
You may also want to ping the mailing list about this PR; probably there are a few people interested in testing this. |
Thanks, will do during today. :) 2015-02-24 5:11 GMT+00:00 Ralf Gommers notifications@github.com:
Kind regards Nick |
great. please ping once that's done - Github doesn't send notifications when only adding commits |
ping @rgommers , requests have been added However, the test is difficult to complete due to different architectures etc. For now it simply checks that the flags are read in by the system_info object in distutils. |
A simple test (distutils/testing/test_system_info.py) to check that the options are read in correctly has been added. This test has a few faults: A) It does not allow strict library checks as that can be _very_ system dependent. B) It compiles some simple C-programs but does currently not link them to a shared library. C) As such the test does not check that the flags are actually used. To circumvent this one should: A) Make a library of the compiled sources. B) Check that a runtime_library_dirs is working by checking with ldd C) Make a preprocessor flag to check the output of two commands which should differ according to the flags in each block I am not too much into the distutils compiler suite. So I have not endeavoured on this path. - The current test shows that the flags are read in by the standard system_info object and can thus be considered a "stable" solution. - Added note of the 1.10 release schedule. - Corrected the site.cfg.example, added runtime_library_dirs to the OpenBLAS example where it seems appropriate. - Bugfix for the site.cfg.example (the [DEFAULT] block should be name [ALL]) This might have lead to some confusion, but many of the libraries are linked explicitly by their own sections, hence it might not have been caught.
The test on Travis does not allow getcwd on python 2.6 The test for python 3+ already is in unicode, hence the str representation was wrong.
The error of getcwd on 2.6 was due to previous fault. We should not request include_dirs as they are not provided. For python 3 I forgot the top ascii writing.
@zerothi nice, those tests are quite a bit more extensive than what I expected! It'll take me some time to wrap my head around it, and test on a few other platforms than only 64-bit Linux (which is what TravisCI uses). |
runtime_library_dirs (sets the runtime library directories to override | ||
LD_LIBRARY_PATH) | ||
extra_compile_args (add extra flags to the compilation of sources) | ||
extra_link_args (add extra flags when linking libraries) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting: this should be a reST list, so -
in front of each entry and blank lines above and below the list. and names with underscores should be surrounded by double backticks, otherwise Sphinx interprets those underscores as markup
Changed self.assert* to assert_ instances through numpys own testing utilities. Fixes for the rst document. Removed unnecessary import statements in the test.
For the extra compile flags, it might be useful to add a comment to point out that this does what now goes into |
I still have to go through this with a debugger (the logic in distutils doesn't fit in my head) but can you confirm that |
Overall I think the logic in this patch looks good, and |
I think you are thinking of the pkg reading of settings. Those are two 2015-02-25 10:14 GMT+01:00 Ralf Gommers notifications@github.com:
Kind regards Nick |
More corrections pointed out by Ralf Changed the get_standard_file to a fully temporary file. This means that the __init__ diverges a bit from the system_info object. However, it only has to do with the setup for the test. All internal things regarding the object have not been altered. I have checked on my box that all files/directories are removed.
Direct writing to files is not the same for 2vs3. Hence we now close the file handle, re-open it and write using the file.
Yes and no, it fully depends on how the extensions/compilations are Example (lapack_lite):
If I wanted a generic extension to take advantage of the ALL section in
If you want to compile a file with some flags from site.cfg you need
extra_postargs=all_info['extra_link_args']+all_info['extra_compile_args'])
2015-02-25 10:16 GMT+01:00 Ralf Gommers notifications@github.com:
Kind regards Nick |
@rgommers I have corrected a few things and added Please advice if anything needs added or tested. |
The original distutils assumes runtime_library_dirs to be located in rpath, however, the internal structures assumes the keyword to be runtime_library_dirs. For now numpy.distutils handles both equivalently. The test has been updated to also test the rpath solution.
Changed all lists to strings
This bug-fix only applies for non gnu-compilers. The fortran compilers in numpy inherited the Ccompier class which had the runtime library directories NotImplemented. Hence the compilers need to define their own runtime library path. I have added that information to the intel/pgi/sun compilers. The rest are either already implemented or I do not know them. I have tested the bug-fix with intel compilers of numpy AND the subsequent installation of scipy (which relies on the fortran compilers). Hence this bug will only occur when linking with the fortran compilers.
# Add additional arguments to the compilation of sources. | ||
# Simple variable with no parsing done. | ||
# Provide a single line with all complete flags. | ||
# extra_compile_args = -g -ftree-vectorize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not clear here what the scope of these arguments are, library/runtime/include-dir are all related to binaries, compile args apply to sources. Does it apply to all numpy sources like the OPT env variable) or only part of them?
I don't see a reason this flag should be specific to sections concerning libraries, maybe having one global one is enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My addition only applies to codes/extensions using the get_info
function from numpy.distutils
. So I can't say if it is used for all numpy sources like OPT
. See my comment on lapack_lite
which shows one place where it would be used. So, these compile flags are not used unless get_info
is called on a section containing the above mentioned args.
I have added the extra_compile_args
mainly for completeness sake, I see no disadvantage of having the possibility of adding extra flags when compiling extensions. You may say it is not necessary for libraries, but it allows people to construct sections which can be used to compiling extensions with different flags, say:
[O2]
extra_compile_args = -O2
[O3]
extra_compile_args = -O3
And then compiling can be done using:
config.add_extension('my_package',
sources = ['my_package.c'],
extra_info = get_info('O2')
)
config.add_extension('my_package3',
sources = ['my_package3.c'],
extra_info = get_info('O3')
)
One can of course extend several sections together.
I like to be able to fully control my compilation of source when using Python, with this PR the user can add new sections to their site.cfg
and then control all sources/extensions individually, if needed.
Furthermore using config files, I think, is much more streamlining the build process than having to use env's. This is a matter of taste, but I see no disadvantage in letting users have a choice of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But mainly I would use it for the rpath
options to control the shared libraries. :)
thanks this looks good, especially nice that you went the extra mile and added the tests for this not very well tested area. I'll try to do some testing with the branch soon. |
@juliantaylor @rgommers What is the status of this? |
I am still following this in case you need anything done. 2015-03-22 23:24 GMT+01:00 Charles Harris notifications@github.com:
Kind regards Nick |
Starting to prepare, yes. I was waiting for @juliantaylor, but this seems to be ready. |
Ok, great. :) 2015-04-07 19:14 GMT+02:00 Charles Harris notifications@github.com:
Kind regards Nick |
@juliantaylor I'm about ready to put this in. Do you want to do any testing? |
OK, putting this in. @juliantaylor can more easily test it now ;) Thanks @zerothi . |
BLD, ENH: Reading of extra flags from site.cfg to extend flexibility
BLD: Because it allows greater flexibility of the build phase for numpy, but no changes to how numpy is build has been made
Addition to the distutils module to be able
to read in more optional arguments and flags
from the site.cfg file.
Up till this commit it has really been a pain in the neck to optimize the build for certain flags, etc.
With this any user should be capable of providing their own flags/linker options to control the build
more easily.
This commit can also be merged in the 1.9 maintenance branch.
Especially the runtime_library_dirs can come handy if users rely on LD_LIBRARY_PATH to super seed such env's.
There is still the caveat that hard-coded flags are not overwritten in any way so that providing additional flags has to be compatible with the hard-coded flags for the specific compiler.
Currently these additional options read:
It allows users to set the runtime
library directories so that LD_LIBRARY_PATH can be ignored.
This has the same format as the library_dirs option.
This allows the user to add specific compiler
flags when compiling sources.
There will be no formatting/checking of these additional compile
flags, the compiler should complain if something is wrong.
This allows the user to add specific linker flags
when linking the .so objects.
There will be no formatting/checking of these additional compile
flags, the linker should complain if something is wrong.
When the config is runned it automatically prints out the
read in information, thereby allowing the user to see
what has been set and what has not.
Tested with and without the added options to check that it builds correctly.