def to_gpu_array(arr): mat = arr.to_gpu_array() dev = device_of_devicendarray(mat) # Return canonical device id as string return mat, dev
def as_gpu_matrix(arr): blap = arr.compute() mat = blap.as_gpu_matrix(order="F") dev = device_of_devicendarray(mat) # Return canonical device id as string return mat, dev
def input_to_device_arrays(X, params): """ Create output arrays and return them w/ the input array(s) :param arr: A tuple in the form of (X, y) :return: """ if len(X[0]) == 0: return None start_idx = X[0].index[0] stop_idx = X[0].index[-1] X_mat = numba_utils.row_matrix(X[0]) dev = device_of_devicendarray(X_mat) shape = X_mat.shape[0] * params["k"] # Create output numba arrays. I_ndarr = numba.cuda.to_device(np.zeros(shape, dtype=np.int64, order="C")) D_ndarr = numba.cuda.to_device(np.zeros(shape, dtype=np.float32, order="C")) # Return canonical device id as string return [(X_mat, I_ndarr, D_ndarr)], dev, (start_idx, stop_idx)
def fit_to_device_arrays(arr): """ :param arr: A tuple in the form of (X, y, coef) :return: """ mats = [(X.compute().as_gpu_matrix(order='F'), y.to_gpu_array(), coef) for X, y, coef in arr] dev = device_of_devicendarray(mats[0][0]) # Return canonical device id as string return mats, dev
def to_gpu_matrix(df): """ Turn input cudf into a Numba array. Returns device of current worker and the start/stop indexes of the cudf. :param df: :return: """ try: start_idx = df.index[0] stop_idx = df.index[-1] gpu_matrix = numba_utils.row_matrix(df) dev = device_of_devicendarray(gpu_matrix) return dev, gpu_matrix, (start_idx, stop_idx) except Exception as e: import traceback logging.error("Error in to_gpu_matrix(" + str(e)) traceback.print_exc() pass
def predict_to_device_arrays(arr, worker, loc_dict, nparts, dtype): """ :param arr: A tuple in the form of (X, y, coef) :return: """ part_number = list(loc_dict.keys())[list(loc_dict.values()).index(worker)] mats = [] for X, coef in arr: nrows = len(X) part_size = ceil(nrows / nparts) up_limit = min((part_number + 1) * part_size, nrows) mat = X.compute().as_gpu_matrix(order='F') pred = cuda.to_device( np.zeros(up_limit - (part_number * part_size), dtype=dtype)) mats.append([mat, coef.to_gpu_array(), pred]) dev = device_of_devicendarray(mats[0][0]) # Return canonical device id as string return mats, dev