Skip to content

Conversation

@cortner
Copy link

@cortner cortner commented Mar 31, 2025

This integrates WithAlloc.jl as discussed in #40 .

@cortner
Copy link
Author

cortner commented Mar 31, 2025

My only concern right now is this block

@inline function _bumper_alloc(allocinfo::Tuple{<: Type, Vararg{Int, N}}) where {N}
   Bumper.alloc!(Bumper.default_buffer(), allocinfo...)
end

I haven't given any thought yet how to allow the use of general buffers, since I never used this myself.

@MasonProtter
Copy link
Owner

Hi @cortner, I think this got buried in my notifications and I missed it, sorry about that.

Yeah, that _bumper_alloc function will need to be modified to take the current active buffer, otherwise using the withalloc stuff would be incorrect anytime the @no_escape block uses a different buffer.

I think what's needed here would be for the @withalloc macro to be integrated into the @no_escape macro, so that the buffer used by @no_escape can be passed directly to the withalloc call, like is done on this section:

if ex.args[1] == Symbol("@alloc")
# replace calls to @alloc(T, size...) with alloc(T, buf, size...) where buf
# is the current buffer in use.
Expr(:block,
:($tsk === $get_task() || $tsk_err()),
Expr(:call, alloc!, b, recursive_handler.(ex.args[3:end])...))

Basically, Bumper.@alloc isn't a real macro, it's actually just a stub, and the @no_escape macro is the one that looks for uses of @alloc, and transforms that into alloc calls on a buffer.

@cortner
Copy link
Author

cortner commented Apr 26, 2025

thanks for the explanation. I'll try and get back to this over the next few days, but it might take longer.

@cortner
Copy link
Author

cortner commented Jun 12, 2025

Apologies for the delay, I will try to get back to it, but it takes some time for me to understand the internals well enough to rewrite this correctly.

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.

2 participants