3

我刚刚使用 OpenCL C++ 的参考 clang 实现来编译规范第 13 页的源代码:

#include <opencl_def>
#include <opencl_memory>
#include <opencl_vector_load_store>

half bar(half a) { //ok: half built-in type passed by value
 half b = a; //ok: copying half data type
 b += 10.0; // not allowed: arithmetic operation
 // vload should be used or cl_khr_fp16 support enabled
 float f = cl::vload_half<1>(0, &b); // ok
 return a; //ok: return half built-in type
}

kernel void foo(cl::global_ptr<half> pg) { //ok: a global pointer
 // passed from the host
 int offset = 1;
 half *ptr = pg.get() + offset; //ok: half pointer arithmetic
 half b = bar(*ptr); //ok: dereferencing half pointer
 if(b < *ptr) { //not allowed: it is only supported if cl_khr_fp16
 // extension is enabled
 }
}

规范说有一条half突变线,这是无效的,因此我预计编译会失败。可悲的是,它编译时没有任何抱怨。

我理解错了吗?

4

0 回答 0