Skip to content

Conversation

@kmaehashi
Copy link
Member

@kmaehashi kmaehashi commented Oct 27, 2024

This PR tries to support OpenCL/Level-Zero devices in CuPy through chipStar, which provides HIP to SPIR-V layer. This could open the door for CuPy to a wider audience, e.g., users of Intel Arc GPUs / Xe Cores (#8054).

For now, this PR is a proof-of-concept (or just for fun on my weekend 😃) and is not intended to be merged as-is to the CuPy's main branch.

I have confirmed the very basic operation (as seen in the run_chip.py script) working under Intel i5-12600K and it's integrated UHD Graphics 770 GPU, using the latest chipStar with pull-request: CHIP-SPV/chipStar#951 merged. although a slight modification to chipStar is needed

OpenCL / UHD Graphics 770 output:

$ python run_chip.py 
OS                        : Linux-5.19.0-50-generic-x86_64-with-glibc2.35
Python Version            : 3.12.4
CuPy Version              : 14.0.0a1
CuPy Platform             : AMD ROCm
NumPy Version             : 2.1.2
SciPy Version             : None
Cython Build Version      : 0.29.37
Cython Runtime Version    : None
CUDA Root                 : /
hipcc PATH                : None
CUDA Build Version        : 60000000
CUDA Driver Version       : 4
CUDA Runtime Version      : 10100000 (linked to CuPy) / 10100000 (locally installed)
CUDA Extra Include Dirs   : None
cuBLAS Version            : (available)
cuFFT Version             : None
cuRAND Version            : ImportError("cannot import name 'curand' from 'cupy_backends.cuda.libs' (/home/chipStarUser/sample/cupy/cupy_backends/cuda/libs/__init__.py)")
cuSOLVER Version          : ImportError("cannot import name 'cusolver' from 'cupy_backends.cuda.libs' (/home/chipStarUser/sample/cupy/cupy_backends/cuda/libs/__init__.py)")
cuSPARSE Version          : (available)
NVRTC Version             : (1, 0)
Thrust Version            : None
CUB Build Version         : -1
Jitify Build Version      : None
cuDNN Build Version       : None
cuDNN Version             : None
NCCL Build Version        : None
NCCL Runtime Version      : None
cuTENSOR Version          : None
cuSPARSELt Build Version  : None
Device 0 Name             : Intel(R) UHD Graphics 770 [0x4680]
Device 0 Arch             : unavailable
Device 0 PCI Bus ID       : 0000:10:40
[0 1 2 3 4 5 6 7 8 9]
[ 3  4  5  6  7  8  9 10 11 12]
45

OpenCL / CPU output:

$ CHIP_DEVICE_TYPE=cpu python run_chip.py 
<... snip ...>
Device 0 Name             : cpu-haswell-12th Gen Intel(R) Core(TM) i5-12600K
Device 0 Arch             : unavailable
Device 0 PCI Bus ID       : 0000:10:40
[0 1 2 3 4 5 6 7 8 9]
[ 3  4  5  6  7  8  9 10 11 12]
45

I haven't tried Level-Zero backend yet. Also note that many libraries are excluded from the build. hipSOLVER and hipFFT seem supported in chipStar's main branch, so it is worth trying.

Steps to run locally

Assuming you are in the pveleskopglc/chipstar:latest docker image:

# Rebuild chipStar from main branch
cd /home/chipStarUser/chipstar
git pull
cd build
cmake .. && make && sudo make install

# Build CuPy
git clone https://github.com/cupy/cupy.git
cd cupy
git fetch origin pull/8700/head:chipstar
git checkout chipstar
git submodule update --init
export CUPY_INSTALL_USE_HIP=1
export ROCM_HOME=/
export CFLAGS="-I/home/chipStarUser/chipStar/build/install/include"
export LDFLAGS="-L/home/chipStarUser/chipStar/build/install/lib"
export LD_LIBRARY_PATH="/home/chipStarUser/chipStar/build/install/lib:${LD_LIBRARY_PATH}"
pip install -e . -v

# Run on OpenCL / GPU
module unload pocl/5.0-llvm-15
export CHIP_DEVICE_TYPE=gpu
python run_chip.py

# Run on OpenCL / CPU
module load pocl/5.0-llvm-15
export CHIP_DEVICE_TYPE=cpu
python run_chip.py

@mergify
Copy link
Contributor

mergify bot commented Dec 17, 2024

This pull request is now in conflicts. Could you fix it @kmaehashi? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant