Skip to content

Instantly share code, notes, and snippets.

@gmarkall
Created September 29, 2022 11:01
Show Gist options
  • Save gmarkall/29d2bbda8d3b54449e57528de812a20b to your computer and use it in GitHub Desktop.
Save gmarkall/29d2bbda8d3b54449e57528de812a20b to your computer and use it in GitHub Desktop.
# Notes for https://numba.discourse.group/t/kernel-within-a-kernel/1582/4
import cupy as cp
def where(d2_array, col_index, _data_):
return d2_array[cp.where(d2_array[:, col_index] == _data_)]
def fill_arrays_with_data_based_on_unique_data(unique_data, cp_data,
cuda_array_of_arrays, col_index,
book_size, long_book):
"""
:param unique_data: unique data is a one dimentional array
:param cp_data: is a huge 2D Array
:param cuda_array_of_arrays: empty array of 2D arrays where data will be
filtered by member of the unique_data
:param col_index: index of the column
:param book_size: book size (int)
:param long_book: is 1 or 0; True/False
:return: cuda_array_of_arrays array of 2D arrays filtered by date
unique_data
"""
for _index in range(unique_data.shape[0]):
arr = cuda_array_of_arrays[_index]
_data_ = unique_data[_index]
counter = 0
rank = book_size
# would be lovely if below (where) function worked, but it doesn't
cp_2d_array = where(cp_data, col_index, _data_)
# would be great if below for loop could execute in parallel using
# seperate kernel function
for row in range(cp_2d_array.shape[0]):
if counter < arr.shape[0]:
for col in range(cp_2d_array.shape[1]):
arr[counter, col] = cp_2d_array[row, col]
if long_book == 1:
# would be very usefuls if np.argsort() worked in numba
# cuda
arr[counter, 3] = rank
arr[counter, 10] = arr[counter, 7]
arr[counter, 13] = arr[counter, 8]
rank -= 1
counter += 1
unique_data = cp.zeros(10)
cp_data = cp.zeros((100, 100))
cuda_array_of_arrays = [cp.zeros((100, 100)) for _ in range(10)]
col_index = 2
book_size = 5
long_book = 1
fill_arrays_with_data_based_on_unique_data(unique_data, cp_data,
cuda_array_of_arrays, col_index,
book_size, long_book)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment