6.3. Using CUDA to accelerate optimization

6.3.1. CUDA calling method

MindOpt supports the use of the Primal-dual Method (PDM) to solve linear programming problems. You can use the parameter Method=3 to start this method. Currently, this method has two execution modes: CPU and GPU. MindOpt will determine this through the parameter PDM/ComputePreference. The CPU version can be used on all platforms, and the GPU version is supported on Windows x86 and Linux x86 platforms. If you need to execute the GPU version, you need to have a CUDA-related environment and an available GPU device.

6.3.2. GPU/CUDA requirements

MindOpt requires CUDA Toolkit version >= 12.0 to run the primal-dual method on GPU. You can directly select the appropriate version from the CUDA official website (https://developer.nvidia.com/cuda-downloads) for installation, and the corresponding GPU driver will also be installed. After the installation is complete, you can execute the command nvidia-smi to verify the installation result.

MindOpt The primal-dual method depends on the following CUDA libraries:

  • CUDA Driver API: libcuda.so (Linux) or nvcuda.dll (Windows).

  • CUDA Toolkit: cudart, cublas, and cusparse.

Environment variables need to be configured before running:

  • Windows: Automatically configure environment variables when installing CUDA.

  • Linux: Manually set LD_LIBRARY_PATH to introduce CUDA dependencies (such as CUDA path: /usr/local/cuda/lib64).

If the prompt “GPU/CUDA is not available.” appears during the solution, or the error “CUDA error occurred while running PDM.” appears when forcing GPU execution, it is recommended to check the installation of the CUDA library and the configuration of environment variables.

At the same time, the operation of this method depends on the GPU device. You can use the command nvidia-smi to check the availability of the GPU device. On multi-GPU devices, use PDM/Device to specify the running Device ID. Mindopt PDM supports Maxwell (GeForce 700 series) and later architectures.

6.3.3. CUDA error codes

If MindOpt encounters a CUDA error during the execution of the primal-dual method, the relevant error information will be given in the error code. The CUDA-related error codes are -45000 to -47999. The code structure is as follows:

  • -45xxx: CUDA Driver/Runtime API error.

  • -46xxx: cuBLAS API error.

  • -47xxx: cuSPARSE API error.

When the last three digits have non-zero values, they represent specific CUDA error codes, and the specific meaning can be queried in the CUDA official documentation. For example:

  • Error code -45002, indicates a CUDA error with error code 2, which is “cudaErrorMemoryAllocation” after query, that is, the CUDA API cannot allocate enough video memory.

  • Error code -45200, indicates a CUDA error with error code 200. which is “the result is “cudaErrorInvalidKernelImage” after query. It is recommended to check whether the CUDA version meets the requirements.