8000 Move dotblas to multiarray by charris · Pull Request #4969 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Move dotblas to multiarray #4969

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

Closed
wants to merge 27 commits into from

Conversation

charris
Copy link
Member
@charris charris commented Aug 17, 2014

Preliminary PR moving dotblas_matrixmultiply down into multiarray. It is not quite complete as the inner funtion should also be done, along with the new __matmult__ method for Python 3.5. However, this lets me test current functionality and provide an opportunity for review. If it seems reasonable to merge this, I can make new PRs to finish the job.

juliantaylor and others added 4 commits May 22, 2014 19:06
The current system works for MKL and OpenBLAS by default because the
mkl_info and openblas_info classes in numpy/distutils/system_info do not
define the macro 'NO_ATLAS_INFO=1' that currently signals the absence of
CBLAS. This PR declares the presence of CBLAS directly by defining the
'HAVE_CBLAS' macro.
Importing _dotblas currently executes _dotblas.alterdot, which replaces
the default descr->f->dot function with a cblas based version for float,
double, complex float, and complex double data types. This PR changes
the default descr->f->dot to use cblas whenever it is available. After
this change, the alterdot and restoredot functions serve no purpose, so
are changed to do nothing and deprecated. Note that those functions were
already doing nothing when _dotblas was not available.
These are no longer needed. Also do C style cleanups.
@charris
Copy link
Member Author
charris commented Aug 17, 2014

Bento failed, works fine on my machine, but with waf-1.7.16, not 1.7.13.

Move the dotblas_matrixproduct function from the _dotblas.c file to a
new cblasfuncs.c file in multiarray and rename it cblas_matrixproduct.
Modify it so that it can called directly from PyArray_MatrixProduct2 and
do so.  Fix up numeric.py and core/__init__.py to reflect these changes.
Move the dotblas_innerproduct function from the _dotblas.c file to a new
cblasfuncs.c file in multiarray and rename it cblas_innerproduct.
Modify it so that it can called directly from PyArray_InnerProduct and
do so.  Fix up numeric.py and the tests to reflect these changes.
@charris
Copy link
Member Author
charris commented Aug 17, 2014

This should be ready now.

@charris
Copy link
Member Author
charris commented Aug 17, 2014

@pv Could you check the treatment of the ufunc override in the ndarray.dot method? I'm not clear on how that should work. Seems to me that calling a.dot(b) is a bad idea if you want b to override the method.

Now that PyArray_MatrixProduct2 is blas enabled, call it directly.
Remove vdot from
8000
 _dotblas and implement it in multiarray.
Remove the files in core/blasdot as they are no longer needed.
Fix tests and build to reflect the changes.

The vdot function is now a bit faster in the common case as ravel
is used instead of flatten. There is also no need to conjugate the
files for clongdouble.
@charris charris force-pushed the move-dotblas-to-multiarray branch from 88f438b to 63cc74e Compare August 22, 2014 14:47
Also move docstrings into the versions in numpy/core/numeric.py as
the functions are no longer in the defunct _dotblas module.
Not all tests from test_blasdot were relevant, as they checked the cblas
implementations against the non-cblas implementations. Those two are no
longer separate.

Remove test_blasdot.py as there nothing is left in it.
@charris
Copy link
Member Author
charris commented Aug 22, 2014

This PR is getting rather large, so I'd like to get it in and make the '@' operator another PR.

# python threads or processes to one core
import os
envbak = os.environ.copy()
if 'openblas_main_free' not in os.environ:
Copy link
Contributor

Choose a reason for hiding this comment

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

the caps disappeared

@charris charris force-pushed the move-dotblas-to-multiarray branch from 54f00fa to a746e3a Compare August 23, 2014 18:48
I had to move convert_shape_to_string to common.h so that _dotblas.c
can access it.
@juliantaylor
Copy link
Contributor

how do I get numpy to link against system blas now? And how do I check if I have dotblas?
previously it was removing the atlas macro from setup.py and checking if a dotblas.so is built.
Now I don't know anymore how it works and how to check. I guess ldd would work?

@juliantaylor
Copy link
Contributor

hm HAVE_CBLAS is now in the files, that makes using system blas tricky.
I guess we have to add a check for a system cblas to our distutils.

do we still need the blas and blas_opt distinction in our distutils?

@charris
Copy link
Member Author
charris commented Aug 24, 2014

The BLAS detection is done the same way it was before by using get_info('blas_opt', 0). What is different is using a define so that bits of BLAS code can be optionally compiled, whereas before it was the whole _dotblas file. My system shows

In [9]: np.__config__.blas_opt_info
np.__config__.blas_opt_info
Out[9]: 
{'define_macros': [('HAVE_CBLAS', None), ('ATLAS_INFO', '"\\"3.8.4\\""')],
 'include_dirs': ['/usr/include'],
 'language': 'c',
 'libraries': ['ptf77blas', 'ptcblas', 'atlas'],
 'library_dirs': ['/usr/lib64/atlas/']}

@juliantaylor
Copy link
Contributor

filed charris#3 which should make using system blas easier

juliantaylor and others added 2 commits August 24, 2014 20:31
Allows building against system installed blas library that might be
optimized.
BLD: check for CBLAS header in "unoptimized" blas
@charris
Copy link
Member Author
charris commented Aug 24, 2014

@juliantaylor Probably only for backwards compatibility. I resisted the temptation to fool with the thing, but we might want to clean things up at some point.

larsmans and others added 9 commits August 25, 2014 08:18
Renamed not_aligned to dot_alignment_error.

Conflicts:
	numpy/core/src/multiarray/cblasfuncs.c
	numpy/core/src/multiarray/common.h
Better "matrices not aligned" message
On OpenBSD with gcc-4.2 log1p(nan) raises an invalid value warning.
This PR disables both 'divide' and 'invalid' for the log1p tests.

Closes numpy#5017.
…ctions

MAINT: Make numpy/lib/polynomial/polyval a bit faster.
BUG: fix percentage reporting when testing.assert_allclose fails.
TST: Silence some warning that turns up on OpenBSD.
@juliantaylor
Copy link
Contributor

needs rebase, is it ready after that?

juliantaylor and others added 2 commits September 2, 2014 23:40
ENH: optimize STRING_compare by using memcmp
* old-move-dotblas:
  STY: Add spaces around '-'.
  BLD: check for CBLAS header in "unoptimized" blas
  ENH: include shapes in "matrices not aligned" msg
  BUG: Capitalize environmental variables in numpy/core/__init__.py.
  ENH: np.dot: better "matrices not aligned" message
  TST: Add vdot tests, move tests from test_blasdot to test_multiarray.
  DOC: Update docs to reflect deprecation of alterdot and restoredot.
  ENH: Move vdot to multiarray.
  MAINT: Refactor ndarray.dot method to call PyArray_MatrixProduct2.
  ENH: Move dotblas_innerproduct down into multiarray.
  MAINT: Update waf to 1.7.16
  ENH: Move dotblas_matrixproduct down into multiarray.
  MAINT, STY: Remove use of alterdot, restoredot in _dotblas.c.
  ENH: When cblas is available use it in descr->f->dot.
  ENH: Add 'HAVE_CBLAS' macro for build purposes.

Conflicts:
	numpy/core/src/multiarray/arraytypes.c.src
Move the functionality of the numpy/core/dotblas module down into
multiarray. Add 'vdot' to the functions in the multiarray module.  This
avoids the need to overwrite the descr->f->dot functions when CBLAS is
available and paves the way to implement the new '@' operator.
@charris
Copy link
Member Author
charris commented Sep 2, 2014

Rebase didn't work :( So I made a new branch off master and merged it there.

return 1;
}
else if (i < 0) {
return -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

how did this get in here

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like it came from master, I merged the old branch into a new branch off master as the rebase route was not giving the proper result. The only problem with merging the old branch, IIRC, was an include of npy_common.h.

Copy link
Member Author

Choose a reason for hiding this comment

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

If you have a better idea of how to do that, let me know.

Copy link
Contributor

Choose a reason for hiding this comment

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

well it can't be merged like this due to the conflict, I'll have a look if I can rebase it

Copy link
Member Author

Choose a reason for hiding this comment

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

You might need to old branch, which is no longer on github.

Copy link
Member Author

Choose a reason for hiding this comment

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

If I omit the larsmans/dot-errmsg-no-dotblas merge the rebase becomes easy. I think that branch is a bit messed up.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes it contains an unnecessary commit that screws everything up, if you squash merge it should work too

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps I can cherry pick the relevant commits.

Copy link
Contributor

Choose a reason for hiding this comment

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

meh, just reset your branch to mine, the authorship is still in the ocmmit log

Copy link
Member Author

Choose a reason for hiding this comment

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

Just put your branch up, that's fine with me.

@juliantaylor juliantaylor ment 783A ioned this pull request Sep 4, 2014
@charris charris deleted the move-dotblas-to-multiarray branch September 4, 2014 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0