Skip to content

Commit

Permalink
Allow rapids_test_add allow with no GPUS argument
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmaynard committed Feb 21, 2023
1 parent 7ba6153 commit 483c8a3
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 16 deletions.
11 changes: 8 additions & 3 deletions rapids-cmake/test/add.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ States how many GPUs and what percent of each a test requires.
.. code-block:: cmake
rapids_test_add(NAME <name> COMMAND <target|command> [<args>...]
GPUS <N> [PERCENT <value>]
[GPUS <N> [PERCENT <value>]]
[INSTALL_COMPONENT_SET <set>]
[WORKING_DIRECTORY <dir>])
Expand All @@ -48,6 +48,8 @@ same GPU and quickly exhaust all memory.
State how many GPUs this test requires. Allows CTest to not over-subscribe
a machine's hardware.
If no value is provided, the test is considered to not use any GPUs
``PERCENT``
By default if no percent is provided, 100 is used.
State how much of each GPU this test requires.
Expand All @@ -63,6 +65,7 @@ same GPU and quickly exhaust all memory.
#]=======================================================================]
# cmake-lint: disable=R0915
function(rapids_test_add)
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.test.add")

Expand Down Expand Up @@ -106,8 +109,10 @@ function(rapids_test_add)
WORKING_DIRECTORY "${_RAPIDS_TEST_WORKING_DIRECTORY}")

include(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/gpu_requirements.cmake)
rapids_test_gpu_requirements(${_RAPIDS_TEST_NAME} GPUS ${_RAPIDS_TEST_GPUS}
PERCENT ${_RAPIDS_TEST_PERCENT})
if(DEFINED _RAPIDS_TEST_GPUS)
rapids_test_gpu_requirements(${_RAPIDS_TEST_NAME} GPUS ${_RAPIDS_TEST_GPUS}
PERCENT ${_RAPIDS_TEST_PERCENT})
endif()

if(_RAPIDS_TEST_INSTALL_COMPONENT_SET)
include(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/detail/record_test_component.cmake)
Expand Down
30 changes: 21 additions & 9 deletions rapids-cmake/test/gpu_requirements.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ same GPU and quickly exhaust all memory.
State how many GPUs this test requires. Allows CTest to not over-subscribe
a machine's hardware.
Any integer value >= 0 is supported
``PERCENT``
State how much of each GPU this test requires. In general 100, 50, and 20
are commonly used values. By default if no percent is provided, 100 is
used.
Any integer value >= 0 and <= 100 is supported
Default value of 100
#]=======================================================================]
function(rapids_test_gpu_requirements test_name)
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.test.gpu_requirements")
Expand All @@ -56,25 +62,31 @@ function(rapids_test_gpu_requirements test_name)
set(multi_value)
cmake_parse_arguments(_RAPIDS_TEST "${options}" "${one_value}" "${multi_value}" ${ARGN})

set(gpus ${_RAPIDS_TEST_GPUS})
if(NOT gpus)
message(FATAL_ERROR "rapids_test_gpu_requirements requires the GPUS option to be provided.")
endif()
if(gpus LESS 1 OR (NOT gpus MATCHES "^[0-9]+$"))
message(FATAL_ERROR "rapids_test_gpu_requirements GPUS requires a numeric value (>= 1) provided ${gpus}."
if(DEFINED _RAPIDS_TEST_PERCENT AND NOT DEFINED _RAPIDS_TEST_GPUS)
message(FATAL_ERROR "rapids_test_gpu_requirements requires the GPUS option to be provided when PERCENT is"
)
endif()

set(gpus 0)
if(DEFINED _RAPIDS_TEST_GPUS)
set(gpus ${_RAPIDS_TEST_GPUS})
endif()

set(percent 100)
if(DEFINED _RAPIDS_TEST_PERCENT)
set(percent ${_RAPIDS_TEST_PERCENT})
endif()

# verify that percent is inside the allowed bounds
if(percent GREATER 100 OR percent LESS 1 OR (NOT percent MATCHES "^[0-9]+$"))
# verify that gpu and percent are withing the allowed bounds
if(NOT gpus GREATER_EQUAL 0)
message(FATAL_ERROR "rapids_test_gpu_requirements requires a numeric GPUS value [0-N].")
endif()
if(NOT (percent GREATER_EQUAL 1 AND percent LESS_EQUAL 100))
message(FATAL_ERROR "rapids_test_gpu_requirements requires a numeric PERCENT value [1-100].")
endif()

set_property(TEST ${test_name} PROPERTY RESOURCE_GROUPS "${gpus},gpus:${percent}")
if(gpus AND percent)
set_property(TEST ${test_name} PROPERTY RESOURCE_GROUPS "${gpus},gpus:${percent}")
endif()

endfunction()
5 changes: 3 additions & 2 deletions testing/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ add_cmake_config_test(generate_resource_spec-simple.cmake)

set(percent_error_message "rapids_test_gpu_requirements requires a numeric PERCENT value [1-100].")
set(gpu_error_message "rapids_test_gpu_requirements GPUS requires a numeric value")
set(gpu_missing_message "rapids_test_gpu_requirements requires the GPUS option to be provided.")
set(gpu_missing_message "rapids_test_gpu_requirements requires the GPUS option to be provided")
add_cmake_config_test(gpu_requirements-char-percent.cmake SHOULD_FAIL "${percent_error_message}")
add_cmake_config_test(gpu_requirements-char-gpu.cmake SHOULD_FAIL "${gpu_error_message}")
add_cmake_config_test(gpu_requirements-zero-gpu.cmake)
add_cmake_config_test(gpu_requirements-max-percent.cmake)
add_cmake_config_test(gpu_requirements-min-percent.cmake)
add_cmake_config_test(gpu_requirements-multi.cmake)
Expand All @@ -44,7 +45,7 @@ add_cmake_config_test(install_relocatable-wrong-component.cmake SHOULD_FAIL "${w

add_cmake_ctest_test(add-impossible-allocation SHOULD_FAIL "Insufficient resources for test")
add_cmake_config_test(add-with-install-component.cmake)
add_cmake_config_test(add-with-no-gpus.cmake SHOULD_FAIL "${gpu_missing_message}")
add_cmake_config_test(add-with-no-gpus.cmake)
if(RAPIDS_CMAKE_TESTING_GPU_COUNT GREATER 0)
add_cmake_ctest_test(add-allocation-simple)
add_cmake_ctest_test(add-multi-allocations-same-gpu)
Expand Down
5 changes: 5 additions & 0 deletions testing/test/add-with-no-gpus.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ add_executable(verify_alloc "${CMAKE_BINARY_DIR}/main.cu")

enable_testing()
rapids_test_add(NAME simple_test COMMAND verify_alloc INSTALL_COMPONENT_SET testing)

get_test_property(simple_test RESOURCE_GROUPS value)
if(value)
message(FATAL_ERROR "Unexpected RESOURCE_GROUPS test property value(${value}) found, should not be set")
endif()
2 changes: 1 addition & 1 deletion testing/test/gpu_requirements-no-gpus.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ include(${rapids-cmake-dir}/test/gpu_requirements.cmake)

add_test(fake_test COMMAND "${CMAKE_COMMAND} -E echo")

rapids_test_gpu_requirements(fake_test PERCENT 120)
rapids_test_gpu_requirements(fake_test PERCENT 50)
2 changes: 1 addition & 1 deletion testing/test/gpu_requirements-no-percent.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ rapids_test_gpu_requirements(fake_test GPUS 9)

get_test_property(fake_test RESOURCE_GROUPS value)
if(NOT value STREQUAL "9,gpus:100")
message(FATAL_ERROR "Unexpected RESOURCE_GROUPS test property value after rapids_test_gpu_requirements")
message(FATAL_ERROR "Unexpected RESOURCE_GROUPS test property value(${value}) after rapids_test_gpu_requirements")
endif()
19 changes: 19 additions & 0 deletions testing/test/gpu_requirements-zero-gpu.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#=============================================================================
# Copyright (c) 2022-2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
include(${rapids-cmake-dir}/test/gpu_requirements.cmake)

add_test(fake_test COMMAND "${CMAKE_COMMAND} -E echo")
rapids_test_gpu_requirements(fake_test GPUS 0 PERCENT 100)

0 comments on commit 483c8a3

Please sign in to comment.