Cannot Able to access another function in Numba?

I’m trying to run this code.

import numpy as np
import time

from numba import vectorize, cuda,jit

@vectorize(['int64(int64)'],target='cuda')
def fact(n):
    result = 1
 for i in range(n):
    result = result * i

   return result

 @vectorize(['float64(uint64)'], target='cuda')
def exp2(n):
  res = 0.0
  for i in range(0,n):
    res = res + 1/fact(n)
    

return res

But it says
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Untyped global name ‘fact’: cannot determine Numba type of <class ‘numba.cuda.dispatcher.CUDAUFuncDispatcher’>

How do I fix this?

The fact function is being called from exp2 to operate on scalars - so rather than using @vectorize to created it as a ufunc, I’d suggest instead using the cuda.jit decorator instead, like:

@cuda.jit(device=True)
def fact(n):
   ...

Some references that might be helpful in understanding what’s happening:

Writing device functions: https://numba.readthedocs.io/en/stable/cuda/device-functions.html
An example of calling device functions from ufuncs: https://numba.readthedocs.io/en/stable/cuda/ufunc.html#example-calling-device-functions