|
| 1 | +cmake_minimum_required(VERSION 3.16) |
| 2 | + |
| 3 | +if(NOT DEFINED ABACUS_SOURCE_DIR OR NOT DEFINED TEST_BINARY_DIR) |
| 4 | + message(FATAL_ERROR "ABACUS_SOURCE_DIR and TEST_BINARY_DIR are required") |
| 5 | +endif() |
| 6 | + |
| 7 | +set(_test_root "${TEST_BINARY_DIR}/cusolvermp-version-guard") |
| 8 | +set(_source_dir "${_test_root}/source") |
| 9 | +set(_fake_prefix "${_test_root}/fake-prefix") |
| 10 | +file(REMOVE_RECURSE "${_test_root}") |
| 11 | +file(MAKE_DIRECTORY "${_source_dir}" "${_fake_prefix}/include" "${_fake_prefix}/lib") |
| 12 | + |
| 13 | +foreach(_library IN ITEMS cusolverMp cal nccl) |
| 14 | + file(WRITE "${_fake_prefix}/lib/lib${_library}.so" "") |
| 15 | +endforeach() |
| 16 | +file(WRITE "${_fake_prefix}/include/cal.h" "") |
| 17 | +file(WRITE "${_fake_prefix}/include/nccl.h" "") |
| 18 | + |
| 19 | +file(WRITE "${_source_dir}/CMakeLists.txt" [=[ |
| 20 | +cmake_minimum_required(VERSION 3.16) |
| 21 | +project(cusolvermp_version_guard LANGUAGES NONE) |
| 22 | +
|
| 23 | +function(abacus_add_feature_definitions) |
| 24 | +endfunction() |
| 25 | +
|
| 26 | +include("${ABACUS_SOURCE_DIR}/cmake/modules/SetupCuSolverMp.cmake") |
| 27 | +abacus_setup_cusolvermp() |
| 28 | +file(WRITE "${CMAKE_BINARY_DIR}/backend.txt" "${_use_cal}") |
| 29 | +]=]) |
| 30 | + |
| 31 | +function(run_version_case case_name version expected_result expected_backend allow_unsupported) |
| 32 | + string(REPLACE "." ";" _version_parts "${version}") |
| 33 | + list(GET _version_parts 0 _major) |
| 34 | + list(GET _version_parts 1 _minor) |
| 35 | + list(GET _version_parts 2 _patch) |
| 36 | + file(WRITE "${_fake_prefix}/include/cusolverMp.h" |
| 37 | + "#define CUSOLVERMP_VER_MAJOR ${_major}\n" |
| 38 | + "#define CUSOLVERMP_VER_MINOR ${_minor}\n" |
| 39 | + "#define CUSOLVERMP_VER_PATCH ${_patch}\n") |
| 40 | + |
| 41 | + set(_build_dir "${_test_root}/build-${case_name}") |
| 42 | + file(REMOVE_RECURSE "${_build_dir}") |
| 43 | + execute_process( |
| 44 | + COMMAND |
| 45 | + "${CMAKE_COMMAND}" |
| 46 | + -S "${_source_dir}" |
| 47 | + -B "${_build_dir}" |
| 48 | + "-DABACUS_SOURCE_DIR=${ABACUS_SOURCE_DIR}" |
| 49 | + "-DCAL_CUSOLVERMP_PATH=${_fake_prefix}" |
| 50 | + "-DNCCL_PATH=${_fake_prefix}" |
| 51 | + "-DALLOW_KNOWN_AFFECTED_CUSOLVERMP=${allow_unsupported}" |
| 52 | + RESULT_VARIABLE _result |
| 53 | + OUTPUT_VARIABLE _stdout |
| 54 | + ERROR_VARIABLE _stderr) |
| 55 | + set(_output "${_stdout}\n${_stderr}") |
| 56 | + |
| 57 | + if(expected_result STREQUAL "success") |
| 58 | + if(NOT _result EQUAL 0) |
| 59 | + message(FATAL_ERROR "${case_name} unexpectedly failed:\n${_output}") |
| 60 | + endif() |
| 61 | + file(READ "${_build_dir}/backend.txt" _backend) |
| 62 | + if(NOT _backend STREQUAL "${expected_backend}") |
| 63 | + message(FATAL_ERROR |
| 64 | + "${case_name} selected backend '${_backend}', expected '${expected_backend}'") |
| 65 | + endif() |
| 66 | + if(allow_unsupported |
| 67 | + AND version VERSION_GREATER_EQUAL "0.7.0" |
| 68 | + AND version VERSION_LESS "0.9.0" |
| 69 | + AND (NOT _output MATCHES "ALLOW_KNOWN_AFFECTED_CUSOLVERMP=ON" |
| 70 | + OR NOT _output MATCHES "may fail or hang")) |
| 71 | + message(FATAL_ERROR |
| 72 | + "${case_name} configured without the expected risk warning:\n${_output}") |
| 73 | + endif() |
| 74 | + else() |
| 75 | + if(_result EQUAL 0) |
| 76 | + message(FATAL_ERROR "${case_name} unexpectedly configured successfully") |
| 77 | + endif() |
| 78 | + if(NOT _output MATCHES "known-affected" |
| 79 | + OR NOT _output MATCHES "0\\.7\\.x/0\\.8\\.x range") |
| 80 | + message(FATAL_ERROR "${case_name} failed without the expected diagnostic:\n${_output}") |
| 81 | + endif() |
| 82 | + endif() |
| 83 | +endfunction() |
| 84 | + |
| 85 | +run_version_case(cal_060 0.6.0 success ON OFF) |
| 86 | +run_version_case(nccl_070 0.7.0 failure OFF OFF) |
| 87 | +run_version_case(nccl_072 0.7.2 failure OFF OFF) |
| 88 | +run_version_case(nccl_080 0.8.0 failure OFF OFF) |
| 89 | +run_version_case(nccl_090 0.9.0 success OFF OFF) |
| 90 | +run_version_case(nccl_072_override 0.7.2 success OFF ON) |
| 91 | + |
| 92 | +message(STATUS "cuSOLVERMp version guard cases passed") |
0 commit comments