Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.24)
project(CUPDLP VERSION 0.0.1)

option(BUILD_CUDA "<BUILD_CUDA_OR_NOT>" OFF)
option(USE_HIP "Build with HIP for AMD GPUs" OFF)
option(BUILD_APPS "<BUILD_APPS_OR_NOT>" OFF)
option(BUILD_PYTHON "<BUILD_PYTHON_OR_NOT>" OFF)
message(NOTICE "----------------------- cuPDLP-C ------------------------")
Expand All @@ -25,8 +26,14 @@ message("reset release flags: ${CMAKE_C_FLAGS_RELEASE}")
message(NOTICE "--------------------- cuPDLP CPU/GPU CONFIG -----------------------")
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
message(NOTICE "-- Sets build with CUDA ${BUILD_CUDA}")
if (${BUILD_CUDA} STREQUAL "ON")
message(NOTICE "-- Sets build with HIP ${USE_HIP}")
if (${USE_HIP} STREQUAL "ON")
include(FindHIPConf.cmake)
set(CUDA_LIBRARY-NOTFOUND false)
set(GPU_LIBRARY ${HIP_LIBRARY})
elseif (${BUILD_CUDA} STREQUAL "ON")
include(FindCUDAConf.cmake)
set(GPU_LIBRARY ${CUDA_LIBRARY})
else ()
set(CUDA_LIBRARY-NOTFOUND true)
endif ()
Expand Down
65 changes: 65 additions & 0 deletions FindHIPConf.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved.
# Author: Jeff Daily <jeff.daily@amd.com>
#
# Locate the ROCm/HIP toolchain and the hipBLAS/hipSPARSE (rocBLAS/rocSPARSE)
# libraries used by the AMD GPU build.

message(NOTICE "Finding HIP/ROCm environment")
message(NOTICE " - ROCM_PATH: $ENV{ROCM_PATH}")

# Default ROCM_PATH if not set
if(NOT DEFINED ENV{ROCM_PATH})
set(ENV{ROCM_PATH} "/opt/rocm")
endif()

set(ROCM_PATH $ENV{ROCM_PATH})

# enable_language(HIP) auto-detects the host GPU arch (and errors on a
# no-GPU build host); pass -DCMAKE_HIP_ARCHITECTURES=... to override.
enable_language(HIP)
message(NOTICE " - CMAKE_HIP_ARCHITECTURES: ${CMAKE_HIP_ARCHITECTURES}")

# Find hipBLAS
find_library(HIP_LIBRARY_BLAS
NAMES hipblas
HINTS "${ROCM_PATH}/lib"
REQUIRED
)

# Find hipSPARSE
find_library(HIP_LIBRARY_SPARSE
NAMES hipsparse
HINTS "${ROCM_PATH}/lib"
REQUIRED
)

# Find amdhip64 runtime
find_library(HIP_LIBRARY_RT
NAMES amdhip64
HINTS "${ROCM_PATH}/lib"
REQUIRED
)

# Find rocBLAS (hipBLAS backend)
find_library(HIP_LIBRARY_ROCBLAS
NAMES rocblas
HINTS "${ROCM_PATH}/lib"
REQUIRED
)

# Find rocSPARSE (hipSPARSE backend)
find_library(HIP_LIBRARY_ROCSPARSE
NAMES rocsparse
HINTS "${ROCM_PATH}/lib"
REQUIRED
)

set(HIP_LIBRARY ${HIP_LIBRARY_RT} ${HIP_LIBRARY_BLAS} ${HIP_LIBRARY_SPARSE} ${HIP_LIBRARY_ROCBLAS} ${HIP_LIBRARY_ROCSPARSE})
message(NOTICE " - HIP Libraries: ${HIP_LIBRARY}")

# Set include directories
set(HIP_INCLUDE_DIRS
"${ROCM_PATH}/include"
"${ROCM_PATH}/include/hipblas"
"${ROCM_PATH}/include/hipsparse"
)
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ cmake -DBUILD_CUDA=ON \
-DCMAKE_CUDA_FLAGS_RELEASE="-O2 -DNDEBUG" ..
```

### Building for AMD GPUs (ROCm/HIP)

The GPU solver also runs on AMD GPUs through ROCm. Install ROCm (which provides hipBLAS, hipSPARSE, rocBLAS, and rocSPARSE) and HiGHS as above, then configure with `-DUSE_HIP=ON` in place of `-DBUILD_CUDA=ON` and select the target GPU architecture with `-DCMAKE_HIP_ARCHITECTURES`:

```shell
export HIGHS_HOME=/path-to-highs
mkdir build
cd build
cmake -DUSE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx90a -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --target plc
```

Set `CMAKE_HIP_ARCHITECTURES` to match your GPU, for example `gfx90a` (MI200 series), `gfx1100` (RDNA3), or `gfx1201` (RDNA4). `ROCM_PATH` defaults to `/opt/rocm`; set it if ROCm is installed elsewhere. The same source builds for NVIDIA (`-DBUILD_CUDA=ON`) and AMD (`-DUSE_HIP=ON`) GPUs.

## Alternative Interfaces
### The Python Interface
If you wish to use the Python interface, use the following steps:
Expand Down
9 changes: 5 additions & 4 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ set_target_properties(onlinelp
)
if (${CUDA_LIBRARY-NOTFOUND})
target_link_libraries(onlinelp PUBLIC cupdlp m)
target_compile_definitions(onlinelp PUBLIC -DCUPDLP_CPU=1)
elseif (${USE_HIP} STREQUAL "ON")
target_link_libraries(onlinelp PUBLIC cupdlp ${HIP_LIBRARY} m)
target_compile_definitions(onlinelp PUBLIC USE_HIP)
target_include_directories(onlinelp PUBLIC ${HIP_INCLUDE_DIRS})
else ()
target_compile_definitions(wrapper_clp
PUBLIC
-DCUPDLP_CPU=1
)
target_link_libraries(onlinelp PUBLIC cupdlp ${CUDA_LIBRARY} m)
endif ()
13 changes: 10 additions & 3 deletions cupdlp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ add_library(cupdlp SHARED
${CUPDLP_INCLUDE_HEADERS}
${CUPDLP_SOURCE_FILES}
)
set_target_properties(cupdlp PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
target_compile_definitions(cupdlp
PUBLIC
# If the debug configuration pass the DEBUG define to the compiler
Expand All @@ -24,11 +25,17 @@ if (${CUDA_LIBRARY-NOTFOUND})
PUBLIC
-DCUPDLP_CPU=1
)
target_link_libraries(cupdlp m)
target_link_libraries(cupdlp $<$<NOT:$<PLATFORM_ID:Windows>>:m>)
elseif (${USE_HIP} STREQUAL "ON")
add_subdirectory(cuda)
message(NOTICE "- GPU version PDLP (HIP/ROCm)")
target_include_directories(cupdlp PUBLIC ${HIP_INCLUDE_DIRS})
target_link_libraries(cupdlp PRIVATE cudalin ${HIP_LIBRARY} $<$<NOT:$<PLATFORM_ID:Windows>>:m>)
set_target_properties(cupdlp PROPERTIES HIP_SEPARABLE_COMPILATION ON)
else()
add_subdirectory(cuda)
message(NOTICE "- GPU version PDLP")
message(NOTICE "- GPU version PDLP (CUDA)")
target_include_directories(cupdlp PUBLIC "/usr/local/cuda/include")
target_link_libraries(cupdlp PRIVATE cudalin ${CUDA_LIBRARY} m)
target_link_libraries(cupdlp PRIVATE cudalin ${CUDA_LIBRARY} $<$<NOT:$<PLATFORM_ID:Windows>>:m>)
set_target_properties(cupdlp PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
endif ()
79 changes: 57 additions & 22 deletions cupdlp/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,64 @@
enable_language(CXX CUDA)

add_library(cudalin SHARED
${CUPDLP_INCLUDE_DIR}/cuda/cupdlp_cuda_kernels.cu
${CUPDLP_INCLUDE_DIR}/cuda/cupdlp_cuda_kernels.cuh
${CUPDLP_INCLUDE_DIR}/cuda/cupdlp_cudalinalg.cuh
${CUPDLP_INCLUDE_DIR}/cuda/cupdlp_cudalinalg.cu
set(CUDA_SOURCES
${CUPDLP_INCLUDE_DIR}/cuda/cupdlp_cuda_kernels.cu
${CUPDLP_INCLUDE_DIR}/cuda/cupdlp_cudalinalg.cu
)
set_target_properties(cudalin PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_include_directories(cudalin PUBLIC "/usr/local/cuda/include")
target_compile_definitions(cudalin
PUBLIC
# If the debug configuration pass the DEBUG define to the compiler
$<$<CONFIG:Debug>:-DCUPDLP_DEBUG=1>

set(CUDA_HEADERS
${CUPDLP_INCLUDE_DIR}/cuda/cupdlp_cuda_kernels.cuh
${CUPDLP_INCLUDE_DIR}/cuda/cupdlp_cudalinalg.cuh
${CUPDLP_INCLUDE_DIR}/cuda/cuda_to_hip.h
)

target_link_libraries(cudalin ${CUDA_LIBRARY} m)
if (${USE_HIP} STREQUAL "ON")
# HIP/ROCm build
enable_language(HIP)
set_source_files_properties(${CUDA_SOURCES} PROPERTIES LANGUAGE HIP)

# add a test
add_executable(testcudalin test_cuda_linalg.c)
add_executable(testcublas test_cublas.c)
add_library(cudalin SHARED
${CUDA_SOURCES}
${CUDA_HEADERS}
)
target_compile_definitions(cudalin PUBLIC USE_HIP)
set_target_properties(cudalin PROPERTIES
HIP_SEPARABLE_COMPILATION ON
HIP_ARCHITECTURES "${CMAKE_HIP_ARCHITECTURES}"
WINDOWS_EXPORT_ALL_SYMBOLS ON
)
target_include_directories(cudalin PUBLIC ${HIP_INCLUDE_DIRS})
target_compile_definitions(cudalin
PUBLIC
$<$<CONFIG:Debug>:-DCUPDLP_DEBUG=1>
)
target_link_libraries(cudalin ${HIP_LIBRARY} $<$<NOT:$<PLATFORM_ID:Windows>>:m>)
else()
# CUDA build
enable_language(CXX CUDA)

set_target_properties(testcudalin PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
#target_include_directories(cudalinalg PRIVATE ${CUPDLP_INCLUDE_DIR}/cuda)
target_link_libraries(testcudalin PRIVATE cudalin ${CUDA_LIBRARY})
add_library(cudalin SHARED
${CUDA_SOURCES}
${CUDA_HEADERS}
)
set_target_properties(cudalin PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_include_directories(cudalin PUBLIC "/usr/local/cuda/include")
target_compile_definitions(cudalin
PUBLIC
$<$<CONFIG:Debug>:-DCUPDLP_DEBUG=1>
)
target_link_libraries(cudalin ${CUDA_LIBRARY} $<$<NOT:$<PLATFORM_ID:Windows>>:m>)
endif()

set_target_properties(testcublas PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(testcublas PRIVATE cudalin ${CUDA_LIBRARY})
# add tests
add_executable(testcudalin test_cuda_linalg.c)
add_executable(testcublas test_cublas.c)

if (${USE_HIP} STREQUAL "ON")
set_target_properties(testcudalin PROPERTIES HIP_SEPARABLE_COMPILATION ON)
target_link_libraries(testcudalin PRIVATE cudalin ${HIP_LIBRARY})
set_target_properties(testcublas PROPERTIES HIP_SEPARABLE_COMPILATION ON)
target_link_libraries(testcublas PRIVATE cudalin ${HIP_LIBRARY})
else()
set_target_properties(testcudalin PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(testcudalin PRIVATE cudalin ${CUDA_LIBRARY})
set_target_properties(testcublas PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(testcublas PRIVATE cudalin ${CUDA_LIBRARY})
endif()
111 changes: 111 additions & 0 deletions cupdlp/cuda/cuda_to_hip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved.
* Author: Jeff Daily <jeff.daily@amd.com>
*
* CUDA-to-HIP compatibility header for cuPDLP-C
*
* On AMD (USE_HIP / __HIP_PLATFORM_AMD__): aliases CUDA symbols to HIP equivalents.
* On NVIDIA: no-op include of CUDA headers.
*/
#pragma once

#if defined(USE_HIP) || defined(__HIP_PLATFORM_AMD__)

// Ensure AMD platform is defined before including HIP headers
#if !defined(__HIP_PLATFORM_AMD__) && !defined(__HIP_PLATFORM_NVIDIA__)
#define __HIP_PLATFORM_AMD__
#endif

#include <hip/hip_runtime.h>
#include <hipblas/hipblas.h>
#include <hipsparse/hipsparse.h>

// Runtime API
#define cudaMalloc hipMalloc
#define cudaFree hipFree
#define cudaMemcpy hipMemcpy
#define cudaMemcpyAsync hipMemcpyAsync
#define cudaMemset hipMemset
#define cudaDeviceSynchronize hipDeviceSynchronize
#define cudaGetLastError hipGetLastError
#define cudaGetErrorString hipGetErrorString
#define cudaGetDeviceCount hipGetDeviceCount
#define cudaGetDeviceProperties hipGetDeviceProperties
#define cudaDeviceGetAttribute hipDeviceGetAttribute
#define cudaRuntimeGetVersion hipRuntimeGetVersion
#define cudaDriverGetVersion hipDriverGetVersion
#define cudaDeviceReset hipDeviceReset

// Memory copy kinds
#define cudaMemcpyDeviceToHost hipMemcpyDeviceToHost
#define cudaMemcpyHostToDevice hipMemcpyHostToDevice
#define cudaMemcpyDeviceToDevice hipMemcpyDeviceToDevice
#define cudaMemcpyDefault hipMemcpyDefault

// Error types
#define cudaError_t hipError_t
#define cudaSuccess hipSuccess

// Device properties
#define cudaDeviceProp hipDeviceProp_t
#define cudaDevAttrMultiProcessorCount hipDeviceAttributeMultiprocessorCount
#define cudaDevAttrWarpSize hipDeviceAttributeWarpSize

// cuBLAS -> hipBLAS
#define cublasHandle_t hipblasHandle_t
#define cublasStatus_t hipblasStatus_t
#define CUBLAS_STATUS_SUCCESS HIPBLAS_STATUS_SUCCESS
#define cublasCreate hipblasCreate
#define cublasDestroy hipblasDestroy
#define cublasDaxpy hipblasDaxpy
#define cublasSaxpy hipblasSaxpy
#define cublasDdot hipblasDdot
#define cublasSdot hipblasSdot
#define cublasDnrm2 hipblasDnrm2
#define cublasSnrm2 hipblasSnrm2
#define cublasDscal hipblasDscal
#define cublasSscal hipblasSscal
#define cublasGetStatusString hipblasStatusToString

// cuSPARSE -> hipSPARSE
#define cusparseHandle_t hipsparseHandle_t
#define cusparseStatus_t hipsparseStatus_t
#define CUSPARSE_STATUS_SUCCESS HIPSPARSE_STATUS_SUCCESS
#define cusparseCreate hipsparseCreate
#define cusparseDestroy hipsparseDestroy
#define cusparseGetVersion hipsparseGetVersion
#define cusparseGetErrorString hipsparseGetErrorString

// Sparse matrix/vector descriptors
#define cusparseSpMatDescr_t hipsparseSpMatDescr_t
#define cusparseDnVecDescr_t hipsparseDnVecDescr_t
#define cusparseCreateCsr hipsparseCreateCsr
#define cusparseCreateCsc hipsparseCreateCsc
#define cusparseCreateDnVec hipsparseCreateDnVec
#define cusparseDestroySpMat hipsparseDestroySpMat
#define cusparseDestroyDnVec hipsparseDestroyDnVec

// SpMV operations
#define cusparseSpMV hipsparseSpMV
#define cusparseSpMV_bufferSize hipsparseSpMV_bufferSize
#define cusparseSpMVAlg_t hipsparseSpMVAlg_t
#define cusparseOperation_t hipsparseOperation_t
#define CUSPARSE_OPERATION_NON_TRANSPOSE HIPSPARSE_OPERATION_NON_TRANSPOSE
#define CUSPARSE_OPERATION_TRANSPOSE HIPSPARSE_OPERATION_TRANSPOSE
#define CUSPARSE_SPMV_CSR_ALG2 HIPSPARSE_SPMV_CSR_ALG2

// Compute type
#define CUDA_R_64F HIP_R_64F
#define CUDA_R_32F HIP_R_32F

// Index base
#define CUSPARSE_INDEX_BASE_ZERO HIPSPARSE_INDEX_BASE_ZERO
#define CUSPARSE_INDEX_32I HIPSPARSE_INDEX_32I

#else // NVIDIA CUDA

#include <cuda_runtime.h>
#include <cublas_v2.h>
#include <cusparse.h>

#endif // USE_HIP
Loading