Repository navigation
Conversation
lkdvos
left a comment
There was a problem hiding this comment.
To give some information about the decision process of what I did in MPSKit:
The idea was that since allocators have state and it is important to not make them long-lived (don't accidentally hold on to the large buffers), nor incorrectly multithread with them (these are absolutely not thread-safe), I basically decided to not really expose that as part of the algorithms, to avoid mis-use. The claim being that there really isn't a good reason to not use the BufferAllocator, and you should be protected from memory corruption etc. In other words, this is not something you can configure in MPSKit.
As a result, within the body of the toplevel/outward-facing functions I simply create the bufferallocators, and then pass that down to all internal functions. In that sense it doesn't really matter all that much if it is keyword or regular argument, and decided this based on what "looked most natural" given the other arguments/keywords.
I agree that in principle you could reuse buffers between different runs of an algorithm, but this is ultimately just the cost of allocating/deallocating a small amount of large vectors, and I don't think we are at the point where that overhead really is dominant.
I do actually still think this might be the correct initial approach, it is not too hard to change afterwards and already gets the benefits, so I'd recommend/suggest following a similar approach here. As far as I can tell, this is exactly what you did, so honestly looks like a great PR to me.
Any chance we can get some benchmarks on this? I'd love to see also how much the CPU version improves from this, and how much of the allocations are still left. Otherwise for me this is good to go, of course with the caveat that we release the TensorOperations version
|
Let me first make sure CI passes 😅 but then yes benchmarks for sure! I think we should allow the scheduler to be settable though, rather than hardcoded. |
8144b60 to
8797cef
Compare
For AMD it might still be because they have no warm pool there, but we can benchmark that |
|
Doing some benchmarking now. This needs QuantumKitHub/TensorKit.jl#608 (or something like it) and a TK release, as well as the TO release (which is not yet tagged) |
|
One annoying complication I hit was that there's a huge slowdown on consumer cards like the 5090 I'm testing on for double precision. This won't be a problem on real HPC hardware but it is annoying. I'll try to get some fp32 benchmarks so we can get a rough idea. |
541557d to
de436ef
Compare
de436ef to
27992a2
Compare
| @@ -131,24 +131,24 @@ function renormalize_simultaneously(enlarged_corners, projectors, network, env) | |||
| dtmap!!(corners_edges′, coordinates) do (dir, r, c) | |||
There was a problem hiding this comment.
looking at this, it might make sense to create some new primitive for threaded maps with allocators, since this is quite easy to accidentally pass a wrong allocator that would break. It's also not that simple to assert the allocator is correct so I'd be slightly more comfortable if we could end up fixing that in one spot. I'm not claiming this has to be in this PR though, opening an issue might actually already suffice
09d0419 to
ff417d8
Compare
|
Some benchmarking info: this + using |
6292e53 to
53408c5
Compare
|
Since CTMRG gauge fixing will also get allocator support, do we want to merge this after or before #320 which does a big refactor of gauge fixing? |
|
My personal preference is to merge this ASAP as for the CUDA runs, it cuts memory usage by like 2/3rds. Would that be too much of a hurdle for your PR? Fine with me if #320 wins out in the end. |
|
@kshyatt I'm ok to follow up immediately; it might be better to first resolve issues on allocators and parallel threads here. |
It also cuts memory usage by 2/3rds :D |
|
How's the saving on CPU? |
0cd5985 to
b6b2788
Compare
|
CPU memory: Default vs Buffer vs Manual (one Julia thread, sequential CTMRG)
here's what I've got so far |
|
And the SU(2) data:
Looks p good! |
| allocator owned by a single task (e.g. a buffer), any other scheduler gets an allocator | ||
| that can be shared between tasks; see `MPSKit.default_allocator`. | ||
| """ | ||
| scheduler_allocator(x) = default_allocator(x, Defaults.scheduler[]) |
There was a problem hiding this comment.
This probably works indeed, although it is still slightly uncomfortable to me that we select the allocator so far up the call stack while using the scheduler much more down. Also, I think this means that in many cases we will just be using the manual allocator, which is a bit cheating in the benchmarks because that just hides the allocations and calls malloc manually. Ultimately, this requires a buffer pool or something similar to really fix, but that probably shouldn't be holding up this PR
9cdc3d5 to
38b066a
Compare
|
@leburgel I think the GPU fails are going to be fixed by QuantumKitHub/TensorKit.jl#637. What do you think about me adding that to |
|
Sure, sounds good to me. |
|
Sorry that stuff keeps breaking. It's apparently harder to keep multiple PRs in sync than to prove GRH... |
Co-authored-by: Lander Burgelman <39218680+leburgel@users.noreply.github.com>
e746bcd to
943ea40
Compare
Needs the TensorOperations branch merged and tagged first, also happy if people want this allocator to be a kwarg. I think the scheduler should also possibly be a kwarg at least at top level? Anyway starting CI just to see how much works.