in my project i would run a python program on my Raspberry pi4 using GPU instead CPU. I try to use py-videocore6 or achieve my result, i write this on my example code:
from videocore6.driver import Driver
from videocore6.assembler import qpu
from time import monotonic
from hashlib import sha256
@qpu
def mine(asm, message, difficulty=1):
assert difficulty >= 1
prefix = '1' * difficulty
for i in range(10000000):
digest = sha256(str(hash(message+ str(i))).encode('utf-8'))
if digest.hexdigest().startswith(prefix):
print ("after " + str(i) + " iterations found nonce: "+ digest.hexdigest())
# This synchronization is needed between the last TMU operation and the
# program end with the thread switch just before the loop above.
barrierid(syncb, sig=thrsw)
nop()
nop()
nop(sig=thrsw)
nop(sig=thrsw)
nop()
nop()
nop(sig=thrsw)
nop()
nop()
nop()
def branch_rel_label():
with Driver() as drv:
start = monotonic()
code = drv.program(mine, "test message", 4)
X = drv.alloc((16, ), dtype = 'uint32')
Y = drv.alloc((16,), dtype = 'uint32')
unif = drv.alloc(2, dtype = 'uint32')
X[:] = np.arange(16)
Y[:] = 0.0
unif[0] = X.addresses()[0]
unif[1] = Y.addresses()[0]
drv.execute(code, unif.addresses()[0], thread=8)
end = monotonic()
print("Time elpsed: ", (end-start))
if __name__ == "__main__":
branch_rel_label()
if i test my code it runs but code are executed when i call
drv.program(mine, "test message", 4)
using normal raspberry resources, and not when i call:
drv.execute(code, unif.addresses()[0], thread=8)
using gpu. Why my code is executed at drv.program call and not drv.execute? in this kind of behavior my code execute function in the exactly same time a in normal python shell..how can i use GPU for execute my funcs?
So many thanks in advance