Skip to content

Commit

Permalink
Merge pull request #105 from nauaneed/bump-cython
Browse files Browse the repository at this point in the history
Bump cython, numpy
  • Loading branch information
prabhuramachandran authored Sep 26, 2024
2 parents e658482 + bca0e31 commit dd566c3
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 17 deletions.
27 changes: 21 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ on:
jobs:
tests:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.8, 3.9]
python-version: [3.11, 3.12]

runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
Expand All @@ -35,6 +36,20 @@ jobs:
conda install -c conda-forge pocl pyopencl
python -c 'import pyopencl as cl'
if: ${{ runner.os != 'Windows' }}
- name: Setup compyle config on MacOS to use openmp enabled clang from homebrew
run: |
brew install libomp
mkdir -p ~/.compyle
touch ~/.compyle/config.py
echo "import os" >> ~/.compyle/config.py
echo "os.environ['CC'] = '$(brew --prefix llvm@15)/bin/clang'" >> ~/.compyle/config.py
echo "os.environ['CXX'] = '$(brew --prefix llvm@15)/bin/clang++'" >> ~/.compyle/config.py
export CPPFLAGS="-I$(brew --prefix libomp)/include -I$(brew --prefix llvm@15)/include -Xclang -fopenmp"
export LDFLAGS="-L$(brew --prefix libomp)/lib -L$(brew --prefix llvm@15)/lib -lomp"
python -c "import os; OMP_CFLAGS=os.environ.get('CPPFLAGS').split(' '); print(f'{OMP_CFLAGS=}')" >> ~/.compyle/config.py
python -c "import os; OMP_LINK=os.environ.get('LDFLAGS').split(' '); print(f'{OMP_LINK=}')" >> ~/.compyle/config.py
cat ~/.compyle/config.py
if: ${{ runner.os == 'macOS' }}
- name: Install dependencies
run: |
conda info
Expand All @@ -46,9 +61,9 @@ jobs:
# Thanks https://stackoverflow.com/a/60942437
- name: Get month to use as cache key.
id: month
run: echo "::set-output name=month::$(date +'%m')"
run: echo "month==$(date +'%m')" >> $GITHUB_OUTPUT
- name: Deal with auto-generated code cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
~/.compyle
Expand All @@ -61,6 +76,6 @@ jobs:
if: ${{ success() }}
run: coverage report
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
env_vars: ${{ matrix.os }}, ${{ matrix.python-version }}
2 changes: 1 addition & 1 deletion compyle/cython_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def _get_c_method_spec(self, name, returns, args):
c_arg_def = ', '.join(c_args)
if self._config.use_openmp:
ignore = ['reduce', 'converged']
gil = " nogil" if name not in ignore else ""
gil = " noexcept nogil" if name not in ignore else ""
else:
gil = ""
cdefn = 'cdef inline {ret} {name}({arg_def}){gil}:'.format(
Expand Down
6 changes: 3 additions & 3 deletions compyle/opencl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def set_context(ctx):
def get_queue():
global _queue
if _queue is None:
properties = None
kwargs = dict()
if get_config().profile:
properties = cl.command_queue_properties.PROFILING_ENABLE
_queue = cl.CommandQueue(get_context(), properties=properties)
kwargs['properties'] = cl.command_queue_properties.PROFILING_ENABLE
_queue = cl.CommandQueue(get_context(), **kwargs)
return _queue


Expand Down
4 changes: 2 additions & 2 deletions compyle/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ def _generate(self, declarations=None):
def _correct_return_type(self, c_data):
code = self.tp.blocks[-1].code.splitlines()
if self._config.use_openmp:
gil = " nogil"
gil = " noexcept nogil"
else:
gil = ""
code[0] = "cdef inline {type} {name}({args}){gil}:".format(
Expand Down Expand Up @@ -904,7 +904,7 @@ def _get_backend_key(self):
def _correct_return_type(self, c_data, modifier):
code = self.tp.blocks[-1].code.splitlines()
if self._config.use_openmp:
gil = " nogil"
gil = " noexcept nogil"
else:
gil = ""
code[0] = "cdef inline {type} {name}_{modifier}({args}){gil}:".format(
Expand Down
14 changes: 11 additions & 3 deletions compyle/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,14 @@ def test_sort_by_keys(backend):
out_array1, out_array2 = array.sort_by_keys([dev_array1, dev_array2])

# Then
order = np.argsort(nparr1)
if backend == 'opencl': # opencl backend => radix sort which is stable
order = np.argsort(nparr1, stable=True)
else:
order = np.argsort(nparr1)
act_result1 = np.take(nparr1, order)
act_result2 = np.take(nparr2, order)

# find positions of duplicate values in the sorted array
assert np.all(out_array1.get() == act_result1)
assert np.all(out_array2.get() == act_result2)

Expand All @@ -295,7 +300,7 @@ def test_radix_sort_by_keys():
use_radix_sort=True)

# Then
order = np.argsort(nparr1)
order = np.argsort(nparr1, stable=True)
act_result1 = np.take(nparr1, order)
act_result2 = np.take(nparr2, order)
assert np.all(out_array1.get() == act_result1)
Expand All @@ -322,7 +327,10 @@ def test_sort_by_keys_with_output(backend):
out_list=out_arrays, use_radix_sort=False)

# Then
order = np.argsort(nparr1)
if backend == 'opencl': # opencl backend => radix sort which is stable
order = np.argsort(nparr1, stable=True)
else:
order = np.argsort(nparr1)
act_result1 = np.take(nparr1, order)
act_result2 = np.take(nparr2, order)
assert np.all(out_arrays[0].get() == act_result1)
Expand Down
2 changes: 1 addition & 1 deletion compyle/tests/test_cython_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def __init__(self, **kwargs):
for key, value in kwargs.items():
setattr(self, key, value)
cdef inline void func(self, long d_idx, double* d_x) nogil:
cdef inline void func(self, long d_idx, double* d_x) noexcept nogil:
cdef double tmp
tmp = abs(self.rho*self.c)*sin(pi*self.c)
d_x[d_idx] = d_x[d_idx]*tmp
Expand Down
1 change: 1 addition & 0 deletions compyle/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def _inject_types_in_module():
NP_C_TYPE_MAP[np.dtype(np.uint64)] = 'unsigned long long'
C_NP_TYPE_MAP['long long'] = np.int64
C_NP_TYPE_MAP['unsigned long long'] = np.uint64
TYPES['long long'] = KnownType('long long')
TYPES['glonglongp'] = KnownType('GLOBAL_MEM long long*', 'long long')
TYPES['gulonglongp'] = KnownType('GLOBAL_MEM unsigned long long*',
'unsigned long long')
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
requires = [
"wheel>=0.29.0",
"setuptools>=42.0.0",
"oldest-supported-numpy",
"numpy>=2.0,<3",
"Cython>=0.20",
"mako",
"pytools"
Expand Down

0 comments on commit dd566c3

Please sign in to comment.