使用原生Clang++编译SYCL程序遇interop_handler弃用警告的问询
原生Clang++编译SYCL代码触发
interop_handler弃用警告的问题 问题场景
使用原生Clang++ 16编译极简SYCL代码时,出现了dpcpp编译不会产生的interop_handler弃用警告,担心是否会导致运行时异常,寻求解决办法。
触发警告的代码
#include <CL/sycl.hpp> int main(){}
编译命令
clang++ -std=c++17 -I$INCLUDEDIR -c t.cpp
警告信息
In file included from t.cpp:1: In file included from /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl.hpp:16: In file included from /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/backend.hpp:18: In file included from /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/detail/backend_traits_opencl.hpp:26: In file included from /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/queue.hpp:20: In file included from /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/handler.hpp:14: In file included from /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/detail/cg.hpp:27: /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/detail/cg_types.hpp:234:32: warning: 'interop_handler' is deprecated: interop_handler class is deprecated, use interop_handle instead with host-task [-Wdeprecated-declarations] std::function<void(cl::sycl::interop_handler)> MFunc; ^ /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/interop_handler.hpp:18:7: note: 'interop_handler' has been explicitly marked deprecated here class __SYCL_DEPRECATED("interop_handler class is deprecated, use" ^ /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/detail/defines_elementary.hpp:45:38: note: expanded from macro '__SYCL_DEPRECATED' #define __SYCL_DEPRECATED(message) [[deprecated(message)]] ^ In file included from t.cpp:1: In file included from /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl.hpp:16: In file included from /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/backend.hpp:18: In file included from /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/detail/backend_traits_opencl.hpp:26: In file included from /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/queue.hpp:20: In file included from /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/handler.hpp:14: In file included from /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/detail/cg.hpp:27: /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/detail/cg_types.hpp:237:44: warning: 'interop_handler' is deprecated: interop_handler class is deprecated, use interop_handle instead with host-task [-Wdeprecated-declarations] InteropTask(std::function<void(cl::sycl::interop_handler)> Func) ^ /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/interop_handler.hpp:18:7: note: 'interop_handler' has been explicitly marked deprecated here class __SYCL_DEPRECATED("interop_handler class is deprecated, use" ^ /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/detail/defines_elementary.hpp:45:38: note: expanded from macro '__SYCL_DEPRECATED' #define __SYCL_DEPRECATED(message) [[deprecated(message)]] ^ In file included from t.cpp:1: In file included from /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl.hpp:16: In file included from /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/backend.hpp:18: In file included from /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/detail/backend_traits_opencl.hpp:26: In file included from /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/queue.hpp:20: In file included from /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/handler.hpp:14: In file included from /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/detail/cg.hpp:27: /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/detail/cg_types.hpp:239:23: warning: 'interop_handler' is deprecated: interop_handler class is deprecated, use interop_handle instead with host-task [-Wdeprecated-declarations] void call(cl::sycl::interop_handler &h) { MFunc(h); } ^ /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/interop_handler.hpp:18:7: note: 'interop_handler' has been explicitly marked deprecated here class __SYCL_DEPRECATED("interop_handler class is deprecated, use" ^ /ONE_API_2022.3/compiler/2022.2.0/linux/include/sycl/CL/sycl/detail/defines_elementary.hpp:45:38: note: expanded from macro '__SYCL_DEPRECATED' #define __SYCL_DEPRECATED(message) [[deprecated(message)]] ^ 3 warnings generated.
是否需要担忧?
- 这些警告来自SYCL标准库内部的弃用代码,并非你的业务代码问题,所以不会直接引发运行时异常。弃用标记仅表示该API会在未来版本中移除,当前版本仍能正常工作。
- dpcpp未触发警告,是因为Intel编译器默认屏蔽了库内部的弃用警告,或是其配套SYCL头文件做了特殊处理过滤了这类信息。
解决方法
1. 屏蔽特定弃用警告
编译时添加-Wno-deprecated-declarations参数,直接关闭弃用警告:
clang++ -std=c++17 -I$INCLUDEDIR -Wno-deprecated-declarations -c t.cpp
该方法不会影响你的业务代码中的弃用提示,仅屏蔽库内部的警告。
2. 使用版本匹配的SYCL实现
你当前使用的是Intel oneAPI 2022.3的SYCL头文件,与原生Clang 16存在版本兼容性问题。建议:
- 直接使用原生Clang 16自带的SYCL支持:编译时添加
-fsycl参数,无需额外引入Intel头文件,命令为clang++ -std=c++17 -fsycl -c t.cpp - 升级Intel oneAPI到新版本:新版本头文件可能已修复与新Clang的兼容性问题,不再触发这类内部警告。
3. 按需包含头文件(可选)
如果代码不需要OpenCL互操作功能,可以尝试只包含所需的SYCL子头文件,而非顶层的<CL/sycl.hpp>。但该方法局限性大,仅适用于极简项目。
内容的提问来源于stack exchange,提问作者Alejandro Arcila
相关产品推荐
相关产品推荐

