├── .flake8 ├── .gitignore ├── .pre-commit-config.yaml ├── LICENSE ├── README.md ├── _render_update_version.py ├── build.sh ├── docs ├── .gitignore ├── Makefile ├── _static │ ├── cuda_interop.PNG │ ├── hip_usage.PNG │ └── pip_install.PNG ├── build.sh ├── conf.py ├── index.md ├── index.md.in ├── make.bat ├── python_api │ ├── bindings.md │ ├── cuda.md │ ├── cudart.md │ ├── hip.md │ ├── hipblas.md │ ├── hipfft.md │ ├── hiprand.md │ ├── hiprtc.md │ ├── hipsolver.md │ ├── hipsparse.md │ ├── nvrtc.md │ ├── rccl.md │ └── roctx.md ├── python_api_manual │ ├── _hip_helpers.md │ └── _util_types.md ├── sphinx │ ├── _toc.yml │ ├── _toc.yml.in │ ├── _toc.yml.in.in │ ├── requirements.in │ └── requirements.txt └── user_guide │ ├── 0_install.md │ ├── 1_usage.md │ ├── 2_cuda_python_interop.md │ ├── 3_datatypes.md │ ├── 4_report_bugs.md │ └── 5_license.md ├── examples ├── 0_Basic_Usage │ ├── hip_deviceattributes.py │ ├── hip_deviceproperties.py │ ├── hip_python_device_array.py │ ├── hip_stream.py │ ├── hipblas_with_numpy.py │ ├── hipblas_with_numpy_and_cu_mask.py │ ├── hipfft.py │ ├── hiprand_monte_carlo_pi.py │ ├── hiprtc_launch_kernel_args.py │ ├── hiprtc_launch_kernel_no_args.py │ ├── rccl_comminitall_bcast.py │ └── requirements.txt ├── 1_CUDA_Interop │ ├── Makefile │ ├── ccuda_stream.pyx │ ├── ccuda_stream_with_cuda_bindings.pyx │ ├── cuda_error_hallucinate_enums.py │ ├── cuda_stream.py │ ├── cuda_stream_with_cuda_bindings.py │ ├── requirements.txt │ └── setup.py ├── 2_Advanced │ ├── hip_jacobi.py │ ├── hiprtc_jit_with_llvm_ir.py │ ├── hiprtc_linking_device_functions.py │ └── hiprtc_linking_llvm_ir.py ├── requirements.txt └── test_examples.py ├── hip-python-as-cuda ├── CHANGELOG.md ├── LICENSE ├── README.md ├── cuda │ ├── __init__.pxd │ ├── __init__.py │ ├── _version.py.in │ ├── bindings │ │ ├── __init__.pxd │ │ ├── __init__.py │ │ ├── cnvrtc.pxd │ │ ├── cydriver.pxd │ │ ├── cyruntime.pxd │ │ ├── driver.pxd │ │ ├── driver.pyx │ │ ├── nvrtc.pxd │ │ ├── nvrtc.pyx │ │ ├── runtime.pxd │ │ └── runtime.pyx │ ├── ccuda.pxd │ ├── ccudart.pxd │ ├── cnvrtc.pxd │ ├── cuda.pxd │ ├── cuda.pyx │ ├── cudart.pxd │ ├── cudart.pyx │ ├── nvrtc.pxd │ └── nvrtc.pyx ├── pyproject.toml ├── requirements.txt.in ├── setup.cfg └── setup.py ├── hip-python ├── CHANGELOG.md ├── LICENSE ├── README.md ├── hip │ ├── __init__.py │ ├── _hip_helpers.pxd │ ├── _hip_helpers.pyx │ ├── _hiprtc_helpers.pxd │ ├── _hiprtc_helpers.pyx │ ├── _util │ │ ├── __init__.py │ │ ├── posixloader.pxd │ │ ├── posixloader.pyx │ │ ├── types.pxd │ │ └── types.pyx │ ├── _version.py.in │ ├── chip.pxd │ ├── chip.pyx │ ├── chipblas.pxd │ ├── chipblas.pyx │ ├── chipfft.pxd │ ├── chipfft.pyx │ ├── chiprand.pxd │ ├── chiprand.pyx │ ├── chiprtc.pxd │ ├── chiprtc.pyx │ ├── chipsolver.pxd │ ├── chipsolver.pyx │ ├── chipsparse.pxd │ ├── chipsparse.pyx │ ├── crccl.pxd │ ├── crccl.pyx │ ├── croctx.pxd │ ├── croctx.pyx │ ├── hip.pxd │ ├── hip.pyx │ ├── hipblas.pxd │ ├── hipblas.pyx │ ├── hipfft.pxd │ ├── hipfft.pyx │ ├── hiprand.pxd │ ├── hiprand.pyx │ ├── hiprtc.pxd │ ├── hiprtc.pyx │ ├── hiprtc_pyext.py │ ├── hipsolver.pxd │ ├── hipsolver.pyx │ ├── hipsparse.pxd │ ├── hipsparse.pyx │ ├── rccl.pxd │ ├── rccl.pyx │ ├── roctx.pxd │ └── roctx.pyx ├── pyproject.toml ├── requirements.txt ├── setup.cfg └── setup.py └── pyproject.toml /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | ignore = E501, W503 3 | # legend: 4 | # E501 - line too long (> 79 characters) 5 | # W503 - line break before binary operator 6 | max-line-length = 79 7 | max-complexity = 18 8 | select = B,C,E,F,W,T4,B9 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.c 2 | *.so 3 | __pycache__ 4 | hip-python/docs/_build 5 | _venv 6 | _build 7 | hip-python/build 8 | hip-python/dist/ 9 | hip-python/hip/_version.py 10 | hip-python/hip_python.egg-info/ 11 | hip-python-as-cuda/build 12 | hip-python-as-cuda/cuda/_version.py 13 | hip-python-as-cuda/dist/ 14 | hip-python-as-cuda/hip_python_as_cuda.egg-info/ 15 | hip-python-as-cuda/requirements.txt 16 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/psf/black 3 | rev: 25.1.0 4 | hooks: 5 | - id: black 6 | - repo: https://github.com/pycqa/flake8 7 | rev: 7.1.2 8 | hooks: 9 | - id: flake8 10 | - repo: https://github.com/MarcoGorelli/cython-lint 11 | rev: v0.16.6 12 | hooks: 13 | - id: cython-lint 14 | # - id: double-quote-cython-strings 15 | - repo: https://github.com/pycqa/isort 16 | rev: 6.0.0 17 | hooks: 18 | - id: isort 19 | name: isort (python) 20 | args: ["--profile", "black"] 21 | - id: isort 22 | name: isort (cython) 23 | types: [ cython ] 24 | args: ["--profile", "black"] 25 | - id: isort 26 | name: isort (pyi) 27 | types: [ pyi ] 28 | args: ["--profile", "black"] 29 | - repo: https://github.com/igorshubovych/markdownlint-cli 30 | rev: v0.41.0 31 | hooks: 32 | - id: markdownlint 33 | exclude: | 34 | (?x)( 35 | ^.gitea/ISSUE_TEMPLATE/| 36 | ^build/premake/| 37 | ^source/third_party/ 38 | ) 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /_render_update_version.py: -------------------------------------------------------------------------------- 1 | # NOTE: Is called by the build script 2 | import os 3 | import subprocess 4 | 5 | 6 | def git_rev(short=True): 7 | """Returns the git revision.""" 8 | cmd = ["git", "rev-parse"] 9 | if short: 10 | cmd.append("--short") 11 | cmd.append("HEAD") 12 | return subprocess.check_output(cmd).decode("utf-8").strip() 13 | 14 | 15 | def git_branch_rev_count(branch): 16 | """Count the number of revisions on branch 'branch'.""" 17 | return int( 18 | subprocess.check_output(["git", "rev-list", branch, "--count"]) 19 | .decode("utf-8") 20 | .strip() 21 | ) 22 | 23 | 24 | def git_current_branch(): 25 | """Return the name of the current branch.""" 26 | return ( 27 | subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]) 28 | .decode("utf-8") 29 | .strip() 30 | ) 31 | 32 | 33 | def replace_version_placeholders(file_content: str) -> str: 34 | return file_content.format( 35 | HIP_PYTHON_VERSION_SHORT=git_branch_rev_count(git_current_branch()), 36 | HIP_PYTHON_VERSION=git_branch_rev_count(git_current_branch()), 37 | HIP_PYTHON_BRANCH=git_current_branch(), 38 | HIP_PYTHON_REV=git_rev(), 39 | ) 40 | 41 | 42 | # render read _version.py (requires git) 43 | def render_version_py(parent_dir: str): 44 | with open(os.path.join(parent_dir, "_version.py.in"), "r") as infile, open( 45 | os.path.join(parent_dir, "_version.py"), "w" 46 | ) as outfile: 47 | rendered: str = replace_version_placeholders(infile.read()) 48 | outfile.write(rendered) 49 | 50 | 51 | def render_hip_python_as_cuda_requirements_txt(): 52 | reqirements_file: str = os.path.join( 53 | "hip-python-as-cuda", "requirements.txt" 54 | ) 55 | with open(reqirements_file + ".in", "r") as infile, open( 56 | reqirements_file, "w" 57 | ) as outfile: 58 | rendered: str = replace_version_placeholders(infile.read()) 59 | outfile.write(rendered) 60 | 61 | 62 | if __name__ == "__main__": 63 | render_version_py( 64 | os.path.join("hip-python", "hip"), 65 | ) 66 | render_version_py(os.path.join("hip-python-as-cuda", "cuda")) 67 | render_hip_python_as_cuda_requirements_txt() 68 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | 404.md 2 | data/AMD-404.png 3 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/_static/cuda_interop.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/hip-python/49e90526bbff06b8e874120fd1ffed7fa28cfd5b/docs/_static/cuda_interop.PNG -------------------------------------------------------------------------------- /docs/_static/hip_usage.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/hip-python/49e90526bbff06b8e874120fd1ffed7fa28cfd5b/docs/_static/hip_usage.PNG -------------------------------------------------------------------------------- /docs/_static/pip_install.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/hip-python/49e90526bbff06b8e874120fd1ffed7fa28cfd5b/docs/_static/pip_install.PNG -------------------------------------------------------------------------------- /docs/build.sh: -------------------------------------------------------------------------------- 1 | python3 -m sphinx -T -E -b html -d _build/doctrees -D language=en . _build/html 2 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # For the full list of built-in configuration values, see the documentation: 4 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 5 | 6 | from datetime import datetime as _datetime 7 | 8 | _today = _datetime.today() 9 | 10 | # Rocm-docs-core 11 | external_projects_remote_repository = "" 12 | external_projects = ["python", "rocm"] 13 | external_projects_current_project = "hip-python" 14 | 15 | setting_all_article_info = True 16 | all_article_info_os = ["linux"] 17 | all_article_info_author = ( 18 | "Advanced Micro Devices, Inc. " 19 | ) 20 | all_article_info_date = _today.strftime(r"%Y-%m-%d") 21 | 22 | # specific settings override any general settings (eg: all_article_info_) 23 | article_pages = [ 24 | { 25 | "file": "index", 26 | "read-time": "1 min read", 27 | }, 28 | { 29 | "file": "user_guide/0_install", 30 | "read-time": "5 min read", 31 | }, 32 | { 33 | "file": "user_guide/1_usage", 34 | "read-time": "60 min read", 35 | }, 36 | { 37 | "file": "user_guide/2_cuda_python_interop", 38 | "read-time": "20 min read", 39 | }, 40 | { 41 | "file": "user_guide/3_datatypes", 42 | "read-time": "10 min read", 43 | }, 44 | { 45 | "file": "user_guide/4_report_bugs", 46 | "read-time": "20 min read", 47 | }, 48 | ] 49 | 50 | html_theme = "rocm_docs_theme" 51 | html_theme_options = {"flavor": "rocm"} 52 | 53 | external_toc_path = "./sphinx/_toc.yml" 54 | 55 | extensions = [ 56 | "rocm_docs", 57 | "sphinx.ext.autodoc", # Automatically create API documentation from Python docstrings 58 | ] 59 | 60 | 61 | project = "HIP Python" 62 | author = "Advanced Micro Devices, Inc. " 63 | copyright = f"Copyright (c) 2023-{_today.strftime(r'%Y')} Advanced Micro Devices, Inc. All rights reserved." 64 | 65 | default_role = ( 66 | "py:obj" # this means that `test` will be expanded to :py:obj`test` 67 | ) 68 | 69 | # NOTE: always install the HIP Python packages, do not add the source folders 70 | # to the sys path, i.e. do not add .. and ../hip-python-as-cuda as 71 | # this breaks autodoc's automodule routine. 72 | 73 | autodoc_default_options = { 74 | "members": True, 75 | "undoc-members": True, 76 | "special-members": "__init__, __getitem__", 77 | "inherited-members": True, 78 | "show-inheritance": True, 79 | "imported-members": False, 80 | "member-order": "bysource", # bysource: seems unfortunately not to work for Cython modules 81 | } 82 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | 23 | # HIP Python 24 | 25 | **Welcome to the documentation pages for HIP Python!** 26 | 27 | HIP Python provides low-level Cython and Python® bindings for the HIP 28 | runtime, HIPRTC, multiple math libraries and the communication library RCCL, 29 | and further a CUDA® Python Interoperability layer that aims to simplify 30 | the porting of CUDA Python Python and Cython programs. 31 | 32 | :::{note} 33 | 34 | This documentation has been generated based on ROCm™ version 6.4.1. 35 | ::: 36 | 37 | ## Spotlight 38 | 39 | ::::{grid} 1 1 2 2 40 | :gutter: 1 41 | 42 | :::{grid-item-card} How to Install HIP Python 43 | 44 | Learn how to identify the correct HIP Python packages 45 | to install for your ROCm™ installation, 46 | where to retrieve the packages and what options 47 | you have to install them. 48 | 49 | - {doc}`/user_guide/0_install` 50 | 51 | ```{eval-rst} 52 | .. image:: _static/pip_install.PNG 53 | :width: 240 54 | :align: center 55 | ``` 56 | 57 | ::: 58 | 59 | :::{grid-item-card} How to Use HIP Python 60 | 61 | Learn how to use HIP Python's interfaces in your Python or Cython program. 62 | We present a large number of examples that cover 63 | HIP and HIPRTC as well as multiple math libraries (HIPBLAS, HIPRAND, HIPFFT) 64 | and the communication library RCCL. 65 | Learn how to launch your own kernels and how the different 66 | libraries interact. 67 | 68 | - {doc}`/user_guide/1_usage` 69 | 70 | ```{eval-rst} 71 | .. image:: _static/hip_usage.PNG 72 | :width: 240 73 | :align: center 74 | ``` 75 | 76 | ::: 77 | 78 | :::{grid-item-card} How to Port CUDA Python Applications 79 | 80 | Learn how you can use HIP Python's CUDA Python interoperability layer 81 | to port or even directly run CUDA Python applications 82 | on AMD GPUs. The chapter covers Python and Cython programs. 83 | 84 | - {doc}`/user_guide/2_cuda_python_interop` 85 | 86 | ```{eval-rst} 87 | .. image:: _static/cuda_interop.PNG 88 | :width: 240 89 | :align: center 90 | ``` 91 | 92 | ::: 93 | 94 | :::{grid-item-card} HIP Python's Adapter Types 95 | 96 | Learn about the datatypes that HIP Python uses to translate between C and Python 97 | and that are designed to ease interoperability with other 98 | packages such as [NumPy](https://numpy.org) and [Numba](https://numba.pydata.org/). 99 | 100 | - {doc}`/user_guide/3_datatypes` 101 | ::: 102 | 103 | :::{grid-item-card} HIP Python's Python API 104 | 105 | The full list of HIP Python Python variables, classes 106 | and functions. 107 | 108 | - {doc}`python_api/hip` 109 | - {doc}`python_api/hiprtc` 110 | - {doc}`python_api/hipblas` 111 | - {doc}`python_api/rccl` 112 | - {doc}`python_api/hiprand` 113 | - {doc}`python_api/hipfft` 114 | - {doc}`python_api/hipsparse` 115 | - {doc}`python_api/roctx` 116 | - {doc}`python_api/hipsolver` 117 | - {doc}`python_api_manual/_hip_helpers` 118 | - {doc}`python_api_manual/_util_types` 119 | ::: 120 | 121 | :::{grid-item-card} The CUDA Python Interoperability Layer's Python API 122 | 123 | The full list of the CUDA Python interoperability layer's Python variables, classes 124 | and functions. 125 | 126 | - {doc}`python_api/cuda` 127 | - {doc}`python_api/cudart` 128 | - {doc}`python_api/nvrtc` 129 | - {doc}`python_api/bindings` 130 | ::: 131 | 132 | ::: 133 | -------------------------------------------------------------------------------- /docs/index.md.in: -------------------------------------------------------------------------------- 1 | 23 | # HIP Python 24 | 25 | **Welcome to the documentation pages for HIP Python!** 26 | 27 | HIP Python provides low-level Cython and Python® bindings for the HIP 28 | runtime, HIPRTC, multiple math libraries and the communication library RCCL, 29 | and further a CUDA® Python Interoperability layer that aims to simplify 30 | the porting of CUDA Python Python and Cython programs. 31 | 32 | :::{note} 33 | 34 | This documentation has been generated based on ROCm™ version {ROCM_VERSION_NAME}. 35 | ::: 36 | 37 | ## Spotlight 38 | 39 | ::::{grid} 1 1 2 2 40 | :gutter: 1 41 | 42 | :::{grid-item-card} How to Install HIP Python 43 | 44 | Learn how to identify the correct HIP Python packages 45 | to install for your ROCm™ installation, 46 | where to retrieve the packages and what options 47 | you have to install them. 48 | 49 | - {doc}`/user_guide/0_install` 50 | 51 | ```{eval-rst} 52 | .. image:: _static/pip_install.PNG 53 | :width: 240 54 | :align: center 55 | ``` 56 | 57 | ::: 58 | 59 | :::{grid-item-card} How to Use HIP Python 60 | 61 | Learn how to use HIP Python's interfaces in your Python or Cython program. 62 | We present a large number of examples that cover 63 | HIP and HIPRTC as well as multiple math libraries (HIPBLAS, HIPRAND, HIPFFT) 64 | and the communication library RCCL. 65 | Learn how to launch your own kernels and how the different 66 | libraries interact. 67 | 68 | - {doc}`/user_guide/1_usage` 69 | 70 | ```{eval-rst} 71 | .. image:: _static/hip_usage.PNG 72 | :width: 240 73 | :align: center 74 | ``` 75 | 76 | ::: 77 | 78 | :::{grid-item-card} How to Port CUDA Python Applications 79 | 80 | Learn how you can use HIP Python's CUDA Python interoperability layer 81 | to port or even directly run CUDA Python applications 82 | on AMD GPUs. The chapter covers Python and Cython programs. 83 | 84 | - {doc}`/user_guide/2_cuda_python_interop` 85 | 86 | ```{eval-rst} 87 | .. image:: _static/cuda_interop.PNG 88 | :width: 240 89 | :align: center 90 | ``` 91 | 92 | ::: 93 | 94 | :::{grid-item-card} HIP Python's Adapter Types 95 | 96 | Learn about the datatypes that HIP Python uses to translate between C and Python 97 | and that are designed to ease interoperability with other 98 | packages such as [NumPy](https://numpy.org) and [Numba](https://numba.pydata.org/). 99 | 100 | - {doc}`/user_guide/3_datatypes` 101 | ::: 102 | 103 | :::{grid-item-card} HIP Python's Python API 104 | 105 | The full list of HIP Python Python variables, classes 106 | and functions. 107 | 108 | {PYTHON_API_DOC_NAMES} 109 | - {doc}`python_api_manual/_hip_helpers` 110 | - {doc}`python_api_manual/_util_types` 111 | ::: 112 | 113 | :::{grid-item-card} The CUDA Python Interoperability Layer's Python API 114 | 115 | The full list of the CUDA Python interoperability layer's Python variables, classes 116 | and functions. 117 | 118 | {PYTHON_API_DOC_NAMES_CUDA} 119 | ::: 120 | 121 | ::: 122 | -------------------------------------------------------------------------------- /docs/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=. 11 | set BUILDDIR=_build 12 | 13 | %SPHINXBUILD% >NUL 2>NUL 14 | if errorlevel 9009 ( 15 | echo. 16 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 17 | echo.installed, then set the SPHINXBUILD environment variable to point 18 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 19 | echo.may add the Sphinx directory to PATH. 20 | echo. 21 | echo.If you don't have Sphinx installed, grab it from 22 | echo.https://www.sphinx-doc.org/ 23 | exit /b 1 24 | ) 25 | 26 | if "%1" == "" goto help 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 | -------------------------------------------------------------------------------- /docs/python_api/bindings.md: -------------------------------------------------------------------------------- 1 | # cuda.bindings 2 | 3 | 4 | 5 | 6 | ```{eval-rst} 7 | .. automodule:: cuda.bindings 8 | :noindex: 9 | 10 | ``` 11 | -------------------------------------------------------------------------------- /docs/python_api/cuda.md: -------------------------------------------------------------------------------- 1 | # cuda.cuda 2 | 3 | 4 | 5 | 6 | ```{eval-rst} 7 | .. automodule:: cuda.cuda 8 | :noindex: 9 | 10 | ``` 11 | -------------------------------------------------------------------------------- /docs/python_api/cudart.md: -------------------------------------------------------------------------------- 1 | # cuda.cudart 2 | 3 | 4 | 5 | 6 | ```{eval-rst} 7 | .. automodule:: cuda.cudart 8 | :noindex: 9 | 10 | ``` 11 | -------------------------------------------------------------------------------- /docs/python_api/hip.md: -------------------------------------------------------------------------------- 1 | # hip.hip 2 | 3 | 4 | 5 | 6 | ```{eval-rst} 7 | .. automodule:: hip.hip 8 | 9 | 10 | ``` 11 | -------------------------------------------------------------------------------- /docs/python_api/hipblas.md: -------------------------------------------------------------------------------- 1 | # hip.hipblas 2 | 3 | 4 | 5 | 6 | ```{eval-rst} 7 | .. automodule:: hip.hipblas 8 | 9 | 10 | ``` 11 | -------------------------------------------------------------------------------- /docs/python_api/hipfft.md: -------------------------------------------------------------------------------- 1 | # hip.hipfft 2 | 3 | 4 | 5 | 6 | ```{eval-rst} 7 | .. automodule:: hip.hipfft 8 | 9 | 10 | ``` 11 | -------------------------------------------------------------------------------- /docs/python_api/hiprand.md: -------------------------------------------------------------------------------- 1 | # hip.hiprand 2 | 3 | 4 | 5 | 6 | ```{eval-rst} 7 | .. automodule:: hip.hiprand 8 | 9 | 10 | ``` 11 | -------------------------------------------------------------------------------- /docs/python_api/hiprtc.md: -------------------------------------------------------------------------------- 1 | # hip.hiprtc 2 | 3 | 4 | 5 | 6 | ```{eval-rst} 7 | .. automodule:: hip.hiprtc 8 | 9 | 10 | ``` 11 | -------------------------------------------------------------------------------- /docs/python_api/hipsolver.md: -------------------------------------------------------------------------------- 1 | # hip.hipsolver 2 | 3 | 4 | 5 | 6 | ```{eval-rst} 7 | .. automodule:: hip.hipsolver 8 | 9 | 10 | ``` 11 | -------------------------------------------------------------------------------- /docs/python_api/hipsparse.md: -------------------------------------------------------------------------------- 1 | # hip.hipsparse 2 | 3 | 4 | 5 | 6 | ```{eval-rst} 7 | .. automodule:: hip.hipsparse 8 | 9 | 10 | ``` 11 | -------------------------------------------------------------------------------- /docs/python_api/nvrtc.md: -------------------------------------------------------------------------------- 1 | # cuda.nvrtc 2 | 3 | 4 | 5 | 6 | ```{eval-rst} 7 | .. automodule:: cuda.nvrtc 8 | :noindex: 9 | 10 | ``` 11 | -------------------------------------------------------------------------------- /docs/python_api/rccl.md: -------------------------------------------------------------------------------- 1 | # hip.rccl 2 | 3 | 4 | 5 | 6 | ```{eval-rst} 7 | .. automodule:: hip.rccl 8 | 9 | 10 | ``` 11 | -------------------------------------------------------------------------------- /docs/python_api/roctx.md: -------------------------------------------------------------------------------- 1 | # hip.roctx 2 | 3 | 4 | 5 | 6 | ```{eval-rst} 7 | .. automodule:: hip.roctx 8 | 9 | 10 | ``` 11 | -------------------------------------------------------------------------------- /docs/python_api_manual/_hip_helpers.md: -------------------------------------------------------------------------------- 1 | 23 | # hip._hip_helpers 24 | 25 | 26 | ```{eval-rst} 27 | .. automodule:: hip._hip_helpers 28 | 29 | ``` 30 | -------------------------------------------------------------------------------- /docs/python_api_manual/_util_types.md: -------------------------------------------------------------------------------- 1 | 23 | # hip._util.types 24 | 25 | 26 | ```{eval-rst} 27 | .. automodule:: hip._util.types 28 | 29 | ``` 30 | -------------------------------------------------------------------------------- /docs/sphinx/_toc.yml: -------------------------------------------------------------------------------- 1 | defaults: 2 | numbered: False 3 | maxdepth: 6 4 | root: index.md 5 | subtrees: 6 | - caption: User Guide 7 | entries: 8 | - file: user_guide/0_install 9 | - file: user_guide/1_usage 10 | - file: user_guide/2_cuda_python_interop 11 | - file: user_guide/3_datatypes 12 | - file: user_guide/4_report_bugs 13 | - file: user_guide/5_license 14 | - caption: "HIP Python: Python API" 15 | entries: 16 | - file: python_api/hip 17 | - file: python_api/hiprtc 18 | - file: python_api/hipblas 19 | - file: python_api/rccl 20 | - file: python_api/hiprand 21 | - file: python_api/hipfft 22 | - file: python_api/hipsparse 23 | - file: python_api/roctx 24 | - file: python_api/hipsolver 25 | - file: python_api_manual/_hip_helpers 26 | - file: python_api_manual/_util_types 27 | - caption: "CUDA Python Interoperability: Python API" 28 | entries: 29 | - file: python_api/cuda 30 | - file: python_api/cudart 31 | - file: python_api/nvrtc 32 | -------------------------------------------------------------------------------- /docs/sphinx/_toc.yml.in: -------------------------------------------------------------------------------- 1 | # Variables of the form ${} are substituted, currently the following 2 | # list is supported: 3 | # - ${branch} (or {branch}) the name of the current branch 4 | # - ${url} (or {url}) github url of the current project 5 | # - ${project:} base url of the documentation of 6 | # based on intersphinx_mapping. 7 | # These comments will also be removed. 8 | defaults: 9 | numbered: False 10 | maxdepth: 6 11 | root: index.md 12 | subtrees: 13 | - caption: User Guide 14 | entries: 15 | - file: user_guide/0_install 16 | - file: user_guide/1_usage 17 | - file: user_guide/2_cuda_python_interop 18 | - file: user_guide/3_datatypes 19 | - file: user_guide/4_report_bugs 20 | - file: user_guide/5_license 21 | - caption: "HIP Python: Python API" 22 | entries: 23 | - file: python_api/hip 24 | - file: python_api/hiprtc 25 | - file: python_api/hipblas 26 | - file: python_api/rccl 27 | - file: python_api/hiprand 28 | - file: python_api/hipfft 29 | - file: python_api/hipsparse 30 | - file: python_api/roctx 31 | - file: python_api/hipsolver 32 | - file: python_api_manual/_hip_helpers 33 | - file: python_api_manual/_util_types 34 | - caption: "CUDA Python Interoperability: Python API" 35 | entries: 36 | - file: python_api/cuda 37 | - file: python_api/cudart 38 | - file: python_api/nvrtc 39 | - file: python_api/bindings 40 | -------------------------------------------------------------------------------- /docs/sphinx/_toc.yml.in.in: -------------------------------------------------------------------------------- 1 | # Variables of the form ${} are substituted, currently the following 2 | # list is supported: 3 | # - ${branch} (or {branch}) the name of the current branch 4 | # - ${url} (or {url}) github url of the current project 5 | # - ${project:} base url of the documentation of 6 | # based on intersphinx_mapping. 7 | # These comments will also be removed. 8 | defaults: 9 | numbered: False 10 | maxdepth: 6 11 | root: index.md 12 | subtrees: 13 | - caption: User Guide 14 | entries: 15 | - file: user_guide/0_install 16 | - file: user_guide/1_usage 17 | - file: user_guide/2_cuda_python_interop 18 | - file: user_guide/3_datatypes 19 | - file: user_guide/4_report_bugs 20 | - file: user_guide/5_license 21 | - caption: "HIP Python: Python API" 22 | entries: 23 | {PYTHON_API_FILE_NAMES} 24 | - file: python_api_manual/_hip_helpers 25 | - file: python_api_manual/_util_types 26 | - caption: "CUDA Python Interoperability: Python API" 27 | entries: 28 | {PYTHON_API_FILE_NAMES_CUDA} 29 | -------------------------------------------------------------------------------- /docs/sphinx/requirements.in: -------------------------------------------------------------------------------- 1 | --extra-index-url https://test.pypi.org/simple/ 2 | rocm-docs-core==1.17.0 3 | autodoc 4 | hip-python 5 | hip-python-as-cuda 6 | -------------------------------------------------------------------------------- /docs/sphinx/requirements.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with Python 3.11 3 | # by the following command: 4 | # 5 | # pip-compile requirements.in 6 | # 7 | --extra-index-url https://test.pypi.org/simple/ 8 | 9 | accessible-pygments==0.0.5 10 | # via pydata-sphinx-theme 11 | alabaster==1.0.0 12 | # via sphinx 13 | asttokens==3.0.0 14 | # via stack-data 15 | attrs==25.1.0 16 | # via 17 | # jsonschema 18 | # jupyter-cache 19 | # referencing 20 | autodoc==0.5.0 21 | # via -r requirements.in 22 | babel==2.17.0 23 | # via 24 | # pydata-sphinx-theme 25 | # sphinx 26 | beautifulsoup4==4.13.3 27 | # via 28 | # pydata-sphinx-theme 29 | # webtest 30 | breathe==4.36.0 31 | # via rocm-docs-core 32 | certifi==2025.1.31 33 | # via requests 34 | cffi==1.17.1 35 | # via 36 | # cryptography 37 | # pynacl 38 | charset-normalizer==3.4.1 39 | # via requests 40 | click==8.1.8 41 | # via 42 | # jupyter-cache 43 | # sphinx-external-toc 44 | comm==0.2.2 45 | # via ipykernel 46 | cryptography==44.0.1 47 | # via pyjwt 48 | debugpy==1.8.12 49 | # via ipykernel 50 | decorator==5.2.1 51 | # via 52 | # autodoc 53 | # ipython 54 | deprecated==1.2.18 55 | # via pygithub 56 | docutils==0.21.2 57 | # via 58 | # myst-parser 59 | # pydata-sphinx-theme 60 | # sphinx 61 | executing==2.2.0 62 | # via stack-data 63 | fastjsonschema==2.21.1 64 | # via 65 | # nbformat 66 | # rocm-docs-core 67 | gitdb==4.0.12 68 | # via gitpython 69 | gitpython==3.1.44 70 | # via rocm-docs-core 71 | greenlet==3.1.1 72 | # via sqlalchemy 73 | hip-python==6.3.0.500.16 74 | # via 75 | # -r requirements.in 76 | # hip-python-as-cuda 77 | hip-python-as-cuda==6.3.0.500.16 78 | # via -r requirements.in 79 | idna==3.10 80 | # via requests 81 | imagesize==1.4.1 82 | # via sphinx 83 | importlib-metadata==8.6.1 84 | # via 85 | # jupyter-cache 86 | # myst-nb 87 | ipykernel==6.29.5 88 | # via myst-nb 89 | ipython==8.32.0 90 | # via 91 | # ipykernel 92 | # myst-nb 93 | jedi==0.19.2 94 | # via ipython 95 | jinja2==3.1.5 96 | # via 97 | # myst-parser 98 | # sphinx 99 | jsonschema==4.23.0 100 | # via nbformat 101 | jsonschema-specifications==2024.10.1 102 | # via jsonschema 103 | jupyter-cache==1.0.1 104 | # via myst-nb 105 | jupyter-client==8.6.3 106 | # via 107 | # ipykernel 108 | # nbclient 109 | jupyter-core==5.7.2 110 | # via 111 | # ipykernel 112 | # jupyter-client 113 | # nbclient 114 | # nbformat 115 | markdown-it-py==3.0.0 116 | # via 117 | # mdit-py-plugins 118 | # myst-parser 119 | markupsafe==3.0.2 120 | # via jinja2 121 | matplotlib-inline==0.1.7 122 | # via 123 | # ipykernel 124 | # ipython 125 | mdit-py-plugins==0.4.2 126 | # via myst-parser 127 | mdurl==0.1.2 128 | # via markdown-it-py 129 | myst-nb==1.2.0 130 | # via rocm-docs-core 131 | myst-parser==4.0.1 132 | # via myst-nb 133 | nbclient==0.10.2 134 | # via 135 | # jupyter-cache 136 | # myst-nb 137 | nbformat==5.10.4 138 | # via 139 | # jupyter-cache 140 | # myst-nb 141 | # nbclient 142 | nest-asyncio==1.6.0 143 | # via ipykernel 144 | packaging==24.2 145 | # via 146 | # ipykernel 147 | # sphinx 148 | parso==0.8.4 149 | # via jedi 150 | pexpect==4.9.0 151 | # via ipython 152 | platformdirs==4.3.6 153 | # via jupyter-core 154 | prompt-toolkit==3.0.50 155 | # via ipython 156 | psutil==7.0.0 157 | # via ipykernel 158 | ptyprocess==0.7.0 159 | # via pexpect 160 | pure-eval==0.2.3 161 | # via stack-data 162 | pycparser==2.22 163 | # via cffi 164 | pydata-sphinx-theme==0.16.1 165 | # via 166 | # rocm-docs-core 167 | # sphinx-book-theme 168 | pygithub==2.6.1 169 | # via rocm-docs-core 170 | pygments==2.19.1 171 | # via 172 | # accessible-pygments 173 | # ipython 174 | # pydata-sphinx-theme 175 | # sphinx 176 | pyjwt[crypto]==2.10.1 177 | # via pygithub 178 | pynacl==1.5.0 179 | # via pygithub 180 | python-dateutil==2.9.0.post0 181 | # via jupyter-client 182 | pyyaml==6.0.2 183 | # via 184 | # jupyter-cache 185 | # myst-nb 186 | # myst-parser 187 | # rocm-docs-core 188 | # sphinx-external-toc 189 | pyzmq==26.2.1 190 | # via 191 | # ipykernel 192 | # jupyter-client 193 | referencing==0.36.2 194 | # via 195 | # jsonschema 196 | # jsonschema-specifications 197 | requests==2.32.3 198 | # via 199 | # pygithub 200 | # sphinx 201 | rocm-docs-core==1.17.0 202 | # via -r requirements.in 203 | rpds-py==0.23.1 204 | # via 205 | # jsonschema 206 | # referencing 207 | six==1.17.0 208 | # via python-dateutil 209 | smmap==5.0.2 210 | # via gitdb 211 | snowballstemmer==2.2.0 212 | # via sphinx 213 | soupsieve==2.6 214 | # via beautifulsoup4 215 | sphinx==8.1.3 216 | # via 217 | # breathe 218 | # myst-nb 219 | # myst-parser 220 | # pydata-sphinx-theme 221 | # rocm-docs-core 222 | # sphinx-book-theme 223 | # sphinx-copybutton 224 | # sphinx-design 225 | # sphinx-external-toc 226 | # sphinx-notfound-page 227 | sphinx-book-theme==1.1.3 228 | # via rocm-docs-core 229 | sphinx-copybutton==0.5.2 230 | # via rocm-docs-core 231 | sphinx-design==0.6.1 232 | # via rocm-docs-core 233 | sphinx-external-toc==1.0.1 234 | # via rocm-docs-core 235 | sphinx-notfound-page==1.1.0 236 | # via rocm-docs-core 237 | sphinxcontrib-applehelp==2.0.0 238 | # via sphinx 239 | sphinxcontrib-devhelp==2.0.0 240 | # via sphinx 241 | sphinxcontrib-htmlhelp==2.1.0 242 | # via sphinx 243 | sphinxcontrib-jsmath==1.0.1 244 | # via sphinx 245 | sphinxcontrib-qthelp==2.0.0 246 | # via sphinx 247 | sphinxcontrib-serializinghtml==2.0.0 248 | # via sphinx 249 | sqlalchemy==2.0.38 250 | # via jupyter-cache 251 | stack-data==0.6.3 252 | # via ipython 253 | tabulate==0.9.0 254 | # via jupyter-cache 255 | tornado==6.4.2 256 | # via 257 | # ipykernel 258 | # jupyter-client 259 | traitlets==5.14.3 260 | # via 261 | # comm 262 | # ipykernel 263 | # ipython 264 | # jupyter-client 265 | # jupyter-core 266 | # matplotlib-inline 267 | # nbclient 268 | # nbformat 269 | typing-extensions==4.12.2 270 | # via 271 | # beautifulsoup4 272 | # ipython 273 | # myst-nb 274 | # pydata-sphinx-theme 275 | # pygithub 276 | # referencing 277 | # sqlalchemy 278 | urllib3==2.3.0 279 | # via 280 | # pygithub 281 | # requests 282 | waitress==3.0.2 283 | # via webtest 284 | wcwidth==0.2.13 285 | # via prompt-toolkit 286 | webob==1.8.9 287 | # via webtest 288 | webtest==3.0.4 289 | # via autodoc 290 | wrapt==1.17.2 291 | # via deprecated 292 | zipp==3.21.0 293 | # via importlib-metadata 294 | -------------------------------------------------------------------------------- /docs/user_guide/0_install.md: -------------------------------------------------------------------------------- 1 | 23 | # Installation 24 | 25 | ## Supported Hardware 26 | 27 | Currently, only AMD GPUs are supported. 28 | 29 | 30 | * See the ROCm™ [Hardware_and_Software_Support](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html) page for a list of supported AMD GPUs. 31 | 32 | ## Supported Operation Systems 33 | 34 | Currently, only Linux is supported by the HIP Python interfaces's library 35 | loader. The next section lists additional constraints with respect to the 36 | required ROCm™ installation. 37 | 38 | ## Software Requirements 39 | 40 | You must install a HIP Python version that is compatible with your 41 | ROCm™ HIP SDK installation, or vice versa -- in particular, if you want 42 | to use the Cython interfaces. See the 43 | [ROCm™ documentation](https://rocm.docs.amd.com/en/latest/index.html) 44 | for more details on how to install the ROCm™ HIP SDK. 45 | 46 | 47 | (subsec_hip_python_versioning)= 48 | ### HIP Python Versioning 49 | 50 | 51 | The ROCm™ HIP SDK is versioned according to the below scheme: 52 | 53 | ``ROCM_VERSION_MAJOR.ROCM_VERSION_MINOR.ROCM_VERSION_PATCH[...]``: 54 | 55 | While HIP Python packages are versioned according to: 56 | 57 | ``ROCM_VERSION_MAJOR.ROCM_VERSION_MINOR.ROCM_VERSION_PATCH.HIP_PYTHON_CODEGEN_VERSION.HIP_PYTHON_RELEASE_VERSION`` 58 | 59 | Any version of HIP Python that matches the first three numbers is suitable 60 | for your ROCm™ HIP SDK installation. 61 | 62 | :::{admonition} Example 63 | 64 | If you have the ROCm™ HIP SDK 5.6.0 installed, any 65 | HIP Python package with version `5.6.0.X.Y` can be used. 66 | ::: 67 | 68 | :::{note} 69 | 70 | The HIP Python Python packages load HIP SDK functions in a lazy manner. 71 | Therefore, you will likely "get away" with using "incompatible" ROCm™ 72 | and HIP Python pairs if the following assumptions apply: 73 | 74 | * You are only using Python code, 75 | * the definitions of the types that you use have not changed between the 76 | respective ROCm™ releases, and 77 | * you are using a subset of functions that is present in both 78 | ROCm™ releases. 79 | 80 | Both assumptions often apply. 81 | ::: 82 | 83 | ### Installation Commands 84 | 85 | :::{important} 86 | 87 | Especially on older operating systems, ensure that your `pip` is upgraded to 88 | the latest version. You can upgrade it, e.g., as follows: 89 | 90 | ```shell 91 | python3 -m pip install --upgrade pip 92 | ``` 93 | 94 | ::: 95 | 96 | After having identified the correct package for your ROCm™ installation, 97 | type: 98 | 99 | ```shell 100 | python3 -m pip install -i https://test.pypi.org/simple hip-python>=. 101 | ``` 102 | 103 | or if you have a HIP Python wheel somewhere in your filesystem: 104 | 105 | ```shell 106 | python3 -m pip install .whl 107 | ``` 108 | 109 | :::{warning} 110 | 111 | Currently, we have not uploaded any HIP Python packages to PyPI yet. So far we 112 | have only uploaded packages to TestPyPI, mainly intended for internal testing 113 | purposes. If you find similar named packages on PyPI they may been provided by 114 | others, possibly with malicious intent. 115 | ::: 116 | 117 | :::{note} 118 | 119 | The first option will only be available after the public release on PyPI. 120 | ::: 121 | -------------------------------------------------------------------------------- /docs/user_guide/4_report_bugs.md: -------------------------------------------------------------------------------- 1 | 23 | # Feedback and Reporting Issues 24 | 25 | We are looking forward to get your positive or negative feedback --- especially 26 | the negative feedback. 27 | 28 | In particular, we are interested to learn: 29 | 30 | * What libraries that you need are missing? 31 | * What changes to the existing interfaces would make your life easier? 32 | * What else blocks you or could be improved? 33 | 34 | ## Reporting Issues 35 | 36 | 37 | We use [GitHub Issues](https://github.com/ROCmSoftwarePlatform/hip-python/issues) 38 | to track public **bugs** and **enhancement requests**. 39 | 40 | 41 | If you have found an issue, please check the [HIP Python documentation](https://rocm.docs.amd.com/projects/hip-python/en/latest/index.html) 42 | to see if it hasn't already been resolved in the latest version of HIP Python. 43 | 44 | ### Bugs 45 | 46 | Please follow the template below to report bugs that you found in HIP Python: 47 | 48 | 1. Description: ***Please be clear and descriptive*** 49 | 2. How to Reproduce the issue: 50 | 51 | * Hardware Information: 52 | * OS version/docker environment: 53 | * HIP Python package version and/or release branch that you have used: 54 | * Expected behavior: 55 | * Actual behavior: 56 | 57 | 3. Any additional information: 58 | 59 | ### Enhancement Requests 60 | 61 | Please follow the template below to request any enhancement for HIP Python: 62 | 63 | 1. Description: ***Please be clear and descriptive*** 64 | 2. Value and Motivation: 65 | 66 | * Feature and functionalities enabled: 67 | * Any alternatives: 68 | 69 | 3. Any additional information: 70 | 71 | * Authors must set labels (and assign a milestone) according to their own understanding. 72 | 73 | Other contributors can change these values if they disagree. That being said, 74 | adding a small comment explaining the motivation is highly recommended. 75 | In this way, we keep the process flexible while cultivating mutual understanding. 76 | 77 | :::{note} 78 | 79 | Most likely, labels like "bug", "feature" or "complexity*" 80 | will not cause discussions while others like "value*" or "urgency*" might 81 | do so. 82 | ::: 83 | 84 | ## Creating Pull Requests 85 | 86 | No changes are allowed to be directly committed to the `dev` and release 87 | branches of the HIP Python repository. All authors are required to 88 | develop their change sets on a separate branch and then create 89 | a pull request (PR) to merge their changes into the respective branch. 90 | 91 | Once a PR has been created, a developer must choose two reviewers 92 | to review the changes made. The first reviewer should be a 93 | technical expert in the portion of the library that the changes 94 | are being made in. The second reviewer should be a peer reviewer. This reviewer 95 | can be any other HIP Python developer. 96 | 97 | ## Responsibility of the Author 98 | 99 | The author of a PR is responsible for: 100 | 101 | * Writing clear, well documented code 102 | * Meeting expectations of code quality 103 | * Verifying that the changes do not break current functionality 104 | * Writing tests to ensure code coverage 105 | * Report on the impact to performance 106 | 107 | ## Responsibility of the Reviewer 108 | 109 | Each reviewer is responsible for verifying that the changes are 110 | clearly written in keeping with the coding styles of the library, 111 | are documented in a way that future developers will be able to 112 | understand the intent of the added functionality, and will 113 | maintain or improve the overall quality of the code base. 114 | 115 | Reviewer's task checklist: 116 | 117 | * [ ] Has the PR passed necessary CI? 118 | * [ ] Does the PR consist of a well-organized sequence of small commits, each 119 | of which is designed to make one specific feature or fix (and ideally should 120 | be able to pass CI testing)? 121 | * [ ] Does the PR only include a reviewable amount of changes? Or it is a 122 | consolidation of already reviewed small batches? e.g. break it into smaller 123 | testable and reviewable tasks instead of a huge chunk at once. 124 | 125 | * [ ] Is PR sufficiently documented and it is easy to read and understand, is 126 | it feasible for test and future maintenance? Do related docs already exist in 127 | the [HIP Python documentation](https://rocm.docs.amd.com/projects/hip-python/en/latest/index.html) 128 | if API or functionality has changed? 129 | * [ ] For bug fixes and new features, new regression test created and included 130 | in CI, or some other holistic test pipeline? 131 | * [ ] Is every PR associated with a ticket or issue number for tracking 132 | purposes? 133 | 134 | ## Passing CI 135 | 136 | The most critical component of the PR process is the CI testing. 137 | All PRs must pass the CI in order to be considered for merger. 138 | Reviewers may choose to defer their review until the CI testing 139 | has passed. 140 | 141 | ## The Review 142 | 143 | During the review, reviewers will look over the changes and make 144 | suggestions or requests for changes. 145 | 146 | In order to assist the reviewer in prioritizing their efforts, 147 | authors can take the following actions: 148 | 149 | * Set the urgency and value labels. 150 | * Set the milestone where the changes need to be delivered. 151 | * Describe the testing procedure and post the measured effect of 152 | the change. 153 | * Remind reviewers via email if a PR needs attention. 154 | * If a PR needs to be reviewed as soon as possible, explain to 155 | the reviewers why a review may need to take priority. 156 | 157 | ### PRs affecting autogenerated code 158 | 159 | In situations where your PR affects code that is autogenerated, the PR creation 160 | and review should take place as described above, however the reviewers should 161 | additionally appoint a HIP Python developer to integrate the fix or enhancement 162 | into the code generator of HIP Python. 163 | 164 | ## Other Feedback/Requests 165 | 166 | For other feedback or requests, please use this address: 167 | 168 | ```text 169 | hip-python.maintainer@amd.com 170 | ``` 171 | -------------------------------------------------------------------------------- /docs/user_guide/5_license.md: -------------------------------------------------------------------------------- 1 | 23 | 24 | 25 | (ch_license)= 26 | # License 27 | 28 | 29 | ```{eval-rst} 30 | .. literalinclude:: ../../LICENSE 31 | :name: license 32 | ``` 33 | -------------------------------------------------------------------------------- /examples/0_Basic_Usage/hip_deviceattributes.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | # [literalinclude-begin] 26 | from hip import hip 27 | 28 | 29 | def hip_check(call_result): 30 | err = call_result[0] 31 | result = call_result[1:] 32 | if len(result) == 1: 33 | result = result[0] 34 | if isinstance(err, hip.hipError_t) and err != hip.hipError_t.hipSuccess: 35 | raise RuntimeError(str(err)) 36 | return result 37 | 38 | 39 | device_num = 0 40 | 41 | for attrib in ( 42 | hip.hipDeviceAttribute_t.hipDeviceAttributeMaxBlockDimX, 43 | hip.hipDeviceAttribute_t.hipDeviceAttributeMaxBlockDimY, 44 | hip.hipDeviceAttribute_t.hipDeviceAttributeMaxBlockDimZ, 45 | hip.hipDeviceAttribute_t.hipDeviceAttributeMaxGridDimX, 46 | hip.hipDeviceAttribute_t.hipDeviceAttributeMaxGridDimY, 47 | hip.hipDeviceAttribute_t.hipDeviceAttributeMaxGridDimZ, 48 | hip.hipDeviceAttribute_t.hipDeviceAttributeWarpSize, 49 | ): 50 | value = hip_check(hip.hipDeviceGetAttribute(attrib, device_num)) 51 | print(f"{attrib.name}: {value}") 52 | print("ok") 53 | -------------------------------------------------------------------------------- /examples/0_Basic_Usage/hip_deviceproperties.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | # [literalinclude-begin] 26 | from hip import hip 27 | 28 | 29 | def hip_check(call_result): 30 | err = call_result[0] 31 | result = call_result[1:] 32 | if len(result) == 1: 33 | result = result[0] 34 | if isinstance(err, hip.hipError_t) and err != hip.hipError_t.hipSuccess: 35 | raise RuntimeError(str(err)) 36 | return result 37 | 38 | 39 | props = hip.hipDeviceProp_t() 40 | hip_check(hip.hipGetDeviceProperties(props, 0)) 41 | 42 | for attrib in sorted(props.PROPERTIES()): 43 | print(f"props.{attrib}={getattr(props,attrib)}") 44 | print("ok") 45 | -------------------------------------------------------------------------------- /examples/0_Basic_Usage/hip_python_device_array.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | """This example demonstrates how to configure the shape and data type 26 | of a device array returned by hipMalloc. 27 | 28 | This example demonstrates how to configure the shape and data type 29 | of a device array returned by hipMalloc (and related routines). 30 | Further showns how to retrieve single elements / contiguous subarrays 31 | with respect to specified type and shape information. 32 | """ 33 | 34 | # [literalinclude-begin] 35 | import ctypes 36 | 37 | import numpy as np 38 | from hip import hip, hipblas 39 | 40 | verbose = False 41 | 42 | 43 | def hip_check(call_result): 44 | err = call_result[0] 45 | result = call_result[1:] 46 | if len(result) == 1: 47 | result = result[0] 48 | if isinstance(err, hip.hipError_t) and err != hip.hipError_t.hipSuccess: 49 | raise RuntimeError(str(err)) 50 | elif ( 51 | isinstance(err, hipblas.hipblasStatus_t) 52 | and err != hipblas.hipblasStatus_t.HIPBLAS_STATUS_SUCCESS 53 | ): 54 | raise RuntimeError(str(err)) 55 | return result 56 | 57 | 58 | # init host array and fill with ones 59 | shape = (3, 20) # shape[1]: inner dim 60 | x_h = np.ones(shape, dtype="float32") 61 | num_bytes = x_h.size * x_h.itemsize 62 | 63 | # init device array and upload host data 64 | x_d = hip_check(hip.hipMalloc(num_bytes)).configure( 65 | typestr="float32", shape=shape 66 | ) 67 | hip_check( 68 | hip.hipMemcpy(x_d, x_h, num_bytes, hip.hipMemcpyKind.hipMemcpyHostToDevice) 69 | ) 70 | 71 | # scale device array entries by row index using hipblasSscal 72 | handle = hip_check(hipblas.hipblasCreate()) 73 | for r in range(0, shape[0]): 74 | row = x_d[r, :] # extract subarray 75 | row_len = row.size 76 | alpha = ctypes.c_float(r) 77 | hip_check( 78 | hipblas.hipblasSscal(handle, row_len, ctypes.addressof(alpha), row, 1) 79 | ) 80 | hip_check(hip.hipDeviceSynchronize()) 81 | hip_check(hipblas.hipblasDestroy(handle)) 82 | 83 | # copy device data back to host 84 | hip_check( 85 | hip.hipMemcpy(x_h, x_d, num_bytes, hip.hipMemcpyKind.hipMemcpyDeviceToHost) 86 | ) 87 | 88 | # deallocate device data 89 | hip_check(hip.hipFree(x_d)) 90 | 91 | for r in range(0, shape[0]): 92 | row_rounded = [round(el) for el in x_h[r, :]] 93 | for c, e in enumerate(row_rounded): 94 | if e != r: 95 | raise ValueError(f"expected '{r}' for element ({r},{c}), is '{e}") 96 | if verbose: 97 | print("\t".join((str(i) for i in row_rounded)) + "\n") 98 | print("ok") 99 | -------------------------------------------------------------------------------- /examples/0_Basic_Usage/hip_stream.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | import array 26 | 27 | # [literalinclude-begin] 28 | import random 29 | 30 | from hip import hip 31 | 32 | 33 | def hip_check(call_result): 34 | err = call_result[0] 35 | result = call_result[1:] 36 | if len(result) == 1: 37 | result = result[0] 38 | if isinstance(err, hip.hipError_t) and err != hip.hipError_t.hipSuccess: 39 | raise RuntimeError(str(err)) 40 | return result 41 | 42 | 43 | # inputs 44 | n = 100 45 | x_h = array.array("i", [int(random.random() * 10) for i in range(0, n)]) 46 | num_bytes = x_h.itemsize * len(x_h) 47 | x_d = hip_check(hip.hipMalloc(num_bytes)) 48 | 49 | stream = hip_check(hip.hipStreamCreate()) 50 | hip_check( 51 | hip.hipMemcpyAsync( 52 | x_d, x_h, num_bytes, hip.hipMemcpyKind.hipMemcpyHostToDevice, stream 53 | ) 54 | ) 55 | hip_check(hip.hipMemsetAsync(x_d, 0, num_bytes, stream)) 56 | hip_check( 57 | hip.hipMemcpyAsync( 58 | x_h, x_d, num_bytes, hip.hipMemcpyKind.hipMemcpyDeviceToHost, stream 59 | ) 60 | ) 61 | hip_check(hip.hipStreamSynchronize(stream)) 62 | hip_check(hip.hipStreamDestroy(stream)) 63 | 64 | # deallocate device data 65 | hip_check(hip.hipFree(x_d)) 66 | 67 | for i, x in enumerate(x_h): 68 | if x != 0: 69 | raise ValueError(f"expected '0' for element {i}, is: '{x}'") 70 | print("ok") 71 | -------------------------------------------------------------------------------- /examples/0_Basic_Usage/hipblas_with_numpy.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | # [literalinclude-begin] 26 | import ctypes 27 | 28 | import numpy as np 29 | from hip import hip, hipblas 30 | 31 | 32 | def hip_check(call_result): 33 | err = call_result[0] 34 | result = call_result[1:] 35 | if len(result) == 1: 36 | result = result[0] 37 | if isinstance(err, hip.hipError_t) and err != hip.hipError_t.hipSuccess: 38 | raise RuntimeError(str(err)) 39 | elif ( 40 | isinstance(err, hipblas.hipblasStatus_t) 41 | and err != hipblas.hipblasStatus_t.HIPBLAS_STATUS_SUCCESS 42 | ): 43 | raise RuntimeError(str(err)) 44 | return result 45 | 46 | 47 | num_elements = 100 48 | 49 | # input data on host 50 | alpha = ctypes.c_float(2) 51 | x_h = np.random.rand(num_elements).astype(dtype=np.float32) 52 | y_h = np.random.rand(num_elements).astype(dtype=np.float32) 53 | 54 | # expected result 55 | y_expected = alpha * x_h + y_h 56 | 57 | # device vectors 58 | num_bytes = num_elements * np.dtype(np.float32).itemsize 59 | x_d = hip_check(hip.hipMalloc(num_bytes)) 60 | y_d = hip_check(hip.hipMalloc(num_bytes)) 61 | 62 | # copy input data to device 63 | hip_check( 64 | hip.hipMemcpy(x_d, x_h, num_bytes, hip.hipMemcpyKind.hipMemcpyHostToDevice) 65 | ) 66 | hip_check( 67 | hip.hipMemcpy(y_d, y_h, num_bytes, hip.hipMemcpyKind.hipMemcpyHostToDevice) 68 | ) 69 | 70 | # call hipblasSaxpy + initialization & destruction of handle 71 | handle = hip_check(hipblas.hipblasCreate()) 72 | hip_check( 73 | hipblas.hipblasSaxpy( 74 | handle, num_elements, ctypes.addressof(alpha), x_d, 1, y_d, 1 75 | ) 76 | ) 77 | hip_check(hipblas.hipblasDestroy(handle)) 78 | 79 | # copy result (stored in y_d) back to host (store in y_h) 80 | hip_check( 81 | hip.hipMemcpy(y_h, y_d, num_bytes, hip.hipMemcpyKind.hipMemcpyDeviceToHost) 82 | ) 83 | 84 | # compare to expected result 85 | if np.allclose(y_expected, y_h): 86 | print("ok") 87 | else: 88 | print("FAILED") 89 | # print(f"{y_h=}") 90 | # print(f"{y_expected=}") 91 | 92 | # clean up 93 | hip_check(hip.hipFree(x_d)) 94 | hip_check(hip.hipFree(y_d)) 95 | -------------------------------------------------------------------------------- /examples/0_Basic_Usage/hipblas_with_numpy_and_cu_mask.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | # [literalinclude-begin] 26 | import ctypes 27 | 28 | import numpy as np 29 | from hip import hip, hipblas 30 | 31 | 32 | def hip_check(call_result): 33 | err = call_result[0] 34 | result = call_result[1:] 35 | if len(result) == 1: 36 | result = result[0] 37 | if isinstance(err, hip.hipError_t) and err != hip.hipError_t.hipSuccess: 38 | raise RuntimeError(str(err)) 39 | elif ( 40 | isinstance(err, hipblas.hipblasStatus_t) 41 | and err != hipblas.hipblasStatus_t.HIPBLAS_STATUS_SUCCESS 42 | ): 43 | raise RuntimeError(str(err)) 44 | return result 45 | 46 | 47 | num_elements = 100 48 | 49 | # input data on host 50 | alpha = ctypes.c_float(2) 51 | x_h = np.random.rand(num_elements).astype(dtype=np.float32) 52 | y_h = np.random.rand(num_elements).astype(dtype=np.float32) 53 | 54 | # expected result 55 | y_expected = alpha * x_h + y_h 56 | 57 | # stream with 2 enabled CUs (we pass a 2x 32-bit mask with two set bits) 58 | stream = hip_check(hip.hipExtStreamCreateWithCUMask(2, [0b1, 0b10])) 59 | 60 | # device vectors 61 | num_bytes = num_elements * np.dtype(np.float32).itemsize 62 | x_d = hip_check(hip.hipMallocAsync(num_bytes, stream)) 63 | y_d = hip_check(hip.hipMallocAsync(num_bytes, stream)) 64 | 65 | # copy input data to device 66 | hip_check( 67 | hip.hipMemcpyAsync( 68 | x_d, x_h, num_bytes, hip.hipMemcpyKind.hipMemcpyHostToDevice, stream 69 | ) 70 | ) 71 | hip_check( 72 | hip.hipMemcpyAsync( 73 | y_d, y_h, num_bytes, hip.hipMemcpyKind.hipMemcpyHostToDevice, stream 74 | ) 75 | ) 76 | 77 | # call hipblasSaxpy + initialization & destruction of handle 78 | handle = hip_check(hipblas.hipblasCreate()) 79 | hip_check(hipblas.hipblasSetStream(handle, stream)) 80 | hip_check( 81 | hipblas.hipblasSaxpy( 82 | handle, num_elements, ctypes.addressof(alpha), x_d, 1, y_d, 1 83 | ) 84 | ) 85 | hip_check(hipblas.hipblasDestroy(handle)) 86 | 87 | # copy result (stored in y_d) back to host (store in y_h) 88 | hip_check( 89 | hip.hipMemcpyAsync( 90 | y_h, y_d, num_bytes, hip.hipMemcpyKind.hipMemcpyDeviceToHost, stream 91 | ) 92 | ) 93 | 94 | hip_check(hip.hipStreamSynchronize(stream)) 95 | hip_check(hip.hipStreamDestroy(stream)) 96 | 97 | # compare to expected result 98 | if np.allclose(y_expected, y_h): 99 | print("ok") 100 | else: 101 | print("FAILED") 102 | # print(f"{y_h=}") 103 | # print(f"{y_expected=}") 104 | 105 | # clean up 106 | hip_check(hip.hipFree(x_d)) 107 | hip_check(hip.hipFree(y_d)) 108 | -------------------------------------------------------------------------------- /examples/0_Basic_Usage/hipfft.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | """This example demonstrates the usage of HIP Python's HIPFFT library. 26 | 27 | This example demonstrates the usage of HIP Python's HIPFFT library. 28 | We perform a double-complex-to-double-complex in-place forward FFT 29 | of a constant time signal f(t) = 1-1j of which we have N samples. 30 | The resulting FFT coefficients are all zero, 31 | except the first one, which has the value N-Nj. 32 | """ 33 | 34 | # [literalinclude-begin] 35 | import numpy as np 36 | from hip import hip, hipfft 37 | 38 | 39 | def hip_check(call_result): 40 | err = call_result[0] 41 | result = call_result[1:] 42 | if len(result) == 1: 43 | result = result[0] 44 | if isinstance(err, hip.hipError_t) and err != hip.hipError_t.hipSuccess: 45 | raise RuntimeError(str(err)) 46 | if ( 47 | isinstance(err, hipfft.hipfftResult) 48 | and err != hipfft.hipfftResult.HIPFFT_SUCCESS 49 | ): 50 | raise RuntimeError(str(err)) 51 | return result 52 | 53 | 54 | # initial data 55 | N = 100 56 | hx = np.zeros(N, dtype=np.cdouble) 57 | hx[:] = 1 - 1j 58 | 59 | # copy to device 60 | dx = hip_check(hip.hipMalloc(hx.size * hx.itemsize)) 61 | hip_check( 62 | hip.hipMemcpy(dx, hx, dx.size, hip.hipMemcpyKind.hipMemcpyHostToDevice) 63 | ) 64 | 65 | # create plan 66 | plan = hip_check(hipfft.hipfftPlan1d(N, hipfft.hipfftType.HIPFFT_Z2Z, 1)) 67 | 68 | # execute plan 69 | hip_check( 70 | hipfft.hipfftExecZ2Z( 71 | plan, idata=dx, odata=dx, direction=hipfft.HIPFFT_FORWARD 72 | ) 73 | ) 74 | hip_check(hip.hipDeviceSynchronize()) 75 | 76 | # copy to host and free device data 77 | hip_check( 78 | hip.hipMemcpy(hx, dx, dx.size, hip.hipMemcpyKind.hipMemcpyDeviceToHost) 79 | ) 80 | hip_check(hip.hipFree(dx)) 81 | 82 | if not np.isclose(hx[0].real, N) or not np.isclose(hx[0].imag, -N): 83 | raise RuntimeError("element 0 must be '{N}-j{N}'.") 84 | for i in range(1, N): 85 | if not np.isclose(abs(hx[i]), 0): 86 | raise RuntimeError(f"element {i} must be '0'") 87 | 88 | hip_check(hipfft.hipfftDestroy(plan)) 89 | print("ok") 90 | -------------------------------------------------------------------------------- /examples/0_Basic_Usage/hiprand_monte_carlo_pi.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | """ 26 | This example uses hiprand to estimate Pi by means of the Monte-Carlo method. 27 | 28 | The unit square has the area 1^2, while the unit circle has the area 29 | pi*(1/2)^2. Therefore, the ratio of the areas is pi/4. 30 | 31 | Using the Monte-Carlo method, we randomly choose N (x,y)-coordinates in the unit square. 32 | We then estimate the ratio of areas as the ratio between those samples 33 | within the unit circle and N. 34 | The accuracy of the approach increases with N. 35 | 36 | Note: 37 | This example was originally taken from the ROCRAND repository on Github. 38 | See this repository for a "more pythonic" object-oriented interface to hiprand/rocrand (ctypes-based, Python-only). 39 | """ 40 | 41 | import math 42 | 43 | import numpy as np 44 | 45 | # [literalinclude-begin] 46 | from hip import hip, hiprand 47 | 48 | 49 | def hip_check(call_result): 50 | err = call_result[0] 51 | result = call_result[1:] 52 | if len(result) == 1: 53 | result = result[0] 54 | if ( 55 | isinstance(err, hiprand.hiprandStatus) 56 | and err != hiprand.hiprandStatus.HIPRAND_STATUS_SUCCESS 57 | ): 58 | raise RuntimeError(str(err)) 59 | if isinstance(err, hip.hipError_t) and err != hip.hipError_t.hipSuccess: 60 | raise RuntimeError(str(err)) 61 | return result 62 | 63 | 64 | print("Estimating Pi via the Monte Carlo method:\n") 65 | 66 | 67 | def calculate_pi(n): 68 | """Calculate Pi for the given number of samples.""" 69 | xy = np.empty(shape=(2, n)) # host array, default type is float64 70 | gen = hip_check( 71 | hiprand.hiprandCreateGenerator( 72 | hiprand.hiprandRngType.HIPRAND_RNG_PSEUDO_DEFAULT 73 | ) 74 | ) 75 | xy_d = hip_check( 76 | hip.hipMalloc(xy.size * xy.itemsize) 77 | ) # create same size device array 78 | hip_check( 79 | hiprand.hiprandGenerateUniformDouble(gen, xy_d, xy.size) 80 | ) # generate device random numbers 81 | hip_check( 82 | hip.hipMemcpy( 83 | xy, 84 | xy_d, 85 | xy.size * xy.itemsize, 86 | hip.hipMemcpyKind.hipMemcpyDeviceToHost, 87 | ) 88 | ) # copy to host 89 | hip_check(hip.hipFree(xy_d)) # free device array 90 | hip_check(hiprand.hiprandDestroyGenerator(gen)) 91 | 92 | inside = xy[0] ** 2 + xy[1] ** 2 <= 1.0 93 | in_xy = xy[:, inside] 94 | estimate = 4 * in_xy[0, :].size / n 95 | return estimate 96 | 97 | 98 | print("#samples\testimate\trelative error") 99 | n = 100 100 | imax = 5 101 | for i in range(1, imax): 102 | n *= 10 103 | estimate = calculate_pi(n) 104 | print(f"{n:12}\t{estimate:1.9f}\t{abs(estimate-math.pi)/math.pi:1.9f}") 105 | print("ok") 106 | -------------------------------------------------------------------------------- /examples/0_Basic_Usage/hiprtc_launch_kernel_args.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | import array 26 | 27 | # [literalinclude-begin] 28 | import ctypes 29 | import math 30 | import random 31 | 32 | from hip import hip, hiprtc 33 | 34 | 35 | def hip_check(call_result): 36 | err = call_result[0] 37 | result = call_result[1:] 38 | if len(result) == 1: 39 | result = result[0] 40 | if isinstance(err, hip.hipError_t) and err != hip.hipError_t.hipSuccess: 41 | raise RuntimeError(str(err)) 42 | elif ( 43 | isinstance(err, hiprtc.hiprtcResult) 44 | and err != hiprtc.hiprtcResult.HIPRTC_SUCCESS 45 | ): 46 | raise RuntimeError(str(err)) 47 | return result 48 | 49 | 50 | source = b"""\ 51 | extern "C" __global__ void scale_vector(float factor, int n, short unused1, int unused2, float unused3, float *x) { 52 | int tid = threadIdx.x + blockIdx.x * blockDim.x; 53 | if ( tid == 0 ) { 54 | printf("tid: %d, factor: %f, x*: %lu, n: %lu, unused1: %d, unused2: %d, unused3: %f\\n",tid,factor,x,n,(int) unused1,unused2,unused3); 55 | } 56 | if (tid < n) { 57 | x[tid] *= factor; 58 | } 59 | } 60 | """ 61 | 62 | prog = hip_check( 63 | hiprtc.hiprtcCreateProgram(source, b"scale_vector", 0, [], []) 64 | ) 65 | 66 | props = hip.hipDeviceProp_t() 67 | hip_check(hip.hipGetDeviceProperties(props, 0)) 68 | arch = props.gcnArchName 69 | 70 | print(f"Compiling kernel for {arch}") 71 | 72 | cflags = [b"--offload-arch=" + arch] 73 | (err,) = hiprtc.hiprtcCompileProgram(prog, len(cflags), cflags) 74 | if err != hiprtc.hiprtcResult.HIPRTC_SUCCESS: 75 | log_size = hip_check(hiprtc.hiprtcGetProgramLogSize(prog)) 76 | log = bytearray(log_size) 77 | hip_check(hiprtc.hiprtcGetProgramLog(prog, log)) 78 | raise RuntimeError(log.decode()) 79 | code_size = hip_check(hiprtc.hiprtcGetCodeSize(prog)) 80 | code = bytearray(code_size) 81 | hip_check(hiprtc.hiprtcGetCode(prog, code)) 82 | module = hip_check(hip.hipModuleLoadData(code)) 83 | kernel = hip_check(hip.hipModuleGetFunction(module, b"scale_vector")) 84 | 85 | # kernel launch 86 | 87 | # - inputs 88 | n = 100 89 | x_h = array.array("f", [random.random() for i in range(0, n)]) 90 | num_bytes = x_h.itemsize * len(x_h) 91 | x_d = hip_check(hip.hipMalloc(num_bytes)) 92 | print(f"{hex(int(x_d))=}") 93 | 94 | # - upload host data 95 | hip_check( 96 | hip.hipMemcpy(x_d, x_h, num_bytes, hip.hipMemcpyKind.hipMemcpyHostToDevice) 97 | ) 98 | 99 | factor = 1.23 100 | 101 | # - expected result 102 | x_expected = [a * factor for a in x_h] 103 | 104 | block = hip.dim3(x=32) 105 | grid = hip.dim3(math.ceil(n / block.x)) 106 | 107 | # - launch 108 | hip_check( 109 | hip.hipModuleLaunchKernel( 110 | kernel, 111 | *grid, 112 | *block, 113 | sharedMemBytes=0, 114 | stream=None, 115 | kernelParams=None, 116 | extra=( 117 | ctypes.c_float(factor), # 4 bytes 118 | ctypes.c_int(n), # 8 bytes 119 | ctypes.c_short(5), # unused1, 10 bytes 120 | ctypes.c_int(2), # unused2, 16 bytes (+2 padding bytes) 121 | ctypes.c_float(5.6), # unused3 20 bytes 122 | x_d, # 32 bytes (+4 padding bytes) 123 | ), 124 | ) 125 | ) 126 | 127 | # copy result back 128 | hip_check( 129 | hip.hipMemcpy(x_h, x_d, num_bytes, hip.hipMemcpyKind.hipMemcpyDeviceToHost) 130 | ) 131 | 132 | for i, x_h_i in enumerate(x_h): 133 | if not math.isclose(x_h_i, x_expected[i], rel_tol=1e-6): 134 | raise RuntimeError( 135 | f"values do not match, {x_h[i]=} vs. {x_expected[i]=}, {i=}" 136 | ) 137 | 138 | hip_check(hip.hipFree(x_d)) 139 | 140 | hip_check(hip.hipModuleUnload(module)) 141 | hip_check(hiprtc.hiprtcDestroyProgram(prog.createRef())) 142 | 143 | print("ok") 144 | -------------------------------------------------------------------------------- /examples/0_Basic_Usage/hiprtc_launch_kernel_no_args.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | # [literalinclude-begin] 26 | from hip import hip, hiprtc 27 | 28 | 29 | def hip_check(call_result): 30 | err = call_result[0] 31 | result = call_result[1:] 32 | if len(result) == 1: 33 | result = result[0] 34 | if isinstance(err, hip.hipError_t) and err != hip.hipError_t.hipSuccess: 35 | raise RuntimeError(str(err)) 36 | elif ( 37 | isinstance(err, hiprtc.hiprtcResult) 38 | and err != hiprtc.hiprtcResult.HIPRTC_SUCCESS 39 | ): 40 | raise RuntimeError(str(err)) 41 | return result 42 | 43 | 44 | source = b"""\ 45 | extern "C" __global__ void print_tid() { 46 | printf("tid: %d\\n", (int) threadIdx.x); 47 | } 48 | """ 49 | 50 | prog = hip_check(hiprtc.hiprtcCreateProgram(source, b"print_tid", 0, [], [])) 51 | 52 | props = hip.hipDeviceProp_t() 53 | hip_check(hip.hipGetDeviceProperties(props, 0)) 54 | arch = props.gcnArchName 55 | 56 | print(f"Compiling kernel for {arch}") 57 | 58 | cflags = [b"--offload-arch=" + arch] 59 | (err,) = hiprtc.hiprtcCompileProgram(prog, len(cflags), cflags) 60 | if err != hiprtc.hiprtcResult.HIPRTC_SUCCESS: 61 | log_size = hip_check(hiprtc.hiprtcGetProgramLogSize(prog)) 62 | log = bytearray(log_size) 63 | hip_check(hiprtc.hiprtcGetProgramLog(prog, log)) 64 | raise RuntimeError(log.decode()) 65 | code_size = hip_check(hiprtc.hiprtcGetCodeSize(prog)) 66 | code = bytearray(code_size) 67 | hip_check(hiprtc.hiprtcGetCode(prog, code)) 68 | module = hip_check(hip.hipModuleLoadData(code)) 69 | kernel = hip_check(hip.hipModuleGetFunction(module, b"print_tid")) 70 | # 71 | hip_check( 72 | hip.hipModuleLaunchKernel( 73 | kernel, 74 | *(1, 1, 1), # grid 75 | *(32, 1, 1), # block 76 | sharedMemBytes=0, 77 | stream=None, 78 | kernelParams=None, 79 | extra=None, 80 | ) 81 | ) 82 | 83 | hip_check(hip.hipDeviceSynchronize()) 84 | hip_check(hip.hipModuleUnload(module)) 85 | hip_check(hiprtc.hiprtcDestroyProgram(prog.createRef())) 86 | 87 | print("ok") 88 | -------------------------------------------------------------------------------- /examples/0_Basic_Usage/rccl_comminitall_bcast.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | # [literalinclude-begin] 26 | import numpy as np 27 | from hip import hip, rccl 28 | 29 | 30 | def hip_check(call_result): 31 | err = call_result[0] 32 | result = call_result[1:] 33 | if len(result) == 1: 34 | result = result[0] 35 | if isinstance(err, hip.hipError_t) and err != hip.hipError_t.hipSuccess: 36 | raise RuntimeError(str(err)) 37 | if ( 38 | isinstance(err, rccl.ncclResult_t) 39 | and err != rccl.ncclResult_t.ncclSuccess 40 | ): 41 | raise RuntimeError(str(err)) 42 | return result 43 | 44 | 45 | # init the communicators 46 | num_gpus = hip_check(hip.hipGetDeviceCount()) 47 | comms = np.empty( 48 | num_gpus, dtype="uint64" 49 | ) # size of pointer type, such as ncclComm 50 | devlist = np.array(range(0, num_gpus), dtype="int32") 51 | hip_check(rccl.ncclCommInitAll(comms, num_gpus, devlist)) 52 | 53 | # init data on the devices 54 | N = 4 55 | ones = np.ones(N, dtype="int32") 56 | zeros = np.zeros(ones.size, dtype="int32") 57 | dxlist = [] 58 | for dev in devlist: 59 | hip_check(hip.hipSetDevice(dev)) 60 | dx = hip_check(hip.hipMalloc(ones.size * ones.itemsize)) # items are bytes 61 | dxlist.append(dx) 62 | hx = ones if dev == 0 else zeros 63 | hip_check( 64 | hip.hipMemcpy(dx, hx, dx.size, hip.hipMemcpyKind.hipMemcpyHostToDevice) 65 | ) 66 | 67 | # perform a broadcast 68 | hip_check(rccl.ncclGroupStart()) 69 | for dev in devlist: 70 | hip_check(hip.hipSetDevice(dev)) 71 | hip_check( 72 | rccl.ncclBcast( 73 | dxlist[dev], 74 | N, 75 | rccl.ncclDataType_t.ncclInt32, 76 | 0, 77 | int(comms[dev]), 78 | None, 79 | ) 80 | ) 81 | # conversion to Python int is required to not let the numpy datatype to be interpreted as single-element Py_buffer 82 | hip_check(rccl.ncclGroupEnd()) 83 | 84 | # download and check the output; confirm all entries are one 85 | hx = np.empty(N, dtype="int32") 86 | for dev in devlist: 87 | dx = dxlist[dev] 88 | hx[:] = 0 89 | hip_check( 90 | hip.hipMemcpy(hx, dx, dx.size, hip.hipMemcpyKind.hipMemcpyDeviceToHost) 91 | ) 92 | for i, item in enumerate(hx): 93 | if item != 1: 94 | raise RuntimeError(f"failed for element {i}") 95 | 96 | # clean up 97 | for dx in dxlist: 98 | hip_check(hip.hipFree(dx)) 99 | for comm in comms: 100 | hip_check(rccl.ncclCommDestroy(int(comm))) 101 | # conversion to Python int is required to not let the numpy datatype to be interpreted as single-element Py_buffer 102 | 103 | print("ok") 104 | -------------------------------------------------------------------------------- /examples/0_Basic_Usage/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | -------------------------------------------------------------------------------- /examples/1_CUDA_Interop/Makefile: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | # [literalinclude-begin] 24 | PYTHON ?= python3 25 | 26 | .PHONY: build run clean 27 | 28 | build: 29 | $(PYTHON) setup.py build_ext --inplace 30 | run: build 31 | $(PYTHON) -c "import ccuda_stream" 32 | clean: 33 | rm -rf *.so *.c build/ -------------------------------------------------------------------------------- /examples/1_CUDA_Interop/ccuda_stream.pyx: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | # [literalinclude-begin] 26 | 27 | cimport cuda.ccudart as ccudart 28 | 29 | 30 | cdef ccudart.cudaError_t err 31 | cdef ccudart.cudaStream_t stream 32 | DEF num_bytes = 4*100 33 | cdef char[num_bytes] x_h 34 | cdef void* x_d 35 | cdef int x 36 | 37 | 38 | def cuda_check(ccudart.cudaError_t err): 39 | IF HIP_PYTHON: # HIP Python CUDA interop layer Cython interface is used like C API 40 | success_status = ccudart.cudaSuccess 41 | ELSE: 42 | success_status = ccudart.cudaError_t.cudaSuccess 43 | if err != success_status: 44 | raise RuntimeError(f"reason: {err}") 45 | 46 | 47 | IF HIP_PYTHON: 48 | print("using HIP Python wrapper for CUDA Python") 49 | 50 | cuda_check(ccudart.cudaStreamCreate(&stream)) 51 | cuda_check(ccudart.cudaMalloc(&x_d, num_bytes)) 52 | cuda_check(ccudart.cudaMemcpyAsync(x_d, x_h, num_bytes, ccudart.cudaMemcpyHostToDevice, 53 | stream)) 54 | cuda_check(ccudart.cudaMemsetAsync(x_d, 0, num_bytes, stream)) 55 | cuda_check(ccudart.cudaMemcpyAsync(x_h, x_d, num_bytes, ccudart.cudaMemcpyDeviceToHost, 56 | stream)) 57 | cuda_check(ccudart.cudaStreamSynchronize(stream)) 58 | cuda_check(ccudart.cudaStreamDestroy(stream)) 59 | 60 | # deallocate device data 61 | cuda_check(ccudart.cudaFree(x_d)) 62 | 63 | for i in range(0, round(num_bytes/4)): 64 | x = (&x_h[4*i])[0] 65 | if x != 0: 66 | raise ValueError(f"expected '0' for element {i}, is: '{x}'") 67 | print("ok") 68 | -------------------------------------------------------------------------------- /examples/1_CUDA_Interop/ccuda_stream_with_cuda_bindings.pyx: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | # [literalinclude-begin] 26 | 27 | cimport cuda.bindings.cyruntime as cyruntime 28 | 29 | 30 | cdef cyruntime.cudaError_t err 31 | cdef cyruntime.cudaStream_t stream 32 | DEF num_bytes = 4*100 33 | cdef char[num_bytes] x_h 34 | cdef void* x_d 35 | cdef int x 36 | 37 | 38 | def cuda_check(cyruntime.cudaError_t err): 39 | IF HIP_PYTHON: # HIP Python CUDA interop layer Cython interface is used like C API 40 | success_status = cyruntime.cudaSuccess 41 | ELSE: 42 | success_status = cyruntime.cudaError_t.cudaSuccess 43 | if err != success_status: 44 | raise RuntimeError(f"reason: {err}") 45 | 46 | 47 | IF HIP_PYTHON: 48 | print("using HIP Python wrapper for CUDA Python") 49 | 50 | cuda_check(cyruntime.cudaStreamCreate(&stream)) 51 | cuda_check(cyruntime.cudaMalloc(&x_d, num_bytes)) 52 | cuda_check(cyruntime.cudaMemcpyAsync(x_d, x_h, num_bytes, 53 | cyruntime.cudaMemcpyHostToDevice, stream)) 54 | cuda_check(cyruntime.cudaMemsetAsync(x_d, 0, num_bytes, stream)) 55 | cuda_check(cyruntime.cudaMemcpyAsync(x_h, x_d, num_bytes, 56 | cyruntime.cudaMemcpyDeviceToHost, stream)) 57 | cuda_check(cyruntime.cudaStreamSynchronize(stream)) 58 | cuda_check(cyruntime.cudaStreamDestroy(stream)) 59 | 60 | # deallocate device data 61 | cuda_check(cyruntime.cudaFree(x_d)) 62 | 63 | for i in range(0, round(num_bytes/4)): 64 | x = (&x_h[4*i])[0] 65 | if x != 0: 66 | raise ValueError(f"expected '0' for element {i}, is: '{x}'") 67 | print("ok") 68 | -------------------------------------------------------------------------------- /examples/1_CUDA_Interop/cuda_error_hallucinate_enums.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | """Enum constant hallucination example. 26 | 27 | Demonstrates the enum constant hallucination feature of HIP Python's enum types 28 | that can be used for porting CUDA applications with enum constants 29 | that have no HIP equivalent. 30 | 31 | The hallucinated enum types act as instances of the original type, 32 | they all have the same value, which does not conflict with the values 33 | of the original enum constants. 34 | 35 | This script: 36 | 37 | * Will fail while initializing error_kinds if you just run it as it is. 38 | 39 | * Will execute fine if you specify environment variable HIP_PYTHON_cudaError_t_HALLUCINATE=1 before running 40 | """ 41 | 42 | # [literalinclude-begin] 43 | from cuda.cudart import cudaError_t 44 | 45 | error_kinds = ( # some of those do not exist in HIP 46 | cudaError_t.cudaErrorInitializationError, 47 | cudaError_t.cudaErrorInsufficientDriver, 48 | cudaError_t.cudaErrorInvalidDeviceFunction, 49 | cudaError_t.cudaErrorInvalidDevice, 50 | cudaError_t.cudaErrorStartupFailure, # no HIP equivalent 51 | cudaError_t.cudaErrorInvalidKernelImage, 52 | cudaError_t.cudaErrorAlreadyAcquired, 53 | cudaError_t.cudaErrorOperatingSystem, 54 | cudaError_t.cudaErrorNotPermitted, # no HIP equivalent 55 | cudaError_t.cudaErrorNotSupported, 56 | cudaError_t.cudaErrorSystemNotReady, # no HIP equivalent 57 | cudaError_t.cudaErrorSystemDriverMismatch, # no HIP equivalent 58 | cudaError_t.cudaErrorCompatNotSupportedOnDevice, # no HIP equivalent 59 | cudaError_t.cudaErrorDeviceUninitialized, 60 | cudaError_t.cudaErrorTimeout, # no HIP equivalent 61 | cudaError_t.cudaErrorUnknown, 62 | cudaError_t.cudaErrorApiFailureBase, # no HIP equivalent 63 | ) 64 | 65 | for err in error_kinds: 66 | assert isinstance(err, cudaError_t) 67 | assert err != cudaError_t.cudaSuccess 68 | print("ok") 69 | -------------------------------------------------------------------------------- /examples/1_CUDA_Interop/cuda_stream.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | import array 26 | 27 | # [literalinclude-begin] 28 | import random 29 | 30 | from cuda import cuda 31 | 32 | 33 | def cuda_check(call_result): 34 | err = call_result[0] 35 | result = call_result[1:] 36 | if len(result) == 1: 37 | result = result[0] 38 | if ( 39 | isinstance(err, cuda.cudaError_t) 40 | and err != cuda.cudaError_t.cudaSuccess 41 | ): 42 | raise RuntimeError(str(err)) 43 | return result 44 | 45 | 46 | # inputs 47 | n = 100 48 | x_h = array.array("i", [int(random.random() * 10) for i in range(0, n)]) 49 | num_bytes = x_h.itemsize * len(x_h) 50 | x_d = cuda_check(cuda.cudaMalloc(num_bytes)) 51 | 52 | stream = cuda_check(cuda.cudaStreamCreate()) 53 | cuda_check( 54 | cuda.cudaMemcpyAsync( 55 | x_d, x_h, num_bytes, cuda.cudaMemcpyKind.cudaMemcpyHostToDevice, stream 56 | ) 57 | ) 58 | cuda_check(cuda.cudaMemsetAsync(x_d, 0, num_bytes, stream)) 59 | cuda_check( 60 | cuda.cudaMemcpyAsync( 61 | x_h, x_d, num_bytes, cuda.cudaMemcpyKind.cudaMemcpyDeviceToHost, stream 62 | ) 63 | ) 64 | cuda_check(cuda.cudaStreamSynchronize(stream)) 65 | cuda_check(cuda.cudaStreamDestroy(stream)) 66 | 67 | # deallocate device data 68 | cuda_check(cuda.cudaFree(x_d)) 69 | 70 | for i, x in enumerate(x_h): 71 | if x != 0: 72 | raise ValueError(f"expected '0' for element {i}, is: '{x}'") 73 | print("ok") 74 | -------------------------------------------------------------------------------- /examples/1_CUDA_Interop/cuda_stream_with_cuda_bindings.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | import array 26 | 27 | # [literalinclude-begin] 28 | import random 29 | 30 | from cuda.bindings import runtime 31 | 32 | 33 | def cuda_check(call_result): 34 | err = call_result[0] 35 | result = call_result[1:] 36 | if len(result) == 1: 37 | result = result[0] 38 | if ( 39 | isinstance(err, runtime.cudaError_t) 40 | and err != runtime.cudaError_t.cudaSuccess 41 | ): 42 | raise RuntimeError(str(err)) 43 | return result 44 | 45 | 46 | # inputs 47 | n = 100 48 | x_h = array.array("i", [int(random.random() * 10) for i in range(0, n)]) 49 | num_bytes = x_h.itemsize * len(x_h) 50 | x_d = cuda_check(runtime.cudaMalloc(num_bytes)) 51 | 52 | stream = cuda_check(runtime.cudaStreamCreate()) 53 | cuda_check( 54 | runtime.cudaMemcpyAsync( 55 | x_d, 56 | x_h, 57 | num_bytes, 58 | runtime.cudaMemcpyKind.cudaMemcpyHostToDevice, 59 | stream, 60 | ) 61 | ) 62 | cuda_check(runtime.cudaMemsetAsync(x_d, 0, num_bytes, stream)) 63 | cuda_check( 64 | runtime.cudaMemcpyAsync( 65 | x_h, 66 | x_d, 67 | num_bytes, 68 | runtime.cudaMemcpyKind.cudaMemcpyDeviceToHost, 69 | stream, 70 | ) 71 | ) 72 | cuda_check(runtime.cudaStreamSynchronize(stream)) 73 | cuda_check(runtime.cudaStreamDestroy(stream)) 74 | 75 | # deallocate device data 76 | cuda_check(runtime.cudaFree(x_d)) 77 | 78 | for i, x in enumerate(x_h): 79 | if x != 0: 80 | raise ValueError(f"expected '0' for element {i}, is: '{x}'") 81 | print("ok") 82 | -------------------------------------------------------------------------------- /examples/1_CUDA_Interop/requirements.txt: -------------------------------------------------------------------------------- 1 | cython>=3.0,<3.1 2 | -------------------------------------------------------------------------------- /examples/1_CUDA_Interop/setup.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | # [literalinclude-begin] 26 | import os 27 | 28 | from Cython.Build import cythonize 29 | from setuptools import Extension, setup 30 | 31 | ROCM_PATH = os.environ.get("ROCM_PATH", "/opt/rocm") 32 | HIP_PLATFORM = os.environ.get("HIP_PLATFORM", "amd") 33 | 34 | if HIP_PLATFORM not in ("amd", "hcc"): 35 | raise RuntimeError("Currently only HIP_PLATFORM=amd is supported") 36 | 37 | 38 | def create_extension(name, sources): 39 | global ROCM_PATH 40 | global HIP_PLATFORM 41 | rocm_inc = os.path.join(ROCM_PATH, "include") 42 | rocm_lib_dir = os.path.join(ROCM_PATH, "lib") 43 | platform = HIP_PLATFORM.upper() 44 | cflags = ["-D", f"__HIP_PLATFORM_{platform}__"] 45 | 46 | return Extension( 47 | name, 48 | sources=sources, 49 | include_dirs=[rocm_inc], 50 | library_dirs=[rocm_lib_dir], 51 | language="c", 52 | extra_compile_args=cflags, 53 | ) 54 | 55 | 56 | setup( 57 | ext_modules=cythonize( 58 | [ 59 | create_extension("ccuda_stream", ["ccuda_stream.pyx"]), 60 | ], 61 | compiler_directives=dict(language_level=3), 62 | compile_time_env=dict(HIP_PYTHON=True), 63 | ) 64 | ) 65 | -------------------------------------------------------------------------------- /examples/2_Advanced/hiprtc_linking_device_functions.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # MIT License 3 | # 4 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | 24 | """In this example, we link a device code file that contains 25 | a device kernel "__global__ void print_tid()" that has an unresolved call 26 | to a function "__device__ void foo()" in its body with a second 27 | device code file that contains the definition of device function "foo". 28 | 29 | To make this work, both snippets need to be compiled with 30 | the ``-fgpu-rdc`` option and the compilation results needs to 31 | be added as `HIPRTC_JIT_INPUT_LLVM_BITCODE` type input to the link object. 32 | """ 33 | 34 | __author__ = "Advanced Micro Devices, Inc. " 35 | 36 | # [literalinclude-begin] 37 | from hip import hip, hiprtc 38 | 39 | 40 | def hip_check(call_result): 41 | err = call_result[0] 42 | result = call_result[1:] 43 | if len(result) == 1: 44 | result = result[0] 45 | if isinstance(err, hip.hipError_t) and err != hip.hipError_t.hipSuccess: 46 | raise RuntimeError(str(err)) 47 | elif ( 48 | isinstance(err, hiprtc.hiprtcResult) 49 | and err != hiprtc.hiprtcResult.HIPRTC_SUCCESS 50 | ): 51 | raise RuntimeError(str(err)) 52 | return result 53 | 54 | 55 | class HiprtcProgram: 56 | def __init__(self, name: str, source: bytes): 57 | self.source = source 58 | self.name = name.encode("utf-8") 59 | self.prog = None 60 | self.llvm_bitcode = None 61 | self.llvm_bitcode_size = None 62 | 63 | def _get_arch(self) -> bytes: 64 | props = hip.hipDeviceProp_t() 65 | hip_check(hip.hipGetDeviceProperties(props, 0)) 66 | return props.gcnArchName 67 | 68 | def compile_to_llvm_bc(self): 69 | self.prog = hip_check( 70 | hiprtc.hiprtcCreateProgram(self.source, self.name, 0, [], []) 71 | ) 72 | cflags = [b"--offload-arch=" + self._get_arch(), b"-fgpu-rdc"] 73 | (err,) = hiprtc.hiprtcCompileProgram(self.prog, len(cflags), cflags) 74 | if err != hiprtc.hiprtcResult.HIPRTC_SUCCESS: 75 | log_size = hip_check(hiprtc.hiprtcGetProgramLogSize(self.prog)) 76 | log = bytearray(log_size) 77 | hip_check(hiprtc.hiprtcGetProgramLog(self.prog, log)) 78 | raise RuntimeError(log.decode()) 79 | self.llvm_bitcode_size = hip_check( 80 | hiprtc.hiprtcGetBitcodeSize(self.prog) 81 | ) 82 | self.llvm_bitcode = bytearray(self.llvm_bitcode_size) 83 | hip_check(hiprtc.hiprtcGetBitcode(self.prog, self.llvm_bitcode)) 84 | 85 | def __enter__(self): 86 | return self 87 | 88 | def __exit__(self, exc_type, exc_value, traceback): 89 | if self.prog is not None: 90 | hip_check(hiprtc.hiprtcDestroyProgram(self.prog.createRef())) 91 | 92 | 93 | class HiprtcLinker: 94 | def __init__(self): 95 | self.link_state = hip_check(hiprtc.hiprtcLinkCreate(0, None, None)) 96 | self.completed = False 97 | self.code = None 98 | self.code_size = None 99 | 100 | def add_program(self, hiprtc_program): 101 | hip_check( 102 | hiprtc.hiprtcLinkAddData( 103 | self.link_state, 104 | hiprtc.hiprtcJITInputType.HIPRTC_JIT_INPUT_LLVM_BITCODE, 105 | hiprtc_program.llvm_bitcode, 106 | hiprtc_program.llvm_bitcode_size, 107 | hiprtc_program.name, 108 | 0, # size of the options 109 | None, # Array of options applied to this input 110 | None, 111 | ) 112 | ) 113 | # Array of option values cast to void* 114 | 115 | def complete(self): 116 | self.code, self.code_size = hip_check( 117 | hiprtc.hiprtcLinkComplete(self.link_state) 118 | ) 119 | 120 | def __enter__(self): 121 | return self 122 | 123 | def __exit__(self, exc_type, exc_value, traceback): 124 | hip_check(hiprtc.hiprtcLinkDestroy(self.link_state)) 125 | 126 | 127 | if __name__ in ("__test__", "__main__"): 128 | import textwrap 129 | 130 | device_fun_src = textwrap.dedent( 131 | """\ 132 | __device__ void foo() { 133 | printf("tid: %d\\n", (int) threadIdx.x); 134 | } 135 | """ 136 | ).encode("utf-8") 137 | 138 | kernel_src = textwrap.dedent( 139 | """\ 140 | __device__ void foo(); // prototype 141 | 142 | extern "C" __global__ void print_tid() { 143 | foo(); 144 | } 145 | """ 146 | ).encode("utf-8") 147 | 148 | with HiprtcLinker() as linker, HiprtcProgram( 149 | "kernel", kernel_src 150 | ) as kernel_prog, HiprtcProgram( 151 | "device_fun", device_fun_src 152 | ) as device_fun_prog: 153 | kernel_prog.compile_to_llvm_bc() 154 | device_fun_prog.compile_to_llvm_bc() 155 | linker.add_program(kernel_prog) 156 | linker.add_program(device_fun_prog) 157 | linker.complete() 158 | module = hip_check(hip.hipModuleLoadData(linker.code)) 159 | kernel = hip_check(hip.hipModuleGetFunction(module, b"print_tid")) 160 | # 161 | hip_check( 162 | hip.hipModuleLaunchKernel( 163 | kernel, 164 | *(1, 1, 1), # grid 165 | *(32, 1, 1), # block 166 | sharedMemBytes=0, 167 | stream=None, 168 | kernelParams=None, 169 | extra=None, 170 | ) 171 | ) 172 | 173 | hip_check(hip.hipDeviceSynchronize()) 174 | hip_check(hip.hipModuleUnload(module)) 175 | 176 | print("ok") 177 | -------------------------------------------------------------------------------- /examples/requirements.txt: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | # Python dependencies required for examples 24 | setuptools>=42 25 | cython>=3.0,<3.1 26 | numpy 27 | # Python dependencies required for testing 28 | pytest -------------------------------------------------------------------------------- /examples/test_examples.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | import os 24 | import runpy 25 | import shlex 26 | import subprocess 27 | 28 | import pytest 29 | from hip import ROCM_VERSION_TUPLE 30 | from hip import hip as hiprt 31 | 32 | device_printf_works = ROCM_VERSION_TUPLE[0:2] != (5, 5) 33 | 34 | props = hiprt.hipDeviceProp_t() 35 | hiprt.hipGetDeviceProperties(props, 0) 36 | gpugen = props.gcnArchName.decode("utf-8").split(":")[0] 37 | have_compatible_gpu_target = gpugen == "gfx90a" 38 | 39 | try: 40 | from cuda import cuda 41 | 42 | del cuda 43 | have_hip_python_as_cuda = True 44 | except ImportError: 45 | have_hip_python_as_cuda = False 46 | 47 | python_examples = [ 48 | "0_Basic_Usage/hip_deviceattributes.py", 49 | "0_Basic_Usage/hip_deviceproperties.py", 50 | "0_Basic_Usage/hip_python_device_array.py", 51 | "0_Basic_Usage/hip_stream.py", 52 | "0_Basic_Usage/hipblas_with_numpy.py", 53 | "0_Basic_Usage/hipblas_with_numpy_and_cu_mask.py", 54 | "0_Basic_Usage/hipfft.py", 55 | "0_Basic_Usage/hiprand_monte_carlo_pi.py", 56 | "0_Basic_Usage/rccl_comminitall_bcast.py", 57 | ] 58 | 59 | if device_printf_works: 60 | python_examples += [ 61 | "0_Basic_Usage/hiprtc_launch_kernel_args.py", 62 | "0_Basic_Usage/hiprtc_launch_kernel_no_args.py", 63 | ] 64 | 65 | if have_hip_python_as_cuda: 66 | python_examples += [ 67 | "1_CUDA_Interop/cuda_stream.py", 68 | "1_CUDA_Interop/cuda_stream_with_cuda_bindings.py", 69 | "1_CUDA_Interop/cuda_error_hallucinate_enums.py", 70 | ] 71 | 72 | python_examples += [ 73 | "2_Advanced/hip_jacobi.py", 74 | "2_Advanced/hiprtc_linking_device_functions.py", 75 | ] 76 | 77 | if have_compatible_gpu_target: 78 | python_examples += [ 79 | "2_Advanced/hiprtc_jit_with_llvm_ir.py", 80 | "2_Advanced/hiprtc_linking_llvm_ir.py", 81 | ] 82 | 83 | 84 | @pytest.mark.parametrize("example", python_examples) 85 | def test_python_examples(example): 86 | abspath = os.path.join(os.path.dirname(__file__), example) 87 | runpy.run_path(abspath) 88 | 89 | 90 | if have_hip_python_as_cuda: 91 | 92 | @pytest.mark.parametrize( 93 | "example", 94 | [ 95 | "1_CUDA_Interop/ccuda_stream.pyx", 96 | "1_CUDA_Interop/ccuda_stream_with_cuda_bindings.pyx", 97 | ], 98 | ) 99 | def test_cython_examples(example): 100 | abspath = os.path.join( 101 | os.path.dirname(__file__), os.path.dirname(example) 102 | ) 103 | subprocess.check_call(shlex.split(f"make -C {abspath} run")) 104 | -------------------------------------------------------------------------------- /hip-python-as-cuda/CHANGELOG.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/hip-python/49e90526bbff06b8e874120fd1ffed7fa28cfd5b/hip-python-as-cuda/CHANGELOG.md -------------------------------------------------------------------------------- /hip-python-as-cuda/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /hip-python-as-cuda/README.md: -------------------------------------------------------------------------------- 1 | 23 | # HIP Python: CUDA Interoperability Layer 24 | 25 | This repository provides an interoperability layer that delegates CUDA® 26 | Python code in Python or Cython programs to HIP Python so that the resulting 27 | code can be executed on AMD GPUs. 28 | 29 | ## LICENSE 30 | 31 | ```text 32 | MIT License 33 | 34 | Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 35 | 36 | Permission is hereby granted, free of charge, to any person obtaining a copy 37 | of this software and associated documentation files (the "Software"), to deal 38 | in the Software without restriction, including without limitation the rights 39 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 40 | copies of the Software, and to permit persons to whom the Software is 41 | furnished to do so, subject to the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be included in all 44 | copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 47 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 49 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 50 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 51 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 52 | SOFTWARE. 53 | ``` 54 | -------------------------------------------------------------------------------- /hip-python-as-cuda/cuda/__init__.pxd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/hip-python/49e90526bbff06b8e874120fd1ffed7fa28cfd5b/hip-python-as-cuda/cuda/__init__.pxd -------------------------------------------------------------------------------- /hip-python-as-cuda/cuda/__init__.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2024 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | # This file has been autogenerated, do not modify. 24 | 25 | __author__ = "Advanced Micro Devices, Inc. " 26 | 27 | from hip._version import * 28 | ROCM_VERSION = 60400001 29 | ROCM_VERSION_NAME = rocm_version_name = "6.4.1" 30 | ROCM_VERSION_TUPLE = rocm_version_tuple = (6,4,1) 31 | HIP_VERSION = 60443483 32 | HIP_VERSION_NAME = hip_version_name = "6.4.43483-a187df25c" 33 | HIP_VERSION_TUPLE = hip_version_tuple = (6,4,43483,"a187df25c") 34 | 35 | 36 | try: 37 | from . import cuda 38 | except ImportError: 39 | pass # may have been excluded from build 40 | try: 41 | from . import cudart 42 | except ImportError: 43 | pass # may have been excluded from build 44 | try: 45 | from . import nvrtc 46 | except ImportError: 47 | pass # may have been excluded from build 48 | try: 49 | from . import bindings 50 | except ImportError: 51 | pass # may have been excluded from build -------------------------------------------------------------------------------- /hip-python-as-cuda/cuda/_version.py.in: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2024 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | # This file has been autogenerated, do not modify. 23 | 24 | __author__ = "Advanced Micro Devices, Inc. " 25 | 26 | VERSION = __version__ = "6.4.1.552.{HIP_PYTHON_VERSION_SHORT}" 27 | LONG_VERSION = __long_version__ = "6.4.1.549.dev3+ga34f943.{HIP_PYTHON_VERSION}" 28 | HIP_PYTHON_CODEGEN_BRANCH = "amd-integration" 29 | HIP_PYTHON_CODEGEN_VERSION = "549.dev3+ga34f943" 30 | HIP_PYTHON_CODEGEN_REV = "a34f943" 31 | HIP_PYTHON_BRANCH = "{HIP_PYTHON_BRANCH}" 32 | HIP_PYTHON_VERSION = "{HIP_PYTHON_VERSION}" 33 | HIP_PYTHON_REV = "{HIP_PYTHON_REV}" -------------------------------------------------------------------------------- /hip-python-as-cuda/cuda/bindings/__init__.pxd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/hip-python/49e90526bbff06b8e874120fd1ffed7fa28cfd5b/hip-python-as-cuda/cuda/bindings/__init__.pxd -------------------------------------------------------------------------------- /hip-python-as-cuda/cuda/bindings/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/hip-python/49e90526bbff06b8e874120fd1ffed7fa28cfd5b/hip-python-as-cuda/cuda/bindings/__init__.py -------------------------------------------------------------------------------- /hip-python-as-cuda/cuda/bindings/cnvrtc.pxd: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2024 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | 24 | cimport hip.chiprtc 25 | 26 | from hip.chiprtc cimport hiprtcResult as nvrtcResult 27 | from hip.chiprtc cimport HIPRTC_SUCCESS 28 | from hip.chiprtc cimport HIPRTC_SUCCESS as NVRTC_SUCCESS 29 | from hip.chiprtc cimport HIPRTC_ERROR_OUT_OF_MEMORY 30 | from hip.chiprtc cimport HIPRTC_ERROR_OUT_OF_MEMORY as NVRTC_ERROR_OUT_OF_MEMORY 31 | from hip.chiprtc cimport HIPRTC_ERROR_PROGRAM_CREATION_FAILURE 32 | from hip.chiprtc cimport HIPRTC_ERROR_PROGRAM_CREATION_FAILURE as NVRTC_ERROR_PROGRAM_CREATION_FAILURE 33 | from hip.chiprtc cimport HIPRTC_ERROR_INVALID_INPUT 34 | from hip.chiprtc cimport HIPRTC_ERROR_INVALID_INPUT as NVRTC_ERROR_INVALID_INPUT 35 | from hip.chiprtc cimport HIPRTC_ERROR_INVALID_PROGRAM 36 | from hip.chiprtc cimport HIPRTC_ERROR_INVALID_PROGRAM as NVRTC_ERROR_INVALID_PROGRAM 37 | from hip.chiprtc cimport HIPRTC_ERROR_INVALID_OPTION 38 | from hip.chiprtc cimport HIPRTC_ERROR_INVALID_OPTION as NVRTC_ERROR_INVALID_OPTION 39 | from hip.chiprtc cimport HIPRTC_ERROR_COMPILATION 40 | from hip.chiprtc cimport HIPRTC_ERROR_COMPILATION as NVRTC_ERROR_COMPILATION 41 | from hip.chiprtc cimport HIPRTC_ERROR_BUILTIN_OPERATION_FAILURE 42 | from hip.chiprtc cimport HIPRTC_ERROR_BUILTIN_OPERATION_FAILURE as NVRTC_ERROR_BUILTIN_OPERATION_FAILURE 43 | from hip.chiprtc cimport HIPRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION 44 | from hip.chiprtc cimport HIPRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION as NVRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION 45 | from hip.chiprtc cimport HIPRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION 46 | from hip.chiprtc cimport HIPRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION as NVRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION 47 | from hip.chiprtc cimport HIPRTC_ERROR_NAME_EXPRESSION_NOT_VALID 48 | from hip.chiprtc cimport HIPRTC_ERROR_NAME_EXPRESSION_NOT_VALID as NVRTC_ERROR_NAME_EXPRESSION_NOT_VALID 49 | from hip.chiprtc cimport HIPRTC_ERROR_INTERNAL_ERROR 50 | from hip.chiprtc cimport HIPRTC_ERROR_INTERNAL_ERROR as NVRTC_ERROR_INTERNAL_ERROR 51 | from hip.chiprtc cimport HIPRTC_ERROR_LINKING 52 | from hip.chiprtc cimport ihiprtcLinkState as CUlinkState_st 53 | from hip.chiprtc cimport hiprtcLinkState as CUlinkState 54 | from hip.chiprtc cimport hiprtcGetErrorString as nvrtcGetErrorString 55 | from hip.chiprtc cimport hiprtcVersion as nvrtcVersion 56 | from hip.chiprtc cimport hiprtcProgram as nvrtcProgram 57 | from hip.chiprtc cimport hiprtcAddNameExpression as nvrtcAddNameExpression 58 | from hip.chiprtc cimport hiprtcCompileProgram as nvrtcCompileProgram 59 | from hip.chiprtc cimport hiprtcCreateProgram as nvrtcCreateProgram 60 | from hip.chiprtc cimport hiprtcDestroyProgram as nvrtcDestroyProgram 61 | from hip.chiprtc cimport hiprtcGetLoweredName as nvrtcGetLoweredName 62 | from hip.chiprtc cimport hiprtcGetProgramLog as nvrtcGetProgramLog 63 | from hip.chiprtc cimport hiprtcGetProgramLogSize as nvrtcGetProgramLogSize 64 | from hip.chiprtc cimport hiprtcGetCode as nvrtcGetPTX 65 | from hip.chiprtc cimport hiprtcGetCodeSize as nvrtcGetPTXSize 66 | from hip.chiprtc cimport hiprtcGetBitcode as nvrtcGetCUBIN 67 | from hip.chiprtc cimport hiprtcGetBitcodeSize as nvrtcGetCUBINSize 68 | from hip.chiprtc cimport hiprtcLinkCreate as cuLinkCreate 69 | from hip.chiprtc cimport hiprtcLinkCreate as cuLinkCreate_v2 70 | from hip.chiprtc cimport hiprtcLinkAddFile as cuLinkAddFile 71 | from hip.chiprtc cimport hiprtcLinkAddFile as cuLinkAddFile_v2 72 | from hip.chiprtc cimport hiprtcLinkAddData as cuLinkAddData 73 | from hip.chiprtc cimport hiprtcLinkAddData as cuLinkAddData_v2 74 | from hip.chiprtc cimport hiprtcLinkComplete as cuLinkComplete 75 | from hip.chiprtc cimport hiprtcLinkDestroy as cuLinkDestroy -------------------------------------------------------------------------------- /hip-python-as-cuda/cuda/bindings/nvrtc.pxd: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2024 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | 24 | __author__ = "Advanced Micro Devices, Inc. " 25 | 26 | cimport hip.chiprtc 27 | cimport hip.hiprtc 28 | 29 | cimport cuda.bindings.cnvrtc 30 | cdef class CUlinkState_st(hip.hiprtc.ihiprtcLinkState): 31 | pass -------------------------------------------------------------------------------- /hip-python-as-cuda/cuda/cnvrtc.pxd: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2024 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | 24 | cimport hip.chiprtc 25 | 26 | from hip.chiprtc cimport hiprtcResult as nvrtcResult 27 | from hip.chiprtc cimport HIPRTC_SUCCESS 28 | from hip.chiprtc cimport HIPRTC_SUCCESS as NVRTC_SUCCESS 29 | from hip.chiprtc cimport HIPRTC_ERROR_OUT_OF_MEMORY 30 | from hip.chiprtc cimport HIPRTC_ERROR_OUT_OF_MEMORY as NVRTC_ERROR_OUT_OF_MEMORY 31 | from hip.chiprtc cimport HIPRTC_ERROR_PROGRAM_CREATION_FAILURE 32 | from hip.chiprtc cimport HIPRTC_ERROR_PROGRAM_CREATION_FAILURE as NVRTC_ERROR_PROGRAM_CREATION_FAILURE 33 | from hip.chiprtc cimport HIPRTC_ERROR_INVALID_INPUT 34 | from hip.chiprtc cimport HIPRTC_ERROR_INVALID_INPUT as NVRTC_ERROR_INVALID_INPUT 35 | from hip.chiprtc cimport HIPRTC_ERROR_INVALID_PROGRAM 36 | from hip.chiprtc cimport HIPRTC_ERROR_INVALID_PROGRAM as NVRTC_ERROR_INVALID_PROGRAM 37 | from hip.chiprtc cimport HIPRTC_ERROR_INVALID_OPTION 38 | from hip.chiprtc cimport HIPRTC_ERROR_INVALID_OPTION as NVRTC_ERROR_INVALID_OPTION 39 | from hip.chiprtc cimport HIPRTC_ERROR_COMPILATION 40 | from hip.chiprtc cimport HIPRTC_ERROR_COMPILATION as NVRTC_ERROR_COMPILATION 41 | from hip.chiprtc cimport HIPRTC_ERROR_BUILTIN_OPERATION_FAILURE 42 | from hip.chiprtc cimport HIPRTC_ERROR_BUILTIN_OPERATION_FAILURE as NVRTC_ERROR_BUILTIN_OPERATION_FAILURE 43 | from hip.chiprtc cimport HIPRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION 44 | from hip.chiprtc cimport HIPRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION as NVRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION 45 | from hip.chiprtc cimport HIPRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION 46 | from hip.chiprtc cimport HIPRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION as NVRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION 47 | from hip.chiprtc cimport HIPRTC_ERROR_NAME_EXPRESSION_NOT_VALID 48 | from hip.chiprtc cimport HIPRTC_ERROR_NAME_EXPRESSION_NOT_VALID as NVRTC_ERROR_NAME_EXPRESSION_NOT_VALID 49 | from hip.chiprtc cimport HIPRTC_ERROR_INTERNAL_ERROR 50 | from hip.chiprtc cimport HIPRTC_ERROR_INTERNAL_ERROR as NVRTC_ERROR_INTERNAL_ERROR 51 | from hip.chiprtc cimport HIPRTC_ERROR_LINKING 52 | from hip.chiprtc cimport ihiprtcLinkState as CUlinkState_st 53 | from hip.chiprtc cimport hiprtcLinkState as CUlinkState 54 | from hip.chiprtc cimport hiprtcGetErrorString as nvrtcGetErrorString 55 | from hip.chiprtc cimport hiprtcVersion as nvrtcVersion 56 | from hip.chiprtc cimport hiprtcProgram as nvrtcProgram 57 | from hip.chiprtc cimport hiprtcAddNameExpression as nvrtcAddNameExpression 58 | from hip.chiprtc cimport hiprtcCompileProgram as nvrtcCompileProgram 59 | from hip.chiprtc cimport hiprtcCreateProgram as nvrtcCreateProgram 60 | from hip.chiprtc cimport hiprtcDestroyProgram as nvrtcDestroyProgram 61 | from hip.chiprtc cimport hiprtcGetLoweredName as nvrtcGetLoweredName 62 | from hip.chiprtc cimport hiprtcGetProgramLog as nvrtcGetProgramLog 63 | from hip.chiprtc cimport hiprtcGetProgramLogSize as nvrtcGetProgramLogSize 64 | from hip.chiprtc cimport hiprtcGetCode as nvrtcGetPTX 65 | from hip.chiprtc cimport hiprtcGetCodeSize as nvrtcGetPTXSize 66 | from hip.chiprtc cimport hiprtcGetBitcode as nvrtcGetCUBIN 67 | from hip.chiprtc cimport hiprtcGetBitcodeSize as nvrtcGetCUBINSize 68 | from hip.chiprtc cimport hiprtcLinkCreate as cuLinkCreate 69 | from hip.chiprtc cimport hiprtcLinkCreate as cuLinkCreate_v2 70 | from hip.chiprtc cimport hiprtcLinkAddFile as cuLinkAddFile 71 | from hip.chiprtc cimport hiprtcLinkAddFile as cuLinkAddFile_v2 72 | from hip.chiprtc cimport hiprtcLinkAddData as cuLinkAddData 73 | from hip.chiprtc cimport hiprtcLinkAddData as cuLinkAddData_v2 74 | from hip.chiprtc cimport hiprtcLinkComplete as cuLinkComplete 75 | from hip.chiprtc cimport hiprtcLinkDestroy as cuLinkDestroy -------------------------------------------------------------------------------- /hip-python-as-cuda/cuda/nvrtc.pxd: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2024 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | 24 | __author__ = "Advanced Micro Devices, Inc. " 25 | 26 | cimport hip.chiprtc 27 | cimport hip.hiprtc 28 | 29 | cimport cuda.cnvrtc 30 | cdef class CUlinkState_st(hip.hiprtc.ihiprtcLinkState): 31 | pass -------------------------------------------------------------------------------- /hip-python-as-cuda/pyproject.toml: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | [build-system] 23 | requires = [ # PEP 508 specifications 24 | "setuptools>=10.0.1", 25 | "wheel", 26 | "cython", 27 | ] 28 | build-backend = "setuptools.build_meta" -------------------------------------------------------------------------------- /hip-python-as-cuda/requirements.txt.in: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2024 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | # This file has been autogenerated, do not modify. 24 | 25 | # Python dependencies required for development 26 | setuptools>=42 27 | cython>=3.0,<3.1 28 | wheel 29 | build 30 | hip-python==6.4.1.552.{HIP_PYTHON_VERSION_SHORT} -------------------------------------------------------------------------------- /hip-python-as-cuda/setup.cfg: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | [metadata] 23 | name = hip-python-as-cuda 24 | description = Use HIP Python via CUDA names 25 | author = Advanced Micro Devices, Inc. 26 | author_email = hip-python.maintainer@amd.com 27 | url = https://github.com/ROCmSoftwarePlatform/hip-python 28 | license = MIT 29 | license_files = LICENSE 30 | long_description = file: README.md 31 | long_description_content_type = text/markdown 32 | # see: https://pypi.org/pypi?%3Aaction=list_classifiers 33 | classifiers = 34 | Intended Audience :: Developers 35 | Topic :: Scientific/Engineering 36 | Topic :: Software Development :: Libraries 37 | Environment :: GPU 38 | Programming Language :: Python :: 3.7 39 | Programming Language :: Cython 40 | License :: OSI Approved :: MIT License 41 | Development Status :: 2 - Pre-Alpha 42 | 43 | [build_ext] 44 | inplace=1 45 | 46 | [options] 47 | python_requires = >=3.7, <4 48 | setup_requires = 49 | cython >=3.0,<3.1 50 | wheel 51 | zip_safe = False 52 | packages = 53 | cuda 54 | cuda.bindings 55 | 56 | [options.package_data] 57 | # Add Python and Cython files to the package 58 | cuda = *.pxd, *.pyx, *.so, __init__.py 59 | cuda.bindings = *.pxd, *.pyx, *.so, __init__.py 60 | -------------------------------------------------------------------------------- /hip-python/CHANGELOG.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/hip-python/49e90526bbff06b8e874120fd1ffed7fa28cfd5b/hip-python/CHANGELOG.md -------------------------------------------------------------------------------- /hip-python/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /hip-python/README.md: -------------------------------------------------------------------------------- 1 | 23 | # HIP Python 24 | 25 | This repository provides low-level Python and Cython bindings for HIP. 26 | Currently, only bindings for the AMD GPU backend of HIP are provided. 27 | 28 | ## Known Issues 29 | 30 | ### The `hiprand` Cython Module Causes Compiler Error 31 | 32 | With all ROCm™ versions before and including version 5.6.0, 33 | compiling/using HIP Python's `hiprand` Cython module results in 34 | a compiler error. 35 | 36 | The error is caused by the following statement in the C compilation 37 | path of `/hiprand/hiprand_hcc.h`, which is not legal in C 38 | for aliasing a `struct` type: 39 | 40 | ```c 41 | typedef rocrand_generator_base_type hiprandGenerator_st; 42 | ``` 43 | 44 | #### Workaround (Requires Access to Header File): Edit Header File 45 | 46 | For this fix, you need write access to the ROCm™ header files. 47 | Then, modify file `/hiprand/hiprand_hcc.h` such that 48 | 49 | ```c 50 | typedef rocrand_generator_base_type hiprandGenerator_st; 51 | ``` 52 | 53 | becomes 54 | 55 | ```c 56 | typedef struct rocrand_generator_base_type hiprandGenerator_st; 57 | ``` 58 | 59 | ### ROCm™ 5.5.0 and ROCm™ 5.5.1 60 | 61 | On systems with ROCm™ HIP SDK 5.5.0 or 5.5.1, the examples 62 | 63 | * hip-python/examples/0_Basic_Usage/hiprtc_launch_kernel_args.py 64 | * hip-python/examples/0_Basic_Usage/hiprtc_launch_kernel_no_args.py 65 | 66 | abort with errors. 67 | 68 | An upgrade to version HIP SDK 5.6 or later (or a downgrade to version 5.4) is 69 | advised if the showcased functionality is needed. 70 | 71 | ## Documentation 72 | 73 | For examples, guides and API reference, please take a 74 | look at the official HIP Python documentation pages: 75 | 76 | 77 | 78 | ## LICENSE 79 | 80 | ```text 81 | MIT License 82 | 83 | Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 84 | 85 | Permission is hereby granted, free of charge, to any person obtaining a copy 86 | of this software and associated documentation files (the "Software"), to deal 87 | in the Software without restriction, including without limitation the rights 88 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 89 | copies of the Software, and to permit persons to whom the Software is 90 | furnished to do so, subject to the following conditions: 91 | 92 | The above copyright notice and this permission notice shall be included in all 93 | copies or substantial portions of the Software. 94 | 95 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 96 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 97 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 98 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 99 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 100 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 101 | SOFTWARE. 102 | ``` 103 | -------------------------------------------------------------------------------- /hip-python/hip/__init__.py: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2024 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | # This file has been autogenerated, do not modify. 24 | 25 | __author__ = "Advanced Micro Devices, Inc. " 26 | 27 | from hip._version import * 28 | ROCM_VERSION = 60400001 29 | ROCM_VERSION_NAME = rocm_version_name = "6.4.1" 30 | ROCM_VERSION_TUPLE = rocm_version_tuple = (6,4,1) 31 | HIP_VERSION = 60443483 32 | HIP_VERSION_NAME = hip_version_name = "6.4.43483-a187df25c" 33 | HIP_VERSION_TUPLE = hip_version_tuple = (6,4,43483,"a187df25c") 34 | 35 | 36 | from . import _util 37 | try: 38 | from . import hip 39 | except ImportError: 40 | pass # may have been excluded from build 41 | try: 42 | from . import hiprtc 43 | except ImportError: 44 | pass # may have been excluded from build 45 | else: # no import error 46 | from . import hiprtc_pyext 47 | setattr(hiprtc,"ext",hiprtc_pyext) 48 | try: 49 | from . import hipblas 50 | except ImportError: 51 | pass # may have been excluded from build 52 | try: 53 | from . import rccl 54 | except ImportError: 55 | pass # may have been excluded from build 56 | try: 57 | from . import hiprand 58 | except ImportError: 59 | pass # may have been excluded from build 60 | try: 61 | from . import hipfft 62 | except ImportError: 63 | pass # may have been excluded from build 64 | try: 65 | from . import hipsparse 66 | except ImportError: 67 | pass # may have been excluded from build 68 | try: 69 | from . import roctx 70 | except ImportError: 71 | pass # may have been excluded from build 72 | try: 73 | from . import hipsolver 74 | except ImportError: 75 | pass # may have been excluded from build -------------------------------------------------------------------------------- /hip-python/hip/_hip_helpers.pxd: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | cimport hip._util.types 26 | 27 | 28 | cdef class HipModuleLaunchKernel_extra(hip._util.types.Pointer): 29 | cdef bint _is_ptr_owner 30 | cdef void* _config[5] 31 | cdef size_t _args_buffer_size 32 | 33 | cdef size_t _aligned_size(self, size_t size, size_t factor) 34 | 35 | @staticmethod 36 | cdef HipModuleLaunchKernel_extra fromPtr(void* ptr) 37 | 38 | cdef void init_from_pyobj(self, object pyobj) 39 | 40 | @staticmethod 41 | cdef HipModuleLaunchKernel_extra fromPyobj(object pyobj) 42 | -------------------------------------------------------------------------------- /hip-python/hip/_hiprtc_helpers.pxd: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2024-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | cimport hip._util.types 26 | 27 | 28 | cdef class HiprtcLinkCreate_option_ptr(hip._util.types.Pointer): 29 | cdef bint _is_ptr_owner 30 | 31 | @staticmethod 32 | cdef HiprtcLinkCreate_option_ptr fromPtr(void* ptr) 33 | 34 | cdef void init_from_pyobj(self, object pyobj) 35 | 36 | @staticmethod 37 | cdef HiprtcLinkCreate_option_ptr fromPyobj(object pyobj) 38 | -------------------------------------------------------------------------------- /hip-python/hip/_hiprtc_helpers.pyx: -------------------------------------------------------------------------------- 1 | cimport cpython.list 2 | cimport cpython.long 3 | cimport hip.chiprtc 4 | cimport libc.stdlib 5 | cimport libc.string 6 | 7 | import hip.hiprtc 8 | 9 | __all__ = [ 10 | # __all__ is important for generating the API documentation in source order 11 | "HiprtcLinkCreate_option_ptr", 12 | "HiprtcLinkCreate_option_vals_pptr", 13 | ] 14 | 15 | cdef class HiprtcLinkCreate_option_ptr(hip._util.types.Pointer): 16 | """Type for handling Python `list` or `tuple` with `~.hiprtcJIT_option` entries. 17 | 18 | Datatype for handling Python `list` or `tuple` objects with `~.hiprtcJIT_option` 19 | entries. 20 | 21 | This type can be initialized from the following Python objects: 22 | 23 | * `list` or `tuple` object: 24 | 25 | `list` or `tuple` object with `~.hiprtcJIT_option` entries. 26 | 27 | * `object` that is accepted as input by `~.Pointer.__init__`: 28 | 29 | In this case, init code from `~.Pointer` is used and the C attribute 30 | `self._is_ptr_owner ` remains unchanged. See `~.Pointer.__init__` for more 31 | information. 32 | 33 | Note: 34 | Type checks are performed in the above order. 35 | 36 | See: 37 | `~.hiprtcLinkCreate` 38 | """ 39 | # members declared in declaration part (.pxd) 40 | 41 | @staticmethod 42 | cdef HiprtcLinkCreate_option_ptr fromPtr(void* ptr): 43 | cdef HiprtcLinkCreate_option_ptr wrapper = HiprtcLinkCreate_option_ptr.__new__( 44 | HiprtcLinkCreate_option_ptr) 45 | wrapper._ptr = ptr 46 | return wrapper 47 | 48 | cdef void init_from_pyobj(self, object pyobj): 49 | cdef Py_ssize_t num_entries = 0 50 | cdef unsigned int* element_ptr = NULL 51 | cdef size_t entry_size = sizeof(unsigned int) # see: hip.hiprtc.hiprtcJIT_option.ctypes_type() # no-cython-lint 52 | 53 | self._py_buffer_acquired = False 54 | self._is_ptr_owner = False 55 | if isinstance(pyobj, HiprtcLinkCreate_option_ptr): 56 | self._ptr = (pyobj)._ptr 57 | elif isinstance(pyobj, (tuple, list)): 58 | self._is_ptr_owner = True 59 | num_entries = len(pyobj) 60 | self._ptr = libc.stdlib.malloc(num_entries*entry_size) 61 | element_ptr = self._ptr # see: hip.hiprtc.hiprtcJIT_option.ctypes_type() # no-cython-lint 62 | 63 | # 3. Copy the data into the struct and calculate the offset 64 | for i in range(0, num_entries): 65 | entry = pyobj[i] 66 | if not isinstance(entry, hip.hiprtc.hiprtcJIT_option): 67 | raise ValueError( 68 | "list/tuple entries must be of type" 69 | + "'hip.hiprtc.hiprtcJIT_option'" 70 | ) 71 | element_ptr[i] = cpython.long.PyLong_AsUnsignedLong( 72 | entry.value) 73 | else: 74 | hip._util.types.Pointer.init_from_pyobj(self, pyobj) 75 | 76 | @staticmethod 77 | def fromObj(pyobj): 78 | """Creates a HiprtcLinkCreate_option_ptr from the given object. 79 | 80 | In case ``pyobj`` is itself a ``HiprtcLinkCreate_option_ptr`` instance, 81 | this method returns it directly. No new ``HiprtcLinkCreate_option_ptr`` is 82 | created. 83 | """ 84 | return HiprtcLinkCreate_option_ptr.fromPyobj(pyobj) 85 | 86 | @staticmethod 87 | cdef HiprtcLinkCreate_option_ptr fromPyobj(object pyobj): 88 | """Creates a HiprtcLinkCreate_option_ptr from the given object. 89 | 90 | In case ``pyobj`` is itself a ``HiprtcLinkCreate_option_ptr`` instance, this 91 | method returns it directly. No new ``HiprtcLinkCreate_option_ptr`` is created. 92 | 93 | Args: 94 | pyobj (`object`): 95 | Must be either ``None``, a simple, contiguous buffer according to the 96 | buffer protocol, or of type ``_util.types.Pointer``, 97 | ``HiprtcLinkCreate_option_ptr``, ``int``, or ``ctypes.c_void_p`` 98 | 99 | Furthermore, ``pyobj`` can be a list or tuple in the following shape, 100 | where each entry must be of type `~.hiprtcJIT_option`. 101 | 102 | Note: 103 | This routine does not perform a copy but returns the original pyobj 104 | if ``pyobj`` is an instance of HiprtcLinkCreate_option_ptr. 105 | """ 106 | cdef HiprtcLinkCreate_option_ptr wrapper = HiprtcLinkCreate_option_ptr.__new__( 107 | HiprtcLinkCreate_option_ptr) 108 | 109 | if isinstance(pyobj, HiprtcLinkCreate_option_ptr): 110 | return pyobj 111 | else: 112 | wrapper = HiprtcLinkCreate_option_ptr.__new__(HiprtcLinkCreate_option_ptr) 113 | wrapper.init_from_pyobj(pyobj) 114 | return wrapper 115 | 116 | def __dealloc__(self): 117 | if self._is_ptr_owner : 118 | libc.stdlib.free(self._ptr) 119 | 120 | def __init__(self, object pyobj): 121 | """Constructor. 122 | 123 | This type can be initialized from the following Python objects: 124 | 125 | * `list` or `tuple` object: 126 | 127 | `list` or `tuple` object with `~.hiprtcJIT_option` entries. 128 | 129 | * `object` that is accepted as input by `~.Pointer.__init__`: 130 | 131 | In this case, init code from `~.Pointer` is used and the C attribute 132 | `self._is_ptr_owner ` remains unchanged. See `~.Pointer.__init__` for more 133 | information. 134 | 135 | Note: 136 | Type checks are performed in the above order. 137 | 138 | Args: 139 | pyobj (`object`): 140 | Must be either a `list` or `tuple` of objects that can be converted 141 | to `~.Pointer`, or any other `object` that is accepted as input by 142 | `~.Pointer.__init__`. 143 | 144 | See: 145 | `~.hipModuleLaunchKernel` 146 | """ 147 | HiprtcLinkCreate_option_ptr.init_from_pyobj(self, pyobj) 148 | -------------------------------------------------------------------------------- /hip-python/hip/_util/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ROCm/hip-python/49e90526bbff06b8e874120fd1ffed7fa28cfd5b/hip-python/hip/_util/__init__.py -------------------------------------------------------------------------------- /hip-python/hip/_util/posixloader.pxd: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2024 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | cdef int open_library(void** lib_handle, const char* path) except 1 nogil 26 | cdef int close_library(void* lib_handle) except 1 nogil 27 | cdef int load_symbol(void** handle, void* lib_handle, const char* name) except 1 nogil 28 | -------------------------------------------------------------------------------- /hip-python/hip/_util/posixloader.pyx: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2024 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | cimport posix.dlfcn 26 | 27 | 28 | cdef int open_library(void** lib_handle, const char* path) except 1 nogil: 29 | """Opens a shared object and returns a handle for it via out parameter. 30 | 31 | Args: 32 | lib_handle (void**, out): 33 | The library handle, the result. 34 | If an error has occured, the dereferenced value is NULL. 35 | Returns: 36 | Positive number if something has gone wrong, '0' otherwise. 37 | """ 38 | lib_handle[0] = posix.dlfcn.dlopen(path, posix.dlfcn.RTLD_NOW) 39 | cdef char* reason = NULL 40 | if lib_handle[0] == NULL: 41 | reason = posix.dlfcn.dlerror() 42 | raise RuntimeError(f"failed to dlopen '{str(path)}': {str(reason)}") 43 | return 0 44 | 45 | cdef int close_library(void* lib_handle) except 1 nogil: 46 | """Closes the given shared object. 47 | 48 | Args: 49 | lib_handle (void*, in): 50 | Handle to the library to close. 51 | Returns: 52 | Positive number if something has gone wrong, '0' otherwise. 53 | """ 54 | if lib_handle == NULL: 55 | raise RuntimeError("handle is NULL") 56 | cdef int rtype = posix.dlfcn.dlclose(lib_handle) 57 | cdef char* reason = NULL 58 | if rtype != 0: 59 | reason = posix.dlfcn.dlerror() 60 | raise RuntimeError(f"failed to dclose given handle: {reason}") 61 | return 0 62 | 63 | cdef int load_symbol(void** handle, void* lib_handle, const char* name) except 1 nogil: 64 | """Returns a symbol handle from an openend shared object via out parameter. 65 | 66 | Args: 67 | handle (void**, in): 68 | The symbol handle, the result. 69 | If an error has occured, the dereferenced value is NULL. 70 | lib_handle (void*, in): 71 | Shared object handle. 72 | name (char*, in): 73 | Name of the symbol. 74 | Returns: 75 | Positive number if something has gone wrong, '0' otherwise. 76 | """ 77 | handle[0] = posix.dlfcn.dlsym(lib_handle, name) 78 | cdef char* reason = NULL 79 | if handle[0] == NULL: 80 | reason = posix.dlfcn.dlerror() 81 | raise RuntimeError(f"failed to dlsym '{name}': {reason}") 82 | return 0 83 | -------------------------------------------------------------------------------- /hip-python/hip/_util/types.pxd: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2024 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | __author__ = "Advanced Micro Devices, Inc. " 24 | 25 | cdef class Pointer: 26 | cdef void* _ptr 27 | cdef Py_buffer _py_buffer 28 | cdef bint _py_buffer_acquired 29 | 30 | # Camel-case used by intent to make this orthogonal to get_(self, i) 31 | # of auto-generated subclasses. 32 | cdef void* getPtr(self) 33 | 34 | cpdef Pointer createRef(self) 35 | 36 | @staticmethod 37 | cdef Pointer fromPtr(void* ptr) 38 | 39 | cdef void init_from_pyobj(self, object pyobj) 40 | 41 | @staticmethod 42 | cdef Pointer fromPyobj(object pyobj) 43 | 44 | cdef class CStr(Pointer): 45 | cdef bint _is_ptr_owner 46 | # These buffer protocol related arrays 47 | # have to stay alive as long 48 | # as any buffer views the data, 49 | # so we store them as members. 50 | cdef Py_ssize_t[1] _shape 51 | 52 | @staticmethod 53 | cdef CStr fromPtr(void* ptr) 54 | 55 | @staticmethod 56 | cdef CStr fromPyobj(object pyobj) 57 | 58 | cdef Py_ssize_t get_or_determine_len(self) 59 | 60 | cdef const char* getElementPtr(self) 61 | 62 | cpdef void malloc(self, Py_ssize_t size_bytes) 63 | 64 | cpdef void free(self) 65 | 66 | cdef class ImmortalCStr(CStr): 67 | 68 | @staticmethod 69 | cdef ImmortalCStr fromPtr(void* ptr) 70 | 71 | @staticmethod 72 | cdef ImmortalCStr fromPyobj(object pyobj) 73 | 74 | cdef class NDBuffer(Pointer): 75 | cdef size_t _itemsize # itemsize is not part of the CUDA array interface 76 | cdef dict __dict__ 77 | cdef Py_ssize_t* _py_buffer_shape # shape info for this Python buffer 78 | cdef int __view_count # For counting the current number of views 79 | 80 | @staticmethod 81 | cdef NDBuffer fromPtr(void* ptr) 82 | 83 | @staticmethod 84 | cdef NDBuffer fromPyobj(object pyobj) 85 | 86 | cdef _set_ptr(self, void* ptr) 87 | 88 | cdef int _numpy_typestr_to_bytes(self, str typestr) 89 | 90 | cdef tuple _handle_int(self, size_t subscript, size_t shape_dim) 91 | 92 | cdef tuple _handle_slice(self, slice subscript, size_t shape_dim) 93 | 94 | cdef class DeviceArray(NDBuffer): 95 | 96 | @staticmethod 97 | cdef DeviceArray fromPtr(void* ptr) 98 | 99 | @staticmethod 100 | cdef DeviceArray fromPyobj(object pyobj) 101 | 102 | cdef class ListOfPointer(Pointer): 103 | cdef bint _is_ptr_owner 104 | 105 | @staticmethod 106 | cdef ListOfPointer fromPtr(void* ptr) 107 | 108 | @staticmethod 109 | cdef ListOfPointer fromPyobj(object pyobj) 110 | 111 | cdef class ListOfBytes(Pointer): 112 | cdef bint _is_ptr_owner 113 | 114 | @staticmethod 115 | cdef ListOfBytes fromPtr(void* ptr) 116 | 117 | @staticmethod 118 | cdef ListOfBytes fromPyobj(object pyobj) 119 | 120 | cdef class ListOfInt(Pointer): 121 | cdef bint _is_ptr_owner 122 | 123 | @staticmethod 124 | cdef ListOfInt fromPtr(void* ptr) 125 | 126 | @staticmethod 127 | cdef ListOfInt fromPyobj(object pyobj) 128 | 129 | cdef class ListOfUnsigned(Pointer): 130 | cdef bint _is_ptr_owner 131 | 132 | @staticmethod 133 | cdef ListOfUnsigned fromPtr(void* ptr) 134 | 135 | @staticmethod 136 | cdef ListOfUnsigned fromPyobj(object pyobj) 137 | 138 | cdef class ListOfUnsignedLong(Pointer): 139 | cdef bint _is_ptr_owner 140 | 141 | @staticmethod 142 | cdef ListOfUnsignedLong fromPtr(void* ptr) 143 | 144 | @staticmethod 145 | cdef ListOfUnsignedLong fromPyobj(object pyobj) 146 | -------------------------------------------------------------------------------- /hip-python/hip/_version.py.in: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2024 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | # This file has been autogenerated, do not modify. 23 | 24 | __author__ = "Advanced Micro Devices, Inc. " 25 | 26 | VERSION = __version__ = "6.4.1.552.{HIP_PYTHON_VERSION_SHORT}" 27 | LONG_VERSION = __long_version__ = "6.4.1.549.dev3+ga34f943.{HIP_PYTHON_VERSION}" 28 | HIP_PYTHON_CODEGEN_BRANCH = "amd-integration" 29 | HIP_PYTHON_CODEGEN_VERSION = "549.dev3+ga34f943" 30 | HIP_PYTHON_CODEGEN_REV = "a34f943" 31 | HIP_PYTHON_BRANCH = "{HIP_PYTHON_BRANCH}" 32 | HIP_PYTHON_VERSION = "{HIP_PYTHON_VERSION}" 33 | HIP_PYTHON_REV = "{HIP_PYTHON_REV}" -------------------------------------------------------------------------------- /hip-python/hip/croctx.pxd: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2021-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | 24 | # This file has been autogenerated, do not modify. 25 | 26 | from libc.stdint cimport * 27 | ctypedef bint _Bool # bool is not a reserved keyword in C, _Bool is 28 | cdef extern from "roctracer/roctx.h": 29 | 30 | cdef int ROCTX_VERSION_MAJOR 31 | 32 | cdef int ROCTX_VERSION_MINOR 33 | 34 | # 35 | # Query the major version of the installed library. 36 | # 37 | # Return the major version of the installed library. This can be used to check 38 | # if it is compatible with this interface version. 39 | # 40 | # \return Returns the major version number. 41 | cdef unsigned int roctx_version_major() 42 | 43 | 44 | # 45 | # Query the minor version of the installed library. 46 | # 47 | # Return the minor version of the installed library. This can be used to check 48 | # if it is compatible with this interface version. 49 | # 50 | # \return Returns the minor version number. 51 | cdef unsigned int roctx_version_minor() 52 | 53 | 54 | # 55 | # Mark an event. 56 | # 57 | # \param[in] message The message associated with the event. 58 | cdef void roctxMarkA(const char * message) 59 | 60 | 61 | # 62 | # Start a new nested range. 63 | # 64 | # Nested ranges are stacked and local to the current CPU thread. 65 | # 66 | # \param[in] message The message associated with this range. 67 | # 68 | # \return Returns the level this nested range is started at. Nested range 69 | # levels are 0 based. 70 | cdef int roctxRangePushA(const char * message) 71 | 72 | 73 | # 74 | # Stop the current nested range. 75 | # 76 | # Stop the current nested range, and pop it from the stack. If a nested range 77 | # was active before the last one was started, it becomes again the current 78 | # nested range. 79 | # 80 | # \return Returns the level the stopped nested range was started at, or a 81 | # negative value if there was no nested range active. 82 | cdef int roctxRangePop() 83 | 84 | 85 | cdef extern from "roctracer/roctx.h": 86 | 87 | ctypedef unsigned long roctx_range_id_t 88 | 89 | # 90 | # Starts a process range. 91 | # 92 | # Start/stop ranges can be started and stopped in different threads. Each 93 | # timespan is assigned a unique range ID. 94 | # 95 | # \param[in] message The message associated with this range. 96 | # 97 | # \return Returns the ID of the new range. 98 | cdef unsigned long roctxRangeStartA(const char * message) 99 | 100 | 101 | # 102 | # Stop a process range. 103 | cdef void roctxRangeStop(unsigned long id) 104 | -------------------------------------------------------------------------------- /hip-python/hip/croctx.pyx: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2021-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | 24 | # This file has been autogenerated, do not modify. 25 | 26 | cimport hip._util.posixloader as loader 27 | cdef void* _lib_handle = NULL 28 | 29 | DLL = b"libroctx64.so" 30 | 31 | cdef int __init() except 1 nogil: 32 | global DLL 33 | global _lib_handle 34 | cdef char* dll = NULL 35 | if _lib_handle == NULL: 36 | with gil: 37 | dll = DLL 38 | return loader.open_library(&_lib_handle,dll) 39 | return 0 40 | 41 | cdef int __init_symbol(void** result, const char* name) except 1 nogil: 42 | global _lib_handle 43 | cdef int init_result = 0 44 | if _lib_handle == NULL: 45 | init_result = __init() 46 | if init_result > 0: 47 | return init_result 48 | if result[0] == NULL: 49 | return loader.load_symbol(result,_lib_handle, name) 50 | return 0 51 | 52 | 53 | cdef void* _roctx_version_major__funptr = NULL 54 | # 55 | # Query the major version of the installed library. 56 | # 57 | # Return the major version of the installed library. This can be used to check 58 | # if it is compatible with this interface version. 59 | # 60 | # \return Returns the major version number. 61 | cdef unsigned int roctx_version_major(): 62 | global _roctx_version_major__funptr 63 | if __init_symbol(&_roctx_version_major__funptr,"roctx_version_major") > 0: 64 | pass 65 | return ( _roctx_version_major__funptr)() 66 | 67 | 68 | cdef void* _roctx_version_minor__funptr = NULL 69 | # 70 | # Query the minor version of the installed library. 71 | # 72 | # Return the minor version of the installed library. This can be used to check 73 | # if it is compatible with this interface version. 74 | # 75 | # \return Returns the minor version number. 76 | cdef unsigned int roctx_version_minor(): 77 | global _roctx_version_minor__funptr 78 | if __init_symbol(&_roctx_version_minor__funptr,"roctx_version_minor") > 0: 79 | pass 80 | return ( _roctx_version_minor__funptr)() 81 | 82 | 83 | cdef void* _roctxMarkA__funptr = NULL 84 | # 85 | # Mark an event. 86 | # 87 | # \param[in] message The message associated with the event. 88 | cdef void roctxMarkA(const char * message): 89 | global _roctxMarkA__funptr 90 | if __init_symbol(&_roctxMarkA__funptr,"roctxMarkA") > 0: 91 | pass 92 | ( _roctxMarkA__funptr)(message) 93 | 94 | 95 | cdef void* _roctxRangePushA__funptr = NULL 96 | # 97 | # Start a new nested range. 98 | # 99 | # Nested ranges are stacked and local to the current CPU thread. 100 | # 101 | # \param[in] message The message associated with this range. 102 | # 103 | # \return Returns the level this nested range is started at. Nested range 104 | # levels are 0 based. 105 | cdef int roctxRangePushA(const char * message): 106 | global _roctxRangePushA__funptr 107 | if __init_symbol(&_roctxRangePushA__funptr,"roctxRangePushA") > 0: 108 | pass 109 | return ( _roctxRangePushA__funptr)(message) 110 | 111 | 112 | cdef void* _roctxRangePop__funptr = NULL 113 | # 114 | # Stop the current nested range. 115 | # 116 | # Stop the current nested range, and pop it from the stack. If a nested range 117 | # was active before the last one was started, it becomes again the current 118 | # nested range. 119 | # 120 | # \return Returns the level the stopped nested range was started at, or a 121 | # negative value if there was no nested range active. 122 | cdef int roctxRangePop(): 123 | global _roctxRangePop__funptr 124 | if __init_symbol(&_roctxRangePop__funptr,"roctxRangePop") > 0: 125 | pass 126 | return ( _roctxRangePop__funptr)() 127 | 128 | 129 | cdef void* _roctxRangeStartA__funptr = NULL 130 | # 131 | # Starts a process range. 132 | # 133 | # Start/stop ranges can be started and stopped in different threads. Each 134 | # timespan is assigned a unique range ID. 135 | # 136 | # \param[in] message The message associated with this range. 137 | # 138 | # \return Returns the ID of the new range. 139 | cdef unsigned long roctxRangeStartA(const char * message): 140 | global _roctxRangeStartA__funptr 141 | if __init_symbol(&_roctxRangeStartA__funptr,"roctxRangeStartA") > 0: 142 | pass 143 | return ( _roctxRangeStartA__funptr)(message) 144 | 145 | 146 | cdef void* _roctxRangeStop__funptr = NULL 147 | # 148 | # Stop a process range. 149 | cdef void roctxRangeStop(unsigned long id): 150 | global _roctxRangeStop__funptr 151 | if __init_symbol(&_roctxRangeStop__funptr,"roctxRangeStop") > 0: 152 | pass 153 | ( _roctxRangeStop__funptr)(id) 154 | -------------------------------------------------------------------------------- /hip-python/hip/hipblas.pxd: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2021-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | 24 | # This file has been autogenerated, do not modify. 25 | 26 | from libc cimport stdlib 27 | from libc cimport string 28 | from libc.stdint cimport * 29 | cimport cpython.long 30 | cimport cpython.buffer 31 | ctypedef bint _Bool # bool is not a reserved keyword in C, _Bool is 32 | from hip.hip cimport * 33 | 34 | cimport hip._util.types 35 | from hip cimport chipblas 36 | 37 | cdef class hipblasHandle_t(hip._util.types.Pointer): pass 38 | 39 | cdef class hipblasBfloat16(hip._util.types.Pointer): 40 | cdef bint _is_ptr_owner 41 | 42 | cdef chipblas.hipblasBfloat16* getElementPtr(self) 43 | 44 | @staticmethod 45 | cdef hipblasBfloat16 fromPtr(void* ptr, bint owner=*) 46 | @staticmethod 47 | cdef hipblasBfloat16 fromPyobj(object pyobj) 48 | @staticmethod 49 | cdef __allocate(void* ptr) 50 | @staticmethod 51 | cdef hipblasBfloat16 new() 52 | @staticmethod 53 | cdef hipblasBfloat16 fromValue(chipblas.hipblasBfloat16 other) 54 | 55 | 56 | cdef class hipblasComplex(hip._util.types.Pointer): 57 | cdef bint _is_ptr_owner 58 | 59 | cdef chipblas.hipblasComplex* getElementPtr(self) 60 | 61 | @staticmethod 62 | cdef hipblasComplex fromPtr(void* ptr, bint owner=*) 63 | @staticmethod 64 | cdef hipblasComplex fromPyobj(object pyobj) 65 | @staticmethod 66 | cdef __allocate(void* ptr) 67 | @staticmethod 68 | cdef hipblasComplex new() 69 | @staticmethod 70 | cdef hipblasComplex fromValue(chipblas.hipblasComplex other) 71 | 72 | 73 | cdef class hipblasDoubleComplex(hip._util.types.Pointer): 74 | cdef bint _is_ptr_owner 75 | 76 | cdef chipblas.hipblasDoubleComplex* getElementPtr(self) 77 | 78 | @staticmethod 79 | cdef hipblasDoubleComplex fromPtr(void* ptr, bint owner=*) 80 | @staticmethod 81 | cdef hipblasDoubleComplex fromPyobj(object pyobj) 82 | @staticmethod 83 | cdef __allocate(void* ptr) 84 | @staticmethod 85 | cdef hipblasDoubleComplex new() 86 | @staticmethod 87 | cdef hipblasDoubleComplex fromValue(chipblas.hipblasDoubleComplex other) 88 | -------------------------------------------------------------------------------- /hip-python/hip/hipfft.pxd: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2021-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | 24 | # This file has been autogenerated, do not modify. 25 | 26 | from libc cimport stdlib 27 | from libc cimport string 28 | from libc.stdint cimport * 29 | cimport cpython.long 30 | cimport cpython.buffer 31 | ctypedef bint _Bool # bool is not a reserved keyword in C, _Bool is 32 | from hip.hip cimport ihipStream_t, float2, double2 33 | 34 | cimport hip._util.types 35 | from hip cimport chipfft 36 | 37 | cdef class hipfftHandle_t(hip._util.types.Pointer): 38 | cdef bint _is_ptr_owner 39 | 40 | cdef chipfft.hipfftHandle_t* getElementPtr(self) 41 | 42 | @staticmethod 43 | cdef hipfftHandle_t fromPtr(void* ptr, bint owner=*) 44 | @staticmethod 45 | cdef hipfftHandle_t fromPyobj(object pyobj) 46 | -------------------------------------------------------------------------------- /hip-python/hip/hiprand.pxd: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2021-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | 24 | # This file has been autogenerated, do not modify. 25 | 26 | from libc cimport stdlib 27 | from libc cimport string 28 | from libc.stdint cimport * 29 | cimport cpython.long 30 | cimport cpython.buffer 31 | ctypedef bint _Bool # bool is not a reserved keyword in C, _Bool is 32 | from hip.hip cimport ihipStream_t 33 | 34 | cimport hip._util.types 35 | from hip cimport chiprand 36 | 37 | cdef class uint4(hip._util.types.Pointer): 38 | cdef bint _is_ptr_owner 39 | 40 | cdef chiprand.uint4* getElementPtr(self) 41 | 42 | @staticmethod 43 | cdef uint4 fromPtr(void* ptr, bint owner=*) 44 | @staticmethod 45 | cdef uint4 fromPyobj(object pyobj) 46 | @staticmethod 47 | cdef __allocate(void* ptr) 48 | @staticmethod 49 | cdef uint4 new() 50 | @staticmethod 51 | cdef uint4 fromValue(chiprand.uint4 other) 52 | 53 | 54 | cdef class rocrand_discrete_distribution_st(hip._util.types.Pointer): 55 | cdef bint _is_ptr_owner 56 | 57 | cdef chiprand.rocrand_discrete_distribution_st* getElementPtr(self) 58 | 59 | @staticmethod 60 | cdef rocrand_discrete_distribution_st fromPtr(void* ptr, bint owner=*) 61 | @staticmethod 62 | cdef rocrand_discrete_distribution_st fromPyobj(object pyobj) 63 | @staticmethod 64 | cdef __allocate(void* ptr) 65 | @staticmethod 66 | cdef rocrand_discrete_distribution_st new() 67 | @staticmethod 68 | cdef rocrand_discrete_distribution_st fromValue(chiprand.rocrand_discrete_distribution_st other) 69 | 70 | 71 | cdef class rocrand_generator_base_type(hip._util.types.Pointer): 72 | cdef bint _is_ptr_owner 73 | 74 | cdef chiprand.rocrand_generator_base_type* getElementPtr(self) 75 | 76 | @staticmethod 77 | cdef rocrand_generator_base_type fromPtr(void* ptr, bint owner=*) 78 | @staticmethod 79 | cdef rocrand_generator_base_type fromPyobj(object pyobj) 80 | 81 | 82 | cdef class hiprandDirectionVectors32_t(hip._util.types.Pointer): 83 | cdef bint _is_ptr_owner 84 | 85 | cdef chiprand.hiprandDirectionVectors32_t* getElementPtr(self) 86 | 87 | @staticmethod 88 | cdef hiprandDirectionVectors32_t fromPtr(void* ptr, bint owner=*) 89 | @staticmethod 90 | cdef hiprandDirectionVectors32_t fromPyobj(object pyobj) 91 | @staticmethod 92 | cdef __allocate(void* ptr) 93 | @staticmethod 94 | cdef hiprandDirectionVectors32_t new() 95 | @staticmethod 96 | cdef hiprandDirectionVectors32_t fromValue(chiprand.hiprandDirectionVectors32_t other) 97 | 98 | 99 | cdef class hiprandDirectionVectors64_t(hip._util.types.Pointer): 100 | cdef bint _is_ptr_owner 101 | 102 | cdef chiprand.hiprandDirectionVectors64_t* getElementPtr(self) 103 | 104 | @staticmethod 105 | cdef hiprandDirectionVectors64_t fromPtr(void* ptr, bint owner=*) 106 | @staticmethod 107 | cdef hiprandDirectionVectors64_t fromPyobj(object pyobj) 108 | @staticmethod 109 | cdef __allocate(void* ptr) 110 | @staticmethod 111 | cdef hiprandDirectionVectors64_t new() 112 | @staticmethod 113 | cdef hiprandDirectionVectors64_t fromValue(chiprand.hiprandDirectionVectors64_t other) 114 | -------------------------------------------------------------------------------- /hip-python/hip/hiprtc.pxd: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2021-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | 24 | # This file has been autogenerated, do not modify. 25 | 26 | from libc cimport stdlib 27 | from libc cimport string 28 | from libc.stdint cimport * 29 | cimport cpython.long 30 | cimport cpython.buffer 31 | ctypedef bint _Bool # bool is not a reserved keyword in C, _Bool is 32 | 33 | cimport hip._util.types 34 | from hip cimport chiprtc 35 | 36 | cdef class ihiprtcLinkState(hip._util.types.Pointer): 37 | cdef bint _is_ptr_owner 38 | 39 | cdef chiprtc.ihiprtcLinkState* getElementPtr(self) 40 | 41 | @staticmethod 42 | cdef ihiprtcLinkState fromPtr(void* ptr, bint owner=*) 43 | @staticmethod 44 | cdef ihiprtcLinkState fromPyobj(object pyobj) 45 | 46 | 47 | cdef class _hiprtcProgram(hip._util.types.Pointer): 48 | cdef bint _is_ptr_owner 49 | 50 | cdef chiprtc._hiprtcProgram* getElementPtr(self) 51 | 52 | @staticmethod 53 | cdef _hiprtcProgram fromPtr(void* ptr, bint owner=*) 54 | @staticmethod 55 | cdef _hiprtcProgram fromPyobj(object pyobj) 56 | -------------------------------------------------------------------------------- /hip-python/hip/hipsolver.pxd: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2021-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | 24 | # This file has been autogenerated, do not modify. 25 | 26 | from libc cimport stdlib 27 | from libc cimport string 28 | from libc.stdint cimport * 29 | cimport cpython.long 30 | cimport cpython.buffer 31 | ctypedef bint _Bool # bool is not a reserved keyword in C, _Bool is 32 | # from hip.hip cimport * # via chipblas 33 | from hip.hipblas cimport * 34 | 35 | cimport hip._util.types 36 | from hip cimport chipsolver 37 | 38 | cdef class hipsolverHandle_t(hip._util.types.Pointer): pass 39 | 40 | cdef class hipsolverGesvdjInfo_t(hip._util.types.Pointer): pass 41 | 42 | cdef class hipsolverSyevjInfo_t(hip._util.types.Pointer): pass 43 | 44 | cdef class hipsolverDnParams_t(hip._util.types.Pointer): pass 45 | 46 | cdef class hipsolverRfHandle_t(hip._util.types.Pointer): pass 47 | 48 | cdef class hipsolverSpHandle_t(hip._util.types.Pointer): pass -------------------------------------------------------------------------------- /hip-python/hip/hipsparse.pxd: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2021-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | 24 | # This file has been autogenerated, do not modify. 25 | 26 | from libc cimport stdlib 27 | from libc cimport string 28 | from libc.stdint cimport * 29 | cimport cpython.long 30 | cimport cpython.buffer 31 | ctypedef bint _Bool # bool is not a reserved keyword in C, _Bool is 32 | from hip.hip cimport ihipStream_t, float2, double2 # C import structs/union types 33 | 34 | cimport hip._util.types 35 | from hip cimport chipsparse 36 | 37 | cdef class bsrsv2Info(hip._util.types.Pointer): 38 | cdef bint _is_ptr_owner 39 | 40 | cdef chipsparse.bsrsv2Info* getElementPtr(self) 41 | 42 | @staticmethod 43 | cdef bsrsv2Info fromPtr(void* ptr, bint owner=*) 44 | @staticmethod 45 | cdef bsrsv2Info fromPyobj(object pyobj) 46 | 47 | 48 | cdef class bsrsm2Info(hip._util.types.Pointer): 49 | cdef bint _is_ptr_owner 50 | 51 | cdef chipsparse.bsrsm2Info* getElementPtr(self) 52 | 53 | @staticmethod 54 | cdef bsrsm2Info fromPtr(void* ptr, bint owner=*) 55 | @staticmethod 56 | cdef bsrsm2Info fromPyobj(object pyobj) 57 | 58 | 59 | cdef class bsrilu02Info(hip._util.types.Pointer): 60 | cdef bint _is_ptr_owner 61 | 62 | cdef chipsparse.bsrilu02Info* getElementPtr(self) 63 | 64 | @staticmethod 65 | cdef bsrilu02Info fromPtr(void* ptr, bint owner=*) 66 | @staticmethod 67 | cdef bsrilu02Info fromPyobj(object pyobj) 68 | 69 | 70 | cdef class bsric02Info(hip._util.types.Pointer): 71 | cdef bint _is_ptr_owner 72 | 73 | cdef chipsparse.bsric02Info* getElementPtr(self) 74 | 75 | @staticmethod 76 | cdef bsric02Info fromPtr(void* ptr, bint owner=*) 77 | @staticmethod 78 | cdef bsric02Info fromPyobj(object pyobj) 79 | 80 | 81 | cdef class csrsv2Info(hip._util.types.Pointer): 82 | cdef bint _is_ptr_owner 83 | 84 | cdef chipsparse.csrsv2Info* getElementPtr(self) 85 | 86 | @staticmethod 87 | cdef csrsv2Info fromPtr(void* ptr, bint owner=*) 88 | @staticmethod 89 | cdef csrsv2Info fromPyobj(object pyobj) 90 | 91 | 92 | cdef class csrsm2Info(hip._util.types.Pointer): 93 | cdef bint _is_ptr_owner 94 | 95 | cdef chipsparse.csrsm2Info* getElementPtr(self) 96 | 97 | @staticmethod 98 | cdef csrsm2Info fromPtr(void* ptr, bint owner=*) 99 | @staticmethod 100 | cdef csrsm2Info fromPyobj(object pyobj) 101 | 102 | 103 | cdef class csrilu02Info(hip._util.types.Pointer): 104 | cdef bint _is_ptr_owner 105 | 106 | cdef chipsparse.csrilu02Info* getElementPtr(self) 107 | 108 | @staticmethod 109 | cdef csrilu02Info fromPtr(void* ptr, bint owner=*) 110 | @staticmethod 111 | cdef csrilu02Info fromPyobj(object pyobj) 112 | 113 | 114 | cdef class csric02Info(hip._util.types.Pointer): 115 | cdef bint _is_ptr_owner 116 | 117 | cdef chipsparse.csric02Info* getElementPtr(self) 118 | 119 | @staticmethod 120 | cdef csric02Info fromPtr(void* ptr, bint owner=*) 121 | @staticmethod 122 | cdef csric02Info fromPyobj(object pyobj) 123 | 124 | 125 | cdef class csrgemm2Info(hip._util.types.Pointer): 126 | cdef bint _is_ptr_owner 127 | 128 | cdef chipsparse.csrgemm2Info* getElementPtr(self) 129 | 130 | @staticmethod 131 | cdef csrgemm2Info fromPtr(void* ptr, bint owner=*) 132 | @staticmethod 133 | cdef csrgemm2Info fromPyobj(object pyobj) 134 | 135 | 136 | cdef class pruneInfo(hip._util.types.Pointer): 137 | cdef bint _is_ptr_owner 138 | 139 | cdef chipsparse.pruneInfo* getElementPtr(self) 140 | 141 | @staticmethod 142 | cdef pruneInfo fromPtr(void* ptr, bint owner=*) 143 | @staticmethod 144 | cdef pruneInfo fromPyobj(object pyobj) 145 | 146 | 147 | cdef class csru2csrInfo(hip._util.types.Pointer): 148 | cdef bint _is_ptr_owner 149 | 150 | cdef chipsparse.csru2csrInfo* getElementPtr(self) 151 | 152 | @staticmethod 153 | cdef csru2csrInfo fromPtr(void* ptr, bint owner=*) 154 | @staticmethod 155 | cdef csru2csrInfo fromPyobj(object pyobj) 156 | 157 | 158 | cdef class hipsparseHandle_t(hip._util.types.Pointer): pass 159 | 160 | cdef class hipsparseMatDescr_t(hip._util.types.Pointer): pass 161 | 162 | cdef class hipsparseHybMat_t(hip._util.types.Pointer): pass 163 | 164 | cdef class hipsparseColorInfo_t(hip._util.types.Pointer): pass 165 | 166 | cdef class hipsparseSpVecDescr_t(hip._util.types.Pointer): pass 167 | 168 | cdef class hipsparseDnVecDescr_t(hip._util.types.Pointer): pass 169 | 170 | cdef class hipsparseSpMatDescr_t(hip._util.types.Pointer): pass 171 | 172 | cdef class hipsparseDnMatDescr_t(hip._util.types.Pointer): pass 173 | 174 | cdef class hipsparseConstSpVecDescr_t(hip._util.types.Pointer): pass 175 | 176 | cdef class hipsparseConstDnVecDescr_t(hip._util.types.Pointer): pass 177 | 178 | cdef class hipsparseConstSpMatDescr_t(hip._util.types.Pointer): pass 179 | 180 | cdef class hipsparseConstDnMatDescr_t(hip._util.types.Pointer): pass 181 | 182 | cdef class hipsparseSpGEMMDescr(hip._util.types.Pointer): 183 | cdef bint _is_ptr_owner 184 | 185 | cdef chipsparse.hipsparseSpGEMMDescr* getElementPtr(self) 186 | 187 | @staticmethod 188 | cdef hipsparseSpGEMMDescr fromPtr(void* ptr, bint owner=*) 189 | @staticmethod 190 | cdef hipsparseSpGEMMDescr fromPyobj(object pyobj) 191 | 192 | 193 | cdef class hipsparseSpSVDescr(hip._util.types.Pointer): 194 | cdef bint _is_ptr_owner 195 | 196 | cdef chipsparse.hipsparseSpSVDescr* getElementPtr(self) 197 | 198 | @staticmethod 199 | cdef hipsparseSpSVDescr fromPtr(void* ptr, bint owner=*) 200 | @staticmethod 201 | cdef hipsparseSpSVDescr fromPyobj(object pyobj) 202 | 203 | 204 | cdef class hipsparseSpSMDescr(hip._util.types.Pointer): 205 | cdef bint _is_ptr_owner 206 | 207 | cdef chipsparse.hipsparseSpSMDescr* getElementPtr(self) 208 | 209 | @staticmethod 210 | cdef hipsparseSpSMDescr fromPtr(void* ptr, bint owner=*) 211 | @staticmethod 212 | cdef hipsparseSpSMDescr fromPyobj(object pyobj) 213 | -------------------------------------------------------------------------------- /hip-python/hip/rccl.pxd: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2021-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | 24 | # This file has been autogenerated, do not modify. 25 | 26 | from libc cimport stdlib 27 | from libc cimport string 28 | from libc.stdint cimport * 29 | cimport cpython.long 30 | cimport cpython.buffer 31 | ctypedef bint _Bool # bool is not a reserved keyword in C, _Bool is 32 | from hip.hip cimport ihipStream_t 33 | 34 | cimport hip._util.types 35 | from hip cimport crccl 36 | 37 | cdef class ncclComm(hip._util.types.Pointer): 38 | cdef bint _is_ptr_owner 39 | 40 | cdef crccl.ncclComm* getElementPtr(self) 41 | 42 | @staticmethod 43 | cdef ncclComm fromPtr(void* ptr, bint owner=*) 44 | @staticmethod 45 | cdef ncclComm fromPyobj(object pyobj) 46 | 47 | 48 | cdef class ncclUniqueId(hip._util.types.Pointer): 49 | cdef bint _is_ptr_owner 50 | 51 | cdef crccl.ncclUniqueId* getElementPtr(self) 52 | 53 | @staticmethod 54 | cdef ncclUniqueId fromPtr(void* ptr, bint owner=*) 55 | @staticmethod 56 | cdef ncclUniqueId fromPyobj(object pyobj) 57 | @staticmethod 58 | cdef __allocate(void* ptr) 59 | @staticmethod 60 | cdef ncclUniqueId new() 61 | @staticmethod 62 | cdef ncclUniqueId fromValue(crccl.ncclUniqueId other) 63 | 64 | 65 | cdef class ncclConfig_v21700(hip._util.types.Pointer): 66 | cdef bint _is_ptr_owner 67 | 68 | cdef crccl.ncclConfig_v21700* getElementPtr(self) 69 | 70 | @staticmethod 71 | cdef ncclConfig_v21700 fromPtr(void* ptr, bint owner=*) 72 | @staticmethod 73 | cdef ncclConfig_v21700 fromPyobj(object pyobj) 74 | @staticmethod 75 | cdef __allocate(void* ptr) 76 | @staticmethod 77 | cdef ncclConfig_v21700 new() 78 | @staticmethod 79 | cdef ncclConfig_v21700 fromValue(crccl.ncclConfig_v21700 other) 80 | 81 | 82 | cdef class ncclSimInfo_v22200(hip._util.types.Pointer): 83 | cdef bint _is_ptr_owner 84 | 85 | cdef crccl.ncclSimInfo_v22200* getElementPtr(self) 86 | 87 | @staticmethod 88 | cdef ncclSimInfo_v22200 fromPtr(void* ptr, bint owner=*) 89 | @staticmethod 90 | cdef ncclSimInfo_v22200 fromPyobj(object pyobj) 91 | @staticmethod 92 | cdef __allocate(void* ptr) 93 | @staticmethod 94 | cdef ncclSimInfo_v22200 new() 95 | @staticmethod 96 | cdef ncclSimInfo_v22200 fromValue(crccl.ncclSimInfo_v22200 other) 97 | -------------------------------------------------------------------------------- /hip-python/hip/roctx.pxd: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2021-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | 24 | # This file has been autogenerated, do not modify. 25 | 26 | from libc cimport stdlib 27 | from libc cimport string 28 | from libc.stdint cimport * 29 | cimport cpython.long 30 | cimport cpython.buffer 31 | ctypedef bint _Bool # bool is not a reserved keyword in C, _Bool is 32 | 33 | cimport hip._util.types 34 | from hip cimport croctx 35 | 36 | -------------------------------------------------------------------------------- /hip-python/hip/roctx.pyx: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2021-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | 24 | # This file has been autogenerated, do not modify. 25 | 26 | 27 | """ 28 | (No short description) 29 | 30 | Attributes: 31 | ROCTX_VERSION_MAJOR (`~.int`): 32 | Macro constant. 33 | 34 | ROCTX_VERSION_MINOR (`~.int`): 35 | Macro constant. 36 | 37 | """ 38 | 39 | import cython 40 | import ctypes 41 | import enum 42 | ROCTX_VERSION_MAJOR = croctx.ROCTX_VERSION_MAJOR 43 | 44 | ROCTX_VERSION_MINOR = croctx.ROCTX_VERSION_MINOR 45 | 46 | @cython.embedsignature(True) 47 | def roctx_version_major(): 48 | r"""(No short description, might be part of a group.) 49 | 50 | Query the major version of the installed library. 51 | 52 | Return the major version of the installed library. This can be used to check 53 | if it is compatible with this interface version. 54 | 55 | Returns: 56 | A `~.tuple` of size 1 that contains (in that order): 57 | 58 | * `~.int`: Returns the major version number. 59 | """ 60 | cdef unsigned int _roctx_version_major__retval = croctx.roctx_version_major() 61 | return (_roctx_version_major__retval,) 62 | 63 | 64 | @cython.embedsignature(True) 65 | def roctx_version_minor(): 66 | r"""(No short description, might be part of a group.) 67 | 68 | Query the minor version of the installed library. 69 | 70 | Return the minor version of the installed library. This can be used to check 71 | if it is compatible with this interface version. 72 | 73 | Returns: 74 | A `~.tuple` of size 1 that contains (in that order): 75 | 76 | * `~.int`: Returns the minor version number. 77 | """ 78 | cdef unsigned int _roctx_version_minor__retval = croctx.roctx_version_minor() 79 | return (_roctx_version_minor__retval,) 80 | 81 | 82 | @cython.embedsignature(True) 83 | def roctxMarkA(object message): 84 | r"""(No short description, might be part of a group.) 85 | 86 | Mark an event. 87 | 88 | Args: 89 | message (`~.hip._util.types.CStr`/`~.object`) -- *IN*: 90 | The message associated with the event. 91 | """ 92 | croctx.roctxMarkA( 93 | hip._util.types.CStr.fromPyobj(message)._ptr) 94 | 95 | 96 | @cython.embedsignature(True) 97 | def roctxRangePushA(object message): 98 | r"""(No short description, might be part of a group.) 99 | 100 | Start a new nested range. 101 | 102 | Nested ranges are stacked and local to the current CPU thread. 103 | 104 | Args: 105 | message (`~.hip._util.types.CStr`/`~.object`) -- *IN*: 106 | The message associated with this range. 107 | 108 | Returns: 109 | A `~.tuple` of size 1 that contains (in that order): 110 | 111 | * `~.int`: Returns the level this nested range is started at. Nested range 112 | levels are 0 based. 113 | """ 114 | cdef int _roctxRangePushA__retval = croctx.roctxRangePushA( 115 | hip._util.types.CStr.fromPyobj(message)._ptr) 116 | return (_roctxRangePushA__retval,) 117 | 118 | 119 | @cython.embedsignature(True) 120 | def roctxRangePop(): 121 | r"""(No short description, might be part of a group.) 122 | 123 | Stop the current nested range. 124 | 125 | Stop the current nested range, and pop it from the stack. If a nested range 126 | was active before the last one was started, it becomes again the current 127 | nested range. 128 | 129 | Returns: 130 | A `~.tuple` of size 1 that contains (in that order): 131 | 132 | * `~.int`: Returns the level the stopped nested range was started at, or a 133 | negative value if there was no nested range active. 134 | """ 135 | cdef int _roctxRangePop__retval = croctx.roctxRangePop() 136 | return (_roctxRangePop__retval,) 137 | 138 | 139 | @cython.embedsignature(True) 140 | def roctxRangeStartA(object message): 141 | r"""(No short description, might be part of a group.) 142 | 143 | Starts a process range. 144 | 145 | Start/stop ranges can be started and stopped in different threads. Each 146 | timespan is assigned a unique range ID. 147 | 148 | Args: 149 | message (`~.hip._util.types.CStr`/`~.object`) -- *IN*: 150 | The message associated with this range. 151 | 152 | Returns: 153 | A `~.tuple` of size 1 that contains (in that order): 154 | 155 | * `~.int`: Returns the ID of the new range. 156 | """ 157 | cdef unsigned long _roctxRangeStartA__retval = croctx.roctxRangeStartA( 158 | hip._util.types.CStr.fromPyobj(message)._ptr) 159 | return (_roctxRangeStartA__retval,) 160 | 161 | 162 | @cython.embedsignature(True) 163 | def roctxRangeStop(unsigned long id): 164 | r"""(No short description, might be part of a group.) 165 | 166 | Stop a process range. 167 | 168 | Args: 169 | id (`~.int`): 170 | (undocumented) 171 | """ 172 | croctx.roctxRangeStop(id) 173 | 174 | __all__ = [ 175 | "ROCTX_VERSION_MAJOR", 176 | "ROCTX_VERSION_MINOR", 177 | "roctx_version_major", 178 | "roctx_version_minor", 179 | "roctxMarkA", 180 | "roctxRangePushA", 181 | "roctxRangePop", 182 | "roctxRangeStartA", 183 | "roctxRangeStop", 184 | ] -------------------------------------------------------------------------------- /hip-python/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ # PEP 508 specifications 3 | "setuptools>=10.0.1", 4 | "wheel", 5 | "cython", 6 | ] 7 | build-backend = "setuptools.build_meta" -------------------------------------------------------------------------------- /hip-python/requirements.txt: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | # Python dependencies required for development 24 | setuptools>=42 25 | cython>=3.0,<3.1 26 | wheel 27 | -------------------------------------------------------------------------------- /hip-python/setup.cfg: -------------------------------------------------------------------------------- 1 | # MIT License 2 | # 3 | # Copyright (c) 2023-2025 Advanced Micro Devices, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | [metadata] 23 | name = hip-python 24 | description = Python and Cython bindings for HIP 25 | author = Advanced Micro Devices, Inc. 26 | author_email = hip-python.maintainer@amd.com 27 | url = https://github.com/ROCmSoftwarePlatform/hip-python 28 | license = MIT 29 | license_files = LICENSE 30 | long_description = file: README.md, CHANGELOG.md 31 | long_description_content_type = text/markdown 32 | # see: https://pypi.org/pypi?%3Aaction=list_classifiers 33 | classifiers = 34 | Intended Audience :: Developers 35 | Topic :: Scientific/Engineering 36 | Topic :: Software Development :: Libraries 37 | Environment :: GPU 38 | Programming Language :: Python :: 3.7 39 | Programming Language :: Cython 40 | License :: OSI Approved :: MIT License 41 | Development Status :: 2 - Pre-Alpha 42 | 43 | [build_ext] 44 | inplace=1 45 | 46 | [options] 47 | python_requires = >=3.7, <4 48 | setup_requires = 49 | cython >=3.0, <3.1 50 | wheel 51 | zip_safe = False 52 | packages = 53 | hip 54 | hip._util 55 | 56 | [options.package_data] 57 | # Add Python and Cython files to the package 58 | hip = *.pxd, *.pyx, *.so, _version.py, __init__.py 59 | hip._util = *.pxd, *.pyx, *.so, __init__.py 60 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.black] 2 | line-length = 79 3 | include = '\.pyi?$' 4 | exclude = ''' 5 | /( 6 | \.git 7 | | _build 8 | | build 9 | | dist 10 | )/ 11 | ''' 12 | --------------------------------------------------------------------------------