pyhip-interface


Namepyhip-interface JSON
Version 0.1.2 PyPI version JSON
download
home_page
SummaryPython Interface to HIP and hiprtc Library
upload_time2023-09-08 08:32:06
maintainer
docs_urlNone
authorJatin Chaudhary
requires_python
license
keywords hip gpu parallel computing scientific computing python wrapper
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyHIP - Python Interface of [HIP](https://github.com/ROCm-Developer-Tools/HIP) and [hip-on-nv](https://github.com/jatinx/hip-on-nv)

## Introduction

This small python lib which hooks into HIP library and provides pythonic interface to it.

There are two parts of it, hip library and hiprtc library.

This also works with [hip-on-nv](https://github.com/jatinx/hip-on-nv).

## Installation

### Prerequisites

Before installing pyhip-interface, please make sure you have the following prerequisites installed:

* The Heterogeneous Interface for Portability - [HIP Installation Guide](https://docs.amd.com/bundle/HIP-Installation-Guide-v5.3/page/Introduction_to_HIP_Installation_Guide.html)

### Install with pip

PyHIP can be installed using pip, a package manager for Python. Run the following command in your terminal to install:

`pip install pyhip-interface`

### Install from source

Alternatively, you can install PyHIP from the source code. First, clone the repository from GitHub:

`git clone https://github.com/jatinx/PyHIP`

Then, navigate to the repository directory and run the following command to install:

`python setup.py install`

## Example Usage

```python
import ctypes
from pyhip import hip, hiprtc
source = """
extern "C" __global__ void set(int *a) {
  *a = 10;
}
"""
prog = hiprtc.hiprtcCreateProgram(source, 'set', [], [])
device_properties = hip.hipGetDeviceProperties(0)
print(f"Compiling kernel for {device_properties.gcnArchName}")
if hip.hipGetPlatformName() == 'amd': # offload arch is amd only
  hiprtc.hiprtcCompileProgram(prog, [f'--offload-arch={device_properties.gcnArchName}'])
else:
  hiprtc.hiprtcCompileProgram(prog, [])
code = hiprtc.hiprtcGetCode(prog)
module = hip.hipModuleLoadData(code)
kernel = hip.hipModuleGetFunction(module, 'set')
ptr = hip.hipMalloc(4)

class PackageStruct(ctypes.Structure):
  _fields_ = [("a", ctypes.c_void_p)]

struct = PackageStruct(ptr)
hip.hipModuleLaunchKernel(kernel, 1, 1, 1, 1, 1, 1, 0, 0, struct)
res = ctypes.c_int(0)
hip.hipMemcpy_dtoh(ctypes.byref(res), ptr, 4)
print(res.value)
```

## Testing

Testing is in it's infancy. I'll try to add more as and when I get some time. Any help here is appreciated :)

### How to run tests

Make sure you have ```pytest``` package installed.

From the project folder run ```pytest ./tests/* -v -r A```

## Help needed

If you are an opensource developer and want to contribute to this project, I can use your help in several places depending on your skillset.

- Adding more tests to the project
- Adding API documentation and samples
- Improving HIP API coverage - adding meaningful APIs instead of direct mapping.

## Common Problems

- Unable to load hip or hiprtc library - OSError: libamdhip64.so: cannot open shared object file: No such file or directory.

  - Make sure that LD_LIBRARY_PATH has hip path on it (/opt/rocm/lib or a custom installation path)

- Getting error and need to debug

  - Set AMD_LOG_LEVEL=7 for maximum verbosity of HIP APIs (this only works on amd platform).



            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pyhip-interface",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "HIP GPU parallel computing scientific computing Python wrapper",
    "author": "Jatin Chaudhary",
    "author_email": "ndjatin@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/2b/eb/bd84247bc3b902cb1e12ffb0c2ff49680a4e88bccd42760dd8e230bb4596/pyhip-interface-0.1.2.tar.gz",
    "platform": null,
    "description": "# PyHIP - Python Interface of [HIP](https://github.com/ROCm-Developer-Tools/HIP) and [hip-on-nv](https://github.com/jatinx/hip-on-nv)\n\n## Introduction\n\nThis small python lib which hooks into HIP library and provides pythonic interface to it.\n\nThere are two parts of it, hip library and hiprtc library.\n\nThis also works with [hip-on-nv](https://github.com/jatinx/hip-on-nv).\n\n## Installation\n\n### Prerequisites\n\nBefore installing pyhip-interface, please make sure you have the following prerequisites installed:\n\n* The Heterogeneous Interface for Portability - [HIP Installation Guide](https://docs.amd.com/bundle/HIP-Installation-Guide-v5.3/page/Introduction_to_HIP_Installation_Guide.html)\n\n### Install with pip\n\nPyHIP can be installed using pip, a package manager for Python. Run the following command in your terminal to install:\n\n`pip install pyhip-interface`\n\n### Install from source\n\nAlternatively, you can install PyHIP from the source code. First, clone the repository from GitHub:\n\n`git clone https://github.com/jatinx/PyHIP`\n\nThen, navigate to the repository directory and run the following command to install:\n\n`python setup.py install`\n\n## Example Usage\n\n```python\nimport ctypes\nfrom pyhip import hip, hiprtc\nsource = \"\"\"\nextern \"C\" __global__ void set(int *a) {\n  *a = 10;\n}\n\"\"\"\nprog = hiprtc.hiprtcCreateProgram(source, 'set', [], [])\ndevice_properties = hip.hipGetDeviceProperties(0)\nprint(f\"Compiling kernel for {device_properties.gcnArchName}\")\nif hip.hipGetPlatformName() == 'amd': # offload arch is amd only\n  hiprtc.hiprtcCompileProgram(prog, [f'--offload-arch={device_properties.gcnArchName}'])\nelse:\n  hiprtc.hiprtcCompileProgram(prog, [])\ncode = hiprtc.hiprtcGetCode(prog)\nmodule = hip.hipModuleLoadData(code)\nkernel = hip.hipModuleGetFunction(module, 'set')\nptr = hip.hipMalloc(4)\n\nclass PackageStruct(ctypes.Structure):\n  _fields_ = [(\"a\", ctypes.c_void_p)]\n\nstruct = PackageStruct(ptr)\nhip.hipModuleLaunchKernel(kernel, 1, 1, 1, 1, 1, 1, 0, 0, struct)\nres = ctypes.c_int(0)\nhip.hipMemcpy_dtoh(ctypes.byref(res), ptr, 4)\nprint(res.value)\n```\n\n## Testing\n\nTesting is in it's infancy. I'll try to add more as and when I get some time. Any help here is appreciated :)\n\n### How to run tests\n\nMake sure you have ```pytest``` package installed.\n\nFrom the project folder run ```pytest ./tests/* -v -r A```\n\n## Help needed\n\nIf you are an opensource developer and want to contribute to this project, I can use your help in several places depending on your skillset.\n\n- Adding more tests to the project\n- Adding API documentation and samples\n- Improving HIP API coverage - adding meaningful APIs instead of direct mapping.\n\n## Common Problems\n\n- Unable to load hip or hiprtc library - OSError: libamdhip64.so: cannot open shared object file: No such file or directory.\n\n  - Make sure that LD_LIBRARY_PATH has hip path on it (/opt/rocm/lib or a custom installation path)\n\n- Getting error and need to debug\n\n  - Set AMD_LOG_LEVEL=7 for maximum verbosity of HIP APIs (this only works on amd platform).\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Python Interface to HIP and hiprtc Library",
    "version": "0.1.2",
    "project_urls": {
        "Source": "https://github.com/jatinx/PyHIP"
    },
    "split_keywords": [
        "hip",
        "gpu",
        "parallel",
        "computing",
        "scientific",
        "computing",
        "python",
        "wrapper"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2bebbd84247bc3b902cb1e12ffb0c2ff49680a4e88bccd42760dd8e230bb4596",
                "md5": "3ecdcd0adaedea916515c9cc59c1e38a",
                "sha256": "0a19f4c2a6ae1ece88d537b8890523d149a12d676591b2ba073ff3ec9b11dfbb"
            },
            "downloads": -1,
            "filename": "pyhip-interface-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "3ecdcd0adaedea916515c9cc59c1e38a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 15959,
            "upload_time": "2023-09-08T08:32:06",
            "upload_time_iso_8601": "2023-09-08T08:32:06.456087Z",
            "url": "https://files.pythonhosted.org/packages/2b/eb/bd84247bc3b902cb1e12ffb0c2ff49680a4e88bccd42760dd8e230bb4596/pyhip-interface-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-08 08:32:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jatinx",
    "github_project": "PyHIP",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pyhip-interface"
}
        
Elapsed time: 0.11950s