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
66 changes: 66 additions & 0 deletions .github/workflows/build-hip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: build-hip

# Compile-only CI for the AMD GPU (HIP/ROCm) backend of HiPDLP.
#
# This job runs inside an official ROCm container and only *compiles and links*
# the HIP backend (-DHIPDLP_HIP=ON). It does NOT execute any GPU code: the
# GitHub-hosted runners have no AMD GPU. Its purpose is to catch HIP build
# regressions (wrong hip* API names, desynchronised #ifdef guards, signature
# mismatches) that are invisible to the CPU/CUDA builds.
#
# Running the GPU code (numerical validation) requires a self-hosted runner
# with an AMD GPU and is intentionally out of scope here.

on:
push:
paths:
- 'highs/pdlp/hipdlp/**'
- 'CMakeLists.txt'
- 'highs/CMakeLists.txt'
- '.github/workflows/build-hip.yml'
pull_request:
paths:
- 'highs/pdlp/hipdlp/**'
- 'CMakeLists.txt'
- 'highs/CMakeLists.txt'
- '.github/workflows/build-hip.yml'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
hip-compile:
runs-on: ubuntu-latest
container:
# 24.04 + ROCm 7.x; the "-complete" image bundles hipBLAS/hipSPARSE.
image: rocm/dev-ubuntu-24.04:7.2.4-complete

steps:
- uses: actions/checkout@v6

- name: Install build dependencies
shell: bash
run: |
apt-get update
apt-get install -y --no-install-recommends \
cmake make git ca-certificates zlib1g-dev
cmake --version
hipcc --version || /opt/rocm/bin/hipcc --version

- name: Configure CMake (HIP backend)
shell: bash
run: |
export PATH=/opt/rocm/bin:$PATH
export CMAKE_PREFIX_PATH=/opt/rocm
cmake -S . -B build_hip \
-DHIPDLP_HIP=ON \
-DBUILD_TESTING=OFF \
-DBUILD_EXAMPLES=OFF \
-DCMAKE_BUILD_TYPE=Release

- name: Build (compile + link, no GPU execution)
shell: bash
run: |
export PATH=/opt/rocm/bin:$PATH
cmake --build build_hip --target highs --parallel
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ $RECYCLE.BIN/
dist/
build/
build_release*/
install/
eggs/
parts/
var/
Expand Down
64 changes: 50 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,18 @@ message(STATUS "Use FindCUDAConf: ${CUPDLP_FIND_CUDA}")
option(HIGHS_GPU_LIB "Build highs GPU as a single lib" OFF)
message(STATUS "Build GPU with delayed loading: ${HIGHS_GPU_LIB}")

option(HIPDLP_HIP "Build HiPDLP with AMD HIP (ROCm)" OFF)
message(STATUS "Build HiPDLP with HIP: ${HIPDLP_HIP}")

# For now
if (HIGHS_GPU_LIB)
set(CUPDLP_GPU ON)
endif()

if (HIPDLP_HIP)
set(HIPDLP_GPU ON)
endif()

if(CUPDLP_GPU AND CMAKE_VERSION VERSION_LESS "3.25.0")
message("CUPDLP FindCUDAConf requires CMake version minumum 3.24. Please use a higher version of CMake.")
endif()
Expand Down Expand Up @@ -182,30 +189,59 @@ if (HIPO AND NOT FAST_BUILD)
message(ERROR "HIPO is only available with FAST_BUILD=ON.")
endif()

if (CUPDLP_GPU)
if (CUPDLP_GPU OR HIPDLP_GPU)
if (WIN32)
set(BUILD_SHARED_LIBS ON)
endif()

set (CUPDLP_CPU OFF)
message(NOTICE "Set build cuPDLP with CUDA")
set(CUPDLP_CPU OFF)

if (HIPDLP_HIP)
message(NOTICE "Set build HiPDLP with HIP (AMD ROCm)")

# ROCm/HIP requires CMake 3.21+
if(CMAKE_VERSION VERSION_LESS "3.21.0")
message(FATAL_ERROR "HIP support requires CMake >= 3.21")
endif()

# Allow the user to point to a non-standard ROCm install
if(DEFINED ENV{ROCM_PATH})
set(CMAKE_PREFIX_PATH "$ENV{ROCM_PATH}" ${CMAKE_PREFIX_PATH})
elseif(EXISTS "/opt/rocm")
set(CMAKE_PREFIX_PATH "/opt/rocm" ${CMAKE_PREFIX_PATH})
endif()

enable_language(HIP)
find_package(hipblas REQUIRED)
find_package(hipsparse REQUIRED)

set(GPU_LIBRARY roc::hipblas roc::hipsparse)
set(GPU_COMPILE_DEFINITIONS USE_HIP)

if (CUPDLP_FIND_CUDA)
# With FindCUDAConf.cmake
# Need to have the CUDA_HOME environment variable set.
include(FindCUDAConf)
else()
# Without FindCUDAConf.cmake
enable_language(CUDA)
find_package(CUDAToolkit REQUIRED)
message(NOTICE "Set build cuPDLP with CUDA")

if (CUPDLP_FIND_CUDA)
# With FindCUDAConf.cmake
# Need to have the CUDA_HOME environment variable set.
include(FindCUDAConf)
else()
# Without FindCUDAConf.cmake
enable_language(CUDA)
find_package(CUDAToolkit REQUIRED)

set(CUDA_LIBRARY-NOTFOUND, OFF)
set(CUDA_LIBRARY CUDA::cudart CUDA::cublas CUDA::cusparse)
endif()

set(CUDA_LIBRARY-NOTFOUND, OFF)
set(CUDA_LIBRARY CUDA::cudart CUDA::cublas CUDA::cusparse)
set(GPU_LIBRARY ${CUDA_LIBRARY})
set(GPU_COMPILE_DEFINITIONS "")
endif()

else()
set (CUPDLP_CPU ON)
set(CUDA_LIBRARY-NOTFOUND true)
set(CUPDLP_CPU ON)
set(CUDA_LIBRARY-NOTFOUND true)
set(HIPDLP_GPU OFF)
endif()

# Option to build static
Expand Down
2 changes: 1 addition & 1 deletion cmake/cpp-highs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ if (NOT HIGHS_COVERAGE)
APPEND FILE "${HIGHS_BINARY_DIR}/highs-targets.cmake")
endif()

if (CUPDLP_GPU AND NOT HIGHS_GPU_LIB)
if (CUPDLP_GPU AND NOT HIGHS_GPU_LIB AND NOT HIPDLP_HIP)
install(TARGETS cudalin
EXPORT ${lower}-targets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
Expand Down
114 changes: 67 additions & 47 deletions highs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,69 +194,89 @@ else()

target_sources(highs PRIVATE ${sources} ${headers} ${win_version_file})

# Optional Cuda
if (CUPDLP_GPU)

target_include_directories(highs PUBLIC "$<BUILD_INTERFACE:${CMAKE_CUDA_PATH}/include>")

if (HIGHS_GPU_LIB)
# like in cuda CMakeLists
enable_language(CXX CUDA)

# Remove /MP flag from CUDA targets (nvcc doesn't support it)
if(MSVC)
string(REPLACE "/MP" "" CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS}")
string(REPLACE "/bigobj" "" CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS}")

foreach(flag_var
CMAKE_CUDA_FLAGS_DEBUG
CMAKE_CUDA_FLAGS_RELEASE
CMAKE_CUDA_FLAGS_RELWITHDEBINFO
CMAKE_CUDA_FLAGS_MINSIZEREL)
string(REPLACE "/MP" "" ${flag_var} "${${flag_var}}")
string(REPLACE "/bigobj" "" ${flag_var} "${${flag_var}}")
endforeach()
endif()
# Optional GPU (CUDA or HIP)
if (CUPDLP_GPU OR HIPDLP_GPU)

target_sources(highs PRIVATE
pdlp/cupdlp/cuda/cupdlp_cuda_kernels.cu
pdlp/cupdlp/cuda/cupdlp_cuda_kernels.cuh
pdlp/cupdlp/cuda/cupdlp_cudalinalg.cuh
pdlp/cupdlp/cuda/cupdlp_cudalinalg.cu
pdlp/cupdlp/cupdlp_cs.c
pdlp/hipdlp/pdhg.cu)
if (HIPDLP_HIP)
# HIP backend — pdhg.cu is compiled as HIP source.
# HIPDLP_GPU activates GPU code in HiPDLP headers.
# CUPDLP_CPU keeps cuPDLP-C in CPU mode so it doesn't pull CUDA headers.
target_compile_definitions(highs PRIVATE HIPDLP_GPU USE_HIP CUPDLP_CPU)

set_target_properties(highs PROPERTIES
CUDA_SEPARABLE_COMPILATION ON
#CUDA_ARCHITECTURES "60;70;75;80;86" )
#Deleted 60;70 due to errors
#nvcc fatal : Unsupported gpu architecture 'compute_60'
#nvcc fatal : Unsupported gpu architecture 'compute_70'
CUDA_ARCHITECTURES "75;80;86" )
set_source_files_properties(pdlp/hipdlp/pdhg.cu PROPERTIES LANGUAGE HIP)

# set_target_properties(cudalin PROPERTIES CUDA_ARCHITECTURES native)
target_sources(highs PRIVATE pdlp/hipdlp/pdhg.cu)

target_include_directories(highs PUBLIC "$<BUILD_INTERFACE:${CMAKE_CUDA_PATH}/include>")
set_target_properties(highs PROPERTIES
HIP_SEPARABLE_COMPILATION ON)

if (WIN32)
target_link_libraries(highs PRIVATE ${CUDA_LIBRARY}) # linking happens here
else() # linux
target_link_libraries(highs PRIVATE ${CUDA_LIBRARY} m)
target_link_libraries(highs PRIVATE ${GPU_LIBRARY})
else()
target_link_libraries(highs PRIVATE ${GPU_LIBRARY} m)
endif()

else()
# CUDA backend
target_include_directories(highs PUBLIC "$<BUILD_INTERFACE:${CMAKE_CUDA_PATH}/include>")

if (HIGHS_GPU_LIB)
# like in cuda CMakeLists
enable_language(CXX CUDA)

# Remove /MP flag from CUDA targets (nvcc doesn't support it)
if(MSVC)
string(REPLACE "/MP" "" CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS}")
string(REPLACE "/bigobj" "" CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS}")

foreach(flag_var
CMAKE_CUDA_FLAGS_DEBUG
CMAKE_CUDA_FLAGS_RELEASE
CMAKE_CUDA_FLAGS_RELWITHDEBINFO
CMAKE_CUDA_FLAGS_MINSIZEREL)
string(REPLACE "/MP" "" ${flag_var} "${${flag_var}}")
string(REPLACE "/bigobj" "" ${flag_var} "${${flag_var}}")
endforeach()
endif()

target_sources(highs PRIVATE
pdlp/cupdlp/cuda/cupdlp_cuda_kernels.cu
pdlp/cupdlp/cuda/cupdlp_cuda_kernels.cuh
pdlp/cupdlp/cuda/cupdlp_cudalinalg.cuh
pdlp/cupdlp/cuda/cupdlp_cudalinalg.cu
pdlp/cupdlp/cupdlp_cs.c
pdlp/hipdlp/pdhg.cu)

set_target_properties(highs PROPERTIES
CUDA_SEPARABLE_COMPILATION ON
#CUDA_ARCHITECTURES "60;70;75;80;86" )
#Deleted 60;70 due to errors
#nvcc fatal : Unsupported gpu architecture 'compute_60'
#nvcc fatal : Unsupported gpu architecture 'compute_70'
CUDA_ARCHITECTURES "75;80;86" )

target_include_directories(highs PUBLIC "$<BUILD_INTERFACE:${CMAKE_CUDA_PATH}/include>")

if (WIN32)
target_link_libraries(highs PRIVATE ${GPU_LIBRARY})
else()
target_link_libraries(highs PRIVATE ${GPU_LIBRARY} m)
endif()

else()
set(CUPDLP_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/highs/pdlp/cupdlp/")
add_subdirectory(pdlp/cupdlp/cuda)

if (WIN32)
target_link_libraries(highs PRIVATE cudalin ${CUDA_LIBRARY})
else()
target_link_libraries(highs PRIVATE cudalin ${CUDA_LIBRARY} m)
endif()
target_link_libraries(highs PRIVATE cudalin ${GPU_LIBRARY})
else()
target_link_libraries(highs PRIVATE cudalin ${GPU_LIBRARY} m)
endif()

set_target_properties(highs PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
set_target_properties(highs PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
endif()
endif()
endif()

target_include_directories(highs PRIVATE ${include_dirs})

Expand Down
3 changes: 2 additions & 1 deletion highs/pdlp/cupdlp/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ add_library(cudalin SHARED
# latest has
# set_target_properties(cudalin PROPERTIES CUDA_SEPARABLE_COMPILATION ON)

set_target_properties(cudalin PROPERTIES
set_target_properties(cudalin PROPERTIES
CUDA_SEPARABLE_COMPILATION ON
#CUDA_ARCHITECTURES "60;70;75;80;86" )
#Deleted 60;70 due to errors
Expand All @@ -28,6 +28,7 @@ CUDA_ARCHITECTURES "75;80;86" )

# set_target_properties(cudalin PROPERTIES CUDA_ARCHITECTURES native)


target_include_directories(cudalin PUBLIC "$<BUILD_INTERFACE:${CMAKE_CUDA_PATH}/include>")

if (WIN32)
Expand Down
Loading
Loading