-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Automatically load AOT functions, if failed, load JIT functions in…
…stead.
- Loading branch information
Showing
9 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Run this script to automatically compile AOT functions for python 3.7, 3.8 and 3.9 | ||
""" | ||
import argparse | ||
import os | ||
import subprocess | ||
import shutil | ||
|
||
|
||
|
||
def main(): | ||
list_of_envs = [] | ||
envs = subprocess.check_output('conda env list').splitlines()[2:-1] | ||
for string in envs: | ||
try: | ||
list_of_envs.append(string.decode("utf-8").split()[0]) | ||
except IndexError: | ||
pass | ||
print(list_of_envs) | ||
# print(env_name) | ||
|
||
versions = ['37', '38', '39'] # pythran seems to only work in 3.7 3.8 3.9 | ||
|
||
for ver in versions: | ||
# Create a virtual environment if necessary. | ||
if f"compile{ver}" in list_of_envs: | ||
print(f"No need to create Conda python {ver} env") | ||
else: | ||
subprocess.run(f'conda create -n compile{ver} python={ver[0]}.{ver[1]} -y') | ||
subprocess.run(f'conda activate compile{ver} && conda install -c conda-forge "numpy<1.22" pythran -y', shell=True) | ||
|
||
# Compile | ||
compile_statement = f"pythran --config compiler.blas=mkl -O3 -ffast-math -DUSE_XSIMD esa/_performance.py -o esa/performance{ver}.pyd" | ||
subprocess.run(f"conda activate compile{ver} && {compile_statement}", shell=True) | ||
print('DONE!') | ||
|
||
print('*' * 80) | ||
print('ALL DONE!') | ||
|
||
|
||
|
||
|
||
if __name__ == '__main__': | ||
main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import numba as nb | ||
|
||
|
||
@nb.njit | ||
def initialize_bound(bpmax, bpmin, bnmax, bnmin, A): | ||
bp0 = A.copy() | ||
bp1 = A.copy() | ||
bn0 = A.copy() | ||
bn1 = A.copy() | ||
for i in range(len(bpmax)): | ||
bp0[i, :] *= bpmax[i] | ||
bp1[i, :] *= bpmin[i] | ||
bn0[i, :] *= bnmax[i] | ||
bn1[i, :] *= bnmin[i] | ||
Wbuf1 = np.maximum(bp0, bp1) | ||
Wbuf2 = np.maximum(bn0, bn1) | ||
w = np.maximum(Wbuf1+Wbuf1.conj().T, Wbuf2+Wbuf2.conj().T) | ||
return w, Wbuf1, Wbuf2 | ||
|
||
|
||
@nb.njit | ||
def calculate_bound(bp, bn, Amax1, Amin1, Wbuf1, Wbuf2): | ||
bp0 = bp.copy() | ||
bp1 = bp.copy() | ||
bn0 = bn.copy() | ||
bn1 = bn.copy() | ||
for i in range(len(Amax1)): | ||
bp0[:, i] *= Amax1[i] | ||
bp1[:, i] *= Amin1[i] | ||
bn0[:, i] *= Amax1[i] | ||
bn1[:, i] *= Amin1[i] | ||
wb1 = np.maximum(bp0, bp1) + Wbuf1 | ||
wb2 = np.maximum(bn0, bn1) + Wbuf2 | ||
w = np.maximum(wb1,wb2) | ||
return w |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters