diff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.md index caa5009..18ec079 100644 --- a/TROUBLESHOOTING.md +++ b/TROUBLESHOOTING.md @@ -1,14 +1,14 @@ # Troubleshooting -While we are making the best effort to support as many applications as possible, realistically, you will run into cases where things are not working. Here's a list of troubleshooting (or debugging) steps you can take, roughly in the order of increasing difficulty and power. +While we do our best effort to support as many applications as possible, realistically, you will run into cases where things do not work. Here's a list of troubleshooting (or debugging) steps you can take, roughly in the order of increasing difficulty and power. ## Check for the presence of ROCm/HIP libraries -At the bare minimum ZLUDA needs to load up HIP runtime and ROCm Compiler Support library. You can confirm that HIP runtime is loaded by executing your applications with environment variable: +At the bare minimum ZLUDA needs to load the HIP runtime and the ROCm compiler support library. You can confirm that the HIP runtime is loaded by running your applications with environment variable: ``` AMD_LOG_LEVEL=3 ``` -you should see additional HIP debugging output this in the console. It should look like this: +you should see additional HIP debug output in the console. It will look like this: ``` :3:rocdevice.cpp :442 : 15186552182 us: [pid:27431 tid:0x7f21a7842000] Initializing HSA stack. :3:comgrctx.cpp :33 : 15186578605 us: [pid:27431 tid:0x7f21a7842000] Loading COMGR library. @@ -31,21 +31,21 @@ you should see additional HIP debugging output this in the console. It should lo :3:hip_device.cpp :171 : 15186582132 us: [pid:27431 tid:0x7f21a7842000] hipDeviceGet: Returned hipSuccess : ``` -If you are on Windows and are trying to run a GUI application that does not use console then you can try to edit the subsystem of the app's exe from Windows GUI to Windows console using [CFF Explorer](https://ntcore.com/?page_id=388) or a similiar tool. +If you are on Windows and are trying to run a GUI application that does not use the console then you can try to edit the subsystem of the application's exe from Windows GUI to Windows console using [CFF Explorer](https://ntcore.com/?page_id=388) or a similar tool. -If there is no HIP logging output that most likely means that ZLUDA could not find runtime libraries. +If there is no HIP logging output, it most likely means that ZLUDA could not find the runtime libraries. #### Linux -On Linux, ZLUDA depends on `libamdhip64.so` and `libamd_comgr.so.2` being present in system paths. Usually it's a case of not adding `/opt/rocm/lib` to system linker paths as instructed [here](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/how-to/native-install/post-install.html). As the last resort can use environment variable `LD_DEBUG=libs` to debug library load process. +On Linux, ZLUDA depends on the presence of `libamdhip64.so` and `libamd_comgr.so.2` being present in the system library search paths. If ZLUDA can't find either of them, it it's usually a case of not adding `/opt/rocm/lib` to the system linker paths as instructed [here](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/how-to/native-install/post-install.html). As a last resort, you can use the `LD_DEBUG=libs` environment variable to debug the library loading process. #### Windows -On Windows, ZLUDA depends on `amdhip64.dll` and `amd_comgr.dll` being present in system paths (usually `C:\Windows\System32`). If they ar enot present consider reinstalling your Radeon GPU driver. +On Windows, ZLUDA depends on the rpesence of `amdhip64.dll` and `amd_comgr.dll` being present in the system library search paths (usually `C:\Windows\System32`). If they are not present consider reinstalling your Radeon GPU driver. ## (Linux only) Trace CUDA calls -If ZLUDA-using application crashes or fails to run, then an easy way to check which function is failing to run it under ltrace: +If an application using ZLUDA crashes or fails to run, then an easy way to check which function is failing is to run it under ltrace: ``` ltrace -f -x "cu*@*-cuda*@*" -L @@ -60,25 +60,25 @@ This will produce extra output to the console that looks like this: [pid 34267] cuCtxPopCurrent@libcuda.so.1(0x7ffce2e3cd38, 0, 3, 0) = 0 [pid 34267] cuModuleGetFunction@libcuda.so.1(0x55ccafd0e558, 0x55ccafdee210, 0x55ccace18090, 0x55ccafb4bf88) = 500 ``` -Look for the call with non-zero return value. In our case `cuModuleGetFunction` with return value 500. You can check what that error code means in NVIDIA's documentation. Search [here](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__TYPES.html) for `enum CUresult`. Below you will find the list of error codes. In our case it is `CUDA_ERROR_NOT_FOUND`. Just the error code is rarely useful to the ZLUDA developers. If you are interested in a more precise CUDA trace you can try the ZLUDA dumper as described in the section below. +Look for the call with a non-zero return value. In our case `cuModuleGetFunction` with a return value of 500. You can check what that error code means in NVIDIA's documentation. Search [here](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__TYPES.html) for `enum CUresult`. Below you will find a list of error codes. In our case it is `CUDA_ERROR_NOT_FOUND`. The error code alone is rarely useful for the ZLUDA developers. If you are interested in a more precise CUDA trace, you can try the ZLUDA dumper as described in the section below. ## ZLUDA dumper -In addition to "normal" implementation of CUDA API, ZLUDA ships with debugging implementation (sometimes called ZLUDA dumper). This implementation does: -- Intercept every call to CUDA APIs. -- Log key information: function name, arguments to console output and log file. -- On GPU code load, saves the GPU input (PTX assembly or compiled binary code). -- Passes CUDA API call for the execution to a real implementation (either ZLUDA or original CUDA). +In addition to the "normal" implementation of CUDA API, ZLUDA ships with debugging implementation (sometimes called ZLUDA dumper). This implementation does the following: +- Intercept any call to CUDA APIs. +- Log imortant information: function name, arguments to console output and log file. +- On GPU code load, saves the GPU code input (PTX assembly or compiled binary code). +- Passes the CUDA API call for the execution to a real implementation (either ZLUDA or original CUDA). -Start by setting two environment variables: -* `ZLUDA_DUMP_DIR`: directory path where ZLUDA dumper will create a subdirectory with all the relevant information for you run. I usually set it to `/tmp/zluda` on Linux and `C:\temp\zluda` on Windows. ZLUDA dumper will create the directory if it does not exist. -* `ZLUDA_CUDA_LIB`: path to the real CUDA library implementation that actually executes CUDA code. If this is not set, ZLUDA dumper by default will try to load NVIDIA CUDA. +First set by setting two environment variables: +* `ZLUDA_DUMP_DIR`: directory path where ZLUDA dumper will create a subdirectory with all the relevant information for you run. I usually set it to `/tmp/zluda` on Linux and `C:\temp\zluda` on Windows. The ZLUDA dumper will create the directory if it does not exist. +* `ZLUDA_CUDA_LIB`: path to the real CUDA library implementation that actually executes CUDA code. If this is not set, the ZLUDA dumper will try to load NVIDIA CUDA by default. -Once you have the environment variables set, you can launch ZLUDA dumper: +Once you have set the environment variables, you can start ZLUDA dumper: ### Windows -ZLUDA loader (`zluda.exe`) can load `nvcuda.dll` from any arbitray path with `--nvcuda` argument. You should also use `--nvml` to pick the right `nvml.dll`. +The ZLUDA loader (`zluda.exe`) can load `nvcuda.dll` from any arbitrary path with the `--nvcuda` argument. You should also use `--nvml` to select the correct `nvml.dll`. If you are dumping ZLUDA use: ``` @@ -92,7 +92,7 @@ If you are dumping original CUDA use: ### Linux -Known bug: dumping from original CUDA you should remove (or rename) all the files in `/dump` except `libcuda.so` and `libcuda.so.1`. +Known bug: when dumping from original CUDA you should remove (or rename) all the files in `/dump` except `libcuda.so` and `libcuda.so.1`. Use it like this: ``` @@ -101,7 +101,7 @@ LD_LIBRARY_PATH="/dump:$LD_LIBRARY_PATH" CUDA_SUCCESS @@ -113,7 +113,7 @@ cuGetProcAddress(symbol: "cuDeviceGetCount", pfn: 0x7f8b9e9fccb0, cudaVersion: 2 cuGetProcAddress(symbol: "cuDeviceGetName", pfn: 0x7f8b9e9fd4f0, cudaVersion: 2000, flags: 0) -> CUDA_SUCCESS ``` -## (Linux only) Debugging GPU code +## Debugging ### Building ZLUDA with debug information @@ -122,15 +122,28 @@ You can build ZLUDA with debugging information by running: cargo xtask ``` -Other than the usual effects on the code it has two consequences: -* Most CUDA API functions will abort and print backtrace in case of failure. In release mode, ZLUDA tries to proceed gracefully and returns an error, allowing application to handle the situation. +Aside from than the usual effects on the code it has two consequences: +* Most CUDA API functions will abort and print backtrace on failure. In release mode, ZLUDA tries to proceed gracefully and returns an error so that the application can handle the situation. * GPU code is compiled with debug information (`-g`). Since ZLUDA does not emit CUDA debug information this only adds backtraces to the GPU code. +* The set of projects being built is slightly different. -### ROCgdb +### (Linux only) ROCgdb -In order to debug GPU code you can use ROCgdb. It's a fork of gdb shipped with ROCm. There are multiple articles out there explaining how to use gdb, so we won't go into the detail here. Some ZLUDA specific pointers: +To debug GPU code you can use ROCgdb. It's a fork of gdb that comes with ROCm. There are multiple articles out there explaining how to use gdb, so we won't go into the detail here. Some ZLUDA-specific notes: * ZLUDA does not emit GPU debug information. If you are lucky you might get a partial stack trace. -* Consider using [gef](https://github.com/hugsy/gef). Among other things it adds an `xinfo` command which can help you understand what a pointer points to (device memory? function pointer? host memory?). -* https://github.com/vosen/amdgpu_debug contains ROCgdb scripts that might be helpful. \ No newline at end of file +* Consider using [gef](https://github.com/hugsy/gef). Among other things, it adds an `xinfo` command that can help you understand what a pointer is pointing to (device memory? function pointer? host memory?). +* https://github.com/vosen/amdgpu_debug has ROCgdb scripts that may be helpful. + +### ZLUDA offline compiler (zoc) + +If you are working with the PTX compiler, you should use zoc. Zoc is built by default when you build in debug mode. You use it like this: +``` +/zoc +``` +It will generate the final GPU binary and most of the intermediate files (LLVM IR, custom ELF section). It has several options: compilation mode, GPU ISA, etc.. For details, run it with `--help` argument. + +Zoc does not use the compiler cache and will always do a full build. + +For the best effect, run it with the ROCm compiler library debugging environment variables. see the details [here](https://github.com/ROCm/llvm-project/blob/amd-staging/amd/comgr/README.md#environment-variables). \ No newline at end of file