Skip to content

Commit

Permalink
Auto-generate resource spec file
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleFromKitware committed Apr 8, 2020
1 parent 2dc624e commit 336991c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
51 changes: 51 additions & 0 deletions cmake/tribits/core/package_arch/TribitsGlobalMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,21 @@ MACRO(TRIBITS_DEFINE_GLOBAL_OPTIONS_AND_DEFINE_EXTRA_REPOS)
"Enable explicit template instantiation in all packages that support it"
)

ADVANCED_SET(${PROJECT_NAME}_AUTOGENERATE_TEST_RESOURCE_FILE OFF
CACHE BOOL
"Auto-generate a resource spec file for use with CTest."
)

ADVANCED_SET(${PROJECT_NAME}_CUDA_NUM_GPUS 1
CACHE STRING
"Number of GPUS to make available in the auto-generated resource spec file."
)

ADVANCED_SET(${PROJECT_NAME}_CUDA_SLOTS_PER_GPU 1
CACHE STRING
"Number of slots per GPU in the auto-generated resource spec file."
)

IF (USE_XSDK_DEFAULTS)
# Need to set BUILD_SHARED_LIBS default here based on USE_XSDK_DEFAULTS
# and not in TRIBITS_SETUP_ENV() in case there is logic in TriBITS or
Expand Down Expand Up @@ -1005,6 +1020,42 @@ MACRO(TRIBITS_SETUP_INSTALLATION_PATHS)
ENDMACRO()


#
# Generate resource spec file
#


MACRO(TRIBITS_GENERATE_RESOURCE_SPEC_FILE)
SET(GPUS_JSON)
MATH(EXPR LAST_GPU "${${PROJECT_NAME}_CUDA_NUM_GPUS} - 1")
SET(FIRST 1)
FOREACH(GPU RANGE 0 ${LAST_GPU})
IF(NOT FIRST)
STRING(APPEND GPUS_JSON ",\n")
ENDIF()
SET(FIRST 0)
STRING(APPEND GPUS_JSON " {
\"id\": \"${GPU}\",
\"slots\": ${${PROJECT_NAME}_CUDA_SLOTS_PER_GPU}
}")
ENDFOREACH()
FILE(WRITE "${CMAKE_BINARY_DIR}/CMakeFiles/resources.json" "{
\"version\": {
\"major\": 1,
\"minor\": 0
},
\"local\": [
{
\"gpus\": [
${GPUS_JSON}
]
}
]
}
")
ENDMACRO()


#
# Repository specializaiton call-back functions
#
Expand Down
22 changes: 21 additions & 1 deletion cmake/tribits/core/package_arch/TribitsProjectImpl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,27 @@ MACRO(TRIBITS_PROJECT_IMPL)
ENDIF()

#
# N) Show final timing and end
# N) Generate resource spec file if applicable
#

IF (${PROJECT_NAME}_AUTOGENERATE_TEST_RESOURCE_FILE)
TRIBITS_GENERATE_RESOURCE_SPEC_FILE()
ADVANCED_SET(CTEST_RESOURCE_SPEC_FILE "${CMAKE_BINARY_DIR}/CMakeFiles/resources.json"
CACHE INTERNAL
"Resource spec file for CTest."
)
ELSEIF(DEFINED CACHE{CTEST_RESOURCE_SPEC_FILE})
GET_PROPERTY(CTEST_RESOURCE_SPEC_FILE_TYPE CACHE CTEST_RESOURCE_SPEC_FILE PROPERTY TYPE)
IF (CTEST_RESOURCE_SPEC_FILE_TYPE STREQUAL "INTERNAL")
ADVANCED_SET(CTEST_RESOURCE_SPEC_FILE ""
CACHE INTERNAL
"Resource spec file for CTest."
)
ENDIF()
ENDIF()

#
# O) Show final timing and end
#

MESSAGE("")
Expand Down

0 comments on commit 336991c

Please sign in to comment.