Repository: numba/numba

Issue:
Warnings executing numba random number generator example with simulator enabled
Numba version: 0.46.0

Executing the example posted in "http://numba.pydata.org/numba-doc/latest/cuda/random.html#example" with:

```
python random_testing.py
```
Works well, but executing it with CUDA simulator enabled:

```
NUMBA_ENABLE_CUDASIM=1 python random_testing.py
```

I get NumbaDeprecationWarning and RuntimeWarning:
```
/home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py:135: NumbaWarning: 
Compilation is falling back to object mode WITH looplifting enabled because Function "xoroshiro128p_uniform_float32" failed type inference due to: non-precise type pyobject
[1] During: typing of argument at /home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py (145)

File "../../../../../../../../../../../../home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py", line 145:
def xoroshiro128p_uniform_float32(states, index):
    <source elided>
    '''
    index = int64(index)
    ^

  @jit
/home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/object_mode_passes.py:178: NumbaWarning: Function "xoroshiro128p_uniform_float32" was compiled in object mode without forceobj=True.

File "../../../../../../../../../../../../home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py", line 136:
@jit
def xoroshiro128p_uniform_float32(states, index):
^

  state.func_ir.loc))
/home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/object_mode_passes.py:187: NumbaDeprecationWarning: 
Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour.

For more information visit http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit

File "../../../../../../../../../../../../home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py", line 136:
@jit
def xoroshiro128p_uniform_float32(states, index):
^

  warnings.warn(errors.NumbaDeprecationWarning(msg, state.func_ir.loc))
/home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py:71: NumbaWarning: 
Compilation is falling back to object mode WITH looplifting enabled because Function "xoroshiro128p_next" failed type inference due to: non-precise type pyobject
[1] During: typing of argument at /home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py (81)

File "../../../../../../../../../../../../home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py", line 81:
def xoroshiro128p_next(states, index):
    <source elided>
    '''
    index = int64(index)
    ^

  @jit
/home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/object_mode_passes.py:178: NumbaWarning: Function "xoroshiro128p_next" was compiled in object mode without forceobj=True.

File "../../../../../../../../../../../../home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py", line 72:
@jit
def xoroshiro128p_next(states, index):
^

  state.func_ir.loc))
/home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/object_mode_passes.py:187: NumbaDeprecationWarning: 
Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour.

For more information visit http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit

File "../../../../../../../../../../../../home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py", line 72:
@jit
def xoroshiro128p_next(states, index):
^

  warnings.warn(errors.NumbaDeprecationWarning(msg, state.func_ir.loc))
random_testing.py:16: RuntimeWarning: overflow encountered in ulong_scalars
  x = xoroshiro128p_uniform_float32(rng_states, thread_id)
random_testing.py:17: RuntimeWarning: overflow encountered in ulong_scalars
  y = xoroshiro128p_uniform_float32(rng_states, thread_id)
random_testing.py:16: RuntimeWarning: overflow encountered in ulong_scalars
  x = xoroshiro128p_uniform_float32(rng_states, thread_id)
pi: 3.1367188
```


Discussion:
I've reduced iterations to 1000 to get output faster, I suppose that's the reason for the bad value of "pi"
A minimal reproducible script is here:

```python
from numba import cuda
from numba.cuda.random import create_xoroshiro128p_states, xoroshiro128p_uniform_float32
import numpy as np

@cuda.jit
def foo(rng_states, x):
    thread_id = cuda.grid(1)
    x[0] = xoroshiro128p_uniform_float32(rng_states, thread_id)

out = np.zeros(shape=1)
out_d = cuda.to_device(out)

rng_states = create_xoroshiro128p_states(1, seed=1)
foo[1, 1](rng_states, out_d)

print(out_d.copy_to_host())
```

Executing with:

```
python minimal_testing2.py
```

Just outputs:

```
[0.13312314]
```
But executing with CUDA simulator enabled raises pointed warnings:

```
NUMBA_ENABLE_CUDASIM=1 python minimal_testing2.py 
```
Traceback:

```
/home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py:135: NumbaWarning: 
Compilation is falling back to object mode WITH looplifting enabled because Function "xoroshiro128p_uniform_float32" failed type inference due to: non-precise type pyobject
[1] During: typing of argument at /home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py (145)

File "../../../../../../../../../../../../home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py", line 145:
def xoroshiro128p_uniform_float32(states, index):
    <source elided>
    '''
    index = int64(index)
    ^

  @jit
/home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/object_mode_passes.py:178: NumbaWarning: Function "xoroshiro128p_uniform_float32" was compiled in object mode without forceobj=True.

File "../../../../../../../../../../../../home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py", line 136:
@jit
def xoroshiro128p_uniform_float32(states, index):
^

  state.func_ir.loc))
/home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/object_mode_passes.py:187: NumbaDeprecationWarning: 
Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour.

For more information visit http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit

File "../../../../../../../../../../../../home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py", line 136:
@jit
def xoroshiro128p_uniform_float32(states, index):
^

  warnings.warn(errors.NumbaDeprecationWarning(msg, state.func_ir.loc))
/home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py:71: NumbaWarning: 
Compilation is falling back to object mode WITH looplifting enabled because Function "xoroshiro128p_next" failed type inference due to: non-precise type pyobject
[1] During: typing of argument at /home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py (81)

File "../../../../../../../../../../../../home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py", line 81:
def xoroshiro128p_next(states, index):
    <source elided>
    '''
    index = int64(index)
    ^

  @jit
/home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/object_mode_passes.py:178: NumbaWarning: Function "xoroshiro128p_next" was compiled in object mode without forceobj=True.

File "../../../../../../../../../../../../home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py", line 72:
@jit
def xoroshiro128p_next(states, index):
^

  state.func_ir.loc))
/home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/object_mode_passes.py:187: NumbaDeprecationWarning: 
Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour.

For more information visit http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit

File "../../../../../../../../../../../../home/jetxeberria/documents/programs/anaconda/anaconda3/envs/testing3/lib/python3.7/site-packages/numba/cuda/random.py", line 72:
@jit
def xoroshiro128p_next(states, index):
^

  warnings.warn(errors.NumbaDeprecationWarning(msg, state.func_ir.loc))
minimal_testing2.py:8: RuntimeWarning: overflow encountered in ulong_scalars
  x[0] = xoroshiro128p_uniform_float32(rng_states, thread_id)
```

@jetxeberria Thanks for the report. Is the issue here that there are warnings present that you don't expect?
this is a reminder to me to go see why our RNG implementations generate warnings when interpreted
> @jetxeberria Thanks for the report. Is the issue here that there are warnings present that you don't expect?

Yes, I find it weird that an example in documentation raises deprecation warnings. 
I think this happens becase typing of calls to `@jit`-ted functions in kernels fails in the simulator. This will be a problem when the fallback is removed for 0.49: http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit (the document states 0.48, but I think it hasn't been updated since 0.48 became a release of "everything that couldn't fit into 0.47").

A reproducer of the failure to type that doesn't require `numba.cuda.random`:

```python
from numba import cuda, jit
import numpy as np

dt = np.dtype([('s0', np.uint64), ('s1', np.uint64)], align=True)


@jit
def func(rng_states, thread_id):
    return rng_states[thread_id]['s0']


@cuda.jit
def foo(rng_states, x):
    thread_id = cuda.grid(1)
    x[0] = func(rng_states, thread_id)


out = np.zeros(shape=1)
out_d = cuda.to_device(out)

rng_states = np.ones(1, dtype=dt)
foo[1, 1](rng_states, out_d)

print(out_d.copy_to_host())
```

produces:

```
$ NUMBA_ENABLE_CUDASIM=1 python test.py
test.py:7: NumbaWarning: 
Compilation is falling back to object mode WITH looplifting enabled because Function "func" failed type inference due to: Invalid use of Function(<built-in function getitem>) with argument(s) of type(s): (Record(s0[type=uint64;offset=0],s1[type=uint64;offset=8];16;True), int64)
 * parameterized
In definition 0:
    All templates rejected with literals.
In definition 1:
    All templates rejected without literals.
In definition 2:
    All templates rejected with literals.
In definition 3:
    All templates rejected without literals.
In definition 4:
    All templates rejected with literals.
In definition 5:
    All templates rejected without literals.
In definition 6:
    All templates rejected with literals.
In definition 7:
    All templates rejected without literals.
In definition 8:
    All templates rejected with literals.
In definition 9:
    All templates rejected without literals.
In definition 10:
    All templates rejected with literals.
In definition 11:
    All templates rejected without literals.
In definition 12:
    All templates rejected with literals.
In definition 13:
    All templates rejected without literals.
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: typing of intrinsic-call at test.py (9)

File "test.py", line 9:
def func(rng_states, thread_id):
    return rng_states[thread_id]['s0']
    ^

  @jit
/home/nfs/gmarkall/numbadev/numba/numba/object_mode_passes.py:178: NumbaWarning: Function "func" was compiled in object mode without forceobj=True.

File "test.py", line 8:
@jit
def func(rng_states, thread_id):
^

  state.func_ir.loc))
/home/nfs/gmarkall/numbadev/numba/numba/object_mode_passes.py:188: NumbaDeprecationWarning: 
Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour.

For more information visit http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit

File "test.py", line 8:
@jit
def func(rng_states, thread_id):
^

  state.func_ir.loc))
[1.]
```

I'm looking into a fix for this.
Some potential solutions (with no predilection as to the correct one at the moment):

- Recommend using `NUMBA_DISABLE_JIT` along with `NUMBA_ENABLE_CUDASIM`. A simple solution, but code using a mix of CPU and GPU JIT will go much slower on the CPU just to enable debugging on the GPU.
- Make `NUMBA_ENABLE_CUDASIM` also disable CPU JIT automatically - simpler than suggesting users use two flags, but provides less control.
- Make changing `config.DISABLE_JIT` have an effect at call time (rather than at decoration time), and then during kernel launch (i.e. in the `swapped_cuda_module` context from `numba.cuda.simulator.kernelapi`) set `DISABLE_JIT` to `True`, then set it back when the kernel finishes. Simple for the user and would "just work", but adds the overhead of checking `DISABLE_JIT` for every jitted function call. (I have not measured this overhead but I would be a bit surprised if it were noticeable in the context of any sensible application).
- State that calling normal `@jit` functions from kernels in the simulator is not supported (only `@cuda.jit(device=True)` functions), and refactor the `numba.cuda.random` module to accommodate this. Simple, but slightly limiting for the user.
I'm just catching up with things, but I see these deprecation warnings are now happening in the CUDA test suite with the hardware (not simulator) target on master:

```
$ python -m numba.runtests numba.cuda.tests
..................................active blocks: 16
grid size: 1280 , block size: 128
............................................................................................................s....................s............................................................................/home/nfs/gmarkall/numbadev/numba/numba/cuda/decorators.py:115: UserWarning: autojit is deprecated and will be removed in a future release. Use jit instead.
  warn('autojit is deprecated and will be removed in a future release. Use jit instead.')
...............................s.............................<CUDA device 0 'b'Tesla V100-SXM2-16GB''>
<CUDA device 1 'b'Tesla V100-SXM2-16GB''>
.........................................can_access_peer <CUDA context c_void_p(94226617368944) of device 0> True
can_access_peer <CUDA context c_void_p(94385563467600) of device 1> True
.s......................./home/nfs/gmarkall/numbadev/numba/numba/cuda/random.py:214: NumbaWarning: 
Compilation is falling back to object mode WITH looplifting enabled because Function "init_xoroshiro128p_states_cpu" failed type inference due to: Invalid use of type(CPUDispatcher(<function xoroshiro128p_jump at 0x7f69ca2dedd0>)) with parameters (array(Record(s0[type=uint64;offset=0],s1[type=uint64;offset=8];16;True), 1d, C), Literal[int](0))
 * parameterized
[1] During: resolving callee type: type(CPUDispatcher(<function xoroshiro128p_jump at 0x7f69ca2dedd0>))
[2] During: typing of call at /home/nfs/gmarkall/numbadev/numba/numba/cuda/random.py (225)


File "numba/cuda/random.py", line 225:
def init_xoroshiro128p_states_cpu(states, seed, subsequence_start):
    <source elided>
        for _ in range(subsequence_start):
            xoroshiro128p_jump(states, 0)
            ^

  @jit
/home/nfs/gmarkall/numbadev/numba/numba/cuda/random.py:214: NumbaWarning: 
Compilation is falling back to object mode WITHOUT looplifting enabled because Function "init_xoroshiro128p_states_cpu" failed type inference due to: cannot determine Numba type of <class 'numba.core.dispatcher.LiftedLoop'>

File "numba/cuda/random.py", line 224:
def init_xoroshiro128p_states_cpu(states, seed, subsequence_start):
    <source elided>
        # advance to starting subsequence number
        for _ in range(subsequence_start):
        ^

  @jit
/home/nfs/gmarkall/numbadev/numba/numba/core/object_mode_passes.py:177: NumbaWarning: Function "init_xoroshiro128p_states_cpu" was compiled in object mode without forceobj=True, but has lifted loops.

File "numba/cuda/random.py", line 216:
def init_xoroshiro128p_states_cpu(states, seed, subsequence_start):
    n = states.shape[0]
    ^

  state.func_ir.loc))
/home/nfs/gmarkall/numbadev/numba/numba/core/object_mode_passes.py:187: NumbaDeprecationWarning: 
Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour.

For more information visit http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit

File "numba/cuda/random.py", line 216:
def init_xoroshiro128p_states_cpu(states, seed, subsequence_start):
    n = states.shape[0]
    ^

  state.func_ir.loc))
/home/nfs/gmarkall/numbadev/numba/numba/cuda/random.py:214: NumbaWarning: 
Compilation is falling back to object mode WITHOUT looplifting enabled because Function "init_xoroshiro128p_states_cpu" failed type inference due to: Invalid use of type(CPUDispatcher(<function xoroshiro128p_jump at 0x7f69ca2dedd0>)) with parameters (array(Record(s0[type=uint64;offset=0],s1[type=uint64;offset=8];16;True), 1d, C), Literal[int](0))
 * parameterized
[1] During: resolving callee type: type(CPUDispatcher(<function xoroshiro128p_jump at 0x7f69ca2dedd0>))
[2] During: typing of call at /home/nfs/gmarkall/numbadev/numba/numba/cuda/random.py (225)


File "numba/cuda/random.py", line 225:
def init_xoroshiro128p_states_cpu(states, seed, subsequence_start):
    <source elided>
        for _ in range(subsequence_start):
            xoroshiro128p_jump(states, 0)
            ^

  @jit
/home/nfs/gmarkall/numbadev/numba/numba/core/object_mode_passes.py:177: NumbaWarning: Function "init_xoroshiro128p_states_cpu" was compiled in object mode without forceobj=True.

File "numba/cuda/random.py", line 224:
def init_xoroshiro128p_states_cpu(states, seed, subsequence_start):
    <source elided>
        # advance to starting subsequence number
        for _ in range(subsequence_start):
        ^

  state.func_ir.loc))
/home/nfs/gmarkall/numbadev/numba/numba/core/object_mode_passes.py:187: NumbaDeprecationWarning: 
Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour.

For more information visit http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit

File "numba/cuda/random.py", line 224:
def init_xoroshiro128p_states_cpu(states, seed, subsequence_start):
    <source elided>
        # advance to starting subsequence number
        for _ in range(subsequence_start):
        ^

  state.func_ir.loc))
/home/nfs/gmarkall/numbadev/numba/numba/cuda/random.py:214: NumbaWarning: 
Compilation is falling back to object mode WITHOUT looplifting enabled because Function "init_xoroshiro128p_states_cpu" failed type inference due to: Invalid use of type(CPUDispatcher(<function xoroshiro128p_jump at 0x7f69ca2dedd0>)) with parameters (array(Record(s0[type=uint64;offset=0],s1[type=uint64;offset=8];16;True), 1d, C), int64)
 * parameterized
[1] During: resolving callee type: type(CPUDispatcher(<function xoroshiro128p_jump at 0x7f69ca2dedd0>))
[2] During: typing of call at /home/nfs/gmarkall/numbadev/numba/numba/cuda/random.py (230)


File "numba/cuda/random.py", line 230:
def init_xoroshiro128p_states_cpu(states, seed, subsequence_start):
    <source elided>
            states[i] = states[i - 1]  # take state of previous generator
            xoroshiro128p_jump(states, i)  # and jump forward 2**64 steps
            ^

  @jit
/home/nfs/gmarkall/numbadev/numba/numba/core/object_mode_passes.py:177: NumbaWarning: Function "init_xoroshiro128p_states_cpu" was compiled in object mode without forceobj=True.

File "numba/cuda/random.py", line 228:
def init_xoroshiro128p_states_cpu(states, seed, subsequence_start):
    <source elided>
        # populate the rest of the array
        for i in range(1, n):
        ^

  state.func_ir.loc))
/home/nfs/gmarkall/numbadev/numba/numba/core/object_mode_passes.py:187: NumbaDeprecationWarning: 
Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour.

For more information visit http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit

File "numba/cuda/random.py", line 228:
def init_xoroshiro128p_states_cpu(states, seed, subsequence_start):
    <source elided>
        # populate the rest of the array
        for i in range(1, n):
        ^

  state.func_ir.loc))
/home/nfs/gmarkall/numbadev/numba/numba/cuda/random.py:95: NumbaWarning: 
Compilation is falling back to object mode WITHOUT looplifting enabled because Function "xoroshiro128p_jump" failed type inference due to: <class 'numpy.uint64'> cannot be used as a literal
  @jit
/home/nfs/gmarkall/numbadev/numba/numba/core/object_mode_passes.py:177: NumbaWarning: Function "xoroshiro128p_jump" was compiled in object mode without forceobj=True.

File "numba/cuda/random.py", line 109:
def xoroshiro128p_jump(states, index):
    <source elided>

    for i in range(2):
    ^

  state.func_ir.loc))
/home/nfs/gmarkall/numbadev/numba/numba/core/object_mode_passes.py:187: NumbaDeprecationWarning: 
Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour.

For more information visit http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit

File "numba/cuda/random.py", line 109:
def xoroshiro128p_jump(states, index):
    <source elided>

    for i in range(2):
    ^

  state.func_ir.loc))
.........................................s......................./home/nfs/gmarkall/numbadev/numba/numba/cuda/decorators.py:115: UserWarning: autojit is deprecated and will be removed in a future release. Use jit instead.
  warn('autojit is deprecated and will be removed in a future release. Use jit instead.')
...................................................................................................................................
----------------------------------------------------------------------
Ran 563 tests in 141.009s

```
Reopening this because it is only half-fixed - the warnings no longer appear for the hardware target, but still appear with the simulator.

IIRC (from investigating recently) the warnings occur with the simulator because some jitted functions are called from within CUDA kernels, that use `FakeWithinKernelCUDAArray` instances, which cause a failure to type for nopython mode.

Resolving patch:
diff --git a/numba/cuda/random.py b/numba/cuda/random.py
--- a/numba/cuda/random.py
+++ b/numba/cuda/random.py
@@ -1,7 +1,7 @@
 import math
 
-from numba import (cuda, float32, float64, uint32, int64, uint64, from_dtype,
-                   jit)
+from numba import (config, cuda, float32, float64, uint32, int64, uint64,
+                   from_dtype, jit)
 
 import numpy as np
 
@@ -33,8 +33,16 @@
                                align=True)
 xoroshiro128p_type = from_dtype(xoroshiro128p_dtype)
 
+# When cudasim is enabled, Fake CUDA arrays are passed to some of the
+# @jit-decorated functions. This causes a fallback to object mode and the
+# emission of a warning at present - this is visible in the test suite with
+# cudasim, but also fallback-by-default will not be permitted in future. In
+# order to avoid the warning / future error, we explicitly specify that
+# object mode with loop lifting is acceptable when using the simulator.
+_forceobj = _looplift = config.ENABLE_CUDASIM
 
-@jit
+
+@jit(forceobj=_forceobj, looplift=_looplift)
 def init_xoroshiro128p_state(states, index, seed):
     '''Use SplitMix64 to generate an xoroshiro128p state from 64-bit seed.
 
@@ -60,7 +68,7 @@ def init_xoroshiro128p_state(states, index, seed):
     states[index]['s1'] = z
 
 
-@jit
+@jit(forceobj=_forceobj, looplift=_looplift)
 def rotl(x, k):
     '''Left rotate x by k bits.'''
     x = uint64(x)
@@ -68,7 +76,7 @@ def rotl(x, k):
     return (x << k) | (x >> uint32(64 - k))
 
 
-@jit
+@jit(forceobj=_forceobj, looplift=_looplift)
 def xoroshiro128p_next(states, index):
     '''Return the next random uint64 and advance the RNG in states[index].
 
@@ -90,7 +98,7 @@ def xoroshiro128p_next(states, index):
     return result
 
 
-@jit
+@jit(forceobj=_forceobj, looplift=_looplift)
 def xoroshiro128p_jump(states, index):
     '''Advance the RNG in ``states[index]`` by 2**64 steps.
 
@@ -117,21 +125,21 @@ def xoroshiro128p_jump(states, index):
     states[index]['s1'] = s1
 
 
-@jit
+@jit(forceobj=_forceobj, looplift=_looplift)
 def uint64_to_unit_float64(x):
     '''Convert uint64 to float64 value in the range [0.0, 1.0)'''
     x = uint64(x)
     return (x >> uint32(11)) * (float64(1) / (uint64(1) << uint32(53)))
 
 
-@jit
+@jit(forceobj=_forceobj, looplift=_looplift)
 def uint64_to_unit_float32(x):
     '''Convert uint64 to float32 value in the range [0.0, 1.0)'''
     x = uint64(x)
     return float32(uint64_to_unit_float64(x))
 
 
-@jit
+@jit(forceobj=_forceobj, looplift=_looplift)
 def xoroshiro128p_uniform_float32(states, index):
     '''Return a float32 in range [0.0, 1.0) and advance ``states[index]``.
 
@@ -145,7 +153,7 @@ def xoroshiro128p_uniform_float32(states, index):
     return uint64_to_unit_float32(xoroshiro128p_next(states, index))
 
 
-@jit
+@jit(forceobj=_forceobj, looplift=_looplift)
 def xoroshiro128p_uniform_float64(states, index):
     '''Return a float64 in range [0.0, 1.0) and advance ``states[index]``.
 
@@ -163,7 +171,7 @@ def xoroshiro128p_uniform_float64(states, index):
 TWO_PI_FLOAT64 = np.float64(2 * math.pi)
 
 
-@jit
+@jit(forceobj=_forceobj, looplift=_looplift)
 def xoroshiro128p_normal_float32(states, index):
     '''Return a normally distributed float32 and advance ``states[index]``.
 
@@ -188,7 +196,7 @@ def xoroshiro128p_normal_float32(states, index):
     return z0
 
 
-@jit
+@jit(forceobj=_forceobj, looplift=_looplift)
 def xoroshiro128p_normal_float64(states, index):
     '''Return a normally distributed float32 and advance ``states[index]``.
 
@@ -213,7 +221,7 @@ def xoroshiro128p_normal_float64(states, index):
     return z0
 
 
-@jit
+@jit(forceobj=_forceobj, looplift=_looplift)
 def init_xoroshiro128p_states_cpu(states, seed, subsequence_start):
     n = states.shape[0]
     seed = uint64(seed)


Test patch: