### Install CMake and Clang on Windows via winget Source: https://github.com/vosen/zluda/blob/master/ext/highs-sys/README.md On Windows, CMake and Clang can be installed using the winget package manager. ```powershell winget install -e --id Kitware.CMake winget install -e --id LLVM.LLVM ``` -------------------------------- ### Install Ninja on Windows via winget Source: https://github.com/vosen/zluda/blob/master/ext/highs-sys/README.md If the Ninja feature is enabled, Ninja can also be installed on Windows using winget. ```powershell winget install -e --id Ninja-build.Ninja ``` -------------------------------- ### Example cuda_check.exe Output Source: https://github.com/vosen/zluda/blob/master/docs/src/hip_sdk.md This is an example of the expected output when `cuda_check.exe` successfully verifies the HIP SDK libraries. It lists the status of libraries like nvcuda, nvml, cufft, cudnn, cublaslt, cusparse, and cublas, along with the path to the loaded HIP SDK DLL. ```text nvcuda : OK (C:\hip_sdk\bin\amdhip64_7.dll) nvml : OK cufft11 : OK cudnn9 : OK (C:\hip_sdk\bin\MIOpen.dll) cudnn8 : OK (C:\hip_sdk\bin\MIOpen.dll) cublaslt13: OK (C:\hip_sdk\bin\libhipblaslt.dll) cusparse12: OK cufft12 : OK cublas13 : OK (C:\hip_sdk\bin\rocblas.dll) cublaslt12: OK (C:\hip_sdk\bin\libhipblaslt.dll) cublas12 : OK (C:\hip_sdk\bin\rocblas.dll) cusparse11: OK ``` -------------------------------- ### Install C++ Standard Library on Debian Source: https://github.com/vosen/zluda/blob/master/ext/highs-sys/README.md On Debian-based systems, install the C++ standard library, which is a runtime dependency for HiGHS. ```bash sudo apt-get install libstdc++6 ``` -------------------------------- ### Build ZLUDA from Source Source: https://context7.com/vosen/zluda/llms.txt Instructions for building ZLUDA from its source code, including installing prerequisites like Rust and CMake, cloning the repository with submodules, and executing build tasks using cargo xtask. Platform-specific dependencies like the HIP SDK on Linux are also mentioned. ```bash # Install prerequisites (Ubuntu/Debian) sudo apt install git cmake python3 ninja-build # Install Rust curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Install HIP SDK (Linux) - follow AMD ROCm installation guide # https://rocm.docs.amd.com/projects/HIP/en/latest/install/install.html # Clone with submodules git clone --recursive https://github.com/vosen/ZLUDA.git cd ZLUDA # Build release version cargo xtask --release # Build debug version (slower LLVM, useful for development) cargo xtask # Build with debug LLVM (very slow, for LLVM debugging only) cargo xtask --profile dev-llvm # Output location # Windows: target/release/*.dll # Linux: target/release/*.so # Run tests cargo test --release # Generate API bindings (for development) cargo run -p zluda_bindgen ``` -------------------------------- ### Run Application with ZLUDA Launcher (Windows) Source: https://github.com/vosen/zluda/blob/master/docs/src/quick_start.md Use the ZLUDA launcher to run your application. Ensure ZLUDA is installed and accessible. ```bash \zluda.exe -- ``` -------------------------------- ### PTX Assembly Example Source: https://github.com/vosen/zluda/blob/master/docs/src/troubleshooting.md This is PTX assembly for an 'add' function, portable across many NVIDIA GPUs. It includes version, target architecture, and entry point definitions. ```ptx .version 8.7 .target sm_80 .address_size 64 // .visible .entry _Z3addiiPi( .param .u32 _Z3addiiPi_param_0, .param .u32 _Z3addiiPi_param_1, .param .u64 _Z3addiiPi_param_2 ) { .reg .b32 %r<4>; .reg .b64 %rd<3>; ld.param.u32 %r1, [_Z3addiiPi_param_0]; ld.param.u32 %r2, [_Z3addiiPi_param_1]; ld.param.u64 %rd1, [_Z3addiiPi_param_2]; cvta.to.global.u64 %rd2, %rd1; add.s32 %r3, %r2, %r1; st.global.u32 [%rd2], %r3; ret; } ``` -------------------------------- ### Install CMake on macOS via Homebrew Source: https://github.com/vosen/zluda/blob/master/ext/highs-sys/README.md On macOS, CMake can be easily installed using the Homebrew package manager. ```bash brew install cmake ``` -------------------------------- ### Verify HIP SDK Installation with ZLUDA Source: https://github.com/vosen/zluda/blob/master/docs/src/hip_sdk.md Run this command to check if ZLUDA can load and initialize the performance libraries from your HIP SDK installation. The output shows the status of various CUDA libraries and the underlying HIP SDK library path. ```bash zluda.exe -- cuda_check.exe ``` -------------------------------- ### Verifying HIP SDK Installation with cuda_check Source: https://context7.com/vosen/zluda/llms.txt Use the cuda_check utility to verify that HIP SDK libraries are installed and accessible. It reports the status of each library and the path to the HIP SDK implementation. ```bash # Windows - Run verification through ZLUDA launcher zluda.exe -- cuda_check.exe ``` ```bash # Expected output showing successful library loading: # nvcuda : OK (C:\hip_sdk\bin\amdhip64_7.dll) # nvml : OK # cufft11 : OK # cudnn9 : OK (C:\hip_sdk\bin\MIOpen.dll) # cudnn8 : OK (C:\hip_sdk\bin\MIOpen.dll) # cublaslt13: OK (C:\hip_sdk\bin\libhipblaslt.dll) # cusparse12: OK # cufft12 : OK # cublas13 : OK (C:\hip_sdk\bin\rocblas.dll) # cublaslt12: OK (C:\hip_sdk\bin\libhipblaslt.dll) # cublas12 : OK (C:\hip_sdk\bin\rocblas.dll) # cusparse11: OK ``` ```bash # Check specific libraries only cuda_check.exe --nvcuda --cublas12 --cudnn9 ``` -------------------------------- ### CUDA Driver API - Streams and Events Example Source: https://context7.com/vosen/zluda/llms.txt Demonstrates the creation and usage of CUDA streams and events for asynchronous operations, memory management, and timing measurements. Requires CUDA driver API. ```c #include #include int main() { cuInit(0); CUcontext ctx; cuCtxCreate(&ctx, 0, 0); // Create streams CUstream stream1, stream2; cuStreamCreate(&stream1, CU_STREAM_DEFAULT); cuStreamCreateWithPriority(&stream2, CU_STREAM_NON_BLOCKING, 0); // Create events for timing CUevent startEvent, stopEvent; cuEventCreate(&startEvent, CU_EVENT_DEFAULT); cuEventCreate(&stopEvent, CU_EVENT_DEFAULT); // Allocate memory size_t size = 1024 * 1024 * sizeof(float); CUdeviceptr d_data; void* h_data; cuMemAlloc(&d_data, size); cuMemHostAlloc(&h_data, size, 0); // Record start event cuEventRecord(startEvent, stream1); // Async memory operations cuMemcpyHtoDAsync(d_data, h_data, size, stream1); cuMemsetD32Async(d_data, 0, size / 4, stream1); cuMemcpyDtoHAsync(h_data, d_data, size, stream1); // Record stop event cuEventRecord(stopEvent, stream1); // Make stream2 wait for stream1's event cuStreamWaitEvent(stream2, stopEvent, 0); // Check if stream operations completed CUresult status = cuStreamQuery(stream1); if (status == CUDA_ERROR_NOT_READY) { printf("Stream 1 still executing\n"); } // Wait for event completion cuEventSynchronize(stopEvent); // Calculate elapsed time float elapsedMs; cuEventElapsedTime(&elapsedMs, startEvent, stopEvent); printf("Elapsed time: %.3f ms\n", elapsedMs); // Synchronize stream cuStreamSynchronize(stream1); // Query stream priority range int leastPriority, greatestPriority; cuCtxGetStreamPriorityRange(&leastPriority, &greatestPriority); // Cleanup cuEventDestroy(startEvent); cuEventDestroy(stopEvent); cuStreamDestroy(stream1); cuStreamDestroy(stream2); cuMemFree(d_data); cuMemFreeHost(h_data); return 0; } ``` -------------------------------- ### ZLUDA Trace Output Example Source: https://github.com/vosen/zluda/blob/master/docs/src/troubleshooting.md Example of zluda_trace output showing CUDA API calls and their return status. This output is captured when running a traced application. ```text [ZLUDA_TRACE] cuCtxSynchronize() -> CUDA_SUCCESS result: 3 [ZLUDA_TRACE] {CONTEXT_LOCAL_STORAGE_INTERFACE_V0301}::context_local_storage_get(value: 0x562c764a73c0, cu_ctx: 0x0, key: 0x562c764ba130) -> CUDA_SUCCESS [ZLUDA_TRACE] cuMemFree_v2(dptr: 0x7f3ca2000000) -> CUDA_SUCCESS [ZLUDA_TRACE] {CONTEXT_LOCAL_STORAGE_INTERFACE_V0301}::context_local_storage_delete(context: 0x562c764ba760, key: 0x562c764ba130) -> CUDA_ERROR_DEINITIALIZED [ZLUDA_TRACE] cuLibraryUnload(library: 0x55ee94d645d0) -> CUDA_ERROR_DEINITIALIZED [ZLUDA_TRACE] cuDevicePrimaryCtxRelease(dev: 0) -> CUDA_ERROR_DEINITIALIZED ``` -------------------------------- ### Install C++ Compiler and CMake on Debian Source: https://github.com/vosen/zluda/blob/master/ext/highs-sys/README.md For building HiGHS on Debian, you need a C++ compiler and CMake. These can be installed using the distribution's package manager. ```bash sudo apt install g++ cmake ``` -------------------------------- ### Initialize CUDA Driver API and Get Device Info Source: https://context7.com/vosen/zluda/llms.txt Initializes the CUDA driver API and retrieves information about available GPUs, including their name, compute capability, multiprocessor count, maximum threads per block, and total memory. Emulates compute capability 8.6 for compatibility. ```c #include int main() { CUresult result; // Initialize CUDA driver API result = cuInit(0); // Get device count int deviceCount; cuDeviceGetCount(&deviceCount); // Get device handle CUdevice device; cuDeviceGet(&device, 0); // Query device name char name[256]; cuDeviceGetName(name, sizeof(name), device); // Output on AMD: "AMD Radeon RX 7900 XTX [ZLUDA]" // Query compute capability (emulated as 8.6 for compatibility) int major, minor; cuDeviceComputeCapability(&major, &minor, device); // Query specific attributes int multiprocessorCount; cuDeviceGetAttribute(&multiprocessorCount, CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT, device); int maxThreadsPerBlock; cuDeviceGetAttribute(&maxThreadsPerBlock, CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK, device); // Get total device memory size_t totalMem; cuDeviceTotalMem(&totalMem, device); return 0; } ``` -------------------------------- ### Zluda PTX Compiler Error Log Source: https://github.com/vosen/zluda/blob/master/docs/src/troubleshooting.md Example of a compiler error log file produced by Zluda when it encounters unsupported PTX instructions during compilation. ```text Unrecognized statement "nanosleep.u32 %r101;" ``` -------------------------------- ### CUDA Program for Adding Two Numbers Source: https://github.com/vosen/zluda/blob/master/docs/src/troubleshooting.md A simple CUDA C++ program that adds two integers on the GPU. This example is used to demonstrate zluda_trace output. ```cpp #include __global__ void add(int a, int b, int *out) { *out = a + b; } int main() { int *result; cudaMallocManaged(&result, sizeof(int)); add<<<1, 1>>>(1, 2, result); cudaDeviceSynchronize(); std::cout << "result: " << *result << std::endl; cudaFree(result); return 0; } ``` -------------------------------- ### Load CUDA Module and Get Kernel Function Source: https://context7.com/vosen/zluda/llms.txt Loads a CUDA module from PTX source or a file, retrieves a kernel function handle, and queries its attributes. Use `cuModuleLoadData` for in-memory PTX or `cuModuleLoad` for file-based cubin/PTX. `cuModuleGetFunction` retrieves the kernel, and `cuFuncGetAttribute` can query properties like max threads per block. ```c #include // Example PTX kernel const char* ptxSource = R"( .version 7.0 .target sm_86 .address_size 64 .visible .entry vectorAdd( .param .u64 a, .param .u64 b, .param .u64 c, .param .u32 n ) { .reg .pred %p<2>; .reg .b32 %r<6>; .reg .b64 %rd<10>; .reg .f32 %f<4>; ld.param.u64 %rd1, [a]; ld.param.u64 %rd2, [b]; ld.param.u64 %rd3, [c]; ld.param.u32 %r1, [n]; mov.u32 %r2, %ctaid.x; mov.u32 %r3, %ntid.x; mov.u32 %r4, %tid.x; mad.lo.s32 %r5, %r2, %r3, %r4; setp.ge.s32 %p1, %r5, %r1; @%p1 bra done; cvt.s64.s32 %rd4, %r5; shl.b64 %rd5, %rd4, 2; add.s64 %rd6, %rd1, %rd5; add.s64 %rd7, %rd2, %rd5; add.s64 %rd8, %rd3, %rd5; ld.global.f32 %f1, [%rd6]; ld.global.f32 %f2, [%rd7]; add.f32 %f3, %f1, %f2; st.global.f32 [%rd8], %f3; done: ret; } )"; int main() { CUmodule module; CUfunction kernel; cuInit(0); CUcontext ctx; cuCtxCreate(&ctx, 0, 0); // Load PTX source directly cuModuleLoadData(&module, ptxSource); // Alternative: Load from file // cuModuleLoad(&module, "kernel.ptx"); // Load with JIT options CUjit_option options[] = {CU_JIT_OPTIMIZATION_LEVEL}; void* values[] = {(void*)4}; cuModuleLoadDataEx(&module, ptxSource, 1, options, values); // Get kernel function handle cuModuleGetFunction(&kernel, module, "vectorAdd"); // Query function attributes int maxThreads; cuFuncGetAttribute(&maxThreads, CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK, kernel); int sharedMem; cuFuncGetAttribute(&sharedMem, CU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES, kernel); // Get global variable from module CUdeviceptr globalVar; size_t globalSize; cuModuleGetGlobal(&globalVar, &globalSize, module, "myGlobal"); // Unload module when done cuModuleUnload(module); return 0; } ``` -------------------------------- ### Launch CUDA Kernel and Manage Memory Source: https://context7.com/vosen/zluda/llms.txt Allocates device memory, copies data from host to device, configures kernel arguments, and launches the kernel. Synchronizes the context to ensure completion and copies results back to the host. Use `cuMemAlloc`, `cuMemcpyHtoD`, `cuLaunchKernel`, `cuCtxSynchronize`, and `cuMemcpyDtoH` for these operations. ```c #include #include int main() { CUmodule module; CUfunction kernel; cuInit(0); CUcontext ctx; cuCtxCreate(&ctx, 0, 0); // Load kernel module (assume vectorAdd from previous example) cuModuleLoadData(&module, ptxSource); cuModuleGetFunction(&kernel, module, "vectorAdd"); // Allocate and initialize data int n = 1024; size_t size = n * sizeof(float); CUdeviceptr d_a, d_b, d_c; cuMemAlloc(&d_a, size); cuMemAlloc(&d_b, size); cuMemAlloc(&d_c, size); float* h_a = (float*)malloc(size); float* h_b = (float*)malloc(size); for (int i = 0; i < n; i++) { h_a[i] = 1.0f; h_b[i] = 2.0f; } cuMemcpyHtoD(d_a, h_a, size); cuMemcpyHtoD(d_b, h_b, size); // Configure kernel parameters void* args[] = { &d_a, &d_b, &d_c, &n }; // Launch kernel with grid and block dimensions unsigned int gridDimX = (n + 255) / 256; unsigned int blockDimX = 256; unsigned int sharedMemBytes = 0; cuLaunchKernel( kernel, gridDimX, 1, 1, // Grid dimensions blockDimX, 1, 1, // Block dimensions sharedMemBytes, // Shared memory per block NULL, // Stream (NULL = default) args, // Kernel arguments NULL // Extra options ); // Synchronize and verify cuCtxSynchronize(); float* h_c = (float*)malloc(size); cuMemcpyDtoH(h_c, d_c, size); printf("Result: %f + %f = %f\n", h_a[0], h_b[0], h_c[0]); // Calculate occupancy int blockSize; int minGridSize; cuOccupancyMaxPotentialBlockSize(&minGridSize, &blockSize, kernel, NULL, 0, 0); // Cleanup cuMemFree(d_a); cuMemFree(d_b); cuMemFree(d_c); cuModuleUnload(module); return 0; } ``` -------------------------------- ### Precompile GPU Code on Windows Source: https://github.com/vosen/zluda/blob/master/docs/src/precompiling.md Use this command on Windows to precompile GPU code. Replace `` with the directory or file path to scan. ```bash zluda_precompile.exe ``` -------------------------------- ### CUDA Driver API Context Management Source: https://context7.com/vosen/zluda/llms.txt Demonstrates creating, managing, and destroying CUDA contexts, including pushing/popping context stacks and utilizing primary contexts. Ensures proper synchronization and cleanup of context resources. ```c #include int main() { CUdevice device; CUcontext context; cuInit(0); cuDeviceGet(&device, 0); // Create a new context on device 0 cuCtxCreate(&context, 0, device); // Get current context CUcontext currentCtx; cuCtxGetCurrent(¤tCtx); // Push/pop context stack for nested operations cuCtxPushCurrent(context); // ... perform operations ... CUcontext poppedCtx; cuCtxPopCurrent(&poppedCtx); // Use primary context (shared default context) CUcontext primaryCtx; cuDevicePrimaryCtxRetain(&primaryCtx, device); cuCtxSetCurrent(primaryCtx); // Query primary context state unsigned int flags; int active; cuDevicePrimaryCtxGetState(device, &flags, &active); // Synchronize all operations on current context cuCtxSynchronize(); // Release primary context cuDevicePrimaryCtxRelease(device); // Destroy explicit context cuCtxDestroy(context); return 0; } ``` -------------------------------- ### Precompile GPU Code on Linux Source: https://github.com/vosen/zluda/blob/master/docs/src/precompiling.md Use this command on Linux to precompile GPU code. Replace `` with the directory or file path to scan. ```bash zluda_precompile ``` -------------------------------- ### Build ZLUDA with Cargo (Release) Source: https://github.com/vosen/zluda/blob/master/docs/src/building.md Build ZLUDA in release mode using cargo xtask. This process may take a significant amount of time. ```bash cargo xtask --release ``` -------------------------------- ### CUDA Assembly Entry Point Source: https://github.com/vosen/zluda/blob/master/ptx/src/test/spirv_fail/local_ptr.txt Defines a simple entry point function 'func' in CUDA assembly. It declares a local 32-bit variable 'foobar' and immediately returns. ```cuda-assembly .version 6.5 .target sm_30 .address_size 64 .visible .entry func() { .local .b32 foobar [1]; ret; } ``` -------------------------------- ### Run Application with ZLUDA Trace on Linux (NVIDIA GPU) Source: https://github.com/vosen/zluda/blob/master/docs/src/troubleshooting.md Use this command to run your application with ZLUDA tracing enabled on Linux for NVIDIA GPUs. LD_LIBRARY_PATH should include the trace directory. ```bash LD_LIBRARY_PATH=/trace/ ZLUDA_LOG_DIR= ``` -------------------------------- ### Build llama.cpp with CUDA and cuBLAS Source: https://context7.com/vosen/zluda/llms.txt Configures and builds the llama.cpp project with CUDA support, targeting specific architectures for ZLUDA compatibility and enabling cuBLAS for acceleration. Requires CMake. ```bash # Clone llama.cpp repository git clone https://github.com/ggerganov/llama.cpp cd llama.cpp # Configure with CUDA and cuBLAS support cmake -B build \ -DGGML_CUDA=ON \ -DCMAKE_CUDA_ARCHITECTURES="86" \ -DGGML_CUDA_FORCE_CUBLAS=true # Build cmake --build build --config Release # Run through ZLUDA (Windows) zluda.exe -- build/bin/llama-cli -m model.gguf -p "Hello" # Run through ZLUDA (Linux) LD_LIBRARY_PATH="/path/to/zluda:$LD_LIBRARY_PATH" \ ./build/bin/llama-cli -m model.gguf -p "Hello" # For multi-architecture builds (include at least one of 80, 86, 89) cmake -B build \ -DGGML_CUDA=ON \ -DCMAKE_CUDA_ARCHITECTURES="80;86;89" \ -DGGML_CUDA_FORCE_CUBLAS=true ``` -------------------------------- ### Run Application with ZLUDA Trace on Windows (NVIDIA GPU) Source: https://github.com/vosen/zluda/blob/master/docs/src/troubleshooting.md Execute your application with ZLUDA tracing enabled on Windows for NVIDIA GPUs using the zluda.exe executable with the --nvidia-trace flag. ```bash zluda.exe --nvidia-trace -- ``` -------------------------------- ### Clone Repository with Submodules Source: https://github.com/vosen/zluda/blob/master/ext/highs-sys/README.md When cloning the repository, ensure you include the submodule for the HiGHS source code. ```bash git clone --recursive git@github.com:rust-or/highs-sys.git ``` -------------------------------- ### Create ZLUDA Log Archive on Linux Source: https://github.com/vosen/zluda/blob/master/docs/src/troubleshooting.md Create a tar.gz archive of ZLUDA logs from the specified directory. This is useful for attaching to GitHub issues. ```bash tar -cvf logs.tar.gz -C . ``` -------------------------------- ### Precompiling GPU Code with zluda_precompile Source: https://context7.com/vosen/zluda/llms.txt The zluda_precompile tool scans applications and precompiles embedded PTX code to accelerate first-run performance by eliminating JIT compilation delays. ```bash # Windows - Precompile all GPU code in a directory zluda_precompile.exe C:\path\to\application\directory ``` ```bash # Linux - Precompile a specific application or directory zluda_precompile /path/to/application ``` ```bash # Precompile with specific GPU device zluda_precompile.exe --device 1 C:\path\to\app ``` ```bash # Follow symbolic links during directory traversal zluda_precompile --follow-links /opt/cuda-apps ``` -------------------------------- ### Running Applications with ZLUDA Source: https://context7.com/vosen/zluda/llms.txt Use the ZLUDA launcher on Windows or LD_LIBRARY_PATH/LD_AUDIT on Linux to redirect CUDA calls to ZLUDA. ```bash # Windows - Using ZLUDA launcher (recommended) zluda.exe -- your_cuda_application.exe --app-arguments ``` ```bash # Windows - Alternative: Copy ZLUDA DLLs to application directory # Copy nvcuda.dll, cublas64_*.dll, etc. from ZLUDA directory to app directory ``` ```bash # Linux - Standard method using LD_LIBRARY_PATH LD_LIBRARY_PATH="/path/to/zluda:$LD_LIBRARY_PATH" ./your_cuda_application ``` ```bash # Linux - Alternative using LD_AUDIT for more robust interception LD_AUDIT="/path/to/zluda/zluda_ld:$LD_AUDIT" ./your_cuda_application ``` -------------------------------- ### Compile llama.cpp with CUDA and cuBLAS Source: https://github.com/vosen/zluda/blob/master/docs/src/llama_cpp.md Use this command to compile llama.cpp with CUDA architecture 86 and cuBLAS enabled for native speed. Ensure your system meets the CUDA requirements. ```bash cmake -B build -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES="86" -DGGML_CUDA_FORCE_CUBLAS=true ``` -------------------------------- ### Run Application with ZLUDA Trace on Windows (AMD GPU) Source: https://github.com/vosen/zluda/blob/master/docs/src/troubleshooting.md Execute your application with ZLUDA tracing enabled on Windows for AMD GPUs using the zluda.exe executable with the --zluda-trace flag. ```bash zluda.exe --zluda-trace -- ``` -------------------------------- ### Set LD_LIBRARY_PATH for ZLUDA (Linux) Source: https://github.com/vosen/zluda/blob/master/docs/src/quick_start.md Recommended method to run applications with ZLUDA on Linux by setting the LD_LIBRARY_PATH environment variable. Ensure ZLUDA is in the specified directory. ```bash LD_LIBRARY_PATH=":$LD_LIBRARY_PATH" ``` -------------------------------- ### Compile and Run CUDA Program with ZLUDA Trace on Linux Source: https://github.com/vosen/zluda/blob/master/docs/src/troubleshooting.md Compile a CUDA program using nvcc and then run it with ZLUDA tracing enabled on Linux. This command assumes the ZLUDA trace libraries are in a specific path. ```bash nvcc add.cu -o add -arch sm_80 LD_LIBRARY_PATH=~/ZLUDA/target/release/trace/ ZLUDA_LOG_DIR=/tmp/zluda ./add ``` -------------------------------- ### Build ZLUDA with Cargo (Debug) Source: https://github.com/vosen/zluda/blob/master/docs/src/building.md Build ZLUDA in debug mode using cargo xtask. This is a faster build option for development. ```bash cargo xtask ``` -------------------------------- ### List ZLUDA Log Directory Contents on Linux Source: https://github.com/vosen/zluda/blob/master/docs/src/troubleshooting.md List the contents of the ZLUDA log directory to see the application-specific log subdirectories. ```bash ls /tmp/zluda ``` -------------------------------- ### Run Application with ZLUDA Trace on Linux (AMD GPU) Source: https://github.com/vosen/zluda/blob/master/docs/src/troubleshooting.md Use this command to run your application with ZLUDA tracing enabled on Linux for AMD GPUs. Ensure ZLUDA_CUDA_LIB points to ZLUDA's libcuda.so and LD_LIBRARY_PATH includes the trace directory. ```bash ZLUDA_CUDA_LIB=/libcuda.so LD_LIBRARY_PATH=/trace/ ZLUDA_LOG_DIR= ``` -------------------------------- ### Solve LP with Highs_call in Rust Source: https://github.com/vosen/zluda/blob/master/ext/highs-sys/README.md This snippet shows how to define and solve a linear programming problem using the Highs_call C interface from Rust. It includes setting up problem dimensions, cost vector, bounds, constraint matrix in column-wise packed format, and result vectors. Ensure all necessary types like `c_int` are correctly defined and imported. ```rust // This illustrates the use of Highs_call, the simple C interface to // HiGHS. It's designed to solve the general LP problem // // Min c^Tx subject to L <= Ax <= U; l <= x <= u // // where A is a matrix with m rows and n columns // // The scalar n is numcol // The scalar m is numrow // // The vector c is colcost // The vector l is collower // The vector u is colupper // The vector L is rowlower // The vector U is rowupper // // The matrix A is represented in packed column-wise form: only its // nonzeros are stored // // * The number of nonzeros in A is nnz // // * The row indices of the nonnzeros in A are stored column-by-column // in aindex // // * The values of the nonnzeros in A are stored column-by-column in // avalue // // * The position in aindex/avalue of the index/value of the first // nonzero in each column is stored in astart // // Note that astart[0] must be zero // // After a successful call to Highs_call, the primal and dual // solution, and the simplex basis are returned as follows // // The vector x is colvalue // The vector Ax is rowvalue // The vector of dual values for the variables x is coldual // The vector of dual values for the variables Ax is rowdual // The basic/nonbasic status of the variables x is colbasisstatus // The basic/nonbasic status of the variables Ax is rowbasisstatus // // The status of the solution obtained is modelstatus // // To solve maximization problems, the values in c must be negated // // The use of Highs_call is illustrated for the LP // // Min f = 2x_0 + 3x_1 // s.t. x_1 <= 6 // 10 <= x_0 + 2x_1 <= 14 // 8 <= 2x_0 + x_1 // 0 <= x_0 <= 3; 1 <= x_1 fn main() { let numcol: usize = 2; let numrow: usize = 3; let nnz: usize = 5; // Define the column costs, lower bounds and upper bounds let colcost: &mut [f64] = &mut [2.0, 3.0]; let collower: &mut [f64] = &mut [0.0, 1.0]; let colupper: &mut [f64] = &mut [3.0, 1.0e30]; // Define the row lower bounds and upper bounds let rowlower: &mut [f64] = &mut [-1.0e30, 10.0, 8.0]; let rowupper: &mut [f64] = &mut [6.0, 14.0, 1.0e30]; // Define the constraint matrix column-wise let astart: &mut [c_int] = &mut [0, 2]; let aindex: &mut [c_int] = &mut [1, 2, 0, 1, 2]; let avalue: &mut [f64] = &mut [1.0, 2.0, 1.0, 2.0, 1.0]; let colvalue: &mut [f64] = &mut vec![0.; numcol]; let coldual: &mut [f64] = &mut vec![0.; numcol]; let rowvalue: &mut [f64] = &mut vec![0.; numrow]; let rowdual: &mut [f64] = &mut vec![0.; numrow]; let colbasisstatus: &mut [c_int] = &mut vec![0; numcol]; let rowbasisstatus: &mut [c_int] = &mut vec![0; numrow]; let modelstatus: &mut c_int = &mut 0; let status: c_int = unsafe { Highs_call( numcol.try_into().unwrap(), numrow.try_into().unwrap(), nnz.try_into().unwrap(), colcost.as_mut_ptr(), collower.as_mut_ptr(), colupper.as_mut_ptr(), rowlower.as_mut_ptr(), rowupper.as_mut_ptr(), astart.as_mut_ptr(), aindex.as_mut_ptr(), avalue.as_mut_ptr(), colvalue.as_mut_ptr(), coldual.as_mut_ptr(), rowvalue.as_mut_ptr(), rowdual.as_mut_ptr(), colbasisstatus.as_mut_ptr(), rowbasisstatus.as_mut_ptr(), modelstatus ) }; assert_eq!(status, 0); // The solution is x_0 = 2 and x_1 = 4 assert_eq!(colvalue, &[2., 4.]); } ``` -------------------------------- ### ZLUDA Environment Variables Source: https://context7.com/vosen/zluda/llms.txt Lists environment variables used to configure ZLUDA's behavior, including specifying custom CUDA library paths, setting log directories for tracing, overriding compute capabilities for compatibility testing, and setting the HIP SDK path on Windows. ```bash # Specify custom CUDA library path for zluda_trace export ZLUDA_CUDA_LIB=/path/to/zluda/libcuda.so # Set log output directory for zluda_trace export ZLUDA_LOG_DIR=/tmp/zluda_logs # Override reported compute capability (for compatibility testing) export ZLUDA_OVERRIDE_COMPUTE_CAPABILITY=8.6 # Windows HIP SDK path (required for unofficial SDK) set HIP_PATH=C:\hip_sdk ``` -------------------------------- ### List Contents of ZLUDA Application Log Directory Source: https://github.com/vosen/zluda/blob/master/docs/src/troubleshooting.md Examine the files generated within a specific ZLUDA application log directory, including log files and compiled modules. ```bash ls /tmp/zluda/add/ ``` -------------------------------- ### Display ZLUDA Log File Content Source: https://github.com/vosen/zluda/blob/master/docs/src/troubleshooting.md Display the content of the log.txt file from the ZLUDA trace output. This file contains detailed information about CUDA API calls. ```bash cat /tmp/zluda/add/log.txt ``` -------------------------------- ### Clone ZLUDA Repository Source: https://github.com/vosen/zluda/blob/master/docs/src/building.md Clone the ZLUDA repository, ensuring submodules are fetched using the --recursive option. ```bash git clone --recursive https://github.com/vosen/ZLUDA.git ``` -------------------------------- ### Performance Library Call Logging Source: https://github.com/vosen/zluda/blob/master/docs/src/troubleshooting.md Zluda trace logs calls to performance libraries and subsequent calls made by those libraries, providing a detailed view of library interactions. ```text cublasCreate_v2(handle: 0x55e502373120) -> CUBLAS_STATUS_SUCCESS cuGetProcAddress_v2(symbol: "", pfn: 0x0, cudaVersion: 0, flags: 0, symbolStatus: NULL) -> CUDA_ERROR_NOT_FOUND ``` -------------------------------- ### Set LD_AUDIT for ZLUDA (Linux) Source: https://github.com/vosen/zluda/blob/master/docs/src/quick_start.md Alternative method to run applications with ZLUDA on Linux using the LD_AUDIT environment variable. Ensure ZLUDA is in the specified directory. ```bash LD_AUDIT="/zluda_ld:$LD_AUDIT" ``` -------------------------------- ### NVIDIA Dark API Calls Source: https://github.com/vosen/zluda/blob/master/docs/src/troubleshooting.md Logs for NVIDIA's Dark API, accessed via function pointer tables from cuGetExportTable. These functions are not publicly documented. ```text {CONTEXT_LOCAL_STORAGE_INTERFACE_V0301}::context_local_storage_get(value: 0x55ee93e083c0, cu_ctx: 0x0, key: 0x55ee93e1b130) -> CUDA_SUCCESS ``` -------------------------------- ### CUDA Driver API Memory Management Operations Source: https://context7.com/vosen/zluda/llms.txt Covers various GPU memory management tasks, including allocation of device, pitched, and pinned host memory, memory transfers (host-to-device, device-to-host, device-to-device), memory setting, and querying memory information. Includes asynchronous transfers using streams and proper resource cleanup. ```c #include int main() { CUdeviceptr devicePtr; void* hostPtr; size_t size = 1024 * sizeof(float); cuInit(0); CUcontext ctx; cuCtxCreate(&ctx, 0, 0); // Allocate device memory cuMemAlloc(&devicePtr, size); // Allocate pitched memory for 2D arrays CUdeviceptr pitched; size_t pitch; cuMemAllocPitch(&pitched, &pitch, 1024 * sizeof(float), 768, sizeof(float)); // Allocate pinned host memory cuMemHostAlloc(&hostPtr, size, CU_MEMHOSTALLOC_PORTABLE); // Get device pointer from host allocation CUdeviceptr hostDevPtr; cuMemHostGetDevicePointer(&hostDevPtr, hostPtr, 0); // Copy host to device float* data = (float*)hostPtr; for (int i = 0; i < 1024; i++) data[i] = (float)i; cuMemcpyHtoD(devicePtr, hostPtr, size); // Async copy with stream CUstream stream; cuStreamCreate(&stream, 0); cuMemcpyHtoDAsync(devicePtr, hostPtr, size, stream); cuStreamSynchronize(stream); // Copy device to host float* result = (float*)malloc(size); cuMemcpyDtoH(result, devicePtr, size); // Device to device copy CUdeviceptr devicePtr2; cuMemAlloc(&devicePtr2, size); cuMemcpyDtoD(devicePtr2, devicePtr, size); // Memory set operations cuMemsetD8(devicePtr, 0, size); cuMemsetD32(devicePtr, 0xDEADBEEF, size / 4); // Query memory info size_t free, total; cuMemGetInfo(&free, &total); // Query allocation address range CUdeviceptr base; size_t allocSize; cuMemGetAddressRange(&base, &allocSize, devicePtr); // Cleanup cuMemFree(devicePtr); cuMemFree(devicePtr2); cuMemFreeHost(hostPtr); cuStreamDestroy(stream); free(result); return 0; } ``` -------------------------------- ### CUDA API Call Logging Source: https://github.com/vosen/zluda/blob/master/docs/src/troubleshooting.md Zluda trace logs all calls made to the CUDA library, including arguments and return status. This helps in debugging and understanding CUDA application behavior. ```text cuLaunchKernel(f: 0x55ee94d645d0, gridDimX: 1, gridDimY: 1, gridDimZ: 1, blockDimX: 1, blockDimY: 1, blockDimZ: 1, sharedMemBytes: 0, hStream: 0x0, kernelParams: 0x7fffe0fa193c, extra: NULL) -> CUDA_SUCCESS {CONTEXT_LOCAL_STORAGE_INTERFACE_V0301}::context_local_storage_get(value: 0x55ee93e083c0, cu_ctx: 0x0, key: 0x55ee93e1b130) -> CUDA_SUCCESS cuCtxSynchronize() -> CUDA_SUCCESS {CONTEXT_LOCAL_STORAGE_INTERFACE_V0301}::context_local_storage_get(value: 0x55ee93e083c0, cu_ctx: 0x0, key: 0x55ee93e1b130) -> CUDA_SUCCESS cuMemFree_v2(dptr: 0x7fbde6000000) -> CUDA_SUCCESS {CONTEXT_LOCAL_STORAGE_INTERFACE_V0301}::context_local_storage_delete(context: 0x55ee93e1b760, key: 0x55ee93e1b130) -> CUDA_ERROR_DEINITIALIZED cuLibraryUnload(library: 0x55ee94d60ae0) -> CUDA_ERROR_DEINITIALIZED cuDevicePrimaryCtxRelease(dev: 0) -> CUDA_ERROR_DEINITIALIZED ``` -------------------------------- ### Debugging CUDA Calls with zluda_trace Source: https://context7.com/vosen/zluda/llms.txt zluda_trace logs all CUDA API calls, arguments, and return values to help identify compatibility issues. It can also extract embedded PTX code for analysis. ```bash # Linux - Trace CUDA calls through ZLUDA on AMD GPU ZLUDA_CUDA_LIB=/path/to/zluda/libcuda.so \ LD_LIBRARY_PATH=/path/to/zluda/trace/ \ ZLUDA_LOG_DIR=/tmp/zluda_logs \ ./your_application ``` ```bash # Linux - Trace native NVIDIA CUDA calls for comparison LD_LIBRARY_PATH=/path/to/zluda/trace/ \ ZLUDA_LOG_DIR=/tmp/zluda_logs \ ./your_application ``` ```bash # Windows - Trace through ZLUDA zluda.exe --zluda-trace -- your_application.exe ``` ```bash # Windows - Trace native NVIDIA calls zluda.exe --nvidia-trace -- your_application.exe ``` ```bash # Archive logs for bug reports tar -cvf logs.tar.gz -C /tmp/zluda_logs . ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.