在 Linux 中在多个平台上启用 OpenCL?如何处理 ICD 文件?

Enable OpenCL over multiple platforms in Linux? How to proceed with ICD files?

详情

我必须安装什么 drivers/packages 才能在多个平台上启用 OpenCL:CPU (Intel)、集成 GPU (Intel)、专用 GPU (NVIDIA)?
最好有所有平台 运行 OpenCL 1.2 或更高版本

我知道这可能是一个简单的修复,也许只是 libraries/SKDs 的正确选择,但我在让更多的平台运行时遇到了一些麻烦。

运行 ubuntu 14.04: 我有一个带有集成英特尔显卡的英特尔酷睿 I5 和一块专用的 NVIDIA Geforce 710m 板。


我用过的资源

https://wiki.tiker.net/OpenCLHowTo
在这里(在 Debian 下)它告诉我我只需要:

  1. ICD加载器包:(你只需要其中一个)
  2. ICD 包
  3. 包 headers

我已经尝试过的

  1. 已安装 CUDA7.5(全部安装)
    • 由于驱动冲突导致黑屏
      • 通过卸载所有nvidia驱动并安装352解决
      • 仍未安装 Cuda SDK
  2. 发件人:How to make OpenCL work on 14.10 + Nvidia 331.89 drivers?
    • sudo apt-get install nvidia-331 nvidia-331-uvm nvidia-opencl-dev nvidia-modprobe
    • 这些软件包将我的驱动程序降级为 331 和 340
  3. 也来自:How to make OpenCL work on 14.10 + Nvidia 331.89 drivers?
    • 链接库有:
      • sudo ln -s /usr/include/nvidia-352/GL /usr/local/include
      • sudo ln -s /usr/lib/x86_64-linux-gnu/libOpenCL.so.1 /usr/local/lib/libOpenCL.so
    • OpenCL 1.1 适用于 NVIDIA GPU
    • 无法获取 OpenCL 1.2,因此决定卸载 331 和 340 并重新安装 352
  4. 已安装 352(再次)
    • OpenCL 1.1 停止工作 NVIDIA GPU(并且仍然不工作)
  5. 已安装英特尔 opencl_runtime_14.2_x64_4.5.0.8.tgz

    • 为英特尔 ICD 创建了一个符号 link:

      • sudo ln -s /opt/intel/opencl-1.2-4.5.0.8/etc/intel64.icd
    • OpenCL 1.2 为 CPU 工作(并且仍然有效)

  6. 已安装 clinfo sudo apt-get install clinfo

    • 仅检测到英特尔 CPU 平台
  7. 试图安装几个不同的 NVIDIA 软件包以使 NVIDIA GPU 再次工作,但没有成功

已安装的软件包和一些信息:

供应商中的 ICD?

ls -l /etc/OpenCL/vendors/
total 4
-rw-r--r-- 1 root root 15 Out 22  2015 Altera.icd
lrwxrwxrwx 1 root root 45 Abr 28 13:48 intel64.icd -> /opt/intel/opencl-1.2-4.5.0.8/etc/intel64.icd

注意缺失的nvidia.icd

CL 和 GL - GL 有一个有效的 link... 现在是红色的

ls -l /usr/local/include
total 4
lrwxrwxrwx 1 root root   31 Abr 28 12:48 CL -> /usr/local/cuda-7.5/include/CL/
lrwxrwxrwx 1 root root   26 Abr 27 11:44 GL -> /usr/include/nvidia-352/GL (IN RED COLOR - folder doesn't exist anymore)

.so 文件

ls -l /usr/local/lib/ | grep CL
lrwxrwxrwx 1 root root    40 Abr 27 11:45 libOpenCL.so -> /usr/lib/x86_64-linux-gnu/libOpenCL.so.1

已安装的软件包

dpkg --get-selections | grep nvidia
nvidia-340                  deinstall
nvidia-352                  install
nvidia-libopencl1-340               deinstall
nvidia-libopencl1-340-updates           deinstall
nvidia-libopencl1-352               deinstall
nvidia-libopencl1-352-updates           install
nvidia-modprobe                 install
nvidia-opencl-icd-340               deinstall
nvidia-opencl-icd-352               deinstall
nvidia-prime                    install
nvidia-settings                 install


dpkg --get-selections | grep opencl
nvidia-libopencl1-340               deinstall
nvidia-libopencl1-340-updates           deinstall
nvidia-libopencl1-352               deinstall
nvidia-libopencl1-352-updates           install
nvidia-opencl-icd-340               deinstall
nvidia-opencl-icd-352               deinstall
ocl-icd-libopencl1:amd64            deinstall
ocl-icd-libopencl1:i386             deinstall
opencl-headers                  install
unity-scope-openclipart             install

clinfo

clinfo 
Number of platforms:                 1
  Platform Profile:              FULL_PROFILE
  Platform Version:              OpenCL 1.2 LINUX
  Platform Name:                 Intel(R) OpenCL
  Platform Vendor:               Intel(R) Corporation
  Platform Extensions:               cl_khr_icd cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_spir cl_intel_exec_by_local_thread cl_khr_depth_images cl_khr_3d_image_writes cl_khr_fp64 


  Platform Name:                 Intel(R) OpenCL
Number of devices:               1
  Device Type:                   CL_DEVICE_TYPE_CPU
  Device ID:                     32902
  Max compute units:                 4
  Max work items dimensions:             3
    Max work items[0]:               8192
    Max work items[1]:               8192
    Max work items[2]:               8192
  Max work group size:               8192
  Preferred vector width char:           1
  Preferred vector width short:          1
  Preferred vector width int:            1
  Preferred vector width long:           1
  Preferred vector width float:          1
  Preferred vector width double:         1
  Native vector width char:          16
  Native vector width short:             8
  Native vector width int:           4
  Native vector width long:          2
  Native vector width float:             8
  Native vector width double:            4
  Max clock frequency:               1800Mhz
  Address bits:                  64
  Max memory allocation:             2040185856
  Image support:                 Yes
  Max number of images read arguments:       480
  Max number of images write arguments:      480
  Max image 2D width:                16384
  Max image 2D height:               16384
  Max image 3D width:                2048
  Max image 3D height:               2048
  Max image 3D depth:                2048
  Max samplers within kernel:            480
  Max size of kernel argument:           3840
  Alignment (bits) of base address:      1024
  Minimum alignment (bytes) for any datatype:    128
  Single precision floating point capability
    Denorms:                     Yes
    Quiet NaNs:                  Yes
    Round to nearest even:           Yes
    Round to zero:               No
    Round to +ve and infinity:           No
    IEEE754-2008 fused multiply-add:         No
  Cache type:                    Read/Write
  Cache line size:               64
  Cache size:                    262144
  Global memory size:                8160743424
  Constant buffer size:              131072
  Max number of constant args:           480
  Local memory type:                 Global
  Local memory size:                 32768
  Error correction support:          0
  Unified memory for Host and Device:        1
  Profiling timer resolution:            1
  Device endianess:              Little
  Available:                     Yes
  Compiler available:                Yes
  Execution capabilities:                
    Execute OpenCL kernels:          Yes
    Execute native function:             Yes
  Queue properties:              
    Out-of-Order:                Yes
    Profiling :                  Yes
  Platform ID:                   0x1659390
  Name:                             Intel(R) Core(TM) i5-3337U CPU @ 1.80GHz
  Vendor:                    Intel(R) Corporation
  Device OpenCL C version:           OpenCL C 1.2 
  Driver version:                1.2.0.8
  Profile:                   FULL_PROFILE
  Version:                   OpenCL 1.2 (Build 8)
  Extensions:                    cl_khr_icd cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_spir cl_intel_exec_by_local_thread cl_khr_depth_images cl_khr_3d_image_writes cl_khr_fp64 

所以...

如何让 NVIDIA GPU 也显示为 OPENCL 1.2(或更高版本)平台?集成英特尔显卡怎么样?
AMD 库可以与我的硬件一起使用吗?
为什么大多数 nvidia 软件包都标记为 deinstall?

如前所述,需要三样东西:

来自 https://wiki.tiker.net/OpenCLHowTo

  • ICD加载器包:(你只需要其中一个)
  • ICD 包
  • 包 headers

因此对于 Intel CPU 和 NVIDIA GPU

  • ICD 加载器 的软件包:
    • ocl-icd-libopencl1
  • ICD 包裹
  • headers
    • opencl-headers

但是,要使其正常工作,必须确保 dpkg --get-selections | grep opencl

将软件包标记为已安装
sudo apt-get install --reinstall nvidia-opencl-icd-352 opencl-headers ocl-icd-libopencl1

最重要的是,您必须确保 intel64.icd 和 nvidia.icd 在 /etc/OpenCL/vendors (ls -l /etc/OpenCL/vendors) 中。

也就是说,我必须 link intel64.icd 与:

cd /etc/OpenCL/vendors/
sudo ln -s /opt/intel/opencl-1.2-X.X.X.X/etc/intel64.icd

而且,由于 nvidia.icd 不在文件夹中(即使在安装了正确的包之后)我不得不解压缩它并手动从 deb 包中移动

dpkg -x /var/cache/apt/archives/nvidia-opencl-icd-352_352.63-0ubuntu0.14.04.1_amd64.deb ~/tempfolder
sudo mv ~/tempfolder/etc/OpenCL/vendors/nvidia.icd /etc/OpenCL/vendors/nvidia.icd
rm -r ~/tempfolder

最后,确保 nvidia 是活动 GPU

sudo prime-select nvidia
sudo reboot -r now

安装并执行 clinfo,两个平台都应该 show-up。

clinfo 
Number of platforms:                 2
  Platform Profile:              FULL_PROFILE
  Platform Version:              OpenCL 1.2 CUDA 7.5.23
  Platform Name:                 NVIDIA CUDA
  Platform Vendor:               NVIDIA Corporation
  Platform Extensions:               cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll cl_nv_copy_opts 
  Platform Profile:              FULL_PROFILE
  Platform Version:              OpenCL 1.2 LINUX
  Platform Name:                 Intel(R) OpenCL
  Platform Vendor:               Intel(R) Corporation
  Platform Extensions:               cl_khr_icd cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_spir cl_intel_exec_by_local_thread cl_khr_depth_images cl_khr_3d_image_writes cl_khr_fp64