Code: Alles auswählen
import numpy as np
from numba import vectorize
@vectorize(['float32(float32, float32)'], target='cuda')
def Add(a, b):
return a + b
# Initialize arrays
N = 100000
A = np.ones(N, dtype=np.float32)
B = np.ones(A.shape, dtype=A.dtype)
C = np.empty_like(A, dtype=A.dtype)
# Add arrays on GPU
C = Add(A, B)
Code: Alles auswählen
cc = np.empty_like(A, dtype=A.dtype)
cc = A + cc
Ich habe auch schon mit ein paar Schleifen aufwendigere Berechnungen ausgeführt. Und dabei war Numba mit der GPU immer erheblich langsamer.
Ist das einfach nur ein schlechtes Beispiel wo GPU Berechnung sich nicht lohnt oder wieso ist Numba mit GPU langsamer?
Als Grafikkarte habe ich eine GTX 1070 mit 8GB Grafikspeicher. Und als CPU ein Intel i7-6700K 4.00GHz.