Add CMake flag to log C API invocations, to aid debugging (#5925)

* Add CMake flag to log C API invocations, to aid debugging

* Remove unnecessary parentheses
This commit is contained in:
Philip Hyunsu Cho 2020-07-30 19:24:28 -07:00 committed by GitHub
parent 3b88bc948f
commit 3fcfaad577
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 1 deletions

View File

@ -34,6 +34,7 @@ option(USE_DEBUG_OUTPUT "Dump internal training results like gradients and predi
Should only be used for debugging." OFF) Should only be used for debugging." OFF)
option(FORCE_COLORED_OUTPUT "Force colored output from compilers, useful when ninja is used instead of make." OFF) option(FORCE_COLORED_OUTPUT "Force colored output from compilers, useful when ninja is used instead of make." OFF)
option(ENABLE_ALL_WARNINGS "Enable all compiler warnings. Only effective for GCC/Clang" OFF) option(ENABLE_ALL_WARNINGS "Enable all compiler warnings. Only effective for GCC/Clang" OFF)
option(LOG_CAPI_INVOCATION "Log all C API invocations for debugging" OFF)
option(GOOGLE_TEST "Build google tests" OFF) option(GOOGLE_TEST "Build google tests" OFF)
option(USE_DMLC_GTEST "Use google tests bundled with dmlc-core submodule" OFF) option(USE_DMLC_GTEST "Use google tests bundled with dmlc-core submodule" OFF)
option(USE_NVTX "Build with cuda profiling annotations. Developers only." OFF) option(USE_NVTX "Build with cuda profiling annotations. Developers only." OFF)

View File

@ -21,7 +21,8 @@ CONFIG = {
"USE_CUDA": "OFF", "USE_CUDA": "OFF",
"USE_NCCL": "OFF", "USE_NCCL": "OFF",
"JVM_BINDINGS": "ON" "JVM_BINDINGS": "ON",
"LOG_CAPI_INVOCATION": "OFF"
} }
@ -70,6 +71,7 @@ def normpath(path):
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--log-capi-invocation', type=str, choices=['ON', 'OFF'], default='OFF')
parser.add_argument('--use-cuda', type=str, choices=['ON', 'OFF'], default='OFF') parser.add_argument('--use-cuda', type=str, choices=['ON', 'OFF'], default='OFF')
cli_args = parser.parse_args() cli_args = parser.parse_args()
@ -93,6 +95,9 @@ if __name__ == "__main__":
else: else:
maybe_parallel_build = "" maybe_parallel_build = ""
if cli_args.log_capi_invocation == 'ON':
CONFIG['LOG_CAPI_INVOCATION'] = 'ON'
if cli_args.use_cuda == 'ON': if cli_args.use_cuda == 'ON':
CONFIG['USE_CUDA'] = 'ON' CONFIG['USE_CUDA'] = 'ON'
CONFIG['USE_NCCL'] = 'ON' CONFIG['USE_NCCL'] = 'ON'

View File

@ -38,6 +38,7 @@
<scala.version>2.12.8</scala.version> <scala.version>2.12.8</scala.version>
<scala.binary.version>2.12</scala.binary.version> <scala.binary.version>2.12</scala.binary.version>
<hadoop.version>2.7.3</hadoop.version> <hadoop.version>2.7.3</hadoop.version>
<log.capi.invocation>OFF</log.capi.invocation>
<use.cuda>OFF</use.cuda> <use.cuda>OFF</use.cuda>
</properties> </properties>
<repositories> <repositories>

View File

@ -84,6 +84,8 @@
<executable>python</executable> <executable>python</executable>
<arguments> <arguments>
<argument>create_jni.py</argument> <argument>create_jni.py</argument>
<argument>--log-capi-invocation</argument>
<argument>${log.capi.invocation}</argument>
<argument>--use-cuda</argument> <argument>--use-cuda</argument>
<argument>${use.cuda}</argument> <argument>${use.cuda}</argument>
</arguments> </arguments>

View File

@ -76,6 +76,9 @@ if (ENABLE_ALL_WARNINGS)
target_compile_options(objxgboost PUBLIC target_compile_options(objxgboost PUBLIC
$<IF:$<COMPILE_LANGUAGE:CUDA>,-Xcompiler=-Wall -Xcompiler=-Wextra,-Wall -Wextra>) $<IF:$<COMPILE_LANGUAGE:CUDA>,-Xcompiler=-Wall -Xcompiler=-Wextra,-Wall -Wextra>)
endif (ENABLE_ALL_WARNINGS) endif (ENABLE_ALL_WARNINGS)
if (LOG_CAPI_INVOCATION)
target_compile_definitions(objxgboost PUBLIC -DLOG_CAPI_INVOCATION=1)
endif (LOG_CAPI_INVOCATION)
set_target_properties(objxgboost PROPERTIES set_target_properties(objxgboost PROPERTIES
POSITION_INDEPENDENT_CODE ON POSITION_INDEPENDENT_CODE ON

View File

@ -10,7 +10,12 @@
#include <dmlc/logging.h> #include <dmlc/logging.h>
/*! \brief macro to guard beginning and end section of all functions */ /*! \brief macro to guard beginning and end section of all functions */
#ifdef LOG_CAPI_INVOCATION
#define API_BEGIN() \
LOG(CONSOLE) << "[XGBoost C API invocation] " << __PRETTY_FUNCTION__; try {
#else // LOG_CAPI_INVOCATION
#define API_BEGIN() try { #define API_BEGIN() try {
#endif // LOG_CAPI_INVOCATION
/*! \brief every function starts with API_BEGIN(); /*! \brief every function starts with API_BEGIN();
and finishes with API_END() or API_END_HANDLE_ERROR */ and finishes with API_END() or API_END_HANDLE_ERROR */
#define API_END() } catch(dmlc::Error &_except_) { return XGBAPIHandleException(_except_); } return 0; // NOLINT(*) #define API_END() } catch(dmlc::Error &_except_) { return XGBAPIHandleException(_except_); } return 0; // NOLINT(*)