You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关闭OpenCL后Arrayfire基于CUDA构建失败问题求助

Arrayfire仅CUDA构建失败:OpenCL依赖残留问题

问题描述

尝试仅基于CUDA构建Arrayfire,已通过CMake设置AF_BUILD_OPENCL=OFF、AF_BUILD_CPU=OFF等参数关闭其他后端,但构建过程仍尝试调用未安装的OpenCL组件,同时出现AF_COMPUTE_LIBRARY相关依赖警告,最终因找不到OpenCL::OpenCL目标导致构建失败。

构建环境

nvcc --version

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Mon_May__3_19:15:13_PDT_2021
Cuda compilation tools, release 11.3, V11.3.109
Build cuda_11.3.r11.3/compiler.29920130_0

CMake缓存变量

CMake Warning:
  No source or binary directory provided.  Both will be assumed to be the
  same as the current working directory, but note that this warning will
  become a fatal error in future CMake releases.


CMake Error: The source directory "/home/hphi344/Documents/arrayfire/build" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
-- Cache values
AF_BUILD_CPU:BOOL=OFF
AF_BUILD_CUDA:BOOL=ON
AF_BUILD_DOCS:BOOL=OFF
AF_BUILD_EXAMPLES:BOOL=OFF
AF_BUILD_FORGE:BOOL=OFF
AF_BUILD_ONEAPI:BOOL=OFF
AF_BUILD_OPENCL:BOOL=OFF
AF_BUILD_UNIFIED:BOOL=ON
AF_COMPUTE_LIBRARY:STRING=FFTW/LAPACK/BLAS
AF_CTEST_SEPARATED:BOOL=OFF
AF_STACKTRACE_TYPE:STRING=Basic
AF_WITH_CUDNN:BOOL=OFF
AF_WITH_EXTERNAL_PACKAGES_ONLY:BOOL=OFF
AF_WITH_FAST_MATH:BOOL=OFF
AF_WITH_FMT_HEADER_ONLY:BOOL=OFF
AF_WITH_SPDLOG_HEADER_ONLY:BOOL=OFF
AF_WITH_STATIC_CUDA_NUMERIC_LIBS:BOOL=OFF
BUILD_TESTING:BOOL=ON
CLBlast_DIR:PATH=CLBlast_DIR-NOTFOUND
CMAKE_BUILD_TYPE:STRING=Release
CMAKE_INSTALL_PREFIX:PATH=/usr/local
CUDA_TOOLKIT_ROOT_DIR:PATH=/usr/local/cuda-11.3
FETCHCONTENT_UPDATES_DISCONNECTED_SPAN-LITE:BOOL=OFF
GTest_DIR:PATH=GTest_DIR-NOTFOUND
MKL_Core_LINK_LIBRARY:FILEPATH=MKL_Core_LINK_LIBRARY-NOTFOUND
MKL_DIR:PATH=MKL_DIR-NOTFOUND
MKL_FFTW_INCLUDE_DIR:PATH=MKL_FFTW_INCLUDE_DIR-NOTFOUND
MKL_INCLUDE_DIR:PATH=MKL_INCLUDE_DIR-NOTFOUND
MKL_Interface_LINK_LIBRARY:FILEPATH=MKL_Interface_LINK_LIBRARY-NOTFOUND
MKL_RT_LINK_LIBRARY:FILEPATH=MKL_RT_LINK_LIBRARY-NOTFOUND
MKL_THREAD_LAYER:STRING=Intel OpenMP
MKL_ThreadLayer_LINK_LIBRARY:FILEPATH=MKL_ThreadLayer_LINK_LIBRARY-NOTFOUND
MKL_ThreadingLibrary_LINK_LIBRARY:FILEPATH=MKL_ThreadingLibrary_LINK_LIBRARY-NOTFOUND
MKL_mkl_avx2_LINK_LIBRARY:FILEPATH=MKL_mkl_avx2_LINK_LIBRARY-NOTFOUND
MKL_mkl_avx512_LINK_LIBRARY:FILEPATH=MKL_mkl_avx512_LINK_LIBRARY-NOTFOUND
MKL_mkl_avx_LINK_LIBRARY:FILEPATH=MKL_mkl_avx_LINK_LIBRARY-NOTFOUND
MKL_mkl_def_LINK_LIBRARY:FILEPATH=MKL_mkl_def_LINK_LIBRARY-NOTFOUND
MKL_mkl_mc3_LINK_LIBRARY:FILEPATH=MKL_mkl_mc3_LINK_LIBRARY-NOTFOUND
MKL_mkl_mc_LINK_LIBRARY:FILEPATH=MKL_mkl_mc_LINK_LIBRARY-NOTFOUND
NVPRUNE:FILEPATH=/usr/local/cuda-11.3/bin/nvprune

错误日志

执行命令:cmake .. -DCMAKE_BUILD_TYPE=Release -DAF_BUILD_OPENCL=OFF -DAF_BUILD_CPU=OFF -DAF_BUILD_EXAMPLES=OFF,输出如下:

CMake Warning (dev) at CMakeLists.txt:64 (find_package):
  Policy CMP0146 is not set: The FindCUDA module is removed.  Run "cmake
  --help-policy CMP0146" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeModules/FindcuDNN.cmake:88 (find_package):
  Policy CMP0146 is not set: The FindCUDA module is removed.  Run "cmake
  --help-policy CMP0146" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

Call Stack (most recent call first):
  CMakeLists.txt:65 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Could NOT find cuDNN (missing: cuDNN_LINK_LIBRARY cuDNN_INCLUDE_DIRS) (Required is at least version "4.0")
-- Could NOT find OpenCL (missing: OpenCL_LIBRARY OpenCL_INCLUDE_DIR) (Required is at least version "1.2")
-- Could NOT find FreeImage (missing: FreeImage_INCLUDE_DIR FreeImage_LINK_LIBRARY) 
-- Checking for module 'fftw3'
--   No package 'fftw3' found
-- Could NOT find FFTW (missing: FFTW_INCLUDE_DIR FFTW_LIBRARY FFTWF_LIBRARY) 
-- Checking for module 'cblas'
--   No package 'cblas' found
-- Checking for [Accelerate]
-- Checking for [vecLib]
-- Checking for [cblas - atlas]
-- Checking for [openblas]
-- Checking for [cblas]
-- Checking for [blas]
-- CBLAS library not found.
-- Could NOT find LAPACKE (missing: LAPACKE_LIB LAPACKE_INCLUDES) 
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
-- MKL: Thread Layer(Intel OpenMP) Interface(4-byte Integer)
-- Could NOT find MKL: Source the compilervars.sh or mklvars.sh scripts included with your installation of MKL. This script searches for the libraries in MKLROOT, LIBRARY_PATHS(Linux), and LIB(Windows) environment variables (missing: MKL_INCLUDE_DIR MKL_Core_LINK_LIBRARY MKL_Interface_LINK_LIBRARY MKL_ThreadLayer_LINK_LIBRARY) 
-- Could NOT find MKL: Source the compilervars.sh or mklvars.sh scripts included with your installation of MKL. This script searches for the libraries in MKLROOT, LIBRARY_PATHS(Linux), and LIB(Windows) environment variables (missing: MKL_INCLUDE_DIR MKL_Core_STATIC_LINK_LIBRARY MKL_Interface_STATIC_LINK_LIBRARY MKL_ThreadLayer_STATIC_LINK_LIBRARY) 
-- Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY) 
CMake Warning (dev) at CMakeLists.txt:81 (find_package):
  Policy CMP0167 is not set: The FindBoost module is removed.  Run "cmake
  --help-policy CMP0167" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning at CMakeLists.txt:144 (find_package):
  By not providing "FindMKL.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "MKL", but
  CMake did not find one.

  Could not find a package configuration file provided by "MKL" (requested
  version 2023.1) with any of the following names:

    MKLConfig.cmake
    mkl-config.cmake

  Add the installation prefix of "MKL" to CMAKE_PREFIX_PATH or set "MKL_DIR"
  to a directory containing one of the above files.  If "MKL" provides a
  separate development package or SDK, be sure it has been installed.


-- Build spdlog: 1.9.2
-- Build type: Release
-- Project 'span_lite', package 'span-lite' version: '0.10.2'
-- Autodetected CUDA architecture(s):  8.6 8.6
-- Autodetected CUDA architecture(s):  8.6 8.6
-- Configuring done (3.1s)
CMake Error:
  Error evaluating generator expression:

    $<TARGET_PROPERTY:OpenCL::OpenCL,INTERFACE_INCLUDE_DIRECTORIES>

  Target "OpenCL::OpenCL" not found.


-- Generating done (0.5s)
CMake Generate step failed.  Build files cannot be regenerated correctly.

解决步骤

1. 彻底禁用OpenCL查找

仅设置AF_BUILD_OPENCL=OFF可能不足以阻止CMake检测OpenCL,需添加额外参数强制禁用:

cmake .. -DCMAKE_BUILD_TYPE=Release -DAF_BUILD_OPENCL=OFF -DAF_BUILD_CPU=OFF -DAF_BUILD_EXAMPLES=OFF -DCMAKE_DISABLE_FIND_PACKAGE_OpenCL=ON

2. 解决计算库依赖问题

当前AF_COMPUTE_LIBRARY指定依赖FFTW/LAPACK/BLAS但未安装,可选择以下方案:

  • 安装系统依赖库(Debian/Ubuntu系):
    sudo apt install libfftw3-dev libopenblas-dev liblapacke-dev
    
  • 使用内置计算库:保持AF_WITH_EXTERNAL_PACKAGES_ONLY=OFF(默认值),让CMake自动构建Arrayfire内置的计算库版本
  • 跳过计算库:若不需要相关功能,尝试设置AF_COMPUTE_LIBRARY=NONE(需确认Arrayfire版本支持此选项)

3. 清理旧CMake缓存

之前的缓存可能残留OpenCL相关配置,删除build目录后重新构建:

rm -rf build && mkdir build && cd build

4. 消除CMake版本兼容警告

若要忽略CMP0146、CMP0167等开发者警告,可在CMake命令中添加-Wno-dev参数:

cmake .. -DCMAKE_BUILD_TYPE=Release -DAF_BUILD_OPENCL=OFF -DAF_BUILD_CPU=OFF -DAF_BUILD_EXAMPLES=OFF -DCMAKE_DISABLE_FIND_PACKAGE_OpenCL=ON -Wno-dev

内容的提问来源于stack exchange,提问作者Hugo Phibbs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 02:17:08