Skip to content

Commit 0f8b59d

Browse files
committed
Add strings with UMF version and useful CMake options
Add strings with UMF version and useful CMake options that can be grepped in the following way: $ strings libumf.so | grep "@(#)" @(#) Intel(R) UMF version: 0.11.0-dev.git66.g89e3831d @(#) Intel(R) UMF CMake variables: "CMAKE_BUILD_TYPE:Debug,... Signed-off-by: Lukasz Dorau <[email protected]>
1 parent a094b44 commit 0f8b59d

File tree

5 files changed

+105
-42
lines changed

5 files changed

+105
-42
lines changed

CMakeLists.txt

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,47 @@ include(CMakePackageConfigHelpers)
3333
include(GNUInstallDirs)
3434
find_package(PkgConfig)
3535

36+
# Define a list to store the names of all options
37+
set(UMF_OPTIONS_LIST "")
38+
list(APPEND UMF_OPTIONS_LIST CMAKE_BUILD_TYPE)
39+
40+
# Define a macro to wrap the option() command and track the options
41+
macro(umf_option)
42+
list(APPEND UMF_OPTIONS_LIST ${ARGV0})
43+
option(${ARGV})
44+
endmacro()
45+
3646
# Build Options
37-
option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
38-
option(UMF_BUILD_LEVEL_ZERO_PROVIDER "Build Level Zero memory provider" ON)
39-
option(UMF_BUILD_CUDA_PROVIDER "Build CUDA memory provider" ON)
40-
option(UMF_BUILD_LIBUMF_POOL_DISJOINT
41-
"Build the libumf_pool_disjoint static library" OFF)
42-
option(UMF_BUILD_LIBUMF_POOL_JEMALLOC
43-
"Build the libumf_pool_jemalloc static library" OFF)
44-
option(UMF_BUILD_TESTS "Build UMF tests" ON)
45-
option(UMF_BUILD_GPU_TESTS "Build UMF GPU tests" OFF)
46-
option(UMF_BUILD_BENCHMARKS "Build UMF benchmarks" OFF)
47-
option(UMF_BUILD_BENCHMARKS_MT "Build UMF multithreaded benchmarks" OFF)
48-
option(UMF_BUILD_EXAMPLES "Build UMF examples" ON)
49-
option(UMF_BUILD_FUZZTESTS "Build UMF fuzz tests" OFF)
50-
option(UMF_BUILD_GPU_EXAMPLES "Build UMF GPU examples" OFF)
51-
option(UMF_DEVELOPER_MODE "Enable additional developer checks" OFF)
52-
option(
47+
umf_option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
48+
umf_option(UMF_BUILD_LEVEL_ZERO_PROVIDER "Build Level Zero memory provider" ON)
49+
umf_option(UMF_BUILD_CUDA_PROVIDER "Build CUDA memory provider" ON)
50+
umf_option(UMF_BUILD_LIBUMF_POOL_DISJOINT
51+
"Build the libumf_pool_disjoint static library" OFF)
52+
umf_option(UMF_BUILD_LIBUMF_POOL_JEMALLOC
53+
"Build the libumf_pool_jemalloc static library" OFF)
54+
umf_option(UMF_BUILD_TESTS "Build UMF tests" ON)
55+
umf_option(UMF_BUILD_GPU_TESTS "Build UMF GPU tests" OFF)
56+
umf_option(UMF_BUILD_BENCHMARKS "Build UMF benchmarks" OFF)
57+
umf_option(UMF_BUILD_BENCHMARKS_MT "Build UMF multithreaded benchmarks" OFF)
58+
umf_option(UMF_BUILD_EXAMPLES "Build UMF examples" ON)
59+
umf_option(UMF_BUILD_FUZZTESTS "Build UMF fuzz tests" OFF)
60+
umf_option(UMF_BUILD_GPU_EXAMPLES "Build UMF GPU examples" OFF)
61+
umf_option(UMF_DEVELOPER_MODE "Enable additional developer checks" OFF)
62+
umf_option(
5363
UMF_DISABLE_HWLOC
5464
"Disable hwloc and UMF features requiring it (OS provider, memtargets, topology discovery)"
5565
OFF)
56-
option(
66+
umf_option(
5767
UMF_LINK_HWLOC_STATICALLY
5868
"Link UMF with HWLOC library statically (supported for Linux, MacOS and Release build on Windows)"
5969
OFF)
60-
option(UMF_FORMAT_CODE_STYLE
61-
"Add clang, cmake, and black -format-check and -format-apply targets"
62-
OFF)
70+
umf_option(
71+
UMF_FORMAT_CODE_STYLE
72+
"Add clang, cmake, and black -format-check and -format-apply targets" OFF)
6373
set(UMF_HWLOC_NAME
6474
"hwloc"
6575
CACHE STRING "Custom name for hwloc library w/o extension")
76+
list(APPEND UMF_OPTIONS_LIST UMF_HWLOC_NAME)
6677
set(UMF_INSTALL_RPATH
6778
""
6879
CACHE
@@ -71,13 +82,13 @@ set(UMF_INSTALL_RPATH
7182
)
7283

7384
# Only a part of skips is treated as a failure now. TODO: extend to all tests
74-
option(UMF_TESTS_FAIL_ON_SKIP "Treat skips in tests as fail" OFF)
75-
option(UMF_USE_ASAN "Enable AddressSanitizer checks" OFF)
76-
option(UMF_USE_UBSAN "Enable UndefinedBehaviorSanitizer checks" OFF)
77-
option(UMF_USE_TSAN "Enable ThreadSanitizer checks" OFF)
78-
option(UMF_USE_MSAN "Enable MemorySanitizer checks" OFF)
79-
option(UMF_USE_VALGRIND "Enable Valgrind instrumentation" OFF)
80-
option(UMF_USE_COVERAGE "Build with coverage enabled (Linux only)" OFF)
85+
umf_option(UMF_TESTS_FAIL_ON_SKIP "Treat skips in tests as fail" OFF)
86+
umf_option(UMF_USE_ASAN "Enable AddressSanitizer checks" OFF)
87+
umf_option(UMF_USE_UBSAN "Enable UndefinedBehaviorSanitizer checks" OFF)
88+
umf_option(UMF_USE_TSAN "Enable ThreadSanitizer checks" OFF)
89+
umf_option(UMF_USE_MSAN "Enable MemorySanitizer checks" OFF)
90+
umf_option(UMF_USE_VALGRIND "Enable Valgrind instrumentation" OFF)
91+
umf_option(UMF_USE_COVERAGE "Build with coverage enabled (Linux only)" OFF)
8192

8293
# set UMF_PROXY_LIB_BASED_ON_POOL to one of: SCALABLE or JEMALLOC
8394
set(KNOWN_PROXY_LIB_POOLS SCALABLE JEMALLOC)
@@ -87,6 +98,7 @@ set(UMF_PROXY_LIB_BASED_ON_POOL
8798
"A UMF pool the proxy library is based on (SCALABLE or JEMALLOC)")
8899
set_property(CACHE UMF_PROXY_LIB_BASED_ON_POOL
89100
PROPERTY STRINGS ${KNOWN_PROXY_LIB_POOLS})
101+
list(APPEND UMF_OPTIONS_LIST UMF_PROXY_LIB_BASED_ON_POOL)
90102

91103
if(UMF_BUILD_TESTS
92104
AND DEFINED ENV{CI}

CONTRIBUTING.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22

33

44
<!-- TODO: Add [Naming convention](#naming-convention) section -->
5-
- [Opening new issues](#opening-new-issues)
6-
- [Submitting Pull Requests](#submitting-pull-requests)
5+
- [Contributing to UMF (Unified Memory Framework)](#contributing-to-umf-unified-memory-framework)
6+
- [Opening new issues](#opening-new-issues)
7+
- [Submitting Pull Requests](#submitting-pull-requests)
78
- [Building and testing](#building-and-testing)
89
- [Code style](#code-style)
9-
- [When my PR is merged?](#when-my-PR-is-merged)
10+
- [When my PR is merged?](#when-my-pr-is-merged)
1011
- [Extending public API](#extending-public-api)
1112
- [License](#license)
1213
- [Adding new dependency](#adding-new-dependency)
13-
- [Code coverage](#code-coverage)
14+
- [Code coverage](#code-coverage)
15+
- [Debugging](#debugging)
16+
- [Checking the UMF version and CMake variables (Linux only)](#checking-the-umf-version-and-cmake-variables-linux-only)
17+
- [Requirements](#requirements)
1418

1519
Below you'll find instructions on how to contribute to UMF, either with code changes
1620
or issues. All contributions are most welcome!
@@ -222,3 +226,19 @@ $ apt install lcov
222226
$ lcov --capture --directory . --output-file coverage.info
223227
$ genhtml -o html_report coverage.info
224228
```
229+
230+
## Debugging
231+
232+
### Checking the UMF version and CMake variables (Linux only)
233+
234+
Strings with the UMF version and useful CMake variables can be grepped in the following way:
235+
236+
```bash
237+
$ strings libumf.so | grep "@(#)"
238+
@(#) Intel(R) UMF version: 0.11.0-dev.git66.g89e3831d
239+
@(#) Intel(R) UMF CMake variables: "CMAKE_BUILD_TYPE:Debug,...
240+
```
241+
242+
#### Requirements
243+
244+
- binutils package (Linux)

src/CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,24 @@ set(UMF_CUDA_INCLUDE_DIR
1111
""
1212
CACHE PATH "Directory containing the CUDA headers")
1313

14+
# Compose the UMF_ALL_CMAKE_VARIABLES variable containing CMake options that
15+
# will be saved in the constant string.
16+
list(SORT UMF_OPTIONS_LIST ORDER DESCENDING)
17+
foreach(_var ${UMF_OPTIONS_LIST})
18+
# Preprocessor definitions containing '#' cannot be passed on to the
19+
# compiler command line because many compilers do not support it.
20+
if(NOT "${${_var}}" MATCHES "#")
21+
set(UMF_ALL_CMAKE_VARIABLES
22+
"${_var}:${${_var}},${UMF_ALL_CMAKE_VARIABLES}")
23+
endif()
24+
endforeach()
25+
1426
# Compile definitions for UMF library.
1527
#
1628
# TODO: Cleanup the compile definitions across all the CMake files
17-
set(UMF_COMMON_COMPILE_DEFINITIONS UMF_VERSION=${UMF_VERSION})
29+
set(UMF_COMMON_COMPILE_DEFINITIONS
30+
UMF_VERSION=${UMF_VERSION}
31+
UMF_ALL_CMAKE_VARIABLES="${UMF_ALL_CMAKE_VARIABLES}")
1832

1933
add_subdirectory(utils)
2034

src/utils/utils_log.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,29 @@
3232
#include "utils_common.h"
3333
#include "utils_log.h"
3434

35+
#define UMF_MAGIC_STR "\x00@(#) "
36+
#define UMF_PREF_STR "Intel(R) "
37+
#define UMF_PREFIX UMF_MAGIC_STR UMF_PREF_STR
38+
39+
// convert a define to a C string
40+
#define STR_(X) #X
41+
#define STR(X) STR_(X)
42+
43+
#ifdef UMF_VERSION
44+
#define STR_UMF_VERSION "UMF version: " STR(UMF_VERSION)
45+
#define LOG_STR_UMF_VERSION STR_UMF_VERSION ", "
46+
char const __umf_str_2_version[] = UMF_PREFIX STR_UMF_VERSION;
47+
#else /* !UMF_VERSION */
48+
#error "UMF_VERSION not defined!"
49+
#endif /* !UMF_VERSION */
50+
51+
#ifdef UMF_ALL_CMAKE_VARIABLES
52+
char const __umf_str_1__all_cmake_vars[] =
53+
UMF_PREFIX "UMF CMake variables: " STR(UMF_ALL_CMAKE_VARIABLES);
54+
#else /* !UMF_ALL_CMAKE_VARIABLES */
55+
#error "UMF_ALL_CMAKE_VARIABLES not defined!"
56+
#endif /* !UMF_ALL_CMAKE_VARIABLES */
57+
3558
#define LOG_MAX 8192
3659
#define LOG_HEADER 256
3760
#define MAX_FILE_PATH 256
@@ -305,17 +328,8 @@ void utils_log_init(void) {
305328
loggerConfig.flushLevel = LOG_FATAL;
306329
}
307330

308-
#ifdef UMF_VERSION
309-
// convert a define to a C string
310-
#define STR_(X) #X
311-
#define STR(X) STR_(X)
312-
#define STR_UMF_VERSION "UMF version: " STR(UMF_VERSION) ", "
313-
#else /* !UMF_VERSION */
314-
#error "UMF_VERSION not defined!"
315-
#endif /* !UMF_VERSION */
316-
317331
LOG_INFO(
318-
"Logger enabled (" STR_UMF_VERSION
332+
"Logger enabled (" LOG_STR_UMF_VERSION
319333
"level: %s, flush: %s, pid: %s, timestamp: %s)",
320334
level_to_str(loggerConfig.level), level_to_str(loggerConfig.flushLevel),
321335
bool_to_str(loggerConfig.pid), bool_to_str(loggerConfig.timestamp));

test/utils/utils_log.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ const char *env_variable = "";
110110
#ifndef UMF_VERSION
111111
#define UMF_VERSION "test version"
112112
#endif
113+
#ifndef UMF_ALL_CMAKE_VARIABLES
114+
#define UMF_ALL_CMAKE_VARIABLES "test UMF_ALL_CMAKE_VARIABLES"
115+
#endif
113116
#include "utils/utils_log.c"
114117
#undef utils_env_var
115118
#undef fopen

0 commit comments

Comments
 (0)