Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
- Changed cmake design by extracting the code into
  cmake/CheckSVEsupport.cmake
- Prefixed the flags with XGBOOST_ and used targeted flags
- Extracted the SVE code into an inlined function
- Added detailed code comments
- Modified vector names for better readability
  • Loading branch information
divya2108 committed Aug 26, 2024
1 parent 5194c17 commit dca00be
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 131 deletions.
52 changes: 7 additions & 45 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,51 +265,6 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "OS400")
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> -X64 qc <TARGET> <OBJECTS>")
endif()

if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
include(CheckCSourceCompiles)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+sve")
check_c_source_compiles("
#if defined(__aarch64__) && defined(__ARM_FEATURE_SVE)
#include <arm_sve.h>
int main() {
svfloat64_t a;
a = svdup_n_f64(0);
return 0;
}
#endif
" COMPILER_HAS_ARM_SVE)

if(COMPILER_HAS_ARM_SVE)
message(STATUS "ARM SVE compiler support detected")
set(SOURCE_CODE "
#include <sys/prctl.h>
int main() {
int ret = prctl(PR_SVE_GET_VL);
return ret >= 0 ? 0 : 1;
}
")
file(WRITE ${CMAKE_BINARY_DIR}/check_sve_support.c "${SOURCE_CODE}")
try_run(RUN_RESULT COMPILE_RESULT
${CMAKE_BINARY_DIR}/check_sve_support_output
${CMAKE_BINARY_DIR}/check_sve_support.c
)

if(RUN_RESULT EQUAL 0)
message(STATUS "ARM SVE hardware support detected")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+sve")
string(APPEND CMAKE_CXX_FLAGS " -DSVE_SUPPORT_DETECTED")
else()
message(STATUS "ARM SVE hardware support not detected")
endif()
else()
message(STATUS "ARM SVE compiler support not detected")
endif()

set(CMAKE_C_FLAGS "${ORIGINAL_CMAKE_C_FLAGS}")
else()
message(STATUS "Not an aarch64 architecture")
endif()

if(USE_NCCL)
find_package(Nccl REQUIRED)
endif()
Expand Down Expand Up @@ -394,6 +349,13 @@ target_include_directories(xgboost
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>)
#-- End shared library

include(${xgboost_SOURCE_DIR}/cmake/CheckSVEsupport.cmake)
check_xgboost_sve_support()
if(XGBOOST_ARM_SVE_HARDWARE_SUPPORT)
target_compile_definitions(objxgboost PUBLIC XGBOOST_SVE_SUPPORT_DETECTED)
target_compile_options(objxgboost PRIVATE ${XGBOOST_SVE_FLAGS})
endif()

#-- CLI for xgboost
if(BUILD_DEPRECATED_CLI)
add_executable(runxgboost ${xgboost_SOURCE_DIR}/src/cli_main.cc)
Expand Down
56 changes: 56 additions & 0 deletions cmake/CheckSVEsupport.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
function(check_xgboost_sve_support)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
include(CheckCSourceCompiles)

# Save the original C_FLAGS to restore later
set(ORIGINAL_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+sve")

# Check if the compiler supports ARM SVE
check_c_source_compiles("
#if defined(__aarch64__) && defined(__ARM_FEATURE_SVE)
#include <arm_sve.h>
int main() {
svfloat64_t a;
a = svdup_n_f64(0);
return 0;
}
#endif
" XGBOOST_COMPILER_HAS_ARM_SVE)

if(XGBOOST_COMPILER_HAS_ARM_SVE)
message(STATUS "ARM SVE compiler support detected")

# Check for hardware support
set(SOURCE_CODE "
#include <sys/prctl.h>
int main() {
int ret = prctl(PR_SVE_GET_VL);
return ret >= 0 ? 0 : 1;
}
")
file(WRITE ${CMAKE_BINARY_DIR}/check_sve_support.c "${SOURCE_CODE}")
try_run(RUN_RESULT COMPILE_RESULT
${CMAKE_BINARY_DIR}/check_sve_support_output
${CMAKE_BINARY_DIR}/check_sve_support.c
)

if(RUN_RESULT EQUAL 0)
message(STATUS "ARM SVE hardware support detected")
# Apply the SVE flags and definitions specifically to the xgboost target
set(XGBOOST_ARM_SVE_HARDWARE_SUPPORT TRUE PARENT_SCOPE)
set(XGBOOST_SVE_FLAGS "-march=armv8-a+sve" PARENT_SCOPE)
set(XGBOOST_SVE_DEFINITIONS "-DXGBOOST_SVE_SUPPORT_DETECTED" PARENT_SCOPE)
else()
message(STATUS "ARM SVE hardware support not detected")
endif()
else()
message(STATUS "ARM SVE compiler support not detected")
endif()

# Restore the original C_FLAGS
set(CMAKE_C_FLAGS "${ORIGINAL_C_FLAGS}")
else()
message(STATUS "Not an aarch64 architecture")
endif()
endfunction()
Loading

0 comments on commit dca00be

Please sign in to comment.