Skip to content

Commit 661fbcb

Browse files
committed
rename examples and mark ctl as experimental in those
1 parent 15e7433 commit 661fbcb

File tree

11 files changed

+104
-56
lines changed

11 files changed

+104
-56
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ documentation, which includes the code of the
2121
[basic example](https://github.com/oneapi-src/unified-memory-framework/blob/main/examples/basic/basic.c).
2222
There are also more advanced examples that allocate USM memory from the [Level Zero device](examples/level_zero_shared_memory/level_zero_shared_memory.c) using the Level Zero API and UMF Level Zero memory provider and [CUDA device](examples/cuda_shared_memory/cuda_shared_memory.c) using the CUDA API and UMF CUDA memory provider.
2323

24+
UMF's experimental CTL API is showcased in the [CTL example](examples/ctl/ctl.c),
25+
which explores provider and pool statistics, and in the [custom CTL example](examples/ctl/custom_ctl.c), which wires CTL support into a custom memory provider. These examples rely on experimental headers which may change in future releases.
26+
2427
## Build
2528

2629
### Requirements

docs/config/ctl.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ configuration options, statistics and auxiliary APIs. CTL entries can also be
88
set through environment variables or a configuration file, allowing adjustment
99
of UMF behavior without modifying the program.
1010

11+
.. note::
12+
The CTL API is experimental and may change in future releases.
13+
1114
Main concepts
1215
=============
1316

@@ -84,7 +87,7 @@ to providers or pools created after the defaults are set. For example::
8487
sizeof(capacity));
8588

8689
Every subsequently created disjoint pool will use ``16`` as its starting
87-
capacity overriding it's creation parameters. Defaults are keyed by the
90+
capacity overriding its creation parameters. Defaults are keyed by the
8891
name returned from the provider or pool ``get_name`` callback, so if pool/provider
8992
has custom name it must be addressed explicitly. Defaults may be supplied programmatically
9093
or via environment variable and are saved internally and applied during initialization of a
@@ -99,7 +102,7 @@ Multiple entries are separated with semicolons, e.g.::
99102

100103
UMF_CONF="umf.logger.output=stdout;umf.logger.level=0"
101104

102-
CTL options available through environment variables are limitedyou can only
105+
CTL options available through environment variables are limitedyou can only
103106
target default nodes when addressing pools. This means that configuration
104107
strings can influence values consumed during pool creation but cannot alter
105108
runtime-only parameters.
@@ -118,7 +121,7 @@ major subsystems:
118121
Within each subsystem the path continues with an addressing scheme followed by
119122
the module or leaf of interest.
120123

121-
Reading this reference
124+
Reading below sections
122125
=======================
123126

124127
Parameter annotations describe the values stored in the node rather than the
@@ -211,8 +214,8 @@ Provider entries are organized beneath ``umf.provider``. Use
211214
:type:`umf_memory_provider_handle_t` argument to reach a specific provider.
212215
Providers can also be addressed by name through ``umf.provider.by_name.{provider}``;
213216
append ``.{index}`` to address specific provider when multiple providers share the same label.
214-
Defaults for future providers reside under ``umf.provider.default.{provider}`` and track the
215-
name returned by each provider's ``get_name`` implementation. Providers have their
217+
Defaults for future providers reside under ``umf.provider.default.{provider}`` where ``{provider`` is
218+
a name returned by each provider's ``get_name`` implementation. Providers have their
216219
default names (``OS``, ``FILE``, ``DEVDAX``, ``FIXED``, ``CUDA`` or ``LEVEL_ZERO``),
217220
unless their name was changed during creation, those renamed providers must be addressed explicitly.
218221
Defaults can be written via ``umf.provider.default.<name>`` either programmatically or through
@@ -663,17 +666,16 @@ The jemalloc-backed pool currently exposes only the common statistics nodes.
663666
Adding CTL support to custom providers and pools
664667
================================================
665668

666-
The :file:`examples/ctl/ctl_example.c` source demonstrates how a minimal
669+
The :file:`examples/ctl/custom_ctl.c` source demonstrates how a minimal
667670
provider can expose configuration entries, statistics and runnables through the
668671
CTL API. To add similar support to your own provider or pool you must implement
669672
an ``ext_ctl`` callback – parse incoming CTL paths and handle
670-
`CTL_QUERY_READ``, ``CTL_QUERY_WRITE`` and ``CTL_QUERY_RUNNABLE`` requests.
673+
``CTL_QUERY_READ``, ``CTL_QUERY_WRITE`` and ``CTL_QUERY_RUNNABLE`` requests.
671674
The callback receives a ``umf_ctl_query_source_t`` indicating whether the
672675
query came from the application or a configuration source. Programmatic
673676
calls pass typed binary data, while configuration sources deliver strings
674677
that must be parsed. Wildcards (``{}``) may appear in paths and are supplied
675678
as additional arguments.
676-
new entries.
677679

678680
During initialization UMF will execute ``post_initialize`` on the callback after
679681
applying any queued defaults, allowing the provider or pool to finalize its

docs/config/examples.rst

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,23 @@ in the UMF repository.
147147

148148
TODO
149149

150-
CTL statistics example
150+
CTL example
151151
==============================================================================
152152

153-
You can find the full example code in the `examples/ctl/ctl_statistics_example.c`_ file
154-
in the UMF repository.
153+
.. note::
154+
The CTL API is experimental and may change in future releases.
155+
156+
You can find the full example code in the `examples/ctl/ctl.c`_ file in the
157+
UMF repository.
155158

156159
The sample configures an OS memory provider and a disjoint pool, reuses the
157160
provider's canonical ``OS`` selector obtained at runtime, assigns a custom pool
158161
name, and then mixes ``by_handle`` and ``by_name`` selectors to explore CTL
159162
statistics. Wildcard nodes are used to choose provider counters, build a
160163
four-segment ``{}.{}`` chain for the named pool, reset the peak tracker, and
161-
drill into per-bucket disjoint pool telemetry. The program prints hints on ``stderr``
162-
explaining which tracing level is necessary when a statistic is unavailable.
164+
drill into per-bucket disjoint pool telemetry. The program prints hints on
165+
``stderr`` explaining which tracing level is necessary when a statistic is
166+
unavailable.
163167

164168
Build and run the example with::
165169

@@ -176,6 +180,26 @@ Tracing level ``1`` enables slab usage counters, level ``2`` adds allocation
176180
and free statistics, and level ``3`` additionally emits verbose log messages
177181
from the pool implementation.
178182

183+
Custom CTL example
184+
==============================================================================
185+
186+
You can find the full example code in the `examples/ctl/custom_ctl.c`_ file in
187+
the UMF repository. The program implements a minimal memory provider with CTL
188+
hooks that accept configuration values, execute runnables, and expose provider
189+
state through the experimental API. It highlights converting wildcard segments
190+
to ``printf``-style format strings and reading integers supplied via
191+
configuration defaults.
192+
193+
Build and run the example with::
194+
195+
cmake -B build
196+
cmake --build build
197+
./build/examples/umf_example_ctl
198+
199+
Optionally supply a modulus via configuration defaults::
200+
201+
UMF_CONF="umf.provider.default.ctl.m=10" ./build/examples/umf_example_ctl
202+
179203
IPC example with Level Zero Memory Provider
180204
==============================================================================
181205
The full code of the example is in the `examples/ipc_level_zero/ipc_level_zero.c`_ file in the UMF repository.
@@ -260,7 +284,8 @@ the :any:`umfCloseIPCHandle` function is called.
260284
.. _examples/cuda_shared_memory/cuda_shared_memory.c: https://github.com/oneapi-src/unified-memory-framework/blob/main/examples/cuda_shared_memory/cuda_shared_memory.c
261285
.. _examples/ipc_level_zero/ipc_level_zero.c: https://github.com/oneapi-src/unified-memory-framework/blob/main/examples/ipc_level_zero/ipc_level_zero.c
262286
.. _examples/custom_file_provider/custom_file_provider.c: https://github.com/oneapi-src/unified-memory-framework/blob/main/examples/custom_file_provider/custom_file_provider.c
263-
.. _examples/ctl/ctl_statistics_example.c: https://github.com/oneapi-src/unified-memory-framework/blob/main/examples/ctl/ctl_statistics_example.c
287+
.. _examples/ctl/ctl.c: https://github.com/oneapi-src/unified-memory-framework/blob/main/examples/ctl/ctl.c
288+
.. _examples/ctl/custom_ctl.c: https://github.com/oneapi-src/unified-memory-framework/blob/main/examples/ctl/custom_ctl.c
264289
.. _examples/memspace: https://github.com/oneapi-src/unified-memory-framework/blob/main/examples/memspace/
265290
.. _README: https://github.com/oneapi-src/unified-memory-framework/blob/main/README.md#memory-pool-managers
266291
.. _umf/ipc.h: https://github.com/oneapi-src/unified-memory-framework/blob/main/include/umf/ipc.h

examples/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ if(LINUX)
277277

278278
add_umf_executable(
279279
NAME ${EXAMPLE_NAME}
280-
SRCS ctl/ctl_example.c
280+
SRCS ctl/custom_ctl.c
281281
LIBS umf ${UMF_HWLOC_NAME})
282282

283283
target_include_directories(
@@ -295,7 +295,7 @@ if(LINUX)
295295

296296
add_umf_executable(
297297
NAME ${EXAMPLE_NAME}
298-
SRCS ctl/ctl_statistics_example.c
298+
SRCS ctl/ctl.c
299299
LIBS umf ${UMF_HWLOC_NAME})
300300

301301
target_include_directories(

examples/README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,28 @@ processes: a producer and a consumer that communicate in the following way
6969

7070
## CTL example
7171

72+
> **Note**: The CTL API is experimental and may change in future releases.
73+
74+
This example configures an OS memory provider and disjoint pool, then queries
75+
statistics through CTL using both ``by_handle`` and ``by_name`` selectors. It
76+
demonstrates wildcard nodes to mix selectors, reset peak counters, and read
77+
disjoint-pool bucket telemetry. Run it with:
78+
79+
./umf_example_ctl_statistics
80+
81+
Tracing for detailed disjoint pool counters can be enabled through:
82+
83+
UMF_CONF="umf.pool.default.disjoint.params.pool_trace=2" ./umf_example_ctl_statistics
84+
85+
## Custom CTL example
86+
87+
> **Note**: The CTL API is experimental and may change in future releases.
88+
7289
This example demonstrates how to add CTL support to a custom memory
7390
provider. It sets variables ``a`` and ``b`` through CTL, plus it allows
74-
for the modulus ``m`` loaded from the environment or a configuration file.
91+
for the modulus ``m`` to be loaded from the environment or a configuration file.
7592
Addition and subtraction operations return results modulo ``m`` and the
7693
result ``c`` can be retrieved using the CTL API. For example, to set the
77-
modulus through an environment variable run::
94+
modulus through an environment variable run:
7895

7996
UMF_CONF="umf.provider.default.ctl.m=10" ./umf_example_ctl

examples/ctl/CMakeLists.txt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,59 +23,59 @@ endif()
2323

2424
# build the example
2525
set(EXAMPLE_NAME umf_example_ctl)
26-
add_executable(${ EXAMPLE_NAME} ctl_example.c)
27-
target_include_directories(${ EXAMPLE_NAME} PRIVATE ${ LIBUMF_INCLUDE_DIRS})
26+
add_executable(${EXAMPLE_NAME} custom_ctl.c)
27+
target_include_directories(${EXAMPLE_NAME} PRIVATE ${LIBUMF_INCLUDE_DIRS})
2828
target_link_directories(
2929
${
3030
EXAMPLE_NAME}
3131
PRIVATE
3232
${
3333
LIBHWLOC_LIBRARY_DIRS})
34-
target_link_libraries(${ EXAMPLE_NAME} PRIVATE ${LIBUMF_LIBRARIES} hwloc)
34+
target_link_libraries(${EXAMPLE_NAME} PRIVATE ${LIBUMF_LIBRARIES} hwloc)
3535

3636
add_test(
3737
NAME ${EXAMPLE_NAME}
38-
COMMAND ${ EXAMPLE_NAME}
39-
WORKING_DIRECTORY ${ CMAKE_CURRENT_BINARY_DIR})
38+
COMMAND ${EXAMPLE_NAME}
39+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
4040

4141
set_tests_properties(${EXAMPLE_NAME} PROPERTIES LABELS "example-standalone")
4242

4343
if(LINUX)
4444
# set LD_LIBRARY_PATH
4545
set_property(
46-
TEST ${ EXAMPLE_NAME}
46+
TEST ${EXAMPLE_NAME}
4747
PROPERTY ENVIRONMENT_MODIFICATION
4848
"LD_LIBRARY_PATH=path_list_append:"
49-
"${LIBUMF_LIBRARY_DIRS};LD_"
50-
"LIBRARY_PATH=path_list_append:${"
49+
"${LIBUMF_LIBRARY_DIRS};"
50+
"LD_LIBRARY_PATH=path_list_append:${"
5151
"LIBHWLOC_LIBRARY_DIRS}")
5252
endif()
5353

5454
set(EXAMPLE_NAME umf_example_ctl_statistics)
55-
add_executable(${ EXAMPLE_NAME} ctl_statistics_example.c)
56-
target_include_directories(${ EXAMPLE_NAME} PRIVATE ${ LIBUMF_INCLUDE_DIRS})
55+
add_executable(${EXAMPLE_NAME} ctl.c)
56+
target_include_directories(${EXAMPLE_NAME} PRIVATE ${LIBUMF_INCLUDE_DIRS})
5757
target_link_directories(
5858
${
5959
EXAMPLE_NAME}
6060
PRIVATE
6161
${
6262
LIBHWLOC_LIBRARY_DIRS})
63-
target_link_libraries(${ EXAMPLE_NAME} PRIVATE ${LIBUMF_LIBRARIES} hwloc)
63+
target_link_libraries(${EXAMPLE_NAME} PRIVATE ${LIBUMF_LIBRARIES} hwloc)
6464

6565
add_test(
6666
NAME ${EXAMPLE_NAME}
67-
COMMAND ${ EXAMPLE_NAME}
68-
WORKING_DIRECTORY ${ CMAKE_CURRENT_BINARY_DIR})
67+
COMMAND ${EXAMPLE_NAME}
68+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
6969

7070
set_tests_properties(${EXAMPLE_NAME} PROPERTIES LABELS "example-standalone")
7171

7272
if(LINUX)
7373
# set LD_LIBRARY_PATH
7474
set_property(
75-
TEST ${ EXAMPLE_NAME}
75+
TEST ${EXAMPLE_NAME}
7676
PROPERTY ENVIRONMENT_MODIFICATION
7777
"LD_LIBRARY_PATH=path_list_append:"
78-
"${LIBUMF_LIBRARY_DIRS};LD_"
79-
"LIBRARY_PATH=path_list_append:${"
78+
"${LIBUMF_LIBRARY_DIRS};"
79+
"LD_LIBRARY_PATH=path_list_append:${"
8080
"LIBHWLOC_LIBRARY_DIRS}")
8181
endif()

examples/ctl/ctl_statistics_example.c renamed to examples/ctl/ctl.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
*
88
*/
99

10-
#include "umf/base.h"
1110
#include <stdbool.h>
1211
#include <stdio.h>
1312

13+
// This example relies on the experimental CTL API, which may change without
14+
// notice.
1415
#include <umf/experimental/ctl.h>
16+
17+
#include <umf/base.h>
1518
#include <umf/memory_pool.h>
1619
#include <umf/memory_provider.h>
1720
#include <umf/pools/pool_disjoint.h>
@@ -153,10 +156,7 @@ int main(void) {
153156
return -1;
154157
}
155158

156-
res = umfMemoryProviderGetName(provider, &provider_name);
157-
if (res != UMF_RESULT_SUCCESS || provider_name == NULL) {
158-
provider_name = "OS";
159-
}
159+
umfMemoryProviderGetName(provider, &provider_name);
160160

161161
print_provider_stats("Provider stats before allocation", provider,
162162
provider_name);

examples/ctl/ctl_example.c renamed to examples/ctl/custom_ctl.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@
1313
#include <stdlib.h>
1414
#include <string.h>
1515

16+
// This example relies on the experimental CTL API, which may change without
17+
// notice.
18+
#include <umf/experimental/ctl.h>
19+
1620
#include <umf.h>
1721
#include <umf/base.h>
18-
#include <umf/experimental/ctl.h>
22+
1923
#include <umf/memory_provider.h>
2024
#include <umf/memory_provider_ops.h>
2125

2226
// Minimal memory provider demonstrating CTL integration
2327

2428
// Provider state exposed via CTL
2529
typedef struct ctl_provider_t {
26-
int a;
27-
int b;
28-
int c;
29-
int m; // modulus value, optional
30+
int a, b, c, m;
3031
} ctl_provider_t;
3132

3233
static umf_result_t ctl_init(const void *params, void **provider) {

src/ctl/ctl_defaults.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
77
*/
88

9-
#include "ctl_defaults.h"
10-
119
#include <string.h>
1210

1311
#include "base_alloc_global.h"
12+
#include "ctl_defaults.h"
1413
#include "utils_concurrency.h"
1514
#include "utils_log.h"
1615
#include "utlist.h"
@@ -33,7 +32,7 @@ umf_result_t ctl_default_subtree(ctl_default_entry_t **list, utils_mutex_t *mtx,
3332
umf_ctl_query_type_t queryType) {
3433
(void)source;
3534
if (strstr(extra_name, "{}") != NULL) {
36-
LOG_ERR("%s, default setting do not support wildcard parameters {}",
35+
LOG_ERR("%s, default setting does not support wildcard parameters {}",
3736
extra_name);
3837
return UMF_RESULT_ERROR_NOT_SUPPORTED;
3938
}

src/pool/pool_disjoint.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@
2828

2929
static char *DEFAULT_NAME = "disjoint";
3030

31-
enum {
32-
DP_OVERRIDE_SLAB_MIN_SIZE = 1 << 0,
33-
DP_OVERRIDE_MAX_POOLABLE_SIZE = 1 << 1,
34-
DP_OVERRIDE_CAPACITY = 1 << 2,
35-
DP_OVERRIDE_MIN_BUCKET_SIZE = 1 << 3,
36-
DP_OVERRIDE_POOL_TRACE = 1 << 4,
37-
};
38-
3931
/* Disjoint pool CTL implementation */
4032
struct ctl disjoint_ctl_root;
4133
static UTIL_ONCE_FLAG ctl_initialized = UTIL_ONCE_FLAG_INIT;
@@ -118,6 +110,15 @@ CTL_READ_HANDLER(slab_min_size)(void *ctx, umf_ctl_query_source_t source,
118110
return UMF_RESULT_SUCCESS;
119111
}
120112

113+
// indicates that param was overriden by CTL
114+
enum {
115+
DP_OVERRIDE_SLAB_MIN_SIZE = 1 << 0,
116+
DP_OVERRIDE_MAX_POOLABLE_SIZE = 1 << 1,
117+
DP_OVERRIDE_CAPACITY = 1 << 2,
118+
DP_OVERRIDE_MIN_BUCKET_SIZE = 1 << 3,
119+
DP_OVERRIDE_POOL_TRACE = 1 << 4,
120+
};
121+
121122
static umf_result_t
122123
CTL_WRITE_HANDLER(slab_min_size)(void *ctx, umf_ctl_query_source_t source,
123124
void *arg, size_t size,

0 commit comments

Comments
 (0)