├── .dockerignore ├── VERSION ├── cupynumeric ├── py.typed ├── _sphinxext │ ├── _templates │ │ └── comparison_table.rst │ ├── __init__.py │ ├── _templates.py │ ├── _cupynumeric_directive.py │ └── ufunc_formatter.py ├── lib │ └── __init__.py ├── _array │ └── __init__.py ├── _thunk │ └── __init__.py ├── install_info.pyi ├── linalg │ ├── _exception.py │ └── __init__.py ├── _utils │ └── __init__.py ├── _ufunc │ └── __init__.py ├── fft │ └── __init__.py ├── ma │ └── __init__.py ├── random │ └── __init__.py ├── patch.py └── types.py ├── tests ├── cpp │ ├── .gitignore │ ├── run.sh │ ├── cmake │ │ └── thirdparty │ │ │ └── get_nccl.cmake │ └── main.cc ├── integration │ ├── utils │ │ └── __init__.py │ ├── test_min_on_gpu.py │ ├── test_inlinemap-keeps-region-alive.py │ ├── test_map_reduce.py │ ├── test_update.py │ ├── test_0d_store.py │ ├── test_copy.py │ └── test_length.py ├── unit │ ├── __init__.py │ ├── cupynumeric │ │ ├── __init__.py │ │ ├── _array │ │ │ └── __init__.py │ │ ├── _utils │ │ │ └── __init__.py │ │ ├── random │ │ │ └── __init__.py │ │ ├── _sphinxext │ │ │ └── __init__.py │ │ └── test_nptest.py │ └── util.py └── todo │ ├── complex_test.py │ └── 2d_reduction_complex.py ├── docs ├── cupynumeric │ ├── source │ │ ├── _static │ │ │ └── .keep │ │ ├── api │ │ │ ├── _grouped.rst │ │ │ ├── classes.rst │ │ │ ├── broadcast.rst │ │ │ ├── index.rst │ │ │ ├── io.rst │ │ │ ├── datatype.rst │ │ │ ├── set.rst │ │ │ ├── settings.rst │ │ │ ├── _generator.rst │ │ │ ├── _bitgenerator.rst │ │ │ ├── window.rst │ │ │ ├── routines.rst │ │ │ ├── comparison.rst │ │ │ ├── binary.rst │ │ │ ├── sorting.rst │ │ │ ├── statistics.rst │ │ │ ├── fft.rst │ │ │ ├── creation.rst │ │ │ ├── indexing.rst │ │ │ ├── logic.rst │ │ │ └── linalg.rst │ │ ├── _images │ │ │ ├── cg.jpeg │ │ │ ├── edge1.png │ │ │ ├── edge2.png │ │ │ ├── jacobi.jpeg │ │ │ ├── matmul2.png │ │ │ ├── matmul1.jpeg │ │ │ ├── black-scholes.jpeg │ │ │ └── developer-build.png │ │ ├── examples │ │ │ ├── image.png │ │ │ └── index.rst │ │ ├── user │ │ │ ├── howtos │ │ │ │ ├── index.rst │ │ │ │ └── patching.rst │ │ │ └── index.rst │ │ ├── developer │ │ │ └── index.rst │ │ ├── _templates │ │ │ └── layout.html │ │ ├── _implemented.rst │ │ ├── acknowledgments.rst │ │ └── index.rst │ └── make.bat └── figures │ └── cfd-demo.png ├── .gitattributes ├── MANIFEST.in ├── scripts ├── release │ └── util │ │ └── __init__.py ├── pre-commit │ └── yamllint.yml ├── get_cupynumeric_dir.py ├── conda-build.sh └── hooks │ └── legate_defined.sh ├── .github ├── copy-pr-bot.yaml ├── CODEOWNERS ├── dependabot.yml ├── workflows │ └── require-labels.yml └── release.yml ├── NOTICE ├── continuous_integration ├── requirements-build.txt └── scripts │ ├── tools │ ├── legate-configure-sccache │ └── legate-gh-run-id │ ├── make-conda-env │ └── conda-dnld-utils ├── setup.cfg ├── conda └── conda-build │ └── conda_build_config.yaml ├── src ├── cupynumeric.h ├── cupynumeric │ ├── slice.h │ ├── bits │ │ └── bits_util.h │ ├── utilities │ │ ├── thrust_util.h │ │ └── thrust_allocator.h │ ├── random │ │ └── randutil │ │ │ ├── randutil_impl.h │ │ │ ├── generator_poisson.inl │ │ │ ├── generator_raw.inl │ │ │ ├── generator_zipf.inl │ │ │ ├── generator_logseries.inl │ │ │ ├── generator_geometric.inl │ │ │ ├── generator_hypergeometric.inl │ │ │ ├── generator_binomial.inl │ │ │ ├── generator_negative_binomial.inl │ │ │ ├── randutil_curand.h │ │ │ ├── generator_beta.inl │ │ │ ├── generator_standard_t.inl │ │ │ ├── generator_vonmises.inl │ │ │ ├── generator_gamma.inl │ │ │ ├── generator_lognormal.inl │ │ │ ├── generator_normal.inl │ │ │ ├── generator_exponential.inl │ │ │ └── generator_uniform.inl │ ├── arg_redop_register.cu │ ├── index │ │ ├── take_omp.cc │ │ ├── putmask.cu │ │ ├── putmask_omp.cc │ │ ├── take.cu │ │ ├── take.cc │ │ └── putmask.cc │ ├── typedefs.h │ ├── set │ │ ├── unique_reduce_omp.cc │ │ ├── unique_reduce.cc │ │ └── unique_reduce.h │ ├── matrix │ │ ├── qr_omp.cc │ │ ├── svd_omp.cc │ │ ├── geev_omp.cc │ │ ├── syev_omp.cc │ │ ├── solve_omp.cc │ │ ├── matmul_omp.cc │ │ ├── matvecmul_omp.cc │ │ ├── mp_qr.h │ │ ├── mp_potrf.h │ │ ├── mp_solve.h │ │ ├── trsm.h │ │ ├── gemm.h │ │ ├── syrk.h │ │ ├── tile.h │ │ ├── potrf.h │ │ ├── qr.cc │ │ ├── svd.cc │ │ ├── geev.cc │ │ ├── solve.cc │ │ ├── syev.cc │ │ ├── diag.h │ │ └── matmul.cc │ ├── unary │ │ ├── scalar_unary_red_omp.cc │ │ ├── scalar_unary_red.cu │ │ └── scalar_unary_red.cc │ ├── ndarray.inl │ ├── cupynumeric_task.h │ ├── sort │ │ ├── cub_sort_bool.cu │ │ ├── cub_sort_double.cu │ │ ├── cub_sort_float.cu │ │ ├── cub_sort_int16.cu │ │ ├── cub_sort_int32.cu │ │ ├── cub_sort_int64.cu │ │ ├── cub_sort_int8.cu │ │ ├── cub_sort_uint8.cu │ │ ├── cub_sort_uint16.cu │ │ ├── cub_sort_uint32.cu │ │ ├── cub_sort_uint64.cu │ │ ├── cub_sort_half.cu │ │ ├── thrust_sort_bool.cu │ │ ├── thrust_sort_double.cu │ │ ├── thrust_sort_float.cu │ │ ├── thrust_sort_int16.cu │ │ ├── thrust_sort_int32.cu │ │ ├── thrust_sort_int64.cu │ │ ├── thrust_sort_int8.cu │ │ ├── thrust_sort_uint8.cu │ │ ├── thrust_sort_uint16.cu │ │ ├── thrust_sort_uint32.cu │ │ ├── thrust_sort_uint64.cu │ │ ├── thrust_sort_half.cu │ │ ├── thrust_sort_complex64.cu │ │ └── thrust_sort_complex128.cu │ ├── stat │ │ ├── histogramdd_omp.cc │ │ ├── histogramdd.cu │ │ └── detail │ │ │ └── histogramdd_using_thrust.h │ ├── nullary │ │ ├── window.h │ │ ├── eye.h │ │ └── fill.h │ ├── item │ │ ├── read.h │ │ └── write.h │ ├── operators.inl │ ├── mapper.h │ └── execution_policy │ │ └── indexing │ │ └── parallel_loop.h └── env_defaults.h ├── cmake ├── versions.json ├── thirdparty │ ├── get_lapack.cmake │ ├── get_cusolvermp.cmake │ ├── get_nccl.cmake │ └── get_cutensor.cmake └── generate_install_info_py.cmake ├── .gitignore └── examples └── cpp ├── stencil ├── build.sh └── CMakeLists.txt └── gemm ├── build.sh └── CMakeLists.txt /.dockerignore: -------------------------------------------------------------------------------- 1 | .gitignore -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 26.01.00 2 | -------------------------------------------------------------------------------- /cupynumeric/py.typed: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/cpp/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/_static/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | cunpyumeric/_version.py export-subst 2 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include versioneer.py 2 | include cupynumeric/_version.py 3 | include cupynumeric/py.typed 4 | -------------------------------------------------------------------------------- /docs/figures/cfd-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nv-legate/cupynumeric/HEAD/docs/figures/cfd-demo.png -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/_grouped.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | .. comparison-table:: 4 | :sections: grouped 5 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/_images/cg.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nv-legate/cupynumeric/HEAD/docs/cupynumeric/source/_images/cg.jpeg -------------------------------------------------------------------------------- /scripts/release/util/__init__.py: -------------------------------------------------------------------------------- 1 | """Utilities used by the cuPyNumeric release helper.""" 2 | 3 | from __future__ import annotations 4 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/_images/edge1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nv-legate/cupynumeric/HEAD/docs/cupynumeric/source/_images/edge1.png -------------------------------------------------------------------------------- /docs/cupynumeric/source/_images/edge2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nv-legate/cupynumeric/HEAD/docs/cupynumeric/source/_images/edge2.png -------------------------------------------------------------------------------- /docs/cupynumeric/source/_images/jacobi.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nv-legate/cupynumeric/HEAD/docs/cupynumeric/source/_images/jacobi.jpeg -------------------------------------------------------------------------------- /docs/cupynumeric/source/_images/matmul2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nv-legate/cupynumeric/HEAD/docs/cupynumeric/source/_images/matmul2.png -------------------------------------------------------------------------------- /docs/cupynumeric/source/examples/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nv-legate/cupynumeric/HEAD/docs/cupynumeric/source/examples/image.png -------------------------------------------------------------------------------- /docs/cupynumeric/source/_images/matmul1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nv-legate/cupynumeric/HEAD/docs/cupynumeric/source/_images/matmul1.jpeg -------------------------------------------------------------------------------- /docs/cupynumeric/source/_images/black-scholes.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nv-legate/cupynumeric/HEAD/docs/cupynumeric/source/_images/black-scholes.jpeg -------------------------------------------------------------------------------- /scripts/pre-commit/yamllint.yml: -------------------------------------------------------------------------------- 1 | --- 2 | extends: default 3 | rules: 4 | truthy: 5 | ignore: ".github/workflows/*.yml" 6 | line-length: disable 7 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/_images/developer-build.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nv-legate/cupynumeric/HEAD/docs/cupynumeric/source/_images/developer-build.png -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/classes.rst: -------------------------------------------------------------------------------- 1 | ------- 2 | Classes 3 | ------- 4 | 5 | .. toctree:: 6 | :maxdepth: 2 7 | 8 | broadcast 9 | ndarray 10 | -------------------------------------------------------------------------------- /.github/copy-pr-bot.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | # Configuration file for `copy-pr-bot` GitHub App 3 | # https://docs.gha-runners.nvidia.com/apps/copy-pr-bot/ 4 | 5 | enabled: true 6 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/user/howtos/index.rst: -------------------------------------------------------------------------------- 1 | Howtos 2 | ====== 3 | 4 | .. toctree:: 5 | :maxdepth: 1 6 | 7 | measuring 8 | benchmarking 9 | patching 10 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | The cuPyNumeric project is independent of the CuPy project. CuPy is a trademark 2 | of Preferred Networks, Inc, and the name 'cuPyNumeric' is used with their 3 | permission. 4 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/broadcast.rst: -------------------------------------------------------------------------------- 1 | .. currentmodule:: cupynumeric 2 | 3 | cupynumeric.broadcast 4 | ===================== 5 | 6 | .. autoclass:: broadcast 7 | :members: 8 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/developer/index.rst: -------------------------------------------------------------------------------- 1 | Developer guide 2 | =============== 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | Contributing 8 | building 9 | testing 10 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Code Ownership 2 | .github @nv-legate/devops-reviewers 3 | continuous_integration @nv-legate/devops-reviewers 4 | conda @nv-legate/devops-reviewers 5 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/index.rst: -------------------------------------------------------------------------------- 1 | API Reference 2 | ============= 3 | 4 | .. currentmodule:: cupynumeric 5 | 6 | .. toctree:: 7 | :maxdepth: 2 8 | 9 | classes 10 | routines 11 | settings 12 | comparison 13 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/user/index.rst: -------------------------------------------------------------------------------- 1 | User guide 2 | ========== 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | usage 8 | practices 9 | howtos/index 10 | advanced 11 | differences 12 | tutorial 13 | task 14 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/_templates/layout.html: -------------------------------------------------------------------------------- 1 | {% extends "!layout.html" %} 2 | 3 | {% block extrahead %} 4 | 5 | 6 | 7 | {% endblock %} 8 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/io.rst: -------------------------------------------------------------------------------- 1 | Input and output 2 | ================ 3 | 4 | .. currentmodule:: cupynumeric 5 | 6 | NumPy binary files (npy, npz) 7 | ----------------------------- 8 | .. autosummary:: 9 | :toctree: generated/ 10 | 11 | load 12 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/datatype.rst: -------------------------------------------------------------------------------- 1 | Data type routines 2 | ================== 3 | 4 | .. currentmodule:: cupynumeric 5 | 6 | Data type testing 7 | ----------------- 8 | 9 | .. autosummary:: 10 | :toctree: generated/ 11 | 12 | find_common_type 13 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/set.rst: -------------------------------------------------------------------------------- 1 | Set routines 2 | ============ 3 | 4 | .. currentmodule:: cupynumeric 5 | 6 | Making proper sets 7 | ------------------ 8 | 9 | .. autosummary:: 10 | :toctree: generated/ 11 | 12 | unique 13 | in1d 14 | isin 15 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/settings.rst: -------------------------------------------------------------------------------- 1 | .. _settings: 2 | 3 | Settings 4 | ======== 5 | 6 | cuPyNumeric has a number of runtime settings that can be configured through 7 | environment variables. 8 | 9 | .. settings:: settings 10 | :module: cupynumeric.settings 11 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/examples/index.rst: -------------------------------------------------------------------------------- 1 | Examples 2 | ======== 3 | 4 | .. toctree:: 5 | :maxdepth: 1 6 | 7 | black_scholes 8 | cholesky 9 | stencil 10 | kmeans 11 | edge_detection 12 | newton_raphson_2d 13 | compact_finite_difference 14 | torchswe 15 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/_generator.rst: -------------------------------------------------------------------------------- 1 | cupynumeric.random.Generator 2 | ============================ 3 | 4 | .. currentmodule:: cupynumeric.random 5 | 6 | .. autoclass:: Generator 7 | 8 | .. automethod:: __init__ 9 | 10 | .. rubric:: Methods 11 | 12 | .. autosummary:: 13 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/_bitgenerator.rst: -------------------------------------------------------------------------------- 1 | cupynumeric.random.BitGenerator 2 | =============================== 3 | 4 | .. currentmodule:: cupynumeric.random 5 | 6 | .. autoclass:: BitGenerator 7 | 8 | .. automethod:: __init__ 9 | 10 | .. rubric:: Methods 11 | 12 | .. autosummary:: 13 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/window.rst: -------------------------------------------------------------------------------- 1 | Window functions 2 | ====================== 3 | 4 | .. currentmodule:: cupynumeric 5 | 6 | Various windows 7 | ----------------------- 8 | 9 | .. autosummary:: 10 | :toctree: generated/ 11 | 12 | 13 | bartlett 14 | blackman 15 | hamming 16 | hanning 17 | kaiser 18 | -------------------------------------------------------------------------------- /continuous_integration/requirements-build.txt: -------------------------------------------------------------------------------- 1 | --extra-index-url=https://pypi.anaconda.org/rapidsai-wheels-nightly/simple 2 | --extra-index-url=https://pypi.nvidia.com 3 | cmake>=3.30.4 4 | ninja 5 | nvidia-nccl-cu12 6 | cutensor-cu12>=2.0,<2.3.0.6 7 | scikit-build 8 | scikit-build-core[pyproject]>=0.10.0 9 | setuptools_scm 10 | cython 11 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/_implemented.rst: -------------------------------------------------------------------------------- 1 | .. This page exists to collect references to all cupynumeric functions and 2 | .. methods that are "implemented". Doing so, any implemented functions or 3 | .. methods that are not present in the docs (but should be) will result in 4 | .. docs build errors 5 | 6 | :orphan: 7 | 8 | .. implemented-index:: 9 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/routines.rst: -------------------------------------------------------------------------------- 1 | -------- 2 | Routines 3 | -------- 4 | 5 | .. toctree:: 6 | :maxdepth: 2 7 | 8 | creation 9 | manipulation 10 | binary 11 | datatype 12 | indexing 13 | io 14 | linalg 15 | logic 16 | math 17 | fft 18 | random 19 | set 20 | sorting 21 | statistics 22 | window 23 | -------------------------------------------------------------------------------- /tests/cpp/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ $# -eq 0 ] 4 | then 5 | REALM_BACKTRACE=1 LEGATE_TEST=1 python run.py 6 | elif [ $# -eq 1 ] && [ "$1" = "ctest" ] 7 | then 8 | echo "Using ctest" 9 | cd build 10 | REALM_BACKTRACE=1 LEGATE_TEST=1 LEGION_DEFAULT_ARGS="-ll:cpu 4" ctest --output-on-failure "$@" 11 | else 12 | echo "Invalid arguments" 13 | fi 14 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/comparison.rst: -------------------------------------------------------------------------------- 1 | Project comparisons 2 | =================== 3 | 4 | Here is a list of NumPy APIs and corresponding cuPyNumeric implementations. 5 | 6 | A dot in the cupynumeric column denotes that cuPyNumeric implementation 7 | is not provided yet. We welcome contributions for these functions. 8 | 9 | NumPy vs cuPyNumeric APIs 10 | ------------------------- 11 | 12 | .. comparison-table:: 13 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2024, NVIDIA CORPORATION. 2 | 3 | [versioneer] 4 | VCS = git 5 | style = pep440 6 | versionfile_source = cupynumeric/_version.py 7 | versionfile_build = cupynumeric/_version.py 8 | tag_prefix = v 9 | parentdir_prefix = cupynumeric- 10 | 11 | [options] 12 | packages = find: 13 | install_requires = 14 | numpy>=1.22,!=2.1.0 15 | # TODO: Add rest of install dependencies 16 | python_requires = >=3.11 17 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/acknowledgments.rst: -------------------------------------------------------------------------------- 1 | .. _acknowledgments: 2 | 3 | Acknowledgments 4 | =============== 5 | 6 | NVIDIA would like to thank the following individuals and institutions for their contributions: 7 | 8 | * This product includes TBLIS - a library and framework for performing tensor 9 | operations, especially tensor contraction, using efficient native algorithms - 10 | https://github.com/MatthewsResearchGroup/tblis. 11 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright (c) 2025-2025 NVIDIA CORPORATION & AFFILIATES. 2 | # All rights reserved. 3 | # SPDX-License-Identifier: Apache-2.0 4 | --- 5 | version: 2 6 | updates: 7 | 8 | - package-ecosystem: "github-actions" 9 | directory: "/" 10 | schedule: 11 | # Check for updates to GitHub Actions every week 12 | interval: "weekly" 13 | labels: 14 | - CI 15 | -------------------------------------------------------------------------------- /conda/conda-build/conda_build_config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | gpu_enabled: 3 | - true 4 | - false 5 | 6 | build_tests: 7 | - true 8 | - false 9 | 10 | python: 11 | - 3.11 12 | - 3.12 13 | - 3.13 14 | 15 | numpy_version: 16 | # Not 2.1.0 which segfaults on asarray() sometimes, see 17 | # https://github.com/numpy/numpy/pull/27249 18 | - ">=1.22,!=2.1.0" 19 | 20 | c_stdlib: 21 | - sysroot 22 | 23 | c_stdlib_version: 24 | - "2.28" 25 | 26 | cmake_version: 27 | - ">=3.30.4" 28 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/binary.rst: -------------------------------------------------------------------------------- 1 | Binary operations 2 | ================= 3 | 4 | .. currentmodule:: cupynumeric 5 | 6 | Elementwise bit operations 7 | -------------------------- 8 | 9 | .. autosummary:: 10 | :toctree: generated/ 11 | 12 | bitwise_and 13 | bitwise_or 14 | bitwise_xor 15 | invert 16 | left_shift 17 | right_shift 18 | 19 | 20 | Bit packing 21 | ----------- 22 | 23 | .. autosummary:: 24 | :toctree: generated/ 25 | 26 | packbits 27 | unpackbits 28 | -------------------------------------------------------------------------------- /scripts/get_cupynumeric_dir.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. 3 | # All rights reserved. 4 | # SPDX-License-Identifier: Apache-2.0 5 | from __future__ import annotations 6 | 7 | from pathlib import Path 8 | 9 | 10 | def get_cupynumeric_dir() -> str: 11 | """Return the absolute path to the cuPyNumeric repository root.""" 12 | 13 | return str(Path(__file__).resolve().parents[1]) 14 | 15 | 16 | def main() -> None: 17 | print(get_cupynumeric_dir(), end="", flush=True) # noqa: T201 18 | 19 | 20 | if __name__ == "__main__": 21 | main() 22 | -------------------------------------------------------------------------------- /tests/integration/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | -------------------------------------------------------------------------------- /cupynumeric/_sphinxext/_templates/comparison_table.rst: -------------------------------------------------------------------------------- 1 | {% for section in sections %} 2 | 3 | {{ section.title }} 4 | {{ "~" * section.title|length }} 5 | 6 | .. currentmodule:: cupynumeric 7 | 8 | .. autosummary:: 9 | :toctree: generated/ 10 | 11 | .. csv-table:: 12 | :header: NumPy, cupynumeric, single-GPU/CPU, multi-GPU/CPU 13 | 14 | {% for item in section.items -%} 15 | {{ item.np_ref }}, {{ item.lg_ref }}, {{ item.single }}, {{ item.multi }} 16 | {% endfor %} 17 | 18 | .. rubric:: Summary 19 | 20 | Number of NumPy functions: {{ section.np_count }} 21 | 22 | Number of functions covered by cupynumeric: {{ section.lg_count }} 23 | 24 | {% endfor %} 25 | -------------------------------------------------------------------------------- /.github/workflows/require-labels.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Pull Request Labels 3 | on: 4 | pull_request: 5 | types: [opened, labeled, unlabeled, synchronize] 6 | jobs: 7 | label: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Check Labels 11 | uses: mheap/github-action-required-labels@v5 12 | with: 13 | mode: minimum 14 | count: 1 15 | labels: | 16 | category:new-feature 17 | category:improvement 18 | category:bug-fix 19 | category:documentation 20 | Bug 21 | Build 22 | CI 23 | Docs 24 | Feature 25 | Maintenance 26 | -------------------------------------------------------------------------------- /cupynumeric/lib/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | from __future__ import annotations 16 | -------------------------------------------------------------------------------- /tests/unit/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | from __future__ import annotations 17 | -------------------------------------------------------------------------------- /cupynumeric/_array/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | from __future__ import annotations 16 | -------------------------------------------------------------------------------- /cupynumeric/_thunk/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | from __future__ import annotations 16 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/sorting.rst: -------------------------------------------------------------------------------- 1 | Sorting, searching, and counting 2 | ================================ 3 | 4 | .. currentmodule:: cupynumeric 5 | 6 | Sorting 7 | ------- 8 | 9 | .. autosummary:: 10 | :toctree: generated/ 11 | 12 | argpartition 13 | argsort 14 | partition 15 | sort 16 | sort_complex 17 | 18 | Searching 19 | --------- 20 | 21 | .. autosummary:: 22 | :toctree: generated/ 23 | 24 | argmax 25 | argmin 26 | argwhere 27 | flatnonzero 28 | nanargmax 29 | nanargmin 30 | nonzero 31 | searchsorted 32 | extract 33 | where 34 | 35 | Counting 36 | -------- 37 | 38 | .. autosummary:: 39 | :toctree: generated/ 40 | 41 | count_nonzero 42 | -------------------------------------------------------------------------------- /tests/unit/cupynumeric/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | from __future__ import annotations 17 | -------------------------------------------------------------------------------- /tests/unit/cupynumeric/_array/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | from __future__ import annotations 17 | -------------------------------------------------------------------------------- /tests/unit/cupynumeric/_utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | from __future__ import annotations 17 | -------------------------------------------------------------------------------- /tests/unit/cupynumeric/random/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | from __future__ import annotations 17 | -------------------------------------------------------------------------------- /tests/unit/cupynumeric/_sphinxext/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # 16 | 17 | from __future__ import annotations 18 | -------------------------------------------------------------------------------- /cupynumeric/install_info.pyi: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | def get_libpath() -> str: ... 17 | 18 | libpath: str 19 | header: str 20 | -------------------------------------------------------------------------------- /.github/release.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. 2 | # All rights reserved. 3 | # SPDX-License-Identifier: Apache-2.0 4 | --- 5 | changelog: 6 | exclude: 7 | labels: 8 | - category:task 9 | - Build 10 | - CI 11 | - Maintenance 12 | categories: 13 | - title: 🐛 Bug Fixes 14 | labels: 15 | - category:bug-fix 16 | - Bug 17 | - title: 🚀 New Features 18 | labels: 19 | - category:new-feature 20 | - Feature 21 | - title: 🛠️ Improvements 22 | labels: 23 | - category:improvement 24 | - title: 📖 Documentation 25 | labels: 26 | - category:documentation 27 | - Docs 28 | -------------------------------------------------------------------------------- /cupynumeric/linalg/_exception.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | __all__ = ("LinAlgError",) 17 | 18 | from numpy.linalg.linalg import LinAlgError # noqa: F401 19 | -------------------------------------------------------------------------------- /src/cupynumeric.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/ndarray.h" 18 | #include "cupynumeric/operators.h" 19 | #include "cupynumeric/slice.h" 20 | -------------------------------------------------------------------------------- /cmake/versions.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": { 3 | "legate": { 4 | "always_download": false, 5 | "anaconda_label": "main", 6 | "artifact_name": "${{ inputs.platform }}-${{ inputs.build-type }}-<>-python${{ inputs.python-version }}-${{ inputs.target-device }}-release-with_tests-${{ inputs.network }}-<>", 7 | "artifact_workflow": "ci-gh.yml", 8 | "git_shallow": false, 9 | "git_tag": "40a4e586599ac9c382bf3068c6e9187bc2ad200a", 10 | "git_url": "git@github.com:nv-legate/legate.internal.git", 11 | "nightly_workflow": "ci-gh-nightly-release.yml", 12 | "org": "nv-legate", 13 | "repo": "legate.internal", 14 | "version": "26.01.00" 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/statistics.rst: -------------------------------------------------------------------------------- 1 | Statistics 2 | ========== 3 | 4 | .. currentmodule:: cupynumeric 5 | 6 | Order statistics 7 | ---------------- 8 | 9 | .. autosummary:: 10 | :toctree: generated/ 11 | 12 | quantile 13 | percentile 14 | nanquantile 15 | nanpercentile 16 | 17 | Averages and variances 18 | ---------------------- 19 | 20 | .. autosummary:: 21 | :toctree: generated/ 22 | 23 | average 24 | mean 25 | nanmean 26 | var 27 | median 28 | nanmedian 29 | 30 | Correlating 31 | ----------- 32 | 33 | .. autosummary:: 34 | :toctree: generated/ 35 | 36 | cov 37 | 38 | Histograms 39 | ---------- 40 | 41 | .. autosummary:: 42 | :toctree: generated/ 43 | 44 | bincount 45 | histogram 46 | histogram2d 47 | histogramdd 48 | digitize 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | \#*# 3 | */typestubs/* 4 | .#* 5 | .DS_Store 6 | *.a 7 | *.d 8 | *.o 9 | *.so 10 | *.gz 11 | *.gcno 12 | *.gcda 13 | *.gcov 14 | core 15 | *.fluid 16 | *.pyc 17 | *.swp 18 | *.log 19 | *.bbl 20 | *.blg 21 | *.aux 22 | *.dylib 23 | legate_python 24 | openblas 25 | OpenBLAS 26 | legion 27 | gasnet* 28 | legion_defines.h 29 | realm_defines.h 30 | cupynumeric/install_info.py 31 | /build/* 32 | /docs/cupynumeric/build 33 | /docs/cupynumeric/source/api/generated 34 | /docs/cupynumeric/source/comparison/comparison_table.rst.inc 35 | *.egg-info 36 | .cache 37 | .vscode 38 | .pytest_cache 39 | /install* 40 | /dist 41 | /_skbuild 42 | /_cmake_test_compile 43 | .ipynb_checkpoints 44 | .legate-test-last-failed 45 | compile_commands.json 46 | reconfigure-* 47 | *-arch/ 48 | scripts/get_cupynumeric_arch.py 49 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/fft.rst: -------------------------------------------------------------------------------- 1 | .. module:: cupynumeric.fft 2 | 3 | Discrete Fourier Transform (:mod:`cupynumeric.fft`) 4 | =================================================== 5 | 6 | Standard FFTs 7 | --------------- 8 | 9 | .. autosummary:: 10 | :toctree: generated/ 11 | 12 | fft 13 | ifft 14 | fft2 15 | ifft2 16 | fftn 17 | ifftn 18 | 19 | 20 | Real FFTs 21 | --------- 22 | 23 | .. autosummary:: 24 | :toctree: generated/ 25 | 26 | rfft 27 | irfft 28 | rfft2 29 | irfft2 30 | rfftn 31 | irfftn 32 | 33 | 34 | Hermitian FFTs 35 | -------------- 36 | 37 | .. autosummary:: 38 | :toctree: generated/ 39 | 40 | hfft 41 | ihfft 42 | 43 | 44 | Helper routines 45 | --------------- 46 | 47 | .. autosummary:: 48 | :toctree: generated/ 49 | 50 | fftshift 51 | ifftshift 52 | -------------------------------------------------------------------------------- /continuous_integration/scripts/tools/legate-configure-sccache: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # A utility script that configures sccache environment variables 3 | 4 | export CMAKE_CUDA_COMPILER_LAUNCHER=sccache 5 | export CMAKE_CXX_COMPILER_LAUNCHER=sccache 6 | export CMAKE_C_COMPILER_LAUNCHER=sccache 7 | export RUSTC_WRAPPER=sccache 8 | export PARALLEL_LEVEL=${PARALLEL_LEVEL:-$(nproc --all --ignore=2)} 9 | export SCCACHE_BUCKET=rapids-sccache-east 10 | export SCCACHE_IDLE_TIMEOUT=32768 11 | export SCCACHE_REGION=us-east-2 12 | export SCCACHE_S3_KEY_PREFIX=legate-cunumeric-dev 13 | export SCCACHE_S3_NO_CREDENTIALS=false 14 | export SCCACHE_S3_USE_SSL=true 15 | 16 | if [[ "${CI:-false}" == "false" ]]; then 17 | # Configure sccache for read-only mode since no credentials 18 | # are available in local builds. 19 | export SCCACHE_S3_NO_CREDENTIALS=true 20 | fi 21 | -------------------------------------------------------------------------------- /cupynumeric/_utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | from __future__ import annotations 16 | 17 | import numpy as np 18 | 19 | is_np2 = np.lib.NumpyVersion(np.__version__) >= "2.0.0b1" 20 | is_np2_1 = np.lib.NumpyVersion(np.__version__) >= "2.1.0b1" 21 | -------------------------------------------------------------------------------- /src/cupynumeric/slice.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | namespace cupynumeric { 22 | 23 | using slice = legate::Slice; 24 | 25 | constexpr auto open = legate::Slice::OPEN; 26 | 27 | } // namespace cupynumeric 28 | -------------------------------------------------------------------------------- /scripts/conda-build.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | 3 | # mamba create -n cupynumeric_build python=$PYTHON_VERSION boa git 4 | 5 | cd $(dirname "$(realpath "$0")")/.. 6 | 7 | mkdir -p /tmp/conda-build/cupynumeric 8 | rm -rf /tmp/conda-build/cupynumeric/* 9 | 10 | PYTHON_VERSION="${PYTHON_VERSION:-3.11}" 11 | 12 | CUDA="$(nvcc --version | head -n4 | tail -n1 | cut -d' ' -f5 | cut -d',' -f1).*" \ 13 | conda mambabuild \ 14 | --override-channels \ 15 | -c conda-forge -c https://github.com/nv-legate/ucx-package/raw/main \ 16 | -c file:///tmp/conda-build/legate_core \ 17 | --croot /tmp/conda-build/cupynumeric \ 18 | --no-test \ 19 | --no-verify \ 20 | --no-build-id \ 21 | --build-id-pat='' \ 22 | --merge-build-host \ 23 | --no-include-recipe \ 24 | --no-anaconda-upload \ 25 | --variants "{gpu_enabled: 'true', python: $PYTHON_VERSION}" \ 26 | ./conda/conda-build 27 | -------------------------------------------------------------------------------- /tests/integration/test_min_on_gpu.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | import pytest 17 | 18 | import cupynumeric as num 19 | 20 | 21 | def test_min(): 22 | x = num.array([1, 2, 3]) 23 | assert num.min(x) == 1 24 | 25 | 26 | if __name__ == "__main__": 27 | import sys 28 | 29 | sys.exit(pytest.main(sys.argv)) 30 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/creation.rst: -------------------------------------------------------------------------------- 1 | Array creation routines 2 | ======================= 3 | 4 | .. currentmodule:: cupynumeric 5 | 6 | From shape or value 7 | ------------------- 8 | 9 | .. autosummary:: 10 | :toctree: generated/ 11 | 12 | empty 13 | empty_like 14 | eye 15 | identity 16 | ones 17 | ones_like 18 | zeros 19 | zeros_like 20 | full 21 | full_like 22 | 23 | 24 | From existing data 25 | ------------------ 26 | 27 | .. autosummary:: 28 | :toctree: generated/ 29 | 30 | array 31 | asarray 32 | copy 33 | copyto 34 | repeat 35 | 36 | 37 | Numerical ranges 38 | ---------------- 39 | 40 | .. autosummary:: 41 | :toctree: generated/ 42 | 43 | arange 44 | logspace 45 | linspace 46 | meshgrid 47 | 48 | 49 | Building matrices 50 | ----------------- 51 | 52 | .. autosummary:: 53 | :toctree: generated/ 54 | 55 | diag 56 | diagflat 57 | tri 58 | tril 59 | triu 60 | -------------------------------------------------------------------------------- /src/cupynumeric/bits/bits_util.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cupynumeric/cupynumeric_c.h" 20 | 21 | namespace cupynumeric { 22 | 23 | enum class Bitorder { 24 | BIG = CUPYNUMERIC_BITORDER_BIG, 25 | LITTLE = CUPYNUMERIC_BITORDER_LITTLE, 26 | }; 27 | 28 | } // namespace cupynumeric 29 | -------------------------------------------------------------------------------- /src/cupynumeric/utilities/thrust_util.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #if THRUST_VERSION >= 101600 23 | #define DEFAULT_POLICY thrust::cuda::par_nosync 24 | #else 25 | #define DEFAULT_POLICY thrust::cuda::par 26 | #endif 27 | -------------------------------------------------------------------------------- /cupynumeric/_ufunc/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | from __future__ import annotations 16 | 17 | from .bit_twiddling import * # noqa: F403 18 | from .comparison import * # noqa: F403 19 | from .math import * # noqa: F403 20 | from .floating import * # noqa: F403 21 | from .trigonometric import * # noqa: F403 22 | from .ufunc import ufunc # noqa: F401 23 | -------------------------------------------------------------------------------- /docs/cupynumeric/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /src/cupynumeric/random/randutil/randutil_impl.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | #include "randutil.h" 19 | 20 | namespace randutilimpl { 21 | 22 | enum class execlocation : int { DEVICE = 0, HOST = 1 }; 23 | 24 | template 25 | struct inner_generator; 26 | 27 | } // namespace randutilimpl 28 | -------------------------------------------------------------------------------- /cupynumeric/_sphinxext/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | from __future__ import annotations 16 | 17 | from typing import TypedDict 18 | 19 | 20 | class SphinxParallelSpec(TypedDict): 21 | parallel_read_safe: bool 22 | parallel_write_safe: bool 23 | 24 | 25 | PARALLEL_SAFE = SphinxParallelSpec( 26 | parallel_read_safe=True, parallel_write_safe=True 27 | ) 28 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/indexing.rst: -------------------------------------------------------------------------------- 1 | Indexing routines 2 | ================= 3 | 4 | .. currentmodule:: cupynumeric 5 | 6 | Generating index arrays 7 | ----------------------- 8 | 9 | .. autosummary:: 10 | :toctree: generated/ 11 | 12 | unravel_index 13 | diag_indices 14 | diag_indices_from 15 | mask_indices 16 | tril_indices 17 | tril_indices_from 18 | triu_indices 19 | triu_indices_from 20 | indices 21 | ix_ 22 | nonzero 23 | flatnonzero 24 | where 25 | ravel_multi_index 26 | 27 | 28 | Indexing-like operations 29 | ------------------------ 30 | 31 | .. autosummary:: 32 | :toctree: generated/ 33 | 34 | choose 35 | compress 36 | diag 37 | diagonal 38 | select 39 | take 40 | take_along_axis 41 | 42 | 43 | Inserting data into arrays 44 | -------------------------- 45 | 46 | .. autosummary:: 47 | :toctree: generated/ 48 | 49 | fill_diagonal 50 | put 51 | putmask 52 | put_along_axis 53 | place 54 | -------------------------------------------------------------------------------- /tests/integration/test_inlinemap-keeps-region-alive.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | import gc 17 | 18 | import pytest 19 | 20 | import cupynumeric as num 21 | 22 | 23 | def test_all(): 24 | for i in range(200): 25 | for arr in num.ones((2,)): 26 | gc.collect() 27 | 28 | 29 | if __name__ == "__main__": 30 | import sys 31 | 32 | sys.exit(pytest.main(sys.argv)) 33 | -------------------------------------------------------------------------------- /cupynumeric/_sphinxext/_templates.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | from __future__ import annotations 16 | 17 | from os.path import dirname, join 18 | 19 | from jinja2 import Environment, FileSystemLoader 20 | 21 | _templates_path = join(dirname(__file__), "_templates") 22 | _env = Environment(loader=FileSystemLoader(_templates_path)) 23 | 24 | COMPARISON_TABLE = _env.get_template("comparison_table.rst") 25 | -------------------------------------------------------------------------------- /src/cupynumeric/arg_redop_register.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/arg_redop_register.h" 18 | 19 | extern "C" { 20 | 21 | ReductionOpIds cupynumeric_register_reduction_ops(int code) 22 | { 23 | return legate::type_dispatch(static_cast(code), 24 | cupynumeric::register_reduction_op_fn{}); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/cupynumeric/random/randutil/generator_poisson.inl: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "generator.h" 18 | 19 | #include "randomizer.h" 20 | 21 | struct poisson { 22 | double lambda = 1.0; 23 | 24 | template 25 | RANDUTIL_QUALIFIERS unsigned operator()(gen_t& gen) 26 | { 27 | return randutilimpl::engine_poisson(gen, lambda); 28 | } 29 | }; 30 | -------------------------------------------------------------------------------- /cupynumeric/fft/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | from __future__ import annotations 16 | 17 | import numpy.fft as _npfft 18 | 19 | from .._array.util import maybe_convert_to_np_ndarray 20 | from .._utils.coverage import clone_module 21 | from .fft import * # noqa: F403 22 | 23 | clone_module(_npfft, globals(), maybe_convert_to_np_ndarray) 24 | 25 | del maybe_convert_to_np_ndarray 26 | del clone_module 27 | del _npfft 28 | -------------------------------------------------------------------------------- /src/cupynumeric/index/take_omp.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2025 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/index/take.h" 18 | #include "cupynumeric/index/take_template.inl" 19 | #include 20 | 21 | namespace cupynumeric { 22 | 23 | using namespace legate; 24 | 25 | void TakeTask::omp_variant(TaskContext context) { take_template(context, thrust::omp::par); } 26 | 27 | } // namespace cupynumeric 28 | -------------------------------------------------------------------------------- /cupynumeric/linalg/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | from __future__ import annotations 16 | 17 | import numpy.linalg as _nplinalg 18 | 19 | from .._array.util import maybe_convert_to_np_ndarray 20 | from .._utils.coverage import clone_module 21 | from .linalg import * # noqa: F403 22 | 23 | clone_module(_nplinalg, globals(), maybe_convert_to_np_ndarray) 24 | 25 | del maybe_convert_to_np_ndarray 26 | del clone_module 27 | del _nplinalg 28 | -------------------------------------------------------------------------------- /src/cupynumeric/random/randutil/generator_raw.inl: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "generator.h" 18 | 19 | #include "randomizer.h" 20 | 21 | template 22 | struct raw; 23 | 24 | template <> 25 | struct raw { 26 | template 27 | RANDUTIL_QUALIFIERS uint32_t operator()(gen_t& gen) 28 | { 29 | return (uint32_t)randutilimpl::engine_rand(gen); 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /src/cupynumeric/random/randutil/generator_zipf.inl: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "generator.h" 18 | #include "random_distributions.h" 19 | 20 | template 21 | struct zipf_t; 22 | 23 | template <> 24 | struct zipf_t { 25 | double a; 26 | 27 | template 28 | RANDUTIL_QUALIFIERS uint32_t operator()(gen_t& gen) 29 | { 30 | return rk_zipf(&gen, a); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /cupynumeric/ma/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | from __future__ import annotations 16 | 17 | import numpy.ma as _ma 18 | 19 | from .._array.util import maybe_convert_to_np_ndarray 20 | from .._utils.coverage import clone_module 21 | from ._masked_array import MaskedArray 22 | 23 | masked_array = MaskedArray 24 | 25 | clone_module(_ma, globals(), maybe_convert_to_np_ndarray) 26 | 27 | del maybe_convert_to_np_ndarray 28 | del clone_module 29 | del _ma 30 | -------------------------------------------------------------------------------- /src/cupynumeric/index/putmask.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/execution_policy/indexing/parallel_loop.cuh" 18 | #include "cupynumeric/index/putmask.h" 19 | #include "cupynumeric/index/putmask_template.inl" 20 | 21 | namespace cupynumeric { 22 | 23 | /*static*/ void PutmaskTask::gpu_variant(TaskContext context) 24 | { 25 | putmask_template(context); 26 | } 27 | 28 | } // namespace cupynumeric 29 | -------------------------------------------------------------------------------- /src/cupynumeric/index/putmask_omp.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/execution_policy/indexing/parallel_loop_omp.h" 18 | #include "cupynumeric/index/putmask.h" 19 | #include "cupynumeric/index/putmask_template.inl" 20 | 21 | namespace cupynumeric { 22 | 23 | /*static*/ void PutmaskTask::omp_variant(TaskContext context) 24 | { 25 | putmask_template(context); 26 | } 27 | 28 | } // namespace cupynumeric 29 | -------------------------------------------------------------------------------- /src/cupynumeric/index/take.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2025 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/index/take.h" 18 | #include "cupynumeric/index/take_template.inl" 19 | #include "cupynumeric/cuda_help.h" 20 | 21 | namespace cupynumeric { 22 | 23 | using namespace legate; 24 | 25 | void TakeTask::gpu_variant(TaskContext context) 26 | { 27 | take_template(context, DEFAULT_POLICY.on(context.get_task_stream())); 28 | } 29 | 30 | } // namespace cupynumeric 31 | -------------------------------------------------------------------------------- /src/cupynumeric/random/randutil/generator_logseries.inl: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "generator.h" 18 | #include "random_distributions.h" 19 | 20 | template 21 | struct logseries_t; 22 | 23 | template <> 24 | struct logseries_t { 25 | double p; 26 | 27 | template 28 | RANDUTIL_QUALIFIERS uint32_t operator()(gen_t& gen) 29 | { 30 | return rk_logseries(&gen, p); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /src/cupynumeric/typedefs.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include "legate.h" 22 | 23 | #ifndef __CUDA_HD__ 24 | #ifdef __CUDACC__ 25 | #define __CUDA_HD__ __host__ __device__ 26 | #else 27 | #define __CUDA_HD__ 28 | #endif 29 | #endif 30 | 31 | namespace cupynumeric { 32 | 33 | using Array = legate::PhysicalStore; 34 | using Scalar = legate::Scalar; 35 | 36 | } // namespace cupynumeric 37 | -------------------------------------------------------------------------------- /src/cupynumeric/random/randutil/generator_geometric.inl: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "generator.h" 18 | #include "random_distributions.h" 19 | 20 | template 21 | struct geometric_t; 22 | 23 | template <> 24 | struct geometric_t { 25 | double p; 26 | 27 | template 28 | RANDUTIL_QUALIFIERS uint32_t operator()(gen_t& gen) 29 | { 30 | return (uint32_t)rk_geometric(&gen, p); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /src/cupynumeric/set/unique_reduce_omp.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/set/unique_reduce.h" 18 | #include "cupynumeric/set/unique_reduce_template.inl" 19 | 20 | #include 21 | 22 | namespace cupynumeric { 23 | 24 | /*static*/ void UniqueReduceTask::omp_variant(TaskContext context) 25 | { 26 | unique_reduce_template(context, thrust::omp::par); 27 | } 28 | 29 | } // namespace cupynumeric 30 | -------------------------------------------------------------------------------- /tests/integration/test_map_reduce.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | import numpy as np 17 | import pytest 18 | 19 | import cupynumeric as num 20 | 21 | 22 | def test_basic(): 23 | x = [1.0, 2, 3] 24 | y = [4, 5, 6] 25 | z = x + y 26 | 27 | cx = num.array(x) 28 | cy = num.array(y) 29 | cz = cx + cy 30 | 31 | assert num.sum(cz) == np.sum(z) 32 | 33 | 34 | if __name__ == "__main__": 35 | import sys 36 | 37 | sys.exit(pytest.main(sys.argv)) 38 | -------------------------------------------------------------------------------- /continuous_integration/scripts/make-conda-env: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -x 4 | 5 | . conda-utils 6 | 7 | make_release_env() { 8 | legate-conda-retry create -q -y -n "${CONDA_ENV}" -c conda-forge boa 9 | } 10 | 11 | make_docs_env() { 12 | set -xeuo pipefail 13 | 14 | export DEBIAN_FRONTEND=non-interactive 15 | export CONDA_ENV=legate 16 | 17 | # Run package updates and install packages 18 | apt-get update 19 | apt-get install -y numactl make 20 | 21 | legate-conda-retry create -yn "${CONDA_ENV}" pandoc doxygen 22 | 23 | . conda-utils; 24 | activate_conda_env; 25 | 26 | # mamba install -y pandoc doxygen 27 | pip install ipython jinja2 "markdown<3.4.0" myst-parser nbsphinx sphinx-copybutton "sphinx>=8" nvidia-sphinx-theme cffi 28 | } 29 | 30 | make_conda_env() { 31 | set -xeuo pipefail 32 | 33 | case "$1" in 34 | ci) make_release_env;; 35 | nightly) make_release_env;; 36 | docs) make_docs_env;; 37 | *) return 1;; 38 | esac 39 | 40 | return 0; 41 | } 42 | 43 | (make_conda_env "$@"); 44 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/logic.rst: -------------------------------------------------------------------------------- 1 | Logic functions 2 | =============== 3 | 4 | .. currentmodule:: cupynumeric 5 | 6 | Truth value testing 7 | ------------------- 8 | 9 | .. autosummary:: 10 | :toctree: generated/ 11 | 12 | all 13 | any 14 | 15 | 16 | Array contents 17 | -------------- 18 | 19 | .. autosummary:: 20 | :toctree: generated/ 21 | 22 | isfinite 23 | isinf 24 | isnan 25 | isneginf 26 | isposinf 27 | 28 | 29 | Array type testing 30 | ------------------ 31 | 32 | .. autosummary:: 33 | :toctree: generated/ 34 | 35 | iscomplex 36 | iscomplexobj 37 | isreal 38 | isrealobj 39 | isscalar 40 | 41 | 42 | Logic operations 43 | ---------------- 44 | 45 | .. autosummary:: 46 | :toctree: generated/ 47 | 48 | logical_and 49 | logical_or 50 | logical_not 51 | logical_xor 52 | 53 | 54 | Comparison 55 | ---------- 56 | 57 | .. autosummary:: 58 | :toctree: generated/ 59 | 60 | allclose 61 | isclose 62 | array_equal 63 | greater 64 | greater_equal 65 | less 66 | less_equal 67 | equal 68 | not_equal 69 | -------------------------------------------------------------------------------- /src/cupynumeric/random/randutil/generator_hypergeometric.inl: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "generator.h" 18 | #include "random_distributions.h" 19 | 20 | template 21 | struct hypergeometric_t { 22 | int_t ngood, nbad, nsample; 23 | 24 | template 25 | RANDUTIL_QUALIFIERS uint32_t operator()(gen_t& gen) 26 | { 27 | return (uint32_t)rk_hypergeometric(&gen, (long)ngood, (long)nbad, (long)nsample); 28 | } 29 | }; 30 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/qr_omp.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/matrix/qr.h" 18 | #include "cupynumeric/matrix/qr_template.inl" 19 | #include "cupynumeric/matrix/qr_cpu.inl" 20 | 21 | #include 22 | 23 | namespace cupynumeric { 24 | 25 | /*static*/ void QrTask::omp_variant(TaskContext context) 26 | { 27 | blas_set_num_threads(omp_get_max_threads()); 28 | qr_template(context); 29 | } 30 | 31 | } // namespace cupynumeric 32 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/svd_omp.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/matrix/svd.h" 18 | #include "cupynumeric/matrix/svd_template.inl" 19 | #include "cupynumeric/matrix/svd_cpu.inl" 20 | 21 | #include 22 | 23 | namespace cupynumeric { 24 | 25 | /*static*/ void SvdTask::omp_variant(TaskContext context) 26 | { 27 | blas_set_num_threads(omp_get_max_threads()); 28 | svd_template(context); 29 | } 30 | 31 | } // namespace cupynumeric 32 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/geev_omp.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/matrix/geev.h" 18 | #include "cupynumeric/matrix/geev_template.inl" 19 | #include "cupynumeric/matrix/geev_cpu.inl" 20 | 21 | #include 22 | 23 | namespace cupynumeric { 24 | 25 | /*static*/ void GeevTask::omp_variant(TaskContext context) 26 | { 27 | blas_set_num_threads(omp_get_max_threads()); 28 | geev_template(context); 29 | } 30 | 31 | } // namespace cupynumeric 32 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/syev_omp.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/matrix/syev.h" 18 | #include "cupynumeric/matrix/syev_template.inl" 19 | #include "cupynumeric/matrix/syev_cpu.inl" 20 | 21 | #include 22 | 23 | namespace cupynumeric { 24 | 25 | /*static*/ void SyevTask::omp_variant(TaskContext context) 26 | { 27 | blas_set_num_threads(omp_get_max_threads()); 28 | syev_template(context); 29 | } 30 | 31 | } // namespace cupynumeric 32 | -------------------------------------------------------------------------------- /src/cupynumeric/unary/scalar_unary_red_omp.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/unary/scalar_unary_red.h" 18 | #include "cupynumeric/unary/scalar_unary_red_template.inl" 19 | #include "cupynumeric/execution_policy/reduction/scalar_reduction_omp.h" 20 | 21 | namespace cupynumeric { 22 | 23 | /*static*/ void ScalarUnaryRedTask::omp_variant(TaskContext context) 24 | { 25 | scalar_unary_red_template(context); 26 | } 27 | 28 | } // namespace cupynumeric 29 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/solve_omp.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/matrix/solve.h" 18 | #include "cupynumeric/matrix/solve_template.inl" 19 | #include "cupynumeric/matrix/solve_cpu.inl" 20 | 21 | #include 22 | 23 | namespace cupynumeric { 24 | 25 | /*static*/ void SolveTask::omp_variant(TaskContext context) 26 | { 27 | blas_set_num_threads(omp_get_max_threads()); 28 | solve_template(context); 29 | } 30 | 31 | } // namespace cupynumeric 32 | -------------------------------------------------------------------------------- /tests/todo/complex_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | import numpy as np 17 | 18 | import cupynumeric as num 19 | 20 | M = 32 21 | alpha = 4.0 22 | beta = -10.0 23 | rate = 0.01 24 | 25 | 26 | def test(): 27 | x = num.linspace(-4.0, 4.0, M) 28 | dz = 1.0 + 1j * rate * (12 * x**2 + 2 * alpha) 29 | 30 | xn = np.linspace(-4.0, 4.0, M) 31 | dzn = 1.0 + 1j * rate * (12 * xn**2 + 2 * alpha) 32 | 33 | assert num.all(num.abs(dz - dzn) < 1e-6) 34 | 35 | 36 | if __name__ == "__main__": 37 | test() 38 | -------------------------------------------------------------------------------- /cmake/thirdparty/get_lapack.cmake: -------------------------------------------------------------------------------- 1 | #============================================================================= 2 | # Copyright 2025 NVIDIA Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | #============================================================================= 16 | 17 | function(find_lapack) 18 | if (TARGET LAPACK::LAPACK) 19 | return() 20 | endif() 21 | rapids_find_package(LAPACK) 22 | endfunction() 23 | 24 | find_lapack() 25 | 26 | if (NOT TARGET LAPACK::LAPACK) 27 | message(FATAL_ERROR "CuPyNumeric could not find a working LAPACK installation") 28 | endif() 29 | -------------------------------------------------------------------------------- /src/cupynumeric/random/randutil/generator_binomial.inl: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "generator.h" 18 | #include "random_distributions.h" 19 | 20 | template 21 | struct binomial_t; 22 | 23 | template <> 24 | struct binomial_t { 25 | uint32_t n; 26 | double p; 27 | 28 | template 29 | RANDUTIL_QUALIFIERS float operator()(gen_t& gen) 30 | { 31 | // TODO: fp32 implementation ? 32 | return (uint32_t)rk_binomial(&gen, n, p); 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/index.rst: -------------------------------------------------------------------------------- 1 | :html_theme.sidebar_secondary.remove: 2 | 3 | NVIDIA cuPyNumeric 4 | ================== 5 | 6 | cuPyNumeric implements the NumPy API on top of the Legate framework, 7 | providing transparent accelerated computing that scales from a single CPU 8 | to a single GPU, and up to multi-node, multi-GPU systems. 9 | 10 | For example, you can run `the final example of the Python CFD course`_ 11 | completely unmodified on 2048 A100 GPUs in a `DGX SuperPOD`_ and achieve 12 | good weak scaling. 13 | 14 | .. toctree:: 15 | :maxdepth: 1 16 | :caption: Contents: 17 | 18 | installation 19 | user/index 20 | examples/index 21 | api/index 22 | faqs 23 | developer/index 24 | acknowledgments 25 | oss-licenses 26 | 27 | 28 | Indices and tables 29 | ------------------ 30 | 31 | * :ref:`genindex` 32 | * :ref:`search` 33 | 34 | .. _NumPy: https://numpy.org/ 35 | .. _Legate: https://github.com/nv-legate/legate 36 | .. _DGX SuperPOD: https://www.nvidia.com/en-us/data-center/dgx-superpod/ 37 | .. _the final example of the Python CFD course: https://github.com/barbagroup/CFDPython/blob/master/lessons/15_Step_12.ipynb 38 | -------------------------------------------------------------------------------- /continuous_integration/scripts/tools/legate-gh-run-id: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # SPDX-FileCopyrightText: Copyright (c) 2025-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 4 | # SPDX-License-Identifier: Apache-2.0 5 | 6 | # A utility script adapted from https://github.com/rapidsai/gha-tools/blob/main/tools/rapids-github-run-id 7 | # This gets the GitHub run ID for the specified workflow and commit SHA. 8 | 9 | set -euo pipefail 10 | 11 | # Default values for the environment variables. 12 | LEGATE_WORKFLOW_NAME=${LEGATE_WORKFLOW_NAME:-"pr.yml"} 13 | LEGATE_REPO_NAME=${LEGATE_REPO_NAME:-"nv-legate/legate.internal"} 14 | 15 | # Check if the script was called with exactly 1 argument 16 | if [[ ${#} -ne 1 ]]; then 17 | echo "Error: This script requires exactly 1 argument (the git SHA). You provided ${#}" 18 | echo "Usage: ${0} git-sha" 19 | exit 1 20 | fi 21 | 22 | gh_run_id=$(gh run list \ 23 | --repo "${LEGATE_REPO_NAME}" \ 24 | --workflow "${LEGATE_WORKFLOW_NAME}" \ 25 | --commit "${1}" \ 26 | --json 'createdAt,databaseId' \ 27 | --jq 'sort_by(.createdAt) | reverse | .[0] | .databaseId') 28 | 29 | echo -n "${gh_run_id}" 30 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/matmul_omp.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/matrix/matmul.h" 18 | #include "cupynumeric/matrix/matmul_template.inl" 19 | #include "cupynumeric/matrix/matmul_cpu.inl" 20 | 21 | #include 22 | 23 | namespace cupynumeric { 24 | 25 | using namespace legate; 26 | 27 | /*static*/ void MatMulTask::omp_variant(TaskContext context) 28 | { 29 | blas_set_num_threads(omp_get_max_threads()); 30 | matmul_template(context); 31 | } 32 | 33 | } // namespace cupynumeric 34 | -------------------------------------------------------------------------------- /tests/integration/test_update.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | import pytest 17 | 18 | import cupynumeric as num 19 | 20 | 21 | def test_basic(): 22 | C = num.random.randn(2, 3, 5) 23 | IFOGf = num.random.randn(2, 3, 20) 24 | C[1] = 1.0 25 | C[1] += IFOGf[1, :, :5] * IFOGf[1, :, 15:] 26 | temp = IFOGf[1, :, :5] * IFOGf[1, :, 15:] 27 | assert not num.array_equal(C[1], temp) 28 | 29 | print(C[1]) 30 | print(temp) 31 | 32 | 33 | if __name__ == "__main__": 34 | import sys 35 | 36 | sys.exit(pytest.main(sys.argv)) 37 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/matvecmul_omp.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/matrix/matvecmul.h" 18 | #include "cupynumeric/matrix/matvecmul_template.inl" 19 | #include "cupynumeric/matrix/matvecmul_cpu.inl" 20 | 21 | #include 22 | 23 | namespace cupynumeric { 24 | 25 | using namespace legate; 26 | 27 | /*static*/ void MatVecMulTask::omp_variant(TaskContext context) 28 | { 29 | blas_set_num_threads(omp_get_max_threads()); 30 | matvecmul_template(context); 31 | } 32 | 33 | } // namespace cupynumeric 34 | -------------------------------------------------------------------------------- /src/cupynumeric/index/take.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2025 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/index/take.h" 18 | #include "cupynumeric/index/take_template.inl" 19 | 20 | namespace cupynumeric { 21 | 22 | using namespace legate; 23 | 24 | void TakeTask::cpu_variant(TaskContext context) { take_template(context, thrust::host); } 25 | 26 | namespace // unnamed 27 | { 28 | 29 | static const auto cupynumeric_reg_task_ = []() -> char { 30 | TakeTask::register_variants(); 31 | return 0; 32 | }(); 33 | 34 | } // namespace 35 | 36 | } // namespace cupynumeric 37 | -------------------------------------------------------------------------------- /src/cupynumeric/ndarray.inl: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | namespace cupynumeric { 18 | 19 | template 20 | legate::AccessorRO NDArray::get_read_accessor() 21 | { 22 | auto mapped = store_.get_physical_store(); 23 | return mapped.read_accessor(); 24 | } 25 | 26 | template 27 | legate::AccessorWO NDArray::get_write_accessor() 28 | { 29 | auto mapped = store_.get_physical_store(); 30 | return mapped.write_accessor(); 31 | } 32 | 33 | } // namespace cupynumeric 34 | -------------------------------------------------------------------------------- /cmake/thirdparty/get_cusolvermp.cmake: -------------------------------------------------------------------------------- 1 | #============================================================================= 2 | # Copyright 2025 NVIDIA Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | #============================================================================= 16 | 17 | function(find_or_configure_cusolvermp) 18 | if(TARGET CUSOLVERMP::CUSOLVERMP) 19 | return() 20 | endif() 21 | 22 | rapids_find_generate_module(CUSOLVERMP 23 | HEADER_NAMES cusolverMp.h 24 | LIBRARY_NAMES cusolverMp 25 | ) 26 | 27 | rapids_find_package(CUSOLVERMP REQUIRED) 28 | endfunction() 29 | 30 | find_or_configure_cusolvermp() 31 | -------------------------------------------------------------------------------- /src/cupynumeric/index/putmask.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/index/putmask.h" 18 | #include "cupynumeric/index/putmask_template.inl" 19 | 20 | namespace cupynumeric { 21 | 22 | /*static*/ void PutmaskTask::cpu_variant(TaskContext context) 23 | { 24 | putmask_template(context); 25 | } 26 | 27 | namespace // unnamed 28 | { 29 | static const auto cupynumeric_reg_task_ = []() -> char { 30 | PutmaskTask::register_variants(); 31 | return 0; 32 | }(); 33 | } // namespace 34 | 35 | } // namespace cupynumeric 36 | -------------------------------------------------------------------------------- /examples/cpp/stencil/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2024 NVIDIA Corporation 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | legate_root=`python -c 'import legate.install_info as i; from pathlib import Path; print(Path(i.libpath).parent.resolve())'` 18 | echo "Using Legate at $legate_root" 19 | cupynumeric_root=`python -c 'import cupynumeric.install_info as i; from pathlib import Path; print(Path(i.libpath).parent.resolve())'` 20 | echo "Using cuPyNumeric at $cupynumeric_root" 21 | cmake -S . -B build -D legate_ROOT="$legate_root" -D cupynumeric_ROOT="$cupynumeric_root" -D CMAKE_BUILD_TYPE=Debug 22 | cmake --build build --parallel 8 23 | -------------------------------------------------------------------------------- /tests/integration/test_0d_store.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | from itertools import product 17 | 18 | import pytest 19 | 20 | import cupynumeric as num 21 | 22 | SIZE = 3 23 | 24 | 25 | def test_0d_region_backed_stores(): 26 | arr = num.arange(9).reshape(3, 3) 27 | 28 | for i, j in product(range(SIZE), range(SIZE)): 29 | i_ind = num.array(i) 30 | j_ind = num.array(j) 31 | v = arr[i_ind, j_ind] 32 | assert int(v) == i * SIZE + j 33 | 34 | 35 | if __name__ == "__main__": 36 | import sys 37 | 38 | sys.exit(pytest.main(sys.argv)) 39 | -------------------------------------------------------------------------------- /examples/cpp/gemm/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2024 NVIDIA Corporation 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | legate_root=`python -c 'import legate.install_info as i; from pathlib import Path; print(Path(i.libpath).parent.resolve())'` 18 | echo "Using Legate at $legate_root" 19 | cupynumeric_root=`python -c 'import cupynumeric.install_info as i; from pathlib import Path; print(Path(i.libpath).parent.resolve())'` 20 | echo "Using cuPyNumeric at $cupynumeric_root" 21 | cmake -S . -B build -D legate_ROOT="$legate_root" -D cupynumeric_ROOT="$cupynumeric_root" -D CMAKE_BUILD_TYPE=RelWithDebInfo 22 | cmake --build build --parallel 8 23 | -------------------------------------------------------------------------------- /src/cupynumeric/unary/scalar_unary_red.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/cupynumeric_task.h" 18 | #include "cupynumeric/unary/scalar_unary_red.h" 19 | #include "cupynumeric/unary/scalar_unary_red_template.inl" 20 | #include "cupynumeric/execution_policy/reduction/scalar_reduction.cuh" 21 | 22 | namespace cupynumeric { 23 | 24 | using namespace legate; 25 | 26 | /*static*/ void ScalarUnaryRedTask::gpu_variant(TaskContext context) 27 | { 28 | scalar_unary_red_template(context); 29 | } 30 | 31 | } // namespace cupynumeric 32 | -------------------------------------------------------------------------------- /src/cupynumeric/set/unique_reduce.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/set/unique_reduce.h" 18 | #include "cupynumeric/set/unique_reduce_template.inl" 19 | 20 | namespace cupynumeric { 21 | 22 | /*static*/ void UniqueReduceTask::cpu_variant(TaskContext context) 23 | { 24 | unique_reduce_template(context, thrust::host); 25 | } 26 | 27 | namespace // unnamed 28 | { 29 | const auto cupynumeric_reg_task_ = []() -> char { 30 | UniqueReduceTask::register_variants(); 31 | return 0; 32 | }(); 33 | } // namespace 34 | 35 | } // namespace cupynumeric 36 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/user/howtos/patching.rst: -------------------------------------------------------------------------------- 1 | Trying Numpy code without changes 2 | ================================= 3 | 4 | The ``lgpatch`` script (in the same location as the ``legate`` executable) can 5 | help facilitate quick demonstrations of ``cupynumeric`` on existing codebases 6 | that make use of ``numpy``. 7 | 8 | To use this tool, invoke it as shown below, with the name of the program to 9 | patch: 10 | 11 | .. code-block:: sh 12 | 13 | lgpatch -patch numpy 14 | 15 | For example, here is a small ``test.py`` program that imports and uses various 16 | ``numpy`` funtions: 17 | 18 | .. code-block:: python 19 | 20 | # test.py 21 | 22 | import numpy as np 23 | input = np.eye(10, dtype=np.float32) 24 | np.linalg.cholesky(input) 25 | 26 | You can invoke ``lgpatch`` to run ``test.py`` using ``cupynumeric`` functions 27 | instead, without any changes to the original source code. Any standard 28 | ``cupynumeric`` runtime options (e.g. for :ref:`measuring api coverage`) may 29 | also be used: 30 | 31 | .. code-block:: sh 32 | 33 | $ CUPYNUMERIC_REPORT_COVERAGE=1 LEGATE_CONFIG="--cpus 4" lgpatch test.py -patch numpy 34 | cuPyNumeric API coverage: 4/4 (100.0%) 35 | -------------------------------------------------------------------------------- /src/cupynumeric/unary/scalar_unary_red.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/unary/scalar_unary_red.h" 18 | #include "cupynumeric/unary/scalar_unary_red_template.inl" 19 | 20 | namespace cupynumeric { 21 | 22 | /*static*/ void ScalarUnaryRedTask::cpu_variant(TaskContext context) 23 | { 24 | scalar_unary_red_template(context); 25 | } 26 | 27 | namespace // unnamed 28 | { 29 | const auto cupynumeric_reg_task_ = []() -> char { 30 | ScalarUnaryRedTask::register_variants(); 31 | return 0; 32 | }(); 33 | } // namespace 34 | 35 | } // namespace cupynumeric 36 | -------------------------------------------------------------------------------- /src/cupynumeric/cupynumeric_task.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "legate.h" 20 | #include "cupynumeric/typedefs.h" 21 | #include "cupynumeric/cupynumeric_c.h" 22 | 23 | namespace cupynumeric { 24 | 25 | enum class VariantKind : int { 26 | CPU = 0, 27 | OMP = 1, 28 | GPU = 2, 29 | }; 30 | 31 | struct CuPyNumericRegistrar { 32 | static legate::TaskRegistrar& get_registrar(); 33 | }; 34 | 35 | template 36 | struct CuPyNumericTask : public legate::LegateTask { 37 | using Registrar = CuPyNumericRegistrar; 38 | }; 39 | 40 | } // namespace cupynumeric 41 | -------------------------------------------------------------------------------- /src/env_defaults.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | // These values are copied manually in cupynumeric.settings and there is a Python 18 | // unit test that will maintain that these values and the Python settings 19 | // values agree. If these values are modified, the corresponding Python values 20 | // must also be updated. 21 | 22 | // 1 << 13 (need actual number for python to parse) 23 | #define MAX_EAGER_VOLUME_DEFAULT 8192 24 | #define MAX_EAGER_VOLUME_TEST 2 25 | 26 | // 1 << 27 (need actual number for python to parse) 27 | #define MATMUL_CACHE_SIZE_DEFAULT 134217728 28 | #define MATMUL_CACHE_SIZE_TEST 4096 29 | -------------------------------------------------------------------------------- /docs/cupynumeric/source/api/linalg.rst: -------------------------------------------------------------------------------- 1 | .. module:: cupynumeric.linalg 2 | 3 | Linear algebra (:mod:`cupynumeric.linalg`) 4 | ========================================== 5 | 6 | .. currentmodule:: cupynumeric 7 | 8 | Matrix and vector products 9 | -------------------------- 10 | 11 | .. autosummary:: 12 | :toctree: generated/ 13 | 14 | dot 15 | vdot 16 | inner 17 | outer 18 | matmul 19 | tensordot 20 | einsum 21 | einsum_path 22 | linalg.matrix_power 23 | linalg.multi_dot 24 | 25 | Decompositions 26 | -------------- 27 | 28 | .. autosummary:: 29 | :toctree: generated/ 30 | 31 | linalg.cholesky 32 | linalg.eig 33 | linalg.eigh 34 | linalg.eigvals 35 | linalg.eigvalsh 36 | linalg.qr 37 | linalg.svd 38 | 39 | Norms and other numbers 40 | ----------------------- 41 | 42 | .. autosummary:: 43 | :toctree: generated/ 44 | 45 | linalg.norm 46 | trace 47 | 48 | 49 | Solving equations and inverting matrices 50 | ---------------------------------------- 51 | 52 | .. autosummary:: 53 | :toctree: generated/ 54 | 55 | linalg.solve 56 | linalg.pinv 57 | 58 | 59 | Matrix Functions 60 | ---------------- 61 | 62 | .. autosummary:: 63 | :toctree: generated/ 64 | 65 | linalg.expm 66 | -------------------------------------------------------------------------------- /src/cupynumeric/utilities/thrust_allocator.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "legate.h" 20 | 21 | namespace cupynumeric { 22 | 23 | class ThrustAllocator : public legate::ScopedAllocator { 24 | public: 25 | using value_type = char; 26 | 27 | ThrustAllocator(legate::Memory::Kind kind) : legate::ScopedAllocator(kind) {} 28 | 29 | char* allocate(size_t num_bytes) 30 | { 31 | return static_cast(ScopedAllocator::allocate(num_bytes)); 32 | } 33 | 34 | void deallocate(char* ptr, size_t n) { ScopedAllocator::deallocate(ptr); } 35 | }; 36 | 37 | } // namespace cupynumeric 38 | -------------------------------------------------------------------------------- /examples/cpp/gemm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #============================================================================= 2 | # Copyright 2024 NVIDIA Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | #============================================================================= 16 | 17 | cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) 18 | 19 | project(stencil VERSION 0.1 LANGUAGES C CXX) 20 | 21 | if (NOT CMAKE_CXX_STANDARD) 22 | set(CMAKE_CXX_STANDARD 17) 23 | endif() 24 | 25 | find_package(cupynumeric REQUIRED) 26 | 27 | add_executable(gemm gemm.cc) 28 | 29 | target_link_libraries(gemm PRIVATE cupynumeric::cupynumeric) 30 | 31 | install(TARGETS gemm DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/cmake-install") 32 | -------------------------------------------------------------------------------- /tests/unit/util.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | from __future__ import annotations 17 | 18 | from itertools import chain, combinations 19 | from typing import Any, Iterable, Iterator, TypeAlias 20 | 21 | import pytest 22 | 23 | Capsys: TypeAlias = pytest.CaptureFixture[str] 24 | 25 | 26 | # ref: https://docs.python.org/3/library/itertools.html 27 | def powerset(iterable: Iterable[Any]) -> Iterator[Any]: 28 | s = list(iterable) 29 | return chain.from_iterable(combinations(s, r) for r in range(len(s) + 1)) 30 | 31 | 32 | def powerset_nonempty(iterable: Iterable[Any]) -> Iterator[Any]: 33 | return (x for x in powerset(iterable) if len(x)) 34 | -------------------------------------------------------------------------------- /src/cupynumeric/random/randutil/generator_negative_binomial.inl: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "generator.h" 18 | #include "random_distributions.h" 19 | 20 | #include "randomizer.h" 21 | 22 | template 23 | struct negative_binomial_t; 24 | 25 | template <> 26 | struct negative_binomial_t { 27 | uint32_t n; 28 | double p; 29 | 30 | template 31 | RANDUTIL_QUALIFIERS float operator()(gen_t& gen) 32 | { 33 | double lambda = rk_standard_gamma(&gen, (double)n) * ((1 - p) / p); 34 | return static_cast(randutilimpl::engine_poisson(gen, lambda)); 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /src/cupynumeric/random/randutil/randutil_curand.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | // This header file imports some head-only part of curand for the HOST-side implementation of 20 | // generators 21 | 22 | // also allow usage of generators on host 23 | #if LEGATE_DEFINED(LEGATE_USE_CUDA) 24 | 25 | #define QUALIFIERS static __forceinline__ __device__ __host__ 26 | #define RANDUTIL_QUALIFIERS __forceinline__ __device__ __host__ 27 | #include 28 | 29 | #else 30 | // host generators are not compiled with nvcc 31 | #define QUALIFIERS static 32 | #define RANDUTIL_QUALIFIERS 33 | #include 34 | #endif 35 | -------------------------------------------------------------------------------- /tests/integration/test_copy.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | import numpy as np 17 | import pytest 18 | 19 | import cupynumeric as num 20 | 21 | 22 | def test_basic(): 23 | x = num.array([[1, 2, 3], [4, 5, 6]]) 24 | y = num.array([[7, 8, 9], [10, 11, 12]]) 25 | xc = x.copy() 26 | yc = y.copy() 27 | x[0, :] = [7, 8, 9] 28 | y = num.array([[10, 12, 13], [25, 26, 27]]) 29 | w = x + y 30 | wc = xc + yc 31 | assert np.array_equal(w, [[17, 20, 22], [29, 31, 33]]) 32 | assert np.array_equal(wc, [[8, 10, 12], [14, 16, 18]]) 33 | 34 | 35 | if __name__ == "__main__": 36 | import sys 37 | 38 | sys.exit(pytest.main(sys.argv)) 39 | -------------------------------------------------------------------------------- /cupynumeric/random/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | from __future__ import annotations 16 | 17 | import numpy.random as _nprandom 18 | 19 | from .._array.util import maybe_convert_to_np_ndarray 20 | from .._utils.coverage import clone_module 21 | from ..runtime import runtime 22 | 23 | from ._random import * # noqa: F403 24 | from ._bitgenerator import * # noqa: F403 25 | from ._generator import * # noqa: F403 26 | 27 | clone_module( 28 | _nprandom, 29 | globals(), 30 | maybe_convert_to_np_ndarray, 31 | include_builtin_function_type=True, 32 | ) 33 | 34 | del maybe_convert_to_np_ndarray 35 | del clone_module 36 | del runtime 37 | del _nprandom 38 | -------------------------------------------------------------------------------- /examples/cpp/stencil/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #============================================================================= 2 | # Copyright 2024 NVIDIA Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | #============================================================================= 16 | 17 | cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) 18 | 19 | project(stencil VERSION 0.1 LANGUAGES C CXX) 20 | 21 | if (NOT CMAKE_CXX_STANDARD) 22 | set(CMAKE_CXX_STANDARD 17) 23 | endif() 24 | 25 | find_package(cupynumeric REQUIRED) 26 | 27 | add_executable(stencil stencil.cc) 28 | 29 | target_link_libraries(stencil PRIVATE cupynumeric::cupynumeric) 30 | 31 | install(TARGETS stencil DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/cmake-install") 32 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/cub_sort_bool.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/cub_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void cub_local_sort(const bool* values_in, 22 | bool* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | cudaStream_t stream) 28 | { 29 | detail::cub_local_sort( 30 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stream); 31 | } 32 | 33 | } // namespace cupynumeric 34 | -------------------------------------------------------------------------------- /cupynumeric/patch.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | """This module may be imported in order to globably replace NumPy with 16 | cuPyNumeric. 17 | 18 | In order to function properly, this module must be imported early (ideally 19 | at the very start of a script). The ``numpy`` module in ``sys.modules`` 20 | will be replaced with ``cupynumeric`` so that any subsequent use of the 21 | ``numpy`` module will use ``cupynumeric`` instead. 22 | 23 | This module is primarily intended for quick demonstrations or proofs of 24 | concept. 25 | 26 | """ 27 | 28 | from __future__ import annotations 29 | 30 | import sys 31 | 32 | import cupynumeric 33 | 34 | sys.modules["numpy"] = cupynumeric 35 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/cub_sort_double.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/cub_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void cub_local_sort(const double* values_in, 22 | double* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | cudaStream_t stream) 28 | { 29 | detail::cub_local_sort( 30 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stream); 31 | } 32 | 33 | } // namespace cupynumeric 34 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/cub_sort_float.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/cub_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void cub_local_sort(const float* values_in, 22 | float* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | cudaStream_t stream) 28 | { 29 | detail::cub_local_sort( 30 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stream); 31 | } 32 | 33 | } // namespace cupynumeric 34 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/cub_sort_int16.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/cub_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void cub_local_sort(const int16_t* values_in, 22 | int16_t* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | cudaStream_t stream) 28 | { 29 | detail::cub_local_sort( 30 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stream); 31 | } 32 | 33 | } // namespace cupynumeric 34 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/cub_sort_int32.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/cub_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void cub_local_sort(const int32_t* values_in, 22 | int32_t* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | cudaStream_t stream) 28 | { 29 | detail::cub_local_sort( 30 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stream); 31 | } 32 | 33 | } // namespace cupynumeric 34 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/cub_sort_int64.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/cub_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void cub_local_sort(const int64_t* values_in, 22 | int64_t* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | cudaStream_t stream) 28 | { 29 | detail::cub_local_sort( 30 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stream); 31 | } 32 | 33 | } // namespace cupynumeric 34 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/cub_sort_int8.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/cub_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void cub_local_sort(const int8_t* values_in, 22 | int8_t* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | cudaStream_t stream) 28 | { 29 | detail::cub_local_sort( 30 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stream); 31 | } 32 | 33 | } // namespace cupynumeric 34 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/cub_sort_uint8.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/cub_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void cub_local_sort(const uint8_t* values_in, 22 | uint8_t* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | cudaStream_t stream) 28 | { 29 | detail::cub_local_sort( 30 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stream); 31 | } 32 | 33 | } // namespace cupynumeric 34 | -------------------------------------------------------------------------------- /cmake/thirdparty/get_nccl.cmake: -------------------------------------------------------------------------------- 1 | #============================================================================= 2 | # Copyright 2024 NVIDIA Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | #============================================================================= 16 | 17 | function(find_or_configure_nccl) 18 | 19 | if(TARGET NCCL::NCCL) 20 | return() 21 | endif() 22 | 23 | rapids_find_generate_module(NCCL 24 | HEADER_NAMES nccl.h 25 | LIBRARY_NAMES nccl 26 | ) 27 | 28 | # Currently NCCL has no CMake build-system so we require 29 | # it built and installed on the machine already 30 | rapids_find_package(NCCL REQUIRED) 31 | 32 | endfunction() 33 | 34 | find_or_configure_nccl() 35 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/mp_qr.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2025 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cupynumeric/cupynumeric_task.h" 20 | 21 | namespace cupynumeric { 22 | 23 | class MpQRTask : public CuPyNumericTask { 24 | public: 25 | static inline const auto TASK_CONFIG = legate::TaskConfig{legate::LocalTaskID{CUPYNUMERIC_MP_QR}}; 26 | 27 | static constexpr auto GPU_VARIANT_OPTIONS = 28 | legate::VariantOptions{}.with_has_allocations(true).with_concurrent(true); 29 | 30 | public: 31 | #if LEGATE_DEFINED(LEGATE_USE_CUDA) 32 | static void gpu_variant(legate::TaskContext context); 33 | #endif 34 | }; 35 | 36 | } // namespace cupynumeric 37 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/cub_sort_uint16.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/cub_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void cub_local_sort(const uint16_t* values_in, 22 | uint16_t* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | cudaStream_t stream) 28 | { 29 | detail::cub_local_sort( 30 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stream); 31 | } 32 | 33 | } // namespace cupynumeric 34 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/cub_sort_uint32.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/cub_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void cub_local_sort(const uint32_t* values_in, 22 | uint32_t* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | cudaStream_t stream) 28 | { 29 | detail::cub_local_sort( 30 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stream); 31 | } 32 | 33 | } // namespace cupynumeric 34 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/cub_sort_uint64.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/cub_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void cub_local_sort(const uint64_t* values_in, 22 | uint64_t* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | cudaStream_t stream) 28 | { 29 | detail::cub_local_sort( 30 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stream); 31 | } 32 | 33 | } // namespace cupynumeric 34 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/cub_sort_half.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/cub_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void cub_local_sort(const legate::Half* values_in, 22 | legate::Half* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | cudaStream_t stream) 28 | { 29 | detail::cub_local_sort( 30 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stream); 31 | } 32 | 33 | } // namespace cupynumeric 34 | -------------------------------------------------------------------------------- /tests/cpp/cmake/thirdparty/get_nccl.cmake: -------------------------------------------------------------------------------- 1 | #============================================================================= 2 | # Copyright 2024 NVIDIA Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | #============================================================================= 16 | 17 | function(find_or_configure_nccl) 18 | 19 | if(TARGET NCCL::NCCL) 20 | return() 21 | endif() 22 | 23 | rapids_find_generate_module(NCCL 24 | HEADER_NAMES nccl.h 25 | LIBRARY_NAMES nccl 26 | ) 27 | 28 | # Currently NCCL has no CMake build-system so we require 29 | # it built and installed on the machine already 30 | rapids_find_package(NCCL REQUIRED) 31 | 32 | endfunction() 33 | 34 | find_or_configure_nccl() 35 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/mp_potrf.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cupynumeric/cupynumeric_task.h" 20 | 21 | namespace cupynumeric { 22 | 23 | class MpPotrfTask : public CuPyNumericTask { 24 | public: 25 | static inline const auto TASK_CONFIG = 26 | legate::TaskConfig{legate::LocalTaskID{CUPYNUMERIC_MP_POTRF}}; 27 | 28 | static constexpr auto GPU_VARIANT_OPTIONS = 29 | legate::VariantOptions{}.with_has_allocations(true).with_concurrent(true); 30 | 31 | public: 32 | #if LEGATE_DEFINED(LEGATE_USE_CUDA) 33 | static void gpu_variant(legate::TaskContext context); 34 | #endif 35 | }; 36 | 37 | } // namespace cupynumeric 38 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/mp_solve.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cupynumeric/cupynumeric_task.h" 20 | 21 | namespace cupynumeric { 22 | 23 | class MpSolveTask : public CuPyNumericTask { 24 | public: 25 | static inline const auto TASK_CONFIG = 26 | legate::TaskConfig{legate::LocalTaskID{CUPYNUMERIC_MP_SOLVE}}; 27 | 28 | static constexpr auto GPU_VARIANT_OPTIONS = 29 | legate::VariantOptions{}.with_has_allocations(true).with_concurrent(true); 30 | 31 | public: 32 | #if LEGATE_DEFINED(LEGATE_USE_CUDA) 33 | static void gpu_variant(legate::TaskContext context); 34 | #endif 35 | }; 36 | 37 | } // namespace cupynumeric 38 | -------------------------------------------------------------------------------- /src/cupynumeric/stat/histogramdd_omp.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2025 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | namespace cupynumeric { 23 | using namespace legate; 24 | 25 | void HistogramDDTask::omp_variant(TaskContext context) 26 | { 27 | auto memkind = Memory::Kind::SOCKET_MEM; 28 | // TODO(tisaac): use ScopedAllocator in the policy when it is safe to call 29 | // from OpenMP thread 30 | auto policy = thrust::omp::par; 31 | 32 | detail::histogramdd_using_thrust(context, policy, memkind); 33 | } 34 | 35 | } // namespace cupynumeric 36 | -------------------------------------------------------------------------------- /scripts/hooks/legate_defined.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | output=$( 3 | grep -E \ 4 | -n \ 5 | -H \ 6 | -C 1 \ 7 | --color=always \ 8 | -e '#\s*if[n]?def\s+LEGATE_\w+' \ 9 | -e '#(\s*if\s+)?[!]?defined\s*\(\s*LEGATE_\w+' \ 10 | -e '#.*defined\s*\(\s*LEGATE_\w+' \ 11 | -e '#\s*elif\s+LEGATE_\w+' \ 12 | -- \ 13 | "$@" 14 | ) 15 | rc=$? 16 | if [[ ${rc} -eq 1 ]]; then 17 | # no matches found, that's a good thing 18 | exit 0 19 | elif [[ ${rc} -eq 0 ]]; then 20 | echo "x ===------------------------------------------------------------------=== x" 21 | echo "${output}" 22 | echo "" 23 | echo "Instances of preprocessor ifdef/ifndef/if defined found, use" 24 | echo "LEGATE_DEFINED() instead:" 25 | echo "" 26 | echo "- #ifdef LEGATE_USE_FOO" 27 | echo "- #include \"foo.h\"" 28 | echo "- #endif" 29 | echo "+ #if LEGATE_DEFINED(LEGATE_USE_FOO)" 30 | echo "+ #include \"foo.h\"" 31 | echo "+ #endif" 32 | echo "" 33 | echo "- #ifdef LEGATE_USE_FOO" 34 | echo "- x = 2;" 35 | echo "- #endif" 36 | echo "+ if (LEGATE_DEFINED(LEGATE_USE_FOO)) {" 37 | echo "+ x = 2;" 38 | echo "+ }" 39 | echo "x ===------------------------------------------------------------------=== x" 40 | exit 1 41 | else 42 | exit ${rc} 43 | fi 44 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/trsm.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cupynumeric/cupynumeric_task.h" 20 | 21 | namespace cupynumeric { 22 | 23 | class TrsmTask : public CuPyNumericTask { 24 | public: 25 | static inline const auto TASK_CONFIG = legate::TaskConfig{legate::LocalTaskID{CUPYNUMERIC_TRSM}}; 26 | 27 | public: 28 | static void cpu_variant(legate::TaskContext context); 29 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 30 | static void omp_variant(legate::TaskContext context); 31 | #endif 32 | #if LEGATE_DEFINED(LEGATE_USE_CUDA) 33 | static void gpu_variant(legate::TaskContext context); 34 | #endif 35 | }; 36 | 37 | } // namespace cupynumeric 38 | -------------------------------------------------------------------------------- /cmake/thirdparty/get_cutensor.cmake: -------------------------------------------------------------------------------- 1 | #============================================================================= 2 | # Copyright 2024 NVIDIA Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | #============================================================================= 16 | 17 | function(find_or_configure_cutensor) 18 | 19 | if(TARGET cutensor::cutensor) 20 | return() 21 | endif() 22 | 23 | rapids_find_generate_module(cutensor 24 | HEADER_NAMES cutensor.h 25 | LIBRARY_NAMES cutensor 26 | ) 27 | 28 | # Currently cutensor has no CMake build-system so we require 29 | # it built and installed on the machine already 30 | rapids_find_package(cutensor REQUIRED) 31 | 32 | endfunction() 33 | 34 | find_or_configure_cutensor() 35 | -------------------------------------------------------------------------------- /src/cupynumeric/stat/histogramdd.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2025 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace cupynumeric { 23 | using namespace legate; 24 | 25 | void HistogramDDTask::gpu_variant(TaskContext context) 26 | { 27 | auto memkind = Memory::Kind::GPU_FB_MEM; 28 | auto alloc = ThrustAllocator(memkind); 29 | auto policy = DEFAULT_POLICY(alloc).on(context.get_task_stream()); 30 | 31 | detail::histogramdd_using_thrust(context, policy, memkind); 32 | } 33 | 34 | } // namespace cupynumeric 35 | -------------------------------------------------------------------------------- /src/cupynumeric/nullary/window.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cupynumeric/cupynumeric_task.h" 20 | 21 | namespace cupynumeric { 22 | 23 | class WindowTask : public CuPyNumericTask { 24 | public: 25 | static inline const auto TASK_CONFIG = 26 | legate::TaskConfig{legate::LocalTaskID{CUPYNUMERIC_WINDOW}}; 27 | 28 | public: 29 | static void cpu_variant(legate::TaskContext context); 30 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 31 | static void omp_variant(legate::TaskContext context); 32 | #endif 33 | #if LEGATE_DEFINED(LEGATE_USE_CUDA) 34 | static void gpu_variant(legate::TaskContext context); 35 | #endif 36 | }; 37 | 38 | } // namespace cupynumeric 39 | -------------------------------------------------------------------------------- /tests/unit/cupynumeric/test_nptest.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | import pytest 17 | 18 | from cupynumeric import test as nptest 19 | 20 | MSG = ( 21 | "cuPyNumeric cannot execute numpy.test() due to reliance " 22 | "on Numpy internals. For information about running the " 23 | "cuPyNumeric test suite, see: " 24 | "https://docs.nvidia.com/cupynumeric/latest/developer/index.html" 25 | ) 26 | 27 | 28 | def test_warning() -> None: 29 | with pytest.warns(UserWarning) as record: 30 | nptest(1, 2, 3, foo=10) 31 | 32 | assert len(record) == 1 33 | assert record[0].message.args[0] == MSG 34 | 35 | 36 | if __name__ == "__main__": 37 | import sys 38 | 39 | sys.exit(pytest.main(sys.argv)) 40 | -------------------------------------------------------------------------------- /cmake/generate_install_info_py.cmake: -------------------------------------------------------------------------------- 1 | #============================================================================= 2 | # Copyright 2024 NVIDIA Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | #============================================================================= 16 | 17 | execute_process( 18 | COMMAND ${CMAKE_C_COMPILER} 19 | -E -DLEGATE_USE_PYTHON_CFFI 20 | -I "${CMAKE_CURRENT_LIST_DIR}/../src/cupynumeric" 21 | -P "${CMAKE_CURRENT_LIST_DIR}/../src/cupynumeric/cupynumeric_c.h" 22 | ECHO_ERROR_VARIABLE 23 | OUTPUT_VARIABLE header 24 | COMMAND_ERROR_IS_FATAL ANY 25 | ) 26 | 27 | set(libpath "") 28 | configure_file( 29 | "${CMAKE_CURRENT_LIST_DIR}/../cupynumeric/install_info.py.in" 30 | "${CMAKE_CURRENT_LIST_DIR}/../cupynumeric/install_info.py" 31 | @ONLY) 32 | -------------------------------------------------------------------------------- /tests/todo/2d_reduction_complex.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | import numpy as np 17 | 18 | import cupynumeric as num 19 | 20 | 21 | def test(): 22 | anp = np.array( 23 | [[1 + 2j, 3 + 4j, 5 + 6j], [7 + 8j, 9 + 10j, 11 + 12j]], np.complex 24 | ) 25 | a = num.array(anp) 26 | 27 | r = a.sum(0) 28 | assert num.all(num.abs(r - anp.sum(0)) < 1e-5) 29 | 30 | r = a.sum(1) 31 | assert num.all(num.abs(r - anp.sum(1)) < 1e-5) 32 | 33 | assert num.all(num.abs(a.mean(0) - anp.mean(0)) < 1e-5) 34 | assert num.all(num.abs(a.mean(1) - anp.mean(1)) < 1e-5) 35 | assert num.all(num.abs(a.mean() - anp.mean()) < 1e-5) 36 | 37 | return 38 | 39 | 40 | if __name__ == "__main__": 41 | test() 42 | -------------------------------------------------------------------------------- /src/cupynumeric/item/read.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cupynumeric/cupynumeric_task.h" 20 | 21 | namespace cupynumeric { 22 | 23 | class ReadTask : public CuPyNumericTask { 24 | public: 25 | static inline const auto TASK_CONFIG = legate::TaskConfig{legate::LocalTaskID{CUPYNUMERIC_READ}}; 26 | 27 | public: 28 | static void cpu_variant(legate::TaskContext context); 29 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 30 | static void omp_variant(legate::TaskContext context) { ReadTask::cpu_variant(context); } 31 | #endif 32 | #if LEGATE_DEFINED(LEGATE_USE_CUDA) 33 | static void gpu_variant(legate::TaskContext context); 34 | #endif 35 | }; 36 | 37 | } // namespace cupynumeric 38 | -------------------------------------------------------------------------------- /src/cupynumeric/item/write.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cupynumeric/cupynumeric_task.h" 20 | 21 | namespace cupynumeric { 22 | 23 | class WriteTask : public CuPyNumericTask { 24 | public: 25 | static inline const auto TASK_CONFIG = legate::TaskConfig{legate::LocalTaskID{CUPYNUMERIC_WRITE}}; 26 | 27 | public: 28 | static void cpu_variant(legate::TaskContext context); 29 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 30 | static void omp_variant(legate::TaskContext context) { WriteTask::cpu_variant(context); } 31 | #endif 32 | #if LEGATE_DEFINED(LEGATE_USE_CUDA) 33 | static void gpu_variant(legate::TaskContext context); 34 | #endif 35 | }; 36 | 37 | } // namespace cupynumeric 38 | -------------------------------------------------------------------------------- /cupynumeric/_sphinxext/_cupynumeric_directive.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | from __future__ import annotations 16 | 17 | from docutils import nodes 18 | from docutils.statemachine import StringList 19 | from sphinx.util.docutils import SphinxDirective 20 | from sphinx.util.nodes import nested_parse_with_titles 21 | 22 | 23 | class CupynumericDirective(SphinxDirective): 24 | def parse(self, rst_text: str, annotation: str) -> list[nodes.Node]: 25 | result = StringList() 26 | for line in rst_text.split("\n"): 27 | result.append(line, annotation) 28 | node = nodes.paragraph() 29 | node.document = self.state.document 30 | nested_parse_with_titles(self.state, result, node) 31 | return node.children 32 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/thrust_sort_bool.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/thrust_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void thrust_local_sort(const bool* values_in, 22 | bool* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | const bool stable, 28 | cudaStream_t stream) 29 | { 30 | detail::thrust_local_sort( 31 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stable, stream); 32 | } 33 | 34 | } // namespace cupynumeric 35 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/thrust_sort_double.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/thrust_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void thrust_local_sort(const double* values_in, 22 | double* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | const bool stable, 28 | cudaStream_t stream) 29 | { 30 | detail::thrust_local_sort( 31 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stable, stream); 32 | } 33 | 34 | } // namespace cupynumeric 35 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/thrust_sort_float.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/thrust_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void thrust_local_sort(const float* values_in, 22 | float* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | const bool stable, 28 | cudaStream_t stream) 29 | { 30 | detail::thrust_local_sort( 31 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stable, stream); 32 | } 33 | 34 | } // namespace cupynumeric 35 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/thrust_sort_int16.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/thrust_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void thrust_local_sort(const int16_t* values_in, 22 | int16_t* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | const bool stable, 28 | cudaStream_t stream) 29 | { 30 | detail::thrust_local_sort( 31 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stable, stream); 32 | } 33 | 34 | } // namespace cupynumeric 35 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/thrust_sort_int32.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/thrust_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void thrust_local_sort(const int32_t* values_in, 22 | int32_t* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | const bool stable, 28 | cudaStream_t stream) 29 | { 30 | detail::thrust_local_sort( 31 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stable, stream); 32 | } 33 | 34 | } // namespace cupynumeric 35 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/thrust_sort_int64.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/thrust_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void thrust_local_sort(const int64_t* values_in, 22 | int64_t* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | const bool stable, 28 | cudaStream_t stream) 29 | { 30 | detail::thrust_local_sort( 31 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stable, stream); 32 | } 33 | 34 | } // namespace cupynumeric 35 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/thrust_sort_int8.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/thrust_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void thrust_local_sort(const int8_t* values_in, 22 | int8_t* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | const bool stable, 28 | cudaStream_t stream) 29 | { 30 | detail::thrust_local_sort( 31 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stable, stream); 32 | } 33 | 34 | } // namespace cupynumeric 35 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/thrust_sort_uint8.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/thrust_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void thrust_local_sort(const uint8_t* values_in, 22 | uint8_t* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | const bool stable, 28 | cudaStream_t stream) 29 | { 30 | detail::thrust_local_sort( 31 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stable, stream); 32 | } 33 | 34 | } // namespace cupynumeric 35 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/gemm.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cupynumeric/cupynumeric_task.h" 20 | #include "cupynumeric/utilities/blas_lapack.h" 21 | 22 | namespace cupynumeric { 23 | 24 | class GemmTask : public CuPyNumericTask { 25 | public: 26 | static inline const auto TASK_CONFIG = legate::TaskConfig{legate::LocalTaskID{CUPYNUMERIC_GEMM}}; 27 | 28 | public: 29 | static void cpu_variant(legate::TaskContext context); 30 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 31 | static void omp_variant(legate::TaskContext context); 32 | #endif 33 | #if LEGATE_DEFINED(LEGATE_USE_CUDA) 34 | static void gpu_variant(legate::TaskContext context); 35 | #endif 36 | }; 37 | 38 | } // namespace cupynumeric 39 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/syrk.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cupynumeric/cupynumeric_task.h" 20 | #include "cupynumeric/utilities/blas_lapack.h" 21 | 22 | namespace cupynumeric { 23 | 24 | class SyrkTask : public CuPyNumericTask { 25 | public: 26 | static inline const auto TASK_CONFIG = legate::TaskConfig{legate::LocalTaskID{CUPYNUMERIC_SYRK}}; 27 | 28 | public: 29 | static void cpu_variant(legate::TaskContext context); 30 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 31 | static void omp_variant(legate::TaskContext context); 32 | #endif 33 | #if LEGATE_DEFINED(LEGATE_USE_CUDA) 34 | static void gpu_variant(legate::TaskContext context); 35 | #endif 36 | }; 37 | 38 | } // namespace cupynumeric 39 | -------------------------------------------------------------------------------- /src/cupynumeric/random/randutil/generator_beta.inl: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "generator.h" 18 | #include "random_distributions.h" 19 | 20 | template 21 | struct beta_t; 22 | 23 | template <> 24 | struct beta_t { 25 | float a, b; 26 | 27 | template 28 | RANDUTIL_QUALIFIERS float operator()(gen_t& gen) 29 | { 30 | // TODO: fp32 implementation ? 31 | return (float)rk_beta(&gen, (double)a, (double)b); // no float implementation 32 | } 33 | }; 34 | 35 | template <> 36 | struct beta_t { 37 | double a, b; 38 | 39 | template 40 | RANDUTIL_QUALIFIERS double operator()(gen_t& gen) 41 | { 42 | return rk_beta(&gen, a, b); 43 | } 44 | }; 45 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/thrust_sort_uint16.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/thrust_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void thrust_local_sort(const uint16_t* values_in, 22 | uint16_t* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | const bool stable, 28 | cudaStream_t stream) 29 | { 30 | detail::thrust_local_sort( 31 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stable, stream); 32 | } 33 | 34 | } // namespace cupynumeric 35 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/thrust_sort_uint32.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/thrust_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void thrust_local_sort(const uint32_t* values_in, 22 | uint32_t* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | const bool stable, 28 | cudaStream_t stream) 29 | { 30 | detail::thrust_local_sort( 31 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stable, stream); 32 | } 33 | 34 | } // namespace cupynumeric 35 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/thrust_sort_uint64.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/thrust_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void thrust_local_sort(const uint64_t* values_in, 22 | uint64_t* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | const bool stable, 28 | cudaStream_t stream) 29 | { 30 | detail::thrust_local_sort( 31 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stable, stream); 32 | } 33 | 34 | } // namespace cupynumeric 35 | -------------------------------------------------------------------------------- /tests/cpp/main.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include 18 | #include "legate.h" 19 | #include "cupynumeric.h" 20 | 21 | class Environment : public ::testing::Environment { 22 | public: 23 | Environment(int argc, char** argv) : argc_(argc), argv_(argv) {} 24 | 25 | void SetUp() override 26 | { 27 | legate::start(); 28 | cupynumeric::initialize(argc_, argv_); 29 | } 30 | void TearDown() override { EXPECT_EQ(legate::finish(), 0); } 31 | 32 | private: 33 | int argc_; 34 | char** argv_; 35 | }; 36 | 37 | int main(int argc, char** argv) 38 | { 39 | ::testing::InitGoogleTest(&argc, argv); 40 | ::testing::AddGlobalTestEnvironment(new Environment(argc, argv)); 41 | 42 | return RUN_ALL_TESTS(); 43 | } 44 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/thrust_sort_half.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/thrust_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void thrust_local_sort(const legate::Half* values_in, 22 | legate::Half* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | const bool stable, 28 | cudaStream_t stream) 29 | { 30 | detail::thrust_local_sort( 31 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stable, stream); 32 | } 33 | 34 | } // namespace cupynumeric 35 | -------------------------------------------------------------------------------- /tests/integration/test_length.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | import pytest 17 | 18 | import cupynumeric as num 19 | 20 | LIST_X = [1, 2, 3] 21 | 22 | 23 | def test_from_list(): 24 | x = num.array(LIST_X) 25 | assert len(x) == len(LIST_X) 26 | 27 | 28 | def test_random(): 29 | N = 100 30 | x = num.random.random(N) 31 | assert N == len(x) 32 | 33 | 34 | def test_binop(): 35 | x = num.array([1, 2, 3, 4]) 36 | y = num.array([1, 2, 3, 4]) 37 | z = x + y 38 | assert len(x) == len(y) == len(z) 39 | 40 | 41 | def test_method(): 42 | x = num.array(LIST_X) 43 | x = num.sqrt(x) 44 | assert len(x) == len(LIST_X) 45 | 46 | 47 | if __name__ == "__main__": 48 | import sys 49 | 50 | sys.exit(pytest.main(sys.argv)) 51 | -------------------------------------------------------------------------------- /src/cupynumeric/stat/detail/histogramdd_using_thrust.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2025 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | namespace cupynumeric { 22 | 23 | namespace detail { 24 | 25 | template 26 | void histogramdd_using_thrust(legate::TaskContext& context, 27 | const exe_policy_t& policy, 28 | legate::Memory::Kind memkind); 29 | 30 | std::optional histogramdd_using_thrust_allocation_pool_size( 31 | const legate::mapping::Task& task, legate::mapping::StoreTarget memory_kind); 32 | 33 | } // namespace detail 34 | 35 | } // namespace cupynumeric 36 | #include 37 | -------------------------------------------------------------------------------- /src/cupynumeric/operators.inl: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | #include "cupynumeric/runtime.h" 17 | namespace cupynumeric { 18 | 19 | template 20 | NDArray arange(T start, std::optional stop, T step) 21 | { 22 | if (!stop.has_value()) { 23 | stop = start; 24 | start = 0; 25 | } 26 | 27 | int64_t _N = static_cast(std::ceil((stop.value() - start) / static_cast(step))); 28 | size_t N = _N < 0 ? 0 : _N; 29 | 30 | auto s_start = Scalar(start); 31 | auto s_stop = Scalar(stop.value()); 32 | auto s_step = Scalar(step); 33 | auto out = CuPyNumericRuntime::get_runtime()->create_array({N}, s_start.type()); 34 | out.arange(s_start, s_stop, s_step); 35 | return out; 36 | } 37 | 38 | } // namespace cupynumeric 39 | -------------------------------------------------------------------------------- /src/cupynumeric/random/randutil/generator_standard_t.inl: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "generator.h" 18 | #include "random_distributions.h" 19 | 20 | template 21 | struct standard_t_t; 22 | 23 | template <> 24 | struct standard_t_t { 25 | float df; 26 | 27 | template 28 | RANDUTIL_QUALIFIERS float operator()(gen_t& gen) 29 | { 30 | // TODO: fp32 implementation ? 31 | return (float)rk_standard_t(&gen, (double)df); // no float implementation 32 | } 33 | }; 34 | 35 | template <> 36 | struct standard_t_t { 37 | double df; 38 | 39 | template 40 | RANDUTIL_QUALIFIERS double operator()(gen_t& gen) 41 | { 42 | return rk_standard_t(&gen, df); 43 | } 44 | }; 45 | -------------------------------------------------------------------------------- /src/cupynumeric/mapper.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cupynumeric/cupynumeric_task.h" 20 | 21 | namespace cupynumeric { 22 | 23 | class CuPyNumericMapper final : public legate::mapping::Mapper { 24 | // Legate mapping functions 25 | public: 26 | [[nodiscard]] std::vector store_mappings( 27 | const legate::mapping::Task& task, 28 | const std::vector& options) override; 29 | [[nodiscard]] legate::Scalar tunable_value(legate::TunableID tunable_id) override; 30 | [[nodiscard]] std::optional allocation_pool_size( 31 | const legate::mapping::Task& task, legate::mapping::StoreTarget memory_kind) override; 32 | }; 33 | 34 | } // namespace cupynumeric 35 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/thrust_sort_complex64.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/thrust_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void thrust_local_sort(const legate::Complex* values_in, 22 | legate::Complex* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | const bool stable, 28 | cudaStream_t stream) 29 | { 30 | detail::thrust_local_sort( 31 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stable, stream); 32 | } 33 | 34 | } // namespace cupynumeric 35 | -------------------------------------------------------------------------------- /src/cupynumeric/nullary/eye.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cupynumeric/cupynumeric_task.h" 20 | 21 | namespace cupynumeric { 22 | 23 | struct EyeArgs { 24 | legate::PhysicalStore out; 25 | int32_t k; 26 | }; 27 | 28 | class EyeTask : public CuPyNumericTask { 29 | public: 30 | static inline const auto TASK_CONFIG = legate::TaskConfig{legate::LocalTaskID{CUPYNUMERIC_EYE}}; 31 | 32 | public: 33 | static void cpu_variant(legate::TaskContext context); 34 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 35 | static void omp_variant(legate::TaskContext context); 36 | #endif 37 | #if LEGATE_DEFINED(LEGATE_USE_CUDA) 38 | static void gpu_variant(legate::TaskContext context); 39 | #endif 40 | }; 41 | 42 | } // namespace cupynumeric 43 | -------------------------------------------------------------------------------- /src/cupynumeric/sort/thrust_sort_complex128.cu: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/sort/thrust_sort.cuh" 18 | 19 | namespace cupynumeric { 20 | 21 | void thrust_local_sort(const legate::Complex* values_in, 22 | legate::Complex* values_out, 23 | const int64_t* indices_in, 24 | int64_t* indices_out, 25 | const size_t volume, 26 | const size_t sort_dim_size, 27 | const bool stable, 28 | cudaStream_t stream) 29 | { 30 | detail::thrust_local_sort( 31 | values_in, values_out, indices_in, indices_out, volume, sort_dim_size, stable, stream); 32 | } 33 | 34 | } // namespace cupynumeric 35 | -------------------------------------------------------------------------------- /src/cupynumeric/execution_policy/indexing/parallel_loop.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cupynumeric/cupynumeric_task.h" 20 | 21 | namespace cupynumeric { 22 | 23 | template 24 | struct ParallelLoopPolicy {}; 25 | 26 | template 27 | struct ParallelLoopPolicy { 28 | legate::TaskContext context; 29 | ParallelLoopPolicy(legate::TaskContext tcontext) : context(tcontext) {} 30 | 31 | template 32 | void operator()(const RECT& rect, KERNEL&& kernel) 33 | { 34 | const size_t volume = rect.volume(); 35 | for (size_t idx = 0; idx < volume; ++idx) { 36 | kernel(idx, Tag{}); 37 | } 38 | } 39 | }; 40 | 41 | } // namespace cupynumeric 42 | -------------------------------------------------------------------------------- /src/cupynumeric/random/randutil/generator_vonmises.inl: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "generator.h" 18 | #include "random_distributions.h" 19 | 20 | template 21 | struct vonmises_t; 22 | 23 | template <> 24 | struct vonmises_t { 25 | float mu, kappa; 26 | 27 | template 28 | RANDUTIL_QUALIFIERS float operator()(gen_t& gen) 29 | { 30 | // TODO: fp32 implementation ? 31 | return (float)rk_vonmises(&gen, (double)mu, (double)kappa); // no float implementation 32 | } 33 | }; 34 | 35 | template <> 36 | struct vonmises_t { 37 | double mu, kappa; 38 | 39 | template 40 | RANDUTIL_QUALIFIERS double operator()(gen_t& gen) 41 | { 42 | return rk_vonmises(&gen, mu, kappa); 43 | } 44 | }; 45 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/tile.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cupynumeric/cupynumeric_task.h" 20 | 21 | namespace cupynumeric { 22 | 23 | struct TileArgs { 24 | legate::PhysicalStore in; 25 | legate::PhysicalStore out; 26 | }; 27 | 28 | class TileTask : public CuPyNumericTask { 29 | public: 30 | static inline const auto TASK_CONFIG = legate::TaskConfig{legate::LocalTaskID{CUPYNUMERIC_TILE}}; 31 | 32 | public: 33 | static void cpu_variant(legate::TaskContext context); 34 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 35 | static void omp_variant(legate::TaskContext context); 36 | #endif 37 | #if LEGATE_DEFINED(LEGATE_USE_CUDA) 38 | static void gpu_variant(legate::TaskContext context); 39 | #endif 40 | }; 41 | 42 | } // namespace cupynumeric 43 | -------------------------------------------------------------------------------- /src/cupynumeric/random/randutil/generator_gamma.inl: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "generator.h" 18 | #include "random_distributions.h" 19 | 20 | template 21 | struct gamma_t; 22 | 23 | template <> 24 | struct gamma_t { 25 | float shape, scale; 26 | 27 | template 28 | RANDUTIL_QUALIFIERS float operator()(gen_t& gen) 29 | { 30 | // TODO: fp32 implementation ? 31 | return (float)rk_standard_gamma(&gen, (double)shape) * scale; // no float implementation 32 | } 33 | }; 34 | 35 | template <> 36 | struct gamma_t { 37 | double shape, scale; 38 | 39 | template 40 | RANDUTIL_QUALIFIERS double operator()(gen_t& gen) 41 | { 42 | return rk_standard_gamma(&gen, shape) * scale; 43 | } 44 | }; 45 | -------------------------------------------------------------------------------- /src/cupynumeric/random/randutil/generator_lognormal.inl: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "generator.h" 18 | 19 | #include "randomizer.h" 20 | 21 | template 22 | struct lognormal_t; 23 | 24 | template <> 25 | struct lognormal_t { 26 | float mean = 0.0; 27 | float stddev = 1.0; 28 | 29 | template 30 | RANDUTIL_QUALIFIERS float operator()(gen_t& gen) 31 | { 32 | return randutilimpl::engine_log_normal(gen, mean, stddev); 33 | } 34 | }; 35 | 36 | template <> 37 | struct lognormal_t { 38 | double mean = 0.0; 39 | double stddev = 1.0; 40 | 41 | template 42 | RANDUTIL_QUALIFIERS double operator()(gen_t& gen) 43 | { 44 | return randutilimpl::engine_log_normal(gen, mean, stddev); 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /src/cupynumeric/random/randutil/generator_normal.inl: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "generator.h" 18 | 19 | #include "randomizer.h" 20 | 21 | template 22 | struct normal_t; 23 | 24 | template <> 25 | struct normal_t { 26 | float mean = 0.0; 27 | float stddev = 1.0; 28 | 29 | template 30 | RANDUTIL_QUALIFIERS float operator()(gen_t& gen) 31 | { 32 | return stddev * randutilimpl::engine_normal(gen) + mean; 33 | } 34 | }; 35 | 36 | template <> 37 | struct normal_t { 38 | double mean = 0.0; 39 | double stddev = 1.0; 40 | 41 | template 42 | RANDUTIL_QUALIFIERS double operator()(gen_t& gen) 43 | { 44 | return stddev * randutilimpl::engine_normal(gen) + mean; 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/potrf.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cupynumeric/cupynumeric_task.h" 20 | 21 | namespace cupynumeric { 22 | 23 | class PotrfTask : public CuPyNumericTask { 24 | public: 25 | static inline const auto TASK_CONFIG = legate::TaskConfig{legate::LocalTaskID{CUPYNUMERIC_POTRF}}; 26 | 27 | static constexpr auto GPU_VARIANT_OPTIONS = legate::VariantOptions{}.with_has_allocations(true); 28 | 29 | public: 30 | static void cpu_variant(legate::TaskContext context); 31 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 32 | static void omp_variant(legate::TaskContext context); 33 | #endif 34 | #if LEGATE_DEFINED(LEGATE_USE_CUDA) 35 | static void gpu_variant(legate::TaskContext context); 36 | #endif 37 | }; 38 | 39 | } // namespace cupynumeric 40 | -------------------------------------------------------------------------------- /src/cupynumeric/nullary/fill.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cupynumeric/cupynumeric_task.h" 20 | 21 | namespace cupynumeric { 22 | 23 | struct FillArgs { 24 | legate::PhysicalStore out; 25 | legate::PhysicalStore fill_value; 26 | }; 27 | 28 | class FillTask : public CuPyNumericTask { 29 | public: 30 | static inline const auto TASK_CONFIG = legate::TaskConfig{legate::LocalTaskID{CUPYNUMERIC_FILL}}; 31 | 32 | public: 33 | static void cpu_variant(legate::TaskContext context); 34 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 35 | static void omp_variant(legate::TaskContext context); 36 | #endif 37 | #if LEGATE_DEFINED(LEGATE_USE_CUDA) 38 | static void gpu_variant(legate::TaskContext context); 39 | #endif 40 | }; 41 | 42 | } // namespace cupynumeric 43 | -------------------------------------------------------------------------------- /continuous_integration/scripts/conda-dnld-utils: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -x 4 | 5 | generate_legate_version() { 6 | legate_json_version="$(jq -r '.packages.legate.version' ${REPO_DIR}/cmake/versions.json)"; 7 | legate_SHA="$(jq -r '.packages.legate.git_tag' ${REPO_DIR}/cmake/versions.json)"; 8 | legate_hash="g${legate_SHA:0:8}" 9 | export LEGATE_VERSION="${legate_json_version}*" 10 | export LEGATE_BUILDSTR="*${legate_hash}*" 11 | echo "LEGATE_VERSION=${LEGATE_VERSION} : LEGATE_BUILDSTR=${LEGATE_BUILDSTR}" 12 | } 13 | 14 | verify_legate_version() { 15 | legate-conda-retry search legate=${LEGATE_VERSION} --channel https://conda.anaconda.org/${CONDA_CHANNEL}/label/${CONDA_LABEL} 16 | if [ $? -ne 0 ]; then 17 | echo "Error: conda search failed for legate." >&2; exit 1 18 | fi 19 | } 20 | 21 | setup_conda_channel() { 22 | if ! command -v jq &> /dev/null; then 23 | echo "Installing jq" 24 | apt-get update -q 25 | apt-get -q install -y jq 26 | fi 27 | # strict channel ordering is required for prioritizing packages from artifacts 28 | conda config --set channel_priority strict 29 | legate_conda_label="$(jq -r '.packages.legate.anaconda_label' ${REPO_DIR}/cmake/versions.json)"; 30 | export CONDA_CHANNEL="legate-nightly" 31 | export CONDA_LABEL="${legate_conda_label}" 32 | echo "CONDA_CHANNEL=${CONDA_CHANNEL} : CONDA_LABEL=${CONDA_LABEL}" 33 | } 34 | -------------------------------------------------------------------------------- /cupynumeric/types.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | from __future__ import annotations 16 | 17 | from typing import Literal, TypeAlias 18 | 19 | BoundsMode: TypeAlias = Literal["raise", "wrap", "clip"] 20 | 21 | CastingKind: TypeAlias = Literal["no", "equiv", "safe", "same_kind", "unsafe"] 22 | 23 | NdShape: TypeAlias = tuple[int, ...] 24 | 25 | NdShapeLike: TypeAlias = int | NdShape 26 | 27 | SortSide: TypeAlias = Literal["left", "right"] 28 | 29 | SortType: TypeAlias = Literal["quicksort", "mergesort", "heapsort", "stable"] 30 | 31 | OrderType: TypeAlias = Literal["A", "C", "F"] 32 | 33 | BitOrder: TypeAlias = Literal["big", "little"] 34 | 35 | ConvolveMode: TypeAlias = Literal["full", "valid", "same"] 36 | 37 | ConvolveMethod: TypeAlias = Literal["auto", "direct", "fft"] 38 | 39 | SelectKind: TypeAlias = Literal["introselect"] 40 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/qr.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/matrix/qr.h" 18 | #include "cupynumeric/matrix/qr_template.inl" 19 | #include "cupynumeric/matrix/qr_cpu.inl" 20 | 21 | namespace cupynumeric { 22 | 23 | using namespace legate; 24 | 25 | /*static*/ const char* QrTask::ERROR_MESSAGE = "Factorization failed"; 26 | 27 | /*static*/ void QrTask::cpu_variant(TaskContext context) 28 | { 29 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 30 | blas_set_num_threads(1); // make sure this isn't overzealous 31 | #endif 32 | qr_template(context); 33 | } 34 | 35 | namespace // unnamed 36 | { 37 | static const auto cupynumeric_reg_task_ = []() -> char { 38 | QrTask::register_variants(); 39 | return 0; 40 | }(); 41 | } // namespace 42 | 43 | } // namespace cupynumeric 44 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/svd.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/matrix/svd.h" 18 | #include "cupynumeric/matrix/svd_template.inl" 19 | #include "cupynumeric/matrix/svd_cpu.inl" 20 | 21 | namespace cupynumeric { 22 | 23 | using namespace legate; 24 | 25 | /*static*/ const char* SvdTask::ERROR_MESSAGE = "Factorization failed"; 26 | 27 | /*static*/ void SvdTask::cpu_variant(TaskContext context) 28 | { 29 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 30 | blas_set_num_threads(1); // make sure this isn't overzealous 31 | #endif 32 | svd_template(context); 33 | } 34 | 35 | namespace // unnamed 36 | { 37 | static const auto cupynumeric_reg_task_ = []() -> char { 38 | SvdTask::register_variants(); 39 | return 0; 40 | }(); 41 | } // namespace 42 | 43 | } // namespace cupynumeric 44 | -------------------------------------------------------------------------------- /src/cupynumeric/random/randutil/generator_exponential.inl: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "generator.h" 18 | 19 | #include "randomizer.h" 20 | 21 | template 22 | struct exponential_t; 23 | 24 | template <> 25 | struct exponential_t { 26 | float scale = 1.0f; 27 | 28 | template 29 | RANDUTIL_QUALIFIERS float operator()(gen_t& gen) 30 | { 31 | float uni = randutilimpl::engine_uniform(gen); 32 | return -::logf(uni) * scale; 33 | } 34 | }; 35 | 36 | template <> 37 | struct exponential_t { 38 | double scale = 1.0f; 39 | 40 | template 41 | RANDUTIL_QUALIFIERS double operator()(gen_t& gen) 42 | { 43 | double uni = randutilimpl::engine_uniform(gen); 44 | return -::logf(uni) * scale; 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /cupynumeric/_sphinxext/ufunc_formatter.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 NVIDIA Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | from __future__ import annotations 16 | 17 | from typing import Any 18 | 19 | from sphinx.application import Sphinx 20 | from sphinx.ext.autodoc import FunctionDocumenter 21 | 22 | from cupynumeric import ufunc 23 | 24 | from . import PARALLEL_SAFE, SphinxParallelSpec 25 | 26 | 27 | class UfuncDocumenter(FunctionDocumenter): 28 | directivetype = "function" 29 | objtype = "ufunc" 30 | priority = 20 31 | 32 | @classmethod 33 | def can_document_member( 34 | cls, member: Any, membername: str, isattr: bool, parent: Any 35 | ) -> bool: 36 | return isinstance(getattr(member, "__wrapped__", None), ufunc) 37 | 38 | 39 | def setup(app: Sphinx) -> SphinxParallelSpec: 40 | app.add_autodocumenter(UfuncDocumenter) 41 | return PARALLEL_SAFE 42 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/geev.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/matrix/geev.h" 18 | #include "cupynumeric/matrix/geev_template.inl" 19 | #include "cupynumeric/matrix/geev_cpu.inl" 20 | 21 | namespace cupynumeric { 22 | 23 | using namespace legate; 24 | 25 | /*static*/ const char* GeevTask::ERROR_MESSAGE = "Factorization failed"; 26 | 27 | /*static*/ void GeevTask::cpu_variant(TaskContext context) 28 | { 29 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 30 | blas_set_num_threads(1); // make sure this isn't overzealous 31 | #endif 32 | geev_template(context); 33 | } 34 | 35 | namespace // unnamed 36 | { 37 | static const auto cupynumeric_reg_task_ = []() -> char { 38 | GeevTask::register_variants(); 39 | return 0; 40 | }(); 41 | } // namespace 42 | 43 | } // namespace cupynumeric 44 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/solve.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/matrix/solve.h" 18 | #include "cupynumeric/matrix/solve_template.inl" 19 | #include "cupynumeric/matrix/solve_cpu.inl" 20 | 21 | namespace cupynumeric { 22 | 23 | using namespace legate; 24 | 25 | /*static*/ const char* SolveTask::ERROR_MESSAGE = "Singular matrix"; 26 | 27 | /*static*/ void SolveTask::cpu_variant(TaskContext context) 28 | { 29 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 30 | blas_set_num_threads(1); // make sure this isn't overzealous 31 | #endif 32 | solve_template(context); 33 | } 34 | 35 | namespace // unnamed 36 | { 37 | static const auto cupynumeric_reg_task_ = []() -> char { 38 | SolveTask::register_variants(); 39 | return 0; 40 | }(); 41 | } // namespace 42 | 43 | } // namespace cupynumeric 44 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/syev.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/matrix/syev.h" 18 | #include "cupynumeric/matrix/syev_template.inl" 19 | #include "cupynumeric/matrix/syev_cpu.inl" 20 | 21 | namespace cupynumeric { 22 | 23 | using namespace legate; 24 | 25 | /*static*/ const char* SyevTask::ERROR_MESSAGE = "Factorization failed"; 26 | 27 | /*static*/ void SyevTask::cpu_variant(TaskContext context) 28 | { 29 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 30 | blas_set_num_threads(1); // make sure this isn't overzealous 31 | #endif 32 | syev_template(context); 33 | } 34 | 35 | namespace // unnamed 36 | { 37 | static const auto cupynumeric_reg_task_ = []() -> char { 38 | SyevTask::register_variants(); 39 | return 0; 40 | }(); 41 | } // namespace 42 | 43 | } // namespace cupynumeric 44 | -------------------------------------------------------------------------------- /src/cupynumeric/random/randutil/generator_uniform.inl: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "generator.h" 18 | 19 | #include "randomizer.h" 20 | 21 | template 22 | struct uniform_t; 23 | 24 | template <> 25 | struct uniform_t { 26 | float offset, mult; 27 | 28 | template 29 | RANDUTIL_QUALIFIERS float operator()(gen_t& gen) 30 | { 31 | auto y = randutilimpl::engine_uniform(gen); // returns (0, 1]; 32 | return offset + mult * y; 33 | } 34 | }; 35 | 36 | template <> 37 | struct uniform_t { 38 | double offset, mult; 39 | 40 | template 41 | RANDUTIL_QUALIFIERS double operator()(gen_t& gen) 42 | { 43 | auto y = randutilimpl::engine_uniform(gen); // returns (0, 1]; 44 | return offset + mult * y; 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /src/cupynumeric/set/unique_reduce.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cupynumeric/cupynumeric_task.h" 20 | 21 | namespace cupynumeric { 22 | 23 | class UniqueReduceTask : public CuPyNumericTask { 24 | public: 25 | static inline const auto TASK_CONFIG = 26 | legate::TaskConfig{legate::LocalTaskID{CUPYNUMERIC_UNIQUE_REDUCE}}; 27 | 28 | static constexpr auto CPU_VARIANT_OPTIONS = legate::VariantOptions{}.with_has_allocations(true); 29 | static constexpr auto OMP_VARIANT_OPTIONS = legate::VariantOptions{}.with_has_allocations(true); 30 | 31 | public: 32 | static void cpu_variant(legate::TaskContext context); 33 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 34 | static void omp_variant(legate::TaskContext context); 35 | #endif 36 | }; 37 | 38 | } // namespace cupynumeric 39 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/diag.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "cupynumeric/cupynumeric_task.h" 20 | 21 | namespace cupynumeric { 22 | 23 | struct DiagArgs { 24 | int naxes; 25 | bool extract; 26 | legate::PhysicalStore matrix; 27 | legate::PhysicalStore diag; 28 | }; 29 | 30 | class DiagTask : public CuPyNumericTask { 31 | public: 32 | static inline const auto TASK_CONFIG = legate::TaskConfig{legate::LocalTaskID{CUPYNUMERIC_DIAG}}; 33 | 34 | public: 35 | static void cpu_variant(legate::TaskContext context); 36 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 37 | static void omp_variant(legate::TaskContext context); 38 | #endif 39 | #if LEGATE_DEFINED(LEGATE_USE_CUDA) 40 | static void gpu_variant(legate::TaskContext context); 41 | #endif 42 | }; 43 | 44 | } // namespace cupynumeric 45 | -------------------------------------------------------------------------------- /src/cupynumeric/matrix/matmul.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2024 NVIDIA Corporation 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "cupynumeric/matrix/matmul.h" 18 | #include "cupynumeric/matrix/matmul_template.inl" 19 | #include "cupynumeric/matrix/matmul_cpu.inl" 20 | 21 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 22 | #include 23 | #endif 24 | 25 | namespace cupynumeric { 26 | 27 | using namespace legate; 28 | 29 | /*static*/ void MatMulTask::cpu_variant(TaskContext context) 30 | { 31 | #if LEGATE_DEFINED(LEGATE_USE_OPENMP) 32 | blas_set_num_threads(1); // make sure this isn't overzealous 33 | #endif 34 | matmul_template(context); 35 | } 36 | 37 | namespace // unnamed 38 | { 39 | static const auto cupynumeric_reg_task_ = []() -> char { 40 | MatMulTask::register_variants(); 41 | return 0; 42 | }(); 43 | } // namespace 44 | 45 | } // namespace cupynumeric 46 | --------------------------------------------------------------------------------