Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows pip installation doesn't find openCL cpu drivers properly #1751

Open
icfaust opened this issue Jul 22, 2024 · 4 comments
Open

windows pip installation doesn't find openCL cpu drivers properly #1751

icfaust opened this issue Jul 22, 2024 · 4 comments

Comments

@icfaust
Copy link

icfaust commented Jul 22, 2024

In this github action example, the conda environment can properly access the installed opencl driver, but pip cannot:

name: pip dpctl validator
on:
  workflow_dispatch:

env:
  PYTHON_VERSION: 3.9
  DPCTL_VERSION: 0.17.0

jobs:
  dpctl:
    name: dpctl_test
    runs-on: windows-2022
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install Python
        uses: actions/setup-python@v5
        with:
          python-version: ${{ env.PYTHON_VERSION }}
      - name: Install dpctl
        shell: cmd
        run: |
          set PATH=C:\msys64\usr\bin;%PATH%
          python -m venv env2
          call .\env2\Scripts\activate.bat
          set DPCTL_SUPPORTED=3.9 3.11
          FOR %%i IN (%DPCTL_SUPPORTED%) DO if ${{ env.PYTHON_VERSION }}==%%i python -m pip install --index-url https://pypi.anaconda.org/intel/simple dpctl==0.17.0
          python -c "import os, os.path, site; path_to_env = site.getsitepackages()[0]; path_to_libs = os.path.join(path_to_env, 'Library', 'bin'); temp=os.add_dll_directory(path_to_libs) if os.path.exists(path_to_libs) else None; import dpctl; print(dpctl.get_devices())"
          python -c "import dpctl; print(dpctl.lsplatform(2))"
          pip list
      - name: Install dpctl conda
        shell: cmd
        run: |
          set PATH=C:\msys64\usr\bin;%PATH%
          call C:\Miniconda\condabin\conda.bat config --add channels https://software.repos.intel.com/python/conda/
          call C:\Miniconda\condabin\conda.bat config --append channels conda-forge
          call C:\Miniconda\condabin\conda.bat create --name dpctl_env dpctl
          call C:\Miniconda\condabin\conda.bat activate dpctl_env
          python -c "import dpctl; print(dpctl.lsplatform(2))"

By installing the opencl cpu driver from here: and including the following path:

  set PATH="C:\Program Files (x86)\Common Files\Intel\Shared Libraries\bin;"%PATH%

The pip version can recover the CPU sycl device.

Could be this is an upstream issue with intel-opencl-rt repository? Either a warning needs to be added to the documentation that the drivers must be installed separately in the pip path, or this would need to be fixed.

@icfaust icfaust changed the title windows pip installation doesn't link openCL cpu drivers properly windows pip installation doesn't find openCL cpu drivers properly Jul 22, 2024
@oleksandr-pavlyk
Copy link
Collaborator

@icfaust This is because in conda, activation script is doing set "OCL_ICD_FILENAMES=%CONDA_PREFIX%\Library\bin\intelocl64.dll" . This step must be performed manually when using pip as package manager.

It may also be necessary to use os.add_dll_directory to ensure that the CPU driver is able to find the required TBB libraries in the Python layout.

@icfaust
Copy link
Author

icfaust commented Jul 29, 2024

Let me try this out on the github runner example to verify if this works.

@icfaust
Copy link
Author

icfaust commented Jul 30, 2024

It didn't seem to work...

@oleksandr-pavlyk
Copy link
Collaborator

@icfaust If you are attempting this in GitHub action runners, you need to take into account that the Python script is executed in a session with elevated privileges. OpenCL loader, for security purposes, ignores environment variable values.

To make location of CPU implementation library, e.g., %CONDA_PREFIX%\Library\bin\intelocl64.dll known to the loader, information must be provided through Windows registry, see https://github.com/IntelPython/dpctl/blob/master/.github/workflows/conda-package.yml#L317-L318

The content of the script file "set-intel-ocl-icd-registry.ps1" is as follow:

#Requires -RunAsAdministrator

$conda_env_library = "$env:CONDA_PREFIX\Library"

if (-not (Test-Path -Path HKLM:\SOFTWARE\Khronos)) {
    New-Item -Path HKLM:\SOFTWARE\Khronos
}
if (-not (Test-Path -Path HKLM:\SOFTWARE\Khronos\OpenCL)) {
    New-Item -Path HKLM:\SOFTWARE\Khronos\OpenCL
}
if (-not (Test-Path -Path HKLM:\SOFTWARE\Khronos\OpenCL\Vendors)) {
    New-Item -Path HKLM:\SOFTWARE\Khronos\OpenCL\Vendors
}
New-ItemProperty -Path HKLM:\SOFTWARE\Khronos\OpenCL\Vendors -Name $conda_env_library\bin\intelocl64.dll -Value 0

Write-Host "Registry value: $(Get-Item -Path HKLM:\SOFTWARE\Khronos\OpenCL\Vendors)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants