In [1]:
import numpy as np
import ngsolve.ngscuda as ncu
CUDA Device Query... There is 1 CUDA device. CUDA Device 0: Quadro RTX 5000, cap 7.5 Using device 0 Initializing cublas and cusparse.
In [2]:
n = 3
v = np.arange(n, dtype=float)
v
Out[2]:
array([0., 1., 2.])
In [3]:
u = ncu.UnifiedVector(v)
print(u)
output unified vector of size 3, host = 1, dev = 0 0 1 2
In [4]:
u.UpdateDevice()
print(u)
output unified vector of size 3, host = 1, dev = 1 0 1 2
In [5]:
w = 2*u
print(w)
<ngsolve.la.DynamicVectorExpression object at 0x7f30683e8370>
In [6]:
we = w.Evaluate()
print(we)
we.UpdateDevice()
print(we)
we.UpdateHost()
print(we)
output unified vector of size 3, host = 0, dev = 0 undefined vector output unified vector of size 3, host = 0, dev = 1 host not up-to-data. printing device data 0 0 0 output unified vector of size 3, host = 1, dev = 1 0 0 0
In [7]:
we = w.Evaluate()
we.UpdateHost()
print(we)
we.UpdateDevice()
print(we)
output unified vector of size 3, host = 1, dev = 0 1.14377e-313 0 0 output unified vector of size 3, host = 1, dev = 1 1.14377e-313 0 0