-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
BENCH: Minor fixes in SciPy benchmarks #745
Conversation
jakirkham
commented
Jan 19, 2016
- Allocate a normal zeroed array instead of a random one.
- Write results into the array.
- Drop unneeded semicolons
- Use environment Python.
- Fix PEP8 issues.
- Use Fortran arrays.
f5599b0
to
75993ff
Compare
C
in advance
I am not the expert in Python. I think the preallocation C is for reducing the overhead in timing BLAS function. |
I am nearly certain that SciPy is still doing this allocation for you. In an event, if C has an array beforehand we are not writing into it here. It will simply be deallocated and a new array will be allocated for the return result. |
@jakirkham , thank you for the answer. |
If we wanted to reuse |
Python variables could be thought of like C pointers with some reference counting attached and possible garbage collection. All Python variables are pointers to Python objects. So, if I assign a new value to a Python variable, it merely points to a new Python object. The old underlying Python object that was pointed to is unaffected by this assignment. |
The only other points I would add are |
However, C gets allocated over and over. The scipy implementation recognizes if the variable is pre-allocated. What should be done is: C = np.zeros([N,N],np.float32) You can check the memory profiling using these small scripts: import numpy as np N = 1000 @Profile @Profile @Profile blas1() print("Mem: {} MB".format(N2*8./10242)) Then use the memory_profiler module to check how it allocates/de-allocates. Hence to get the best timing, one should:
2016-01-19 18:54 GMT+01:00 jakirkham notifications@github.com:
Kind regards Nick |
I am not following by what you mean in terms of reservation vs. allocation here, @zerothi. Can you please clarify? In particular, why would the two functions below be any different?
|
When you do: Hence, if you do:
you will effectively also time the allocation of the variable. Essentially... Take this code:
the memory profiler yields:
However, if you used
Empty has it usages, but I would not use it for benchmarks. |
Interesting, so if I do the following...
Does this result in allocation when printing |
There are corner cases I am not fully sure about. In this case it depends on what It also depends on the allocation routines that is linked in to Python/numpy. |
After some initial issues with
In short, allocation does not occur until the |
78926a8
to
e8cef82
Compare
… randomly generating it.
… randomly generating it.
e8cef82
to
1153459
Compare
Oh, remark that your PR should still do |
@zerothi, do you know why this |
No, I do not know why. You could perhaps create an issue with |
Added ( scipy/scipy#5738 ). Will change. Though I think it would be desirable to benefit from this option. |
…ray of the correct type.
…ray of the correct type.
Turns out |
How does this look? |
Hi, dsyrk is defined as: C := alpha_A'_A + beta*C I use the benchmark scripts to compare the performance against If you don't preallocate and initialize the matrix C, then you will have Best regards On 01/19/2016 06:35 PM, Zhang Xianyi wrote:
|
Ok, so, we are still initializing the array in advance. It is just a bit more cleaned up. Also, we are making sure this array is passed in as BTW, have you seen this ( #730 ), @wernsaar? We are kind of at a loss for why this weird behavior is happening. |
Hi, could you please benchmark sgemm and dgemm with scipy on your platform. Best regards Werner On 01/20/2016 02:53 PM, jakirkham wrote:
|
So, I did, but I don't see similar behavior. It is the second graph in the issue description. Or is there another way that you would like me to benchmark these? |
BENCH: Minor fixes in SciPy benchmarks