-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Feature request: gramma to enforce type stability proactively #30007
Comments
I just want to leave a reproducible example julia> B_64 = rand(Float64,1000,1000);
julia> A_32 = rand(Float32,1000,1000);
julia> B_32 = rand(Float32,1000,1000);
julia> @btime A_32 * B_32;
8.949 ms (2 allocations: 3.81 MiB)
julia> @btime A_32 * B_64;
836.115 ms (8 allocations: 7.63 MiB) I do not want functions to crash if they are type unstable but it would be nice to have an optional mechanism to force them to crush when type conversions are done inside a function. |
You're mixing two different terminologies here. The non-BLAS multiplication example is still type-stable, but it's hitting a generic fallback. We have an issue for a proactively declared type-stable block — and if I remember right Jeff promised to add this during a JuliaCon talk. #10980 On the other front — the fallback generic algorithms that are correct but slow — is a harder one. |
To be concrete, I will give two more examples where this functionality is needed. 1). see this issue comment When Einsum is type unstable, error is better. 2). In my project, in order to implement high performance quantum circuit simulator, I have to keep every elementals function type stable
However, people can ruin the performance easily with all tests passed. |
Duplicate of #10980. |
There should be gramma/macro in Julia to declare a function as type stable (or no box). Like
stable function(x) = ...
, so that the program can break down/warn immediately when unexpected allocations occur.1). Speed and type stability are defining features of Julia, it should allow enforced type stable functions. I’d like to cite Tim’s comment in his GPU paper
In many cases, I prefer my program to error automatically if some of my functions (e.g. designed to be used inside a loop) are type unstable (or have to use a Box).
2). Julia is a powerful language that can support GPU and TPU programming easily. However, kernel functions on these devices can not allocate memories, meanwhile hard to debug. Half of my debugging experiences are related to type instability. In this case, proactive type stability assurance is extremely important for noticing the bug immediately.
One may argue
@code_warntype
is enough, but it is not true. I think David Buchana gives a perfect example:rand([0,1],10)
vsrand([0.,1.],10)
make the code like 30 times slower due to not calling the BLAS. This kind of debugging is often time consuming: you should first notice your program is running slow, benchmark to verify it is slower than before, and profile to locate where it slows down, then@code_warntype
can be helpful. So@code_warntype
can only help in the final stage.The text was updated successfully, but these errors were encountered: