# Buggy code
def compile_device_template(pyfunc, debug=False, inline=False, opt=True):
    """Create a DeviceFunctionTemplate object and register the object to
    the CUDA typing context.
    """
    from .descriptor import CUDATargetDesc

    dft = DeviceFunctionTemplate(pyfunc, debug=debug, inline=inline, opt=opt)

    class device_function_template(AbstractTemplate):
        key = dft

        def generic(self, args, kws):
            assert not kws
            return dft.compile(args).signature

        def get_template_info(cls):
            basepath = os.path.dirname(os.path.dirname(numba.__file__))
            code, firstlineno = inspect.getsourcelines(pyfunc)
            path = inspect.getsourcefile(pyfunc)
            sig = str(utils.pysignature(pyfunc))
            info = {
                "kind": "overload",
                "name": getattr(cls.key, "__name__", "unknown"),
                "sig": sig,
                "filename": utils.safe_relpath(path, start=basepath),
                "lines": (firstlineno, firstlineno + len(code) - 1),
                "docstring": pyfunc.__doc__,
            }
            return info

    typingctx = CUDATargetDesc.typingctx
    typingctx.insert_user_function(dft, device_function_template)
    return dft


# Traceback (numba.cuda.cudadrv.error.NvvmError)
Traceback (most recent call last):
File "repro.py", line 6, in <module>
cuda.compile_ptx_for_current_device(f, [], device=True, debug=True)
File "/home/gmarkall/numbadev/numba/numba/cuda/compiler.py", line 124, in compile_ptx_for_current_device
return compile_ptx(pyfunc, args, debug=-debug, device=device,
File "/home/gmarkall/numbadev/numba/numba/core/compiler_lock.py", line 35, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/gmarkall/numbadev/numba/numba/cuda/compiler.py", line 114, in compile_ptx
ptx = nvvm.llvm_to_ptx(llvmir, opt=opt, arch=arch, **options)
File "/home/gmarkall/numbadev/numba/numba/cuda/cudadrv/nvvm.py", line 669, in llvm_to_ptx
ptx = cu.compile(**opts)
File "/home/gmarkall/numbadev/numba/numba/cuda/cudadrv/nvvm.py", line 265, in compile
self._try_error(err, 'Failed to compile\n')
File "/home/gmarkall/numbadev/numba/numba/cuda/cudadrv/nvvm.py", line 283, in _try_error
self.driver.check_error(err, "%s\n%s" % (msg, self.get_log()))
File "/home/gmarkall/numbadev/numba/numba/cuda/cudadrv/nvvm.py", line 173, in check_error
raise exc
numba.cuda.cudadrv.error.NvvmError: Failed to compile

DBG version 1.0 incompatible with current version 3.0
<unnamed>: error: incompatible IR detected. Possible mix of compiler/IR from different releases.
NVVM_ERROR_IR_VERSION_MISMATCH

# Fixed code
def compile_device_template(pyfunc, debug=False, inline=False, opt=True):
    """Create a DeviceFunctionTemplate object and register the object to
    the CUDA typing context.
    """
    from .descriptor import cuda_target

    dft = DeviceFunctionTemplate(pyfunc, debug=debug, inline=inline, opt=opt)

    class device_function_template(AbstractTemplate):
        key = dft

        def generic(self, args, kws):
            assert not kws
            return dft.compile(args).signature

        def get_template_info(cls):
            basepath = os.path.dirname(os.path.dirname(numba.__file__))
            code, firstlineno = inspect.getsourcelines(pyfunc)
            path = inspect.getsourcefile(pyfunc)
            sig = str(utils.pysignature(pyfunc))
            info = {
                "kind": "overload",
                "name": getattr(cls.key, "__name__", "unknown"),
                "sig": sig,
                "filename": utils.safe_relpath(path, start=basepath),
                "lines": (firstlineno, firstlineno + len(code) - 1),
                "docstring": pyfunc.__doc__,
            }
            return info

    typingctx = cuda_target.typingctx
    typingctx.insert_user_function(dft, device_function_template)
    return dft