私はこの問題の回避策を見つけました。私はそれを働かせることができる唯一の方法です。 @jit
と@cuda.jit
の代わりに@myjit
デコレータを使用し、すべての配列をcuda.local.array
として割り当てます。
def myjit(f):
'''
f : function
Decorator to assign the right jit for different targets
In case of non-cuda targets, all instances of `cuda.local.array`
are replaced by `np.empty`. This is a dirty fix, hopefully in the
near future numba will support numpy array allocation and this will
not be necessary anymore
'''
if target == 'cuda':
return cuda.jit(f, device=True)
else:
source = inspect.getsource(f).splitlines()
assert '@myjit' in source[0]
source = '\n'.join(source[1:]) + '\n'
source = source.replace('cuda.local.array', 'np.empty')
exec(source)
fun = eval(f.__name__)
newfun = jit(fun, nopython=True)
# needs to be exported to globals
globals()[f.__name__] = newfun
return newfun
あなたの関数の型をテストできませんでしたか? – 0TTT0
問題は、numbaはコードとフリークアウトをコンパイルするので、私の関数内には何の記述もできません。それ以外の場合、私は単純なif/elseまたはそのようなことをします。 それを扱う自然な方法は、Cのプリプロセッサディレクティブですが、Pythonで利用可能なものはありません –