|
| 1 | +<!---======================= begin_copyright_notice ============================ |
| 2 | +
|
| 3 | +Copyright (C) 2019-2021 Intel Corporation |
| 4 | +
|
| 5 | +SPDX-License-Identifier: MIT |
| 6 | +
|
| 7 | +============================= end_copyright_notice ==========================--> |
| 8 | + |
| 9 | +# Intel® Graphics Compiler for OpenCL™ |
| 10 | + |
| 11 | +## Producing shader dumps |
| 12 | + |
| 13 | +Shader dumps (further abbreviated as *dumps*) are intermediate compilation snapshots created during IGC runtime. They are the main IGC debugging tool. For example: producing dumps from two consecutive builds and comparing them will show exactly what effect the change has had on the compilation process. |
| 14 | + |
| 15 | +### Enabling the functionality |
| 16 | + |
| 17 | +To produce shader dumps you need to set an environmental variable: |
| 18 | +```bash |
| 19 | +export IGC_ShaderDumpEnable=1 |
| 20 | +``` |
| 21 | +When this is set simply run any application that uses IGC to compile shaders and IGC will produce dumps in the default directory `/tmp/IntelIGC`. |
| 22 | + |
| 23 | +To compile a standalone `*.cl` shader file use `ocloc` compiler frontend executable from [Intel Compute Runtime](https://github.com/intel/compute-runtime) repository. |
| 24 | + |
| 25 | +### List of dump products |
| 26 | + |
| 27 | +Shader dumps include (in order of creation): |
| 28 | + |
| 29 | +| Product | Description | |
| 30 | +|-|-| |
| 31 | +| `*.cl` file | Original shader file. Passed to `clang` wrapped with `opencl-clang`. | |
| 32 | +| `*.spv` file | SPIR-V binary produced by `opencl-clang`. Passed to IGC's baked-in [SPIRVReader](https://github.com/intel/intel-graphics-compiler/blob/master/IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp). | |
| 33 | +| `*.spvasm` file | Disassembled SPIR-V binary only for debugging purposes. | |
| 34 | +| `*_beforeUnification.ll` file | Result of `*.spv` translation. Start of IGC compilation. | |
| 35 | +| `*_afterUnification.ll` file | Result of all unification passes. | |
| 36 | +| `*_optimized.ll` file | Result of all optimization passes. | |
| 37 | +| `*_codegen.ll` file | Result of all codegen passes. | |
| 38 | +| `*.visa.ll` files | Mappings between LLVM IR ↔ vISA. May not be legal LLVM IR representation. | |
| 39 | +| `*.visaasm` files | vISA assembly file. | |
| 40 | +| `*.asm` files | Kernels in assembly form. | |
| 41 | +| `*.isa` files | Kernels' binaries. | |
| 42 | + |
| 43 | +There are also additional products that are not a part of compilation pipeline: |
| 44 | + |
| 45 | +| Additional products | Description | |
| 46 | +|-|-| |
| 47 | +|`*_options.txt` file | Options passed to `clBuildProgram`. | |
| 48 | +|`*.cos` files | "Patch tokens" - information about kernels that is passed between IGC and Intel Compute Runtime. | |
| 49 | + |
| 50 | +#### Notes |
| 51 | +1. There is a separate SPIR-V translator for `*.cl` → `*.spv` translation (`opencl-clang`'s) and another for `*.spv` → `*.ll` translation (baked into into IGC). |
| 52 | +2. vISA is an intermediate language for IGC backend. |
| 53 | + |
| 54 | +### Additional options |
| 55 | + |
| 56 | +To customize the process use configuration flags. Here are some of them: |
| 57 | + |
| 58 | +|Flag|Description| |
| 59 | +|-|-| |
| 60 | +|`IGC_DumpToCustomDir`| Path to a directory to produce dumps to. | |
| 61 | +|`IGC_ShaderDumpEnableAll`| Dump LLVM passes between stages. | |
| 62 | +|`IGC_ShaderDumpPidDisable`| Do not append PID to dumps directory. | |
| 63 | + |
| 64 | +You can learn more about dumping options in configuration flags documentation [here](https://github.com/intel/intel-graphics-compiler/blob/master/documentation/configuration_flags.md). |
| 65 | + |
| 66 | +## Shader overriding |
| 67 | + |
| 68 | +This is a more advanced debugging functionality that allows overriding most of the compilation steps with own dumps during IGC runtime. |
| 69 | + |
| 70 | +### Basic overview |
| 71 | + |
| 72 | +After producing the dumps once a step can be modified manually and then injected into the compiler pipeline during next executions. |
| 73 | + |
| 74 | +Let us say we would like to modify the `*_afterUnification.ll` step produced by some particular IGC compilation to see how the compilation proceeded. We can patch IGC itself but it may be difficult or not worth the effort. A simpler solution is to use shader overriding and inject modified `*_afterUnification.ll` dump. |
| 75 | + |
| 76 | +### Enabling overriding |
| 77 | + |
| 78 | +To enable overrides you need to set an environmental variable: |
| 79 | +```bash |
| 80 | +export IGC_ShaderOverride=1 |
| 81 | +``` |
| 82 | + |
| 83 | +### Overriding dumps |
| 84 | + |
| 85 | +To inject a dump into a compilation pipeline: |
| 86 | +1. Produce shader dumps normally. |
| 87 | +2. Choose a dump to be injected and modify it however is needed. |
| 88 | +3. Copy modified dump to the `/tmp/IntelIGC/ShaderOverride` directory. |
| 89 | +4. The hash in the name of the dump being injected needs to be the same as the dumps produced normally by the program. |
| 90 | + |
| 91 | +The next time a compilation is run IGC will take files from this directory and override its running compilation. If the process is successful a log message `OVERRIDEN: ...` will be printed to `stdout`. |
0 commit comments