We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
constant<T>
tiling
1 parent 33245d7 commit 2851957Copy full SHA for 2851957
docs/api.rst
@@ -11,4 +11,5 @@ API Reference
11
api/fast_math.rst
12
api/conditional.rst
13
api/memory_read_write.rst
14
+ api/utilities.rst
15
docs/build_api.py
@@ -27,7 +27,10 @@ def build_doxygen_page(name, items):
27
content += "-" * len(title) + "\n"
28
29
for symbol in symbols:
30
- content += f".. doxygen{directive}:: kernel_float::{symbol}\n\n"
+ if directive == "define":
31
+ content += f".. doxygendefine:: {symbol}\n\n"
32
+ else:
33
+ content += f".. doxygen{directive}:: kernel_float::{symbol}\n\n"
34
35
stripped_name = name.lower().replace(" ", "_").replace("/", "_")
36
filename = f"api/{stripped_name}.rst"
@@ -218,6 +221,11 @@ def build_index_page(groups):
218
221
("storen", "storen(const V&, T*, size_t)"),
219
222
("storen", "storen(const V&, T*, size_t, size_t)"),
220
223
("aligned_ptr", "aligned_ptr", "struct"),
224
+ ],
225
+ "Utilities": [
226
+ ("constant", "constant", "struct"),
227
+ ("tiling", "tiling", "struct"),
228
+ ("KERNEL_FLOAT_TILING_FOR", "KERNEL_FLOAT_TILING_FOR", "define"),
229
]
230
}
231
docs/guides.rst
@@ -6,3 +6,4 @@ Guides
6
guides/introduction.rst
7
guides/promotion.rst
8
guides/prelude.rst
9
+ guides/constant.rst
docs/guides/constant.md
@@ -0,0 +1,38 @@
1
+Using `kernel_float::constant`
2
+===
3
+
4
+When working with mixed precision types, you will find that working with constants presents a bit a challenge.
5
+For example, a simple expression such as `3.14 * x` where `x` is of type `vec<float, 2>` will NOT be performed
+in `float` precision as you might expect, but instead in `double` precision.
+This happens since the left-hand side of this expression
+(a constant) is a `double` and thus `kernel_float` will also cast the right-hand side to `double`.
10
+To solve this problem, `kernel_float` offers a type called `constant<T>` that can be used to represents
+constants. Any binary operations between a value of type `U` and a `constant<T>` will result in both
+operands being cast to type `U` and the operation is performed in the precision of type `U`. This makes
+`constant<T>` useful for representing constant in your code.
16
17
+For example, consider the following code:
18
19
+```
20
+#include "kernel_float.h"
21
+namespace kf = kernel_float;
22
23
+int main() {
24
+ using Type = float;
25
+ const int N = 8;
26
+ static constexpr auto PI = kf::make_constant(3.14);
+ kf::vec<int, N> i = kf::range<int, N>();
+ kf::vec<Type, N> x = kf::cast<Type>(i) * PI;
+ kf::vec<Type, N> y = x * kf::sin(x);
+ Type result = kf::sum(y);
+ printf("result=%f", double(result));
+ return EXIT_SUCCESS;
+}
37
38
+This code example uses the ``make_constant`` utility function to create `constant<T>`.
0 commit comments