Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallelize JIT functions #440

Merged
merged 3 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/galois/_domains/_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def set_globals(self):
_SIGNATURE: numba.types.FunctionType
"""The function's Numba signature."""

_PARALLEL = False
"""Indicates if parallel processing should be performed."""

implementation: Callable
"""The function's implementation in pure Python."""

Expand Down Expand Up @@ -78,7 +81,7 @@ def jit(self) -> numba.types.FunctionType:

if key_2 not in self._CACHE[key_1]:
self.set_globals() # Set the globals once before JIT compiling the function
self._CACHE[key_1][key_2] = numba.jit(self._SIGNATURE.signature, nopython=True)(self.implementation)
self._CACHE[key_1][key_2] = numba.jit(self._SIGNATURE.signature, parallel=self._PARALLEL, nopython=True)(self.implementation)

return self._CACHE[key_1][key_2]

Expand Down
5 changes: 3 additions & 2 deletions src/galois/_domains/_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def set_globals(self):
MULTIPLY = self.field._multiply.ufunc_call_only

_SIGNATURE = numba.types.FunctionType(int64[:,:](int64[:,:], int64[:,:]))
_PARALLEL = True

@staticmethod
def implementation(A, B):
Expand All @@ -228,8 +229,8 @@ def implementation(A, B):
M, K = A.shape
K, N = B.shape
C = np.zeros((M, N), dtype=A.dtype)
for i in range(M):
for j in range(N):
for i in numba.prange(M): # pylint: disable=not-an-iterable
for j in numba.prange(N): # pylint: disable=not-an-iterable
for k in range(K):
C[i,j] = ADD(C[i,j], MULTIPLY(A[i,k], B[k,j]))

Expand Down
3 changes: 2 additions & 1 deletion src/galois/_polys/_dense.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,12 @@ def set_globals(self):
MULTIPLY = self.field._multiply.ufunc_call_only

_SIGNATURE = numba.types.FunctionType(int64[:](int64[:], int64[:]))
_PARALLEL = True

@staticmethod
def implementation(coeffs, values):
y = np.zeros(values.size, dtype=values.dtype)
for i in range(values.size):
for i in numba.prange(values.size): # pylint: disable=not-an-iterable
y[i] = coeffs[0]
for j in range(1, coeffs.size):
y[i] = ADD(coeffs[j], MULTIPLY(y[i], values[i]))
Expand Down