I'm currently constructing a mathematical model in C++, which will be run/processed on a graphics card. It currently uses a lot of functions from math.h, such as sin, cos, sqrt and pow.
"Avoid using calls to external libraries such as math.h," said my manager, "Because it's expensive on the graphics card. So you can't use sin or cos functions. Sqrt is probably fine, but, if you can, use a polynomial function for the trigonometry."
I have a number of questions arising from this. Sure, you can use Taylor series to work out sin and cos, but...
- Why is sqrt "probably fine" and sin/cos not? (And if sqrt is fine, is pow fine too?)
- EDIT: I likely misunderstood my manager here as meaning 'using sqrt from math.h is fine' when he likely meant 'calculating a square root is fine' using some other method
- How costly is it to access a library from a graphics card, and why is it costly? (I'm assuming it's run time cost and not compile time cost)
- How would implementing my own sin/cos/sqrt/pow functions compare cost-wise to calling from the library, given they're likely to be far less optimised?
Apologies if this question is somewhat vague; alas, both my manager and my team's senior dev are away, so I'm a little short on people to ask. If I've just misunderstood because none of what I thought my manager said makes sense, that's helpful in and of itself. Cheers!
Possibly related: