官方提供了一个名为 KhronosGroup/SPIR 的开源项目,支持OpenCL
编译成SPIR
代码的功能
注意: Vulkan
使用SPIR-V
也就是 spirv-1.0
分支,不使用此分支。本文实际上可以作为 llvm-3.2
在最新的 macOS Mojave(10.14.2)
上的编译指南。
这个工具使用的LLVM的版本非常古老,编译的时候问题多多。
这个工具在 macOS Mojave(10.14.2)
系统上使用 gcc 8.2.0
的编译流程如下:
如果使用 Xcode Version 10.1 (10B61)
编译会报告如下错误:
上述错误产生的原因在于 macOS
官方提供的 C++
标准库中增加了校验 is_constructible
(要求模版中的类必须明确构造函数和析构函数)这个逻辑,这个功能貌似在 C++ 14
中才加入的,显然这个校验有些操之过急了。
如果编译的时候出现如下错误信息:
则说明编译的时候,没有指定使用 macOS
官方提供的 ar
, ranlib
,链接这两个程序到Xcode
提供的即可。
如果编译的时候出现如下错误信息:
这是由于llvm/tools/clang/include/clang/Sema/AttributeList.h
这个文件中的 ~AttributeList() LLVM_DELETED_FUNCTION;
这句话造成的,按理说这个析构函数不应该被调用到才对,但是代码中仍然有地方隐式调用了,我们需要做的就是去掉这行代码的 LLVM_DELETED_FUNCTION
属性即可。
编译完成后的使用方式如下:
<triple>
: for 32 bit SPIR use spir-unknown-unknown, for 64 bit SPIR use spir64-unknown-unknown.- Note:
<OpenCL compile options>
appears twice. The command line option-cl-spir-compile-options "<OpenCL compile options>"
specifies the compile options that occur in the SPIR metadata. - <opencl_spir.h>: download opencl_spir.h from https://github.com/KhronosGroup/SPIR-Tools/blob/master/headers/opencl_spir.h
- -O: -O0 (default) is the only tested option value at the moment. It's assumed by design that all optimizations are executed by SPIR consumer.
参考链接
- Vulkan, SPIR-V and OpenCL 2.1 - Khronos Group
- OpenCl -> Vulkan: A Porting Guide - Duskborn
- KhronosGroup/SPIR
- LLVM/SPIR-V Bi-Directional Translator
- Not Compiling on macOS
- llvm @3.2 build failure
- llvm-3.2 Build Error in CodeExtractor.cpp:751
- [LLVMdev] error compiling llvm 2.9/3.2 from source on macosx (possibly stdlibc++ issue)
- 修改mac默认的gcc到自己安装的gcc
- brew list should show version numbers #245
- shell命令,从字符串中提取数字
- CMake 指定gcc编译版本
- 六、如何使用外部共享库和头文件
- Static library built for archive which is not the architecture being linked (x86_64)
- Cannot link librsvg static library #23772
- Linker problem: file was built for archive which is not the architecture being linked #11
- 题 具有非公共析构函数的类型的std :: is_constructible
- Is constructible?
- Build failure on Mac OS X: file was built for archive which is not the architecture being linked (x86_64)
- CMake Multiarchitecture Compilation
- Static library link issue with Mac OS X: symbol(s) not found for architecture x86_64