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
proposal: math32: add float32 math package #45915
Comments
Why couldn't the compiler generate highly optimized code for specific instances of the generic API? |
Yeah, I fail to see why this isn't viable.
Since these would be "well-known" functions, the compiler could potentially elide any overhead incurred by switching. |
I'm not sure @smasher164 and @bcmills are saying the same thing: @bcmills is perhaps suggesting that you could write the functions themselves generically, and if the compiler was really good, it would generate sufficiently optimized code relative to the current hand-optimized versions, for both 64 and 32 bit? But it looks like a number of functions in the existing @smasher164 is suggesting that you have exported wrapper functions that call the private optimized assembly functions. In the latter case, given that the 32bit versions of all these functions would need to be implemented anyway, an intermediate step would be to create the transitional |
I did not interpret @bcmills's comment that way, mainly because it is nontrivial to write these functions generically. I interpreted it as "assuming you have some generic signature
Yeah I think the real discussion here would be centered around the cost of implementation/maintenance. I've wondered for a while if we'd be able to leverage work done in metalibm to generate these procedures. |
For graphics it was common a while ago to use tables instead of I know less about machine learning but even there my understanding It's just unclear that there is enough widespread benefit for the standard library. There are no compiler intrinsics used for Sin, Cos today. |
This proposal has been added to the active column of the proposals project |
@rsc even basic methods like Min / Max are widely used but seem to benefit from hand-coded assembly in the existing |
Ultimately the only answer for a very broad range of applications is to support third-party packages well. That seems entirely possible here. math32 need not be in the standard library. |
Based on the discussion above, this proposal seems like a likely decline. |
I guess the most compelling counter-argument would be that there are few things more basic and central to any programming environment than standard math functions. It seems unfortunate that such a core aspect of functionality, for one of the two types of floating point numbers, which affords significant performance advantages, would not be supported by the language's standard library. For example, there is an existing math32 library: https://github.com/chewxy/math32 -- it is not frequently updated and a user recently reported significant performance issues. What are the implications of this decision for the idea discussed above for generic wrappers? |
Making the existing math package functions generic would be a breaking change, so we are not considering that. |
No change in consensus, so declined. |
This proposal is to add a separate
math32
library to parallel the existingmath
library.This was discussed very briefly back in 2010: #725 but I wasn't able to find another more recent ticket or discussion.
Currently, there is a significant overhead for using
float32
for cases where optimized computation is important, for example in neural networks or 3D graphics, when callingmath.
functions. These functions are complicated and platform dependent and difficult for a third party to maintain, and require knowledge of different hardware for assembly level implementations to achieve highest performance.Obviously, the cost is significant for the main team in terms of ongoing maintenance and initial implementation, but now that things are otherwise seeming rather stable, aside from generics of course, perhaps there is some headroom to do this?
Also, generics will not be a solution here, as the whole point is to have highly optimized code specifically calling e.g., 32bit MMX functions etc. Perhaps some of the issue was waiting to see how generics turn out, but it seems clear that this will not obviate the need for a custom implementation.
The text was updated successfully, but these errors were encountered: