-
Notifications
You must be signed in to change notification settings - Fork 272
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
Reduce volume memory usage #168
Conversation
Reduce memory usage when computing variance normalization on volume files.
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.
Were you able to check the memory performance of this relative to the previous version?
I will not have time to mess with this any more, so if you wish to make further adjustments, you can do this after it is merged or we can stick with what we have that uses more memory. This approach minimizes the memory footprint as much as is easily possible regarding the zeros in the NIFTI volume. One clears the full array immediately after using it so as to never have that in memory when doing other steps that may temporarily increase memory usage over the amount needed when the full array is being used (e.g. icaDim). This was tested with both detrending and hp2000, but is anticipated to only be used with detrending given current recommendations. |
The above changes are fine with me. Were they tested with hp=0 and hp=2000 (and now I guess hp=-1)? |
5740f07
to
8ad2ca5
Compare
FYI: The push I just forced just corrects the variable indentation. I was hoping that you could quickly test this with what you already have set up, since I'm not really set up to test under interpreted matlab. Also, still unclear though if you have empirically tested the memory reduction, which I would like to be established before I work with @hodgem to get these changes into the compiled matlab. I wonder if the matlab profiler would make it easy to assess the memory usage... |
…mri file as input
I can run the basic run to completion tests; however, I don't think it is necessary to test the memory reduction (and I don't have a way to do that)--it will be reduced considerably. |
The code runs through the VN function for hp=0 and hp=2000. hp=-1 apparently is not allowed. |
That's good. |
Sticking a |
?? |
"maxresident" refers to memory. In posix mode, it will only report time, so you might need to give it some options in your environment. |
This is interesting (from CHPC):
The
But, then, I'd expect that
I guess that isn't how |
|
Any particular reason |
Esp. considering that |
As I edited my reply to show, |
And here is your answer on the chpc:
From here via /etc/profile:
|
I see that my comment about
I see that you just made the same discovery... |
With my change to |
From the master commit this PR started from, here are the outputs of
Before changing
So, those edits saved a fair amount of memory used by matlab in that function. Strange that it took more time, maybe from the stdev computation? After
So, not really any change to the maximum there. |
My version, with First pass:
Second run had more major pagefaults, so ignore the memory difference between the two. Concatenated:
Some major pagefaults, so expect another 100MB or so...I still have On another note, does |
The numbers tell you if the golden search is behaving sensibly. |
Do you mean if the golden mean search has a bug in it, or do you mean if there isn't anything particularly good for the search to find? If it is only for debugging, then it can be commented out when not debugging. |
If there is something wrong with the data it can floor or ceil, which is bad. |
That sounds like you can just print the end result and the initial endpoints, and that will tell you whether what it found was an initial endpoint. |
So, for my 2-run test, the concatenated highpass is now only barely above the melodic memory usage, and fix_3_clean (fix -f) is now in line with fix -c: melodic:
fix -f (LOTS of major pagefaults, so this number could be wrong, but it mostly matches a much-earlier run of fix -f):
fix -c:
fix -a:
So, my versions appear to peak at only slightly more memory than melodic (which we can't edit easily). Emailing them to Mike for change resolution. |
ICAFIX/scripts/icaDim.m
Outdated
% Apply mask, reusing 'data' variable for memory efficiency | ||
data = data(mask,:); |
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.
Input variables don't count as used memory until they are assigned to, nor does a trivial copy (no indexing expression). I prefer not overwriting variables with modified versions, and in this case and data_detrend, it shouldn't improve memory usage versus my version.
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.
I'll add the usemask
stuff, but I don't see the disadvantage of overwriting variables with a modified version, esp. since it is a misnomer to name the variable data_detrend
since whether it is actually detrended depends on the value of DEMDT
.
… 'std' to compute mask
…d Tim's modifications to not mask if it isn't actually helpful
Ok, see latest commits, that role in Tim's changes. I restored @glasserm: Given that Update: I realized that |
@coalsont: If you could run this version, that would be appreciated! |
For f1b2c5f:
Concatenated VN:
|
Let's get this merged, compiled, and running on the CHPC. |
@glasserm: Do you have scripts in place to quickly test all three |
It runs in all three conditions. |
Fabulous! @coalsont: Anything else you want to change (or are still reviewing), before I request this gets recompiled? |
The excessive amount of text output isn't that important, and is easy enough to comment out when it gets annoying. I'd say go ahead. |
ARGH!!! There is no doubt that we've improved the memory utilization of interpreted matlab. We've been assuming that any such gains there would readily translate to the compiled matlab as well. But, what if that isn't actually the case?!? I just ran a test of the compiled matlab, and the results of I've checked with @hodgem and he is confident that recompiled from the tip of this PR (although to be absolutely 100% sure, it might be worth adding an The results above would be consistent with the hypothesis that in compiled matlab, the |
Ok, another wrinkle. The 2nd pass VN stage just completed from my compiled matlab run, and the results are even more confusing (to me at least) The output of the
i.e., 39 GB, which represents no improvement relative to the version that created the spatial mask using
i.e., |
/usr/bin/time should measure the true memory peak, while other resource tracking may be polling the process, so if the peak was extremely short... I would have expected compiled matlab to be no worse than interpreted, there doesn't seem like any good reason their compiler should be dumber (though maybe the compiler exists for bad reasons in the first place...). |
I agree we should add an echo statement and retry. |
I ran the 2nd pass VN stage two more times using the compiled matlab, just to see if my previously reported result (with the inconsistent reported peak memory: #168 (comment)) was repeatable, and in each case the reported
Of note, in each of these other two instances, the duration of the job on the node was much longer than the earlier test (which took only 33 min), so the longer duration for the latest two test may have given the TORQUE polling process the opportunity to catch the memory peak (consistent with @coalsont's hypothesis). I'll ask @hodgem to do a recompile after I add an |
25f3e1f
to
ca736b1
Compare
I have confirmed that the expected out of the We do still have a small reduction (~10% in compiled matlab mode in the 2nd pass VN stage), and of course the more efficient memory is obviously beneficial for interpreted matlab. So, I suggest we merge this PR and tag a new release ( |
Reduce memory usage when computing variance normalization on volume files.