-
Notifications
You must be signed in to change notification settings - Fork 8
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
Memory allocated in vectorized operations #135
Comments
When reverting to ACSets 0.2.17 I'm getting very similar results so this seems to have a separate cause from that in issue #121. |
I have a feeling that this is again due to problems in constant propagation, specifically in the function here: ACSets.jl/src/ACSetInterface.jl Lines 264 to 268 in d6e41b1
I think the issue here is the broadcast and I've written up a small script showcasing it. using ACSets
SchTest = BasicSchema([:V,:E], [(:v0,:E,:V)])
@acset_type Test(SchTest, index=[:v0])
s = Test()
N = 100
add_parts!(s, :V, N)
idx = add_parts!(s, :E, N)
entry = ones(Int64, N);
function add_broadcast(s, idx, entry, symbol)
broadcast(idx, entry) do i, id
set_subpart!(s, i, symbol, id)
end
end
function add_broadcast(s, idx, entry)
broadcast(idx, entry) do i, id
set_subpart!(s, i, :v0, id)
end
end
begin
add_broadcast(s, idx, entry);
add_broadcast(s, idx, entry, :v0);
end;
@info "Using add_broadcast known symbol"
@time add_broadcast(s, idx, entry);
@info "Using add_broadcast passed symbol"
@time add_broadcast(s, idx, entry, :v0); Here are results. Both seem to scale with the number of parts to be added but the broadcast with the known symbol performs much better. [ Info: Using add_broadcast known symbol
0.000010 seconds (1 allocation: 144 bytes)
[ Info: Using add_broadcast passed symbol
0.000030 seconds (18 allocations: 1.188 KiB) |
Adding onto my previous comment it seems turning the symbol pass into a function add_broadcast(s, idx, entry, ::Val{symbol}) where symbol
broadcast(idx, entry) do i, id
set_subpart!(s, i, symbol, id)
end
end
begin
add_broadcast(s, idx, entry, Val(:v0));
end;
@info "Using add_broadcast passed val(symbol)"
@time add_broadcast(s, idx, entry, Val(:v0)); Results: [ Info: Using add_broadcast passed val(symbol)
0.000008 seconds (1 allocation: 144 bytes) |
I ran code warn type on this and the problem seems to be that the symbol is not getting constant propped and so the return type of set_parts can't be inferred. It would be great if there is another inlining based fix like for the single index case that was just fixed. When you pass in Val{s} where s <:Symbol there are no warnings type problems. Maybe we should just switch to telling users to call their functions with Val(:f) instead of :f |
I'm assuming this issue was adequately resolved by #136. Please reopen if not. |
Re-opening since issue still exists. |
To be clear, I assume that a fix means zero allocations. |
Yeah that's right. |
This is an extension of issue #121. While individual accesses and sets have been fixed, vectorized operations are still allocating significantly more than they should. Here's a MWE:
As well as the results:
The text was updated successfully, but these errors were encountered: