diff --git a/INSTALL.rst b/INSTALL.rst index cfa6275fb..53fef4926 100644 --- a/INSTALL.rst +++ b/INSTALL.rst @@ -111,6 +111,31 @@ Or you could install Kernel Tuner and PyOpenCL together if you haven't done so a If this fails, please see the PyOpenCL installation guide (https://wiki.tiker.net/PyOpenCL/Installation) +HIP and PyHIP +------------- + +Before we can install PyHIP, you'll need to have the HIP runtime and compiler installed on your system. +The HIP compiler is included as part of the ROCm software stack. Here is AMD's installation guide: + +* `ROCm Documentation: HIP Installation Guide `__ + +After you've installed HIP, you will need to install PyHIP. Run the following command in your terminal to install: + +.. code-block:: bash + + pip install pyhip-interface + +Alternatively, you can install PyHIP from the source code. First, clone the repository from GitHub: + +.. code-block:: bash + + git clone https://github.com/jatinx/PyHIP + +Then, navigate to the repository directory and run the following command to install: + +.. code-block:: bash + + python setup.py install Installing the git version -------------------------- @@ -128,6 +153,7 @@ You can install Kernel Tuner with several optional dependencies, the full list i - `cuda`: install pycuda along with kernel_tuner - `opencl`: install pycuda along with kernel_tuner +- `hip`: install pyhip along with kernel_tuner - `doc`: installs packages required to build the documentation - `tutorial`: install packages required to run the guides - `dev`: install everything you need to start development on Kernel Tuner diff --git a/README.rst b/README.rst index 08e641061..2f8e8bcc0 100644 --- a/README.rst +++ b/README.rst @@ -28,9 +28,14 @@ To tune OpenCL kernels: - First, make sure you have an OpenCL compiler for your intended OpenCL platform - Then type: ``pip install kernel_tuner[opencl]`` -Or both: +To tune HIP kernels: -- ``pip install kernel_tuner[cuda,opencl]`` +- First, make sure you have an HIP runtime and compiler installed +- Then type: ``pip install kernel_tuner[hip]`` + +Or all: + +- ``pip install kernel_tuner[cuda,opencl,hip]`` More information about how to install Kernel Tuner and its dependencies can be found in the `installation guide diff --git a/doc/source/architecture.png b/doc/source/architecture.png new file mode 100644 index 000000000..bedeefa5b Binary files /dev/null and b/doc/source/architecture.png differ diff --git a/doc/source/design.rst b/doc/source/design.rst index 614ac608d..4ca515e26 100644 --- a/doc/source/design.rst +++ b/doc/source/design.rst @@ -12,7 +12,7 @@ The Kernel Tuner is designed to be extensible and support different search and execution strategies. The current architecture of the Kernel Tuner can be seen as: -.. image:: architecture_0.4.3.png +.. image:: architecture.png :width: 500pt At the top we have the kernel code and the Python script that tunes it, @@ -48,7 +48,7 @@ building blocks for implementing runners. The observers are explained in :ref:`observers`. At the bottom, the backends are shown. -PyCUDA, CuPy, cuda-python and PyOpenCL are for tuning either CUDA or OpenCL kernels. +PyCUDA, CuPy, cuda-python, PyOpenCL and PyHIP are for tuning either CUDA, OpenCL, or HIP kernels. The C Functions implementation can actually call any compiler, typically NVCC or GCC is used. There is limited support for tuning Fortran kernels. @@ -128,6 +128,12 @@ kernel_tuner.backends.c.CFunctions :special-members: __init__ :members: +kernel_tuner.backends.hip.HipFunctions +~~~~~~~~~~~~~~~~~~~~~~~~~ +.. autoclass:: kernel_tuner.backends.hip.HipFunctions + :special-members: __init__ + :members: + Util Functions -------------- diff --git a/doc/source/index.rst b/doc/source/index.rst index 4a66d893b..c8af5e745 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -27,9 +27,14 @@ To tune OpenCL kernels: - First, make sure you have an OpenCL compiler for your intended OpenCL platform - Then type: ``pip install kernel_tuner[opencl]`` -Or both: +To tune HIP kernels: -- ``pip install kernel_tuner[cuda,opencl]`` +- First, make sure you have an HIP runtime and compiler installed +- Then type: ``pip install kernel_tuner[hip]`` + +Or all: + +- ``pip install kernel_tuner[cuda,opencl,hip]`` More information about how to install Kernel Tuner and its dependencies can be found under :ref:`install`. diff --git a/examples/hip/test_vector_add.py b/examples/hip/test_vector_add.py new file mode 100644 index 000000000..6c342632e --- /dev/null +++ b/examples/hip/test_vector_add.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +"""Minimal example for a HIP Kernel unit test with the Kernel Tuner""" + +import numpy +from kernel_tuner import run_kernel +import pytest + +#Check pyhip is installed and if a HIP capable device is present, if not skip the test +try: + from pyhip import hip, hiprtc +except ImportError: + pytest.skip("PyHIP not installed or PYTHONPATH does not includes PyHIP") + hip = None + hiprtc = None + +def test_vector_add(): + + kernel_string = """ + __global__ void vector_add(float *c, float *a, float *b, int n) { + int i = blockIdx.x * block_size_x + threadIdx.x; + if (i=11.4.1"], "opencl": ["pyopencl"], "cuda_opencl": ["pycuda", "pyopencl"], + "hip": ["pyhip-interface"], "tutorial": ["jupyter", "matplotlib", "pandas"], "dev": [ "numpy>=1.13.3", diff --git a/test/context.py b/test/context.py index 08d2a190a..763b3b7c9 100644 --- a/test/context.py +++ b/test/context.py @@ -1,6 +1,7 @@ import sys import subprocess import shutil +import os import pytest @@ -44,6 +45,15 @@ except Exception: cuda_present = False +PYHIP_PATH = os.environ.get('PYHIP_PATH') # get the PYHIP_PATH environment variable +try: + if PYHIP_PATH is not None: + sys.path.insert(0, PYHIP_PATH) + from pyhip import hip, hiprtc + pyhip_present = True +except ImportError: + pyhip_present = False + skip_if_no_pycuda = pytest.mark.skipif(not pycuda_present, reason="PyCuda not installed or no CUDA device detected") skip_if_no_pynvml = pytest.mark.skipif(not pynvml_present, reason="NVML not installed") skip_if_no_cupy = pytest.mark.skipif(not cupy_present, reason="CuPy not installed or no CUDA device detected") @@ -52,6 +62,7 @@ skip_if_no_gcc = pytest.mark.skipif(not gcc_present, reason="No gcc on PATH") skip_if_no_gfortran = pytest.mark.skipif(not gfortran_present, reason="No gfortran on PATH") skip_if_no_openmp = pytest.mark.skipif(not openmp_present, reason="No OpenMP found") +skip_if_no_pyhip = pytest.mark.skipif(not pyhip_present, reason="No PyHIP found") def skip_backend(backend: str): diff --git a/test/test_hip_functions.py b/test/test_hip_functions.py new file mode 100644 index 000000000..ce3eb0642 --- /dev/null +++ b/test/test_hip_functions.py @@ -0,0 +1,167 @@ +import numpy as np +import ctypes +from .context import skip_if_no_pyhip +from collections import OrderedDict + +import pytest +import kernel_tuner +from kernel_tuner import tune_kernel +from kernel_tuner.backends import hip as kt_hip +from kernel_tuner.core import KernelSource, KernelInstance + +try: + from pyhip import hip, hiprtc + hip_present = True +except ImportError: + pass + +@pytest.fixture +def env(): + kernel_string = """ + extern "C" __global__ void vector_add(float *c, float *a, float *b, int n) { + int i = blockIdx.x * block_size_x + threadIdx.x; + if (i