back

by raphlinus·4y ago·view on hn ↗
While this might work on your specific device, it is an undocumented interface and there is no guarantee at all for future compatibility.

If you do get a definitive answer from Apple you can share, please follow up here, as I would like to be able to cite it. I would be quite shocked if it's different than what I just said, though.

1 comments
> While this might work on your specific device

it's what is used for OpenCL on Metal (which is the impl present on M1) to provide the semantics there. AIR is a stable, forward compatible bytecode. Will ask and see what Apple says...

edit: thinking about this, OpenCL doesn't actually need those semantics either

The Open CL 1.2 barrier() function is threadgroup scope, same as threadgroup_barrier on Metal. OpenCL 2.0 introduced a proper barrier function (work_group_barrier), which takes a memory scope parameter, which can be memory_scope_device (all this is pretty similar to the Vulkan memory model, and at least some of the same people worked on both). I know of no way to reliably support those semantics on Metal.

Claiming OpenCL bitcode is "forward compatible" is a pretty strong claim considering that OpenCL has been deprecated for over 3 years, and the main thing you get when searching OpenCL docs on the Apple site is an exhortation to migrate to Metal. To the extent there's a forward compatibility guarantee for AIR, I'm sure it only applies to output generated by official Apple tools, and I'm pretty sure by now there's no way to get those to output a device-scope barrier.

> The Open CL 1.2 barrier() function is threadgroup scope, same as threadgroup_barrier on Metal

Interestingly, the Apple driver seems to have that screwed up, with giving much stronger semantics than necessary...

#define _AIR_MEM_SCOPE_WORK_GROUP 0x2 in the OpenCL header

And for metal_types.h...

#define _AIR_MEM_SCOPE_WORK_GROUP 0x1

#define _AIR_MEM_SCOPE_DEVICE 0x2

Which made me have even more questions, that's why I couldn't give a straight answer earlier.

> OpenCL has been deprecated for over 3 years

The OpenCL implementation using AIR is new, for Apple Silicon.