ZLUDA
repository·master·Indexed 12 days ago
https://github.com/vosen/zludaA drop-in replacement for CUDA that allows unmodified CUDA applications to run on non-NVIDIA GPUs with near-native performance. Includes a compiler to convert PTX files into LLVM bitcode and Rust procedural macros for generating CUDA and library function declarations for core CUDA, cuBLAS, cuDNN, cuFFT, cuSPARSE, and NVML.
What's inside ZLUDA
- ZLUDA is a drop-in replacement for CUDA designed for non-NVIDIA GPUs. It enables the execution of unmodified CUDA applications on alternative hardware (such as AMD GPUs) with near-native performance.
Use detours-sys Rust bindings
masterdetours-sysprovides Rust bindings to Microsoft Detours. For detailed information on the underlying Detours functionality, refer to the Microsoft Detours Documentation.How trace* samples and withdll work
masterThe
trace*samples use the following mechanism:- They log output through the
syelogd.exedaemon. - They hook
CreateProcessWto automatically load themselves into any child processes.
You can use
withdllto inject a DLL into a process. For example, usingwithdll -d:traceapi.dll cmd.exewill launch a command shell where all subsequent processes log their API calls throughtraceapi.dll.withdll -d:traceapi.dll cmd.exe- They log output through the
Understand zluda_trace output files
masterWhen
zluda_traceruns, it creates a directory named after the command (e.g.,add/). Inside this directory, you will find several files:log.txt: Contains a record of every CUDA library call, including arguments passed and the returned status code. It also captures calls to NVIDIA's "Dark API" (functions formatted as{INTERFACE_NAME}::function_name).module_NNNN_NN.elf: Precompiled SASS assembly for a single GPU architecture.module_NNNN_NN.ptx: Portable PTX assembly.module_NNNN_NN.log: (Optional) A compiler error log produced if ZLUDA's PTX compiler encounters an error while processing a PTX module. This is useful for identifying unsupported PTX instructions.
Prepare logs for a GitHub issue
masterIf you are filing a bug report, you should provide an archive of your trace logs.
Linux
Create a tar archive of the contents of your
<LOG_DIRECTORY>:tar -cvf logs.tar.gz -C <LOG_DIRECTORY> .Windows
- Navigate to
%TEMP%\zludain Windows Explorer. - Right-click the directory created for your application.
- Select "Send to" -> "Compressed (zipped) folder" (exact steps may vary by Windows version).
- Navigate to
Compile llama.cpp for optimal performance with ZLUDA
masterTo achieve native performance when using ZLUDA with
llama.cpp, you should compile it for CUDA architecture 86 with cuBLAS enabled. While you can compile for multiple architectures, ensure that at least one of them is80,86, or89. Disabling cuBLAS may result in performance degradation.cmake -B build -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES="86" -DGGML_CUDA_FORCE_CUBLAS=trueInstall and build Detours via vcpkg
masterYou can use the
vcpkgdependency manager to install Detours. Follow these steps to bootstrap vcpkg and install the package:- Clone the vcpkg repository.
- Bootstrap vcpkg.
- Integrate vcpkg with your build environment.
- Install the
detoursport.
git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install vcpkg install detoursLink against a pre-installed version of HiGHS
masterTo avoid building HiGHS from source, you can link against an existing installation on your system.
- Install
pkg-configon your system. - Enable the
discoverfeature in yourCargo.toml.
Note: This method typically results in dynamic linking, meaning HiGHS must be present on any system where you deploy your application. Since HiGHS is not widely available in many package managers, you may still need to build and install it from source manually before using this feature.
- Install
Precompile GPU code with zluda_precompile
masterWhen running large applications, you can use
zluda_precompileto avoid long initial launch delays. This tool scans a specified directory or file, extracts all GPU code, compiles it, and saves the results to the cache. This ensures the GPU code is already cached when the application is launched for the first time.Key characteristics:
- Performance: It uses all available machine threads to speed up the compilation process compared to the application's default behavior.
- Trade-off: It may compile more code than the application actually requires, which might make the precompilation process itself slower than if the application handled it incrementally.
# Windows zluda_precompile.exe <PATH> # Linux zluda_precompile <PATH>Run Detours sample tests
masterYou can test the samples using
nmake:- Individual samples: Navigate to a specific sample directory and run
nmake test. - All samples: Navigate to the main
samplesdirectory and runnmake test.
Note: Some samples are architecture-specific. Tests for these will be skipped if run on an unsupported architecture. Most executables also support the
/?flag to display usage information.# Run all tests from the samples directory cd path/to/detours/samples nmake test # View usage for a specific executable executable_name.exe /?- Individual samples: Navigate to a specific sample directory and run
Download ZLUDA
masterZLUDA is under heavy development. It is recommended to download the most recent pre-release version from the GitHub Releases page. Stable versions are periodically marked in the same section.Build HiGHS from source using highs-sys
masterBy default,
highs-sysbuilds HiGHS and links it statically. To do this, you must have a C++ compiler andcmakeinstalled.Linux (Debian)
sudo apt install g++ cmakemacOS
- Install C++ compiler:
xcode-select --install - Install cmake:
brew install cmake - (Optional) If using
libzorninjafeatures, install them via brew:brew install ninja(and ensure libz is available).
Windows
Install
cmakeandClang(via LLVM) usingwinget:winget install -e --id Kitware.CMake winget install -e --id LLVM.LLVMIf the
ninjafeature is enabled:winget install -e --id Ninja-build.NinjaNote on libz: If you enable the
libzfeature, you must either addlibz-sysas a dependency in your project or manually set theZLIB_ROOTenvironment variable.- Install C++ compiler: