I’m using python’s multiprocessing library to divide the work I want my code to do an array. I have an Nvidia card and have downloaded Cuda, and I want to use the Nvidia graphic card’s cores now instead of my CPU’s. So, I have a basic example of my code pasted below, and I wonder if there is a simple way to execute this code to use the Nvidia GPU’s cores, without necessarily rewriting everything with numba and other cuda functions.
import numpy as np
import time
import multiprocessing
from multiprocessing import Process, freeze_support
import os
import random
var1 = 6
var2 = 6
array = np.zeros((var1, var2))
for i in range(var2):
array[i,0] = 10
start = time.time()
def function(array):
for t in range(var1 - 1):
for i in range(len(array)):
variable = (np.random.poisson( 1, 1))
array[i,t+1] =array[i,t]+ variable
x=0
if variable > 0:
variable = int(sum(variable))
for x in range(variable):
addition = np.zeros(var2)
addition[t+1] = 1
array = np.vstack([array,addition])
print(array)
return(array)
def new_function(array):
p1 = multiprocessing.Process(target = function, args = (array[ 0: int((len(array))/2) ],))
p2 = multiprocessing.Process(target = function, args = (array[ int((len(array))/2): 2 * int((len(array))/2) ],))
p1.start()
p2.start()
p1.join()
p2.join()
if __name__ == "__main__":
freeze_support()
array = (new_function(array))