|
1 | | -When performing a code review, pay close attention to code modifying a function's |
2 | | -control flow. Could the change result in the corruption of performance profile |
3 | | -data? Could the change result in invalid debug information, in particular for |
4 | | -branches and calls? |
| 1 | +# Intel LLVM (DPC++ / oneAPI) — Copilot Instructions |
| 2 | + |
| 3 | +## Repository overview |
| 4 | + |
| 5 | +This is Intel's LLVM fork (`intel/llvm`, `sycl` branch), hosting: |
| 6 | +- **oneAPI DPC++ compiler** — a SYCL implementation built on top of Clang/LLVM |
| 7 | +- **DPC++ runtime library** (`sycl/`) |
| 8 | +- **Unified Runtime (UR)** (`unified-runtime/`) — backend abstraction over Level-Zero, OpenCL, CUDA, HIP |
| 9 | +- **LLVM-SPIRV translator** (`llvm-spirv/`) |
| 10 | +- **SYCL JIT** (`sycl-jit/`), instrumentation (`xpti/`, `xptifw/`), device libraries (`libdevice/`) |
| 11 | + |
| 12 | +For non-SYCL/DPC++ changes, submit patches upstream to https://llvm.org/ directly. |
| 13 | + |
| 14 | +## Build |
| 15 | + |
| 16 | +Use the buildbot scripts (default output directory: `./build`): |
| 17 | + |
| 18 | +```bash |
| 19 | +python buildbot/configure.py # Run CMake; use --help for full flag list |
| 20 | +python buildbot/compile.py # Build; default target is deploy-sycl-toolchain |
| 21 | +``` |
| 22 | + |
| 23 | +Common `configure.py` flags: `--cuda`, `--hip`, `--native_cpu`, `--shared-libs`, `-t Debug`, `-o <build_dir>`, `--werror` |
| 24 | +Common `compile.py` flags: `-o <build_dir>`, `-t <target>` (e.g. `clang`, `llvm-spirv`), `-j <N>` |
| 25 | + |
| 26 | +After build, add to environment: |
| 27 | +```bash |
| 28 | +export PATH=$DPCPP_HOME/llvm/build/bin:$PATH |
| 29 | +export LD_LIBRARY_PATH=$DPCPP_HOME/llvm/build/lib:$LD_LIBRARY_PATH |
| 30 | +``` |
| 31 | + |
| 32 | +## Testing |
| 33 | + |
| 34 | +### In-tree LIT tests (device-independent) |
| 35 | + |
| 36 | +Run the full check via the buildbot helper: |
| 37 | +```bash |
| 38 | +python buildbot/check.py |
| 39 | +``` |
| 40 | + |
| 41 | +Or run individual check targets from the build directory: |
| 42 | +```bash |
| 43 | +ninja check-sycl # DPC++ headers + runtime unit tests |
| 44 | +ninja check-clang # Clang (including SYCL FE tests) |
| 45 | +ninja check-llvm # Core LLVM |
| 46 | +ninja check-llvm-spirv # LLVM-SPIRV translator |
| 47 | +``` |
| 48 | + |
| 49 | +Run a single LIT test file: |
| 50 | +```bash |
| 51 | +llvm-lit sycl/test/path/to/test.cpp |
| 52 | +llvm-lit clang/test/path/to/test.cpp |
| 53 | +``` |
| 54 | + |
| 55 | +### E2E tests (require hardware / backend runtimes) |
| 56 | + |
| 57 | +```bash |
| 58 | +# Run all E2E tests on all available devices |
| 59 | +llvm-lit sycl/test-e2e |
| 60 | + |
| 61 | +# Limit to specific devices |
| 62 | +llvm-lit --param sycl_devices="level_zero:gpu;opencl:cpu" sycl/test-e2e |
| 63 | + |
| 64 | +# Run a single E2E test |
| 65 | +llvm-lit sycl/test-e2e/Basic/vector_add.cpp |
| 66 | +``` |
| 67 | + |
| 68 | +### Unified Runtime tests (from UR build directory) |
| 69 | + |
| 70 | +```bash |
| 71 | +make check-unified-runtime # All UR tests |
| 72 | +python -m lit test/conformance/device/ -a --filter="urDeviceGetInfo" # Single UR conformance test |
| 73 | +``` |
| 74 | + |
| 75 | +## Code formatting |
| 76 | + |
| 77 | +Use `git-clang-format` against the `sycl` branch merge base. Match the CI `clang-format` version (see `.github/workflows/pr-code-format.yml`): |
| 78 | + |
| 79 | +```bash |
| 80 | +# Check format of staged changes |
| 81 | +./clang/tools/clang-format/git-clang-format `git merge-base origin/sycl HEAD` |
| 82 | + |
| 83 | +# Also fix unstaged changes |
| 84 | +./clang/tools/clang-format/git-clang-format -f `git merge-base origin/sycl HEAD` |
| 85 | +``` |
| 86 | + |
| 87 | +## Architecture |
| 88 | + |
| 89 | +### DPC++ compilation pipeline |
| 90 | + |
| 91 | +1. **Clang front-end** (`clang/`) — parses SYCL source, outlines device code, generates integration headers, enforces device-code restrictions (no exceptions, no virtual calls) |
| 92 | +2. **Device middle-end / back-end** — applies LLVM passes (address space inference, etc.), translates to SPIR-V via `llvm-spirv`, or targets NVPTX/AMDGCPU directly |
| 93 | +3. **Host compilation** — standard Clang compilation of host code |
| 94 | +4. **Linking** — `clang-offload-wrapper` embeds device images into the fat binary |
| 95 | +5. **Runtime** (`sycl/source/`) — manages command queues, buffers, kernels; dispatches work to backend via Unified Runtime |
| 96 | +6. **Unified Runtime** (`unified-runtime/`) — adapters translate UR calls to Level-Zero, OpenCL, CUDA, or HIP |
| 97 | + |
| 98 | +### Key directories |
| 99 | + |
| 100 | +| Path | Contents | |
| 101 | +|---|---| |
| 102 | +| `clang/lib/Sema/`, `clang/lib/CodeGen/` | SYCL-specific FE logic | |
| 103 | +| `sycl/include/sycl/` | Public SYCL headers | |
| 104 | +| `sycl/source/` | DPC++ runtime library implementation | |
| 105 | +| `sycl/test/` | Device-independent LIT + unit tests | |
| 106 | +| `sycl/test-e2e/` | End-to-end tests (need real hardware) | |
| 107 | +| `sycl/unittests/` | GoogleTest unit tests (use UrMock, no device required) | |
| 108 | +| `unified-runtime/source/adapters/` | Level-Zero, OpenCL, CUDA, HIP adapters | |
| 109 | +| `unified-runtime/scripts/core/*.yml` | UR API spec (source of truth — run `make generate` after edits) | |
| 110 | +| `llvm-spirv/` | LLVM IR ↔ SPIR-V translator | |
| 111 | +| `sycl-jit/` | JIT/runtime compilation support | |
| 112 | +| `xpti/`, `xptifw/` | Instrumentation (XPTI tracing) | |
| 113 | + |
| 114 | +### Unified Runtime code generation |
| 115 | + |
| 116 | +UR API is defined in YAML (`unified-runtime/scripts/core/*.yml`). After any YAML changes: |
| 117 | +```bash |
| 118 | +# From unified-runtime build directory |
| 119 | +make generate |
| 120 | +``` |
| 121 | +Do **not** hand-edit generated files (`ur_api.h`, `ur_ddi.h`, `ur_libapi.cpp`, `ur_ldrddi.cpp`, `ur_valddi.cpp`, etc.). |
| 122 | + |
| 123 | +## Key conventions |
| 124 | + |
| 125 | +### Commit messages & PRs |
| 126 | + |
| 127 | +- SYCL/DPC++ changes must include `[SYCL]` in the title. Add sub-tags for components: `[UR]`, `[CUDA]`, `[HIP]`, `[Doc]`, `[NFC]`. |
| 128 | +- Commits are squash-merged; the PR description becomes the commit message — keep it accurate. |
| 129 | +- Gatekeepers: `@intel/llvm-gatekeepers`. |
| 130 | + |
| 131 | +### ABI/API stability |
| 132 | + |
| 133 | +- Public DPC++ APIs must remain ABI/API compatible. Experimental APIs are exempted (placed in experimental namespaces). |
| 134 | +- Deprecation order: implement new API → add deprecation warning → wait → remove from headers → remove from library. |
| 135 | +- See `sycl/doc/developer/ABIPolicyGuide.md`. |
| 136 | + |
| 137 | +### Test placement |
| 138 | + |
| 139 | +| Test type | Location | When to use | |
| 140 | +|---|---|---| |
| 141 | +| Clang FE / compile-time checks | `clang/test/ASTSYCL/`, `sycl/test/` | Checking diagnostics, IR, `static_assert` | |
| 142 | +| Runtime unit tests (no device) | `sycl/unittests/` | Runtime behavior, use `UrMock` | |
| 143 | +| Device-independent LIT | `sycl/test/` | Header/IR checks, syntax-only | |
| 144 | +| E2E (requires backend) | `sycl/test-e2e/` | Full stack, actual device execution | |
| 145 | + |
| 146 | +- Use `-fsyntax-only` when only checking compilation succeeds. |
| 147 | +- Device code checks go under `sycl/test/check_device_code/`. |
| 148 | +- Use `sycl::` namespace, not `cl::sycl::`. |
| 149 | +- Always redirect compiler output to `%t` (temp) to avoid race conditions in parallel lit runs. |
| 150 | + |
| 151 | +### SYCL-specific C++ rules |
| 152 | + |
| 153 | +- Never `#include <iostream>` in library/header files. Use `sycl/detail/iostream_proxy.hpp` instead (avoids static constructors). |
| 154 | +- All identifiers in `llvm/sycl` headers must contain at least one lowercase letter (avoids macro conflicts). |
| 155 | +- Target C++17. |
| 156 | + |
| 157 | +### Release notes |
| 158 | + |
| 159 | +Record changes in `sycl/ReleaseNotes.md` under "upcoming release" when changing public interfaces, fixing bugs, or making observable behavioral changes. Reference PRs as `intel/llvm#NNNNN`. |
| 160 | + |
| 161 | +### Code review focus |
| 162 | + |
| 163 | +- When reviewing changes to control flow, check whether the change could corrupt performance profile data or produce invalid debug information (especially for branches and calls). |
| 164 | +- For LLDB code specifically, see `.github/instructions/lldb.instructions.md` for naming conventions (`snake_case` variables, `UpperCamelCase` methods, `m_`/`s_`/`g_` prefixes) and other LLDB-specific rules. |
0 commit comments