intel / llvm

Intel staging area for llvm.org contribution. Home for Intel LLVM-based projects.
Other
1.25k stars 738 forks source link

Add support for Apple Silicon CPU #12318

Open ZzEeKkAa opened 10 months ago

ZzEeKkAa commented 10 months ago

Is your feature request related to a problem? Please describe Not related to any problem, just wondering why isn't it working on apple silicone that is being run through the x86_64 docker

>docker run -it --rm --platform linux/x86_64 ghcr.io/intel/llvm/sycl_ubuntu2204_nightly:build-3468f496c04ca9091da19ff5c73aa5f7ef792924 bash
>root@360aa2f7f76b:/# sycl-ls --verbose

Platforms: 0
default_selector()      : No device of requested type available. -1 (PI_ERRO...
accelerator_selector()  : No device of requested type available. -1 (PI_ERRO...
cpu_selector()          : No device of requested type available. -1 (PI_ERRO...
gpu_selector()          : No device of requested type available. -1 (PI_ERRO...
custom_selector(gpu)    : No device of requested type available. -1 (PI_ERRO...
custom_selector(cpu)    : No device of requested type available. -1 (PI_ERRO...
custom_selector(acc)    : No device of requested type available. -1 (PI_ERRO...

Describe the solution you would like


At least one cpu device should appear

**Describe alternatives you have considered**
N/A

**Additional context**
N/A
AlexeySachkov commented 10 months ago

Hi @ZzEeKkAa,

macOS is generally unsupported by the project. The compiler is buildable in there, but it is completely untested and may not be useable at all.

Not related to any problem, just wondering why isn't it working on apple silicone that is being run through the x86_64 docker

This is caused by lack of a low-level runtime on your system. SYCL is an abstraction layer on top of actual offloading mechanisms such as OpenCL, CUDA, Level Zero, etc. The flow here is that SYCL RT queries PI plugins (or Unified Runtime adapters once the transition is complete) to get a list of available devices. Those plugins/adapters in turn access low-level APIs to query list of available devices.

There is no special OS-based filtering and I would expect to see at least a CPU device discoverable if you install POCL for example. AFAIK, @alexbatashev did some experiments with trying to run some SYCL apps on macOS over POCL, but that was a while ago.

We also have native CPU device support in development, which should help us to expand to macOS (and to any system with no low-level runtimes installed, really). It theoretically should be of help, but I don't have experience with it and haven't tried it yet myself. Tagging @PietroGhg here for awareness/comments

PietroGhg commented 10 months ago

Hello, yeah the Native CPU device should help with environments with no low-level runtimes, it is still in an experimental stage but we are actively working to improve both its performances and correctness. We would definitely like to see it working on macOS, but haven't tried that yet.

alexbatashev commented 10 months ago

There is no special OS-based filtering and I would expect to see at least a CPU device discoverable if you install POCL for example. AFAIK, @alexbatashev did some experiments with trying to run some SYCL apps on macOS over POCL, but that was a while ago.

The compiler heavily uses Intel-only SPIR-V opcodes, which makes it virtually impossible to use any OpenCL implementation other than Intel. Many of those are actually trivial, like arbitrary precision integers, and PoCL does indeed support some of Intel extensions, like USM or Intel sub-groups, but AFAIK, that's still not enough to successfully run SYCL code. From my experiments, tests that did not require actual kernel execution, passed as-is with very small tuning to build system and the runtime. I upstreamed those changes a couple of years ago, but they might be outdated. I also tried to implement OpenCL 3.0 on top of Apple Metal framework (https://github.com/alexbatashev/librecl) but gave up due to the differences in memory and execution models that made the implementation extremely non-trivial (e.g., lack of generic address space).

Anyway, it's not like SYCL on Apple Silicon is impossible, it's just that it requires a significant investment of time and money, and the reward is probably not worth it: the adoption of SYCL is not that big, and you wouldn't use a MacBook for anything other than unit-tests for your production code.

ZzEeKkAa commented 10 months ago

Thank you! This was really informative! I'll go and check POCL and will wait for native CPU device support if does not work. In the current state, yes it is mostly to run unit test before running in production.

KornevNikita commented 8 months ago

Hi @ZzEeKkAa, were the guys able to answer your question? Can we close this issue?

AlexeySachkov commented 6 months ago

Hi @ZzEeKkAa, were the guys able to answer your question? Can we close this issue?

Not the original reporter, but I think that we can leave this issue open, because even though we provided the current status of macOS and Apple Silicon support that is unsupported, we haven't enabled the platform itself. I think that the issue can stay in the backlog as an indicator of the current state of things for everyone else who is wondering about this platform as well.

2360 is related