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

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:

def fact(n):

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

Writing device functions:
An example of calling device functions from ufuncs: