-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
runtime::Printer has a scratch
field that is ~never used
#6469
Comments
Good catch, yikes! I definitely did not understand this was the behavior. Pinging @slomp to chime in about the one in |
The API is really a bit too clever for its own good |
When I implemented What seems to have happened is that @abadams did some improvements on Halide's |
Yup, malloc'ing on the 64k case is fine (it's on a debug path, just to dump shader code). Everywhere else, stack allocation is preferred, since it's small and scoped (very short lived). |
Right -- and the point is that that only happens currently in those two cases (16 and 256) |
Removing As for the regular (Although, to be honest, I kind of prefer to also have an explicit |
IIRC I had to remove the large stack allocations because it was causing failures to even compile the runtime in some circumstances. |
Instead of trying to optimize every Printer instance to use stack (and failing), move the StackPrinter concept into printer.h directly and require opt-in at the point of compilation to use stack instead of malloc. This PR also does a few other drive-by cleanups: - Ensures that all Printer ctors are explicit - Makes some template aliases to make using (e.g.) ErrorPrinter with a custom buffer size slightly cleaner syntax - Have tracing use the `.str()` method, which already deals with MSAN internally - Make all the Printer data members private - Fix some evil code in opencl.cpp that previously used the now-private data members
Instead of trying to optimize every Printer instance to use stack (and failing), move the StackPrinter concept into printer.h directly and require opt-in at the point of compilation to use stack instead of malloc. This PR also does a few other drive-by cleanups: - Ensures that all Printer ctors are explicit - Makes some template aliases to make using (e.g.) ErrorPrinter with a custom buffer size slightly cleaner syntax - Have tracing use the `.str()` method, which already deals with MSAN internally - Make all the Printer data members private - Fix some evil code in opencl.cpp that previously used the now-private data members
The runtime Printer has a
scratch
field that (presumably) is meant to avoid usingmalloc()
for small print jobs, but in practice, it appears to ~never be used:scratch
is (theoretically) a template parameter, which defaults to 1024scratch
is actually declared aschar scratch[length <= 256 ? length : 1];
, so any length of > 256 becomes just 1 (which in practice means "always use malloc")So basically, there are only two places (in d3d12compute) that are ever using this field.
The whole thing looks wonky to me -- my guess is that length was a straight passthrough in the past, but got limited this way due to stack-size issues on some architecture, and the ramifications never thought thru.
Anyway, this is an ugly wart that should really be resolved somehow, either by removing scratch entirely (since it's rarely used currently), or by deciding that a 1024-byte sized stack scratch is OK after all, or by deciding that 256-byte scratch is adequate for most things, or... something else.
(Note that d3d12compute.cpp has a
StackPrinter
class that attempts to make use of this, but the class is unused and should be removed.)The text was updated successfully, but these errors were encountered: