You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many of the functions in Kernel Float take an additional `Accuracy` option as a template parameter.
5
+
This option can be used to increase the performance of certain operations, at the cost of lower accuracy.
6
+
7
+
There are four possible values for this parameter:
8
+
9
+
*`accurate_policy`: Use the most accurate version of the function available.
10
+
*`fast_policy`: Use the "fast math" version (for example, `__sinf` for sin on CUDA devices). Falls back to `accurate_policy` if such a version is not available.
11
+
*`approx_policy<N>`: Rough approximation using a polynomial of degree `N`. Falls back to `fast_policy` if no such polynomial exists.
12
+
*`default_policy`: Use a global default policy (see the next section).
13
+
14
+
15
+
For example, consider this code:
16
+
17
+
```C++
18
+
19
+
#include"kernel_float.h"
20
+
namespacekf = kernel_float;
21
+
22
+
23
+
int main() {
24
+
kf::vec<float, 2> input = {1.0f, 2.0f};
25
+
26
+
// Use the default policy
27
+
kf::vec<float, 2> A = kf::cos(input);
28
+
29
+
// Use the most accuracy policy
30
+
kf::vec<float, 2> B = kf::cos<kf::accurate_policy>(input);
31
+
32
+
// Use the fastest policy
33
+
kf::vec<float, 2> C = kf::cos<kf::fast_policy>(input);
34
+
35
+
printf("A = %f, %f", A[0], A[1]);
36
+
printf("B = %f, %f", B[0], B[1]);
37
+
printf("C = %f, %f", C[0], C[1]);
38
+
39
+
return EXIT_SUCCESS;
40
+
}
41
+
42
+
```
43
+
44
+
45
+
Setting `default_policy`
46
+
---
47
+
By default, the value for `default_policy` is `accurate_policy`.
48
+
49
+
Set the preprocessor option `KERNEL_FLOAT_FAST_MATH=1` to change the default policy to `fast_policy`.
0 commit comments