# Help with fastmath

**URL:** https://numba.discourse.group/t/help-with-fastmath/401
**Category:** Development
**Created:** [December 17, 2020, 3:31am UTC](https://numba.discourse.group/t/help-with-fastmath/401 "2020-12-17T03:31:55Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![testhound](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/testhound/32/776_2.png) [@testhound](https://numba.discourse.group/u/testhound)
#### Post date: [December 17, 2020, 3:31am UTC](https://numba.discourse.group/t/help-with-fastmath/401/1 "2020-12-17T03:31:56Z")

</div>

I am trying to understand when and where in the code the fastmath option is enabled. I am working on:

> <https://github.com/numba/numba/issues/6183>
>
> (cc @mnicely who I think will have an interest in the resolution of this)
> Compiling the following with nvcc and fast math...

and have a patch that generates the improved sequence ignoring the fastmath option. However when I set the fast math option to True using a decorator and check it using context.fastmath, it is always false. What else do I need to do to correctly check or set fastmath?

---

<div class="post-metadata">

### Author: ![stuartarchibald](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/stuartarchibald/32/10_2.png) [@stuartarchibald](https://numba.discourse.group/u/stuartarchibald)
#### Post date: [December 17, 2020, 8:46pm UTC](https://numba.discourse.group/t/help-with-fastmath/401/2 "2020-12-17T20:46:06Z")

</div>

Hi @testhound,

Thanks for looking at this ticket. I’ve put a patch here:

> <https://github.com/stuartarchibald/numba/commit/ef5cbd59e6cfc56a9581b4f60bea8a64da597d23>

Something like:

```python
from numba.cuda import jit
import numpy as np
import math

@jit(fastmath=True)
def foo(x, out):
    out[0] = math.sin(x)

out_arr = np.empty((1,))
foo[1, 1](3.1415, out_arr)
print(out_arr)

```

will trigger the lowering for unary math implementations on the CUDA target and it should print (in this example):

```auto
Lowering for key <built-in function sin>. Fastmath is True
[9.26535897e-05]

```

Note that on the CPU the fastmath “flag” actually comprises a load of options, which may be something to consider depending on what is involved in addition to wiring in these new transcendental functions. [https://github.com/numba/numba/blob/release0.52/numba/core/cpu\_options.py](https://github.com/numba/numba/blob/release0.52/numba/core/cpu_options.py)

Hope this helps?

---

<div class="post-metadata">

### Author: ![testhound](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/testhound/32/776_2.png) [@testhound](https://numba.discourse.group/u/testhound)
#### Post date: [December 18, 2020, 3:27am UTC](https://numba.discourse.group/t/help-with-fastmath/401/3 "2020-12-18T03:27:10Z")

</div>

Thank you @stuartarchibald , your patch worked perfectly.

---

<div class="post-metadata">

### Author: ![stuartarchibald](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/stuartarchibald/32/10_2.png) [@stuartarchibald](https://numba.discourse.group/u/stuartarchibald)
#### Post date: [December 18, 2020, 9:47am UTC](https://numba.discourse.group/t/help-with-fastmath/401/4 "2020-12-18T09:47:43Z")

</div>

No problem, glad it helped 🙂
