Skip to content

Conversation

lplewa
Copy link
Contributor

@lplewa lplewa commented Sep 17, 2025

No description provided.

@lplewa lplewa changed the title Ctl split The last CTL patch :) Sep 17, 2025
@lplewa lplewa force-pushed the ctl_split branch 11 times, most recently from 629b379 to 2706166 Compare September 18, 2025 14:44
@lplewa lplewa marked this pull request as ready for review September 18, 2025 15:22
@lplewa lplewa requested a review from a team as a code owner September 18, 2025 15:22
Copy link
Contributor

@lukaszstolarczuk lukaszstolarczuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after all, this is super huge PR - I'd split this somehow, if easily done...


UMF's experimental CTL API is showcased in the [CTL example](examples/ctl/ctl.c),
which explores provider and pool statistics, and in the [custom CTL example](examples/ctl/custom_ctl.c), which wires CTL support into a bespoke memory
provider. These examples rely on experimental headers whose interfaces may
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whose refer to people -> perhaps: ... experimental headers which may change ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

sizeof(alloc_count), name, i);
}

Ensure that the types of wildcard arguments match the expected node types.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise what? you get an error, a crash, ...?

Copy link
Contributor Author

@lplewa lplewa Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined behavior may happen

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined by C standard not our code.

sizeof(capacity));

Every subsequently created disjoint pool will use ``16`` as its starting
capacity overriding it's creation parameters. Defaults are keyed by the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's -> its

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


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

CTL options available through environment variables are limited—you can only
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

limited—you misspell

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done?

Within each subsystem the path continues with an addressing scheme followed by
the module or leaf of interest.

Reading this reference
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider renaming this section to Reading below sections or dunno, something else ;d

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

w/e done.

:type:`umf_memory_provider_handle_t` argument to reach a specific provider.
Providers can also be addressed by name through ``umf.provider.by_name.{provider}``;
append ``.{index}`` to address specific provider when multiple providers share the same label.
Defaults for future providers reside under ``umf.provider.default.{provider}`` and track the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what you meant by ... and track the name ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

===========

A ``{}`` in the path acts as a wildcard and is replaced with successive
arguments of ``umfCtlGet``, ``umfCtlSet`` or ``umfCtlExec``. Wildcards can
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set and get are explained, but umfCtlExec wasn't

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH we do not explain set or get either. Do we need such section?

target_include_directories(${ EXAMPLE_NAME} PRIVATE ${ LIBUMF_INCLUDE_DIRS})
target_link_directories(
${
EXAMPLE_NAME}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a weird formatting - can you make it like ${EXAMPLE_NAME}...?

// fix below, as well pls

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not my faults - this is done by cmake format

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.

UMF's experimental CTL API is showcased in the [CTL example](examples/ctl/ctl.c),
which explores provider and pool statistics, and in the [custom CTL example](examples/ctl/custom_ctl.c), which wires CTL support into a bespoke memory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bespoke -> customized

UMF repository.

The sample configures an OS memory provider and a disjoint pool, reuses the
provider's canonical ``OS`` selector obtained at runtime, assigns a custom pool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannonical?

name, and then mixes ``by_handle`` and ``by_name`` selectors to explore CTL
statistics. Wildcard nodes are used to choose provider counters, build a
four-segment ``{}.{}`` chain for the named pool, reset the peak tracker, and
drill into per-bucket disjoint pool telemetry. The program prints hints on
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drill

This example configures an OS memory provider and disjoint pool, then queries
statistics through CTL using both ``by_handle`` and ``by_name`` selectors. It
demonstrates wildcard nodes to mix selectors, reset peak counters, and drill
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drill into?

add_executable(${ EXAMPLE_NAME} custom_ctl.c)
target_include_directories(${ EXAMPLE_NAME} PRIVATE ${ LIBUMF_INCLUDE_DIRS})
target_link_directories(
${
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix formatting

TEST ${ EXAMPLE_NAME}
PROPERTY ENVIRONMENT_MODIFICATION
"LD_LIBRARY_PATH=path_list_append:"
"${LIBUMF_LIBRARY_DIRS};LD_"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not break "LD_LIBRARY..."

*
*/

#include "umf/base.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use <> for system headers, group and change order

* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

#include "ctl_defaults.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move down to other internal includes


static char *DEFAULT_NAME = "disjoint";

enum {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a comment how this is used
as I understand you create single bitmask instead of multiple bool flags .. maybe you could keep this enum close to "params_overriden" filed?

static char *DEFAULT_NAME = "disjoint";

enum {
DP_OVERRIDE_SLAB_MIN_SIZE = 1 << 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you initialize the bitmask to 0 does it mean that by default slab min size is always overriden?

@bratpiorka bratpiorka requested a review from Copilot October 8, 2025 08:37
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR consolidates final CTL (Control Interface) changes for version 1.0, including error code adjustments and comprehensive implementation of CTL functionality for providers and pools. The CTL system provides a hierarchical interface for configuring and querying UMF components.

Key changes:

  • Introduced new error code UMF_RESULT_ERROR_INVALID_CTL_PATH for invalid CTL paths
  • Added comprehensive CTL parameter support for disjoint pools with default overrides
  • Enhanced provider and pool initialization with post-initialization hooks
  • Added extensive test coverage and examples for CTL functionality

Reviewed Changes

Copilot reviewed 49 out of 49 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
include/umf/base.h Added new error code UMF_RESULT_ERROR_INVALID_CTL_PATH
test/utils/cpp_helpers.hpp Updated default error return from UMF_RESULT_ERROR_UNKNOWN to UMF_RESULT_ERROR_INVALID_CTL_PATH
test/pools/disjoint_pool_ctl.cpp Added comprehensive CTL tests for disjoint pool parameters and defaults
test/pools/disjoint_pool.cpp Added post-initialization CTL calls to existing tests
src/pool/pool_disjoint.c Implemented extensive CTL parameter support with read/write handlers
src/memory_provider.c Added provider CTL defaults system and post-initialization support
src/memory_pool.c Enhanced pool creation with CTL defaults and post-initialization
examples/ctl/ Added comprehensive CTL usage examples

Comment on lines 803 to +805
ret = umfCtlGet("umf.pool.by_handle.{}.stats.buckets.count", &arg, 1,
poolWrapper.get());
EXPECT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
EXPECT_EQ(ret, UMF_RESULT_ERROR_INVALID_CTL_PATH);
Copy link
Preview

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buffer size is too small (1 byte) for a size_t value. This should be sizeof(arg) to match the expected data type size.

Copilot uses AI. Check for mistakes.

Comment on lines 811 to +813
ret = umfCtlGet("umf.pool.by_handle.{}.stats.1.alloc_num", &arg, 1,
poolWrapper.get());
EXPECT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
EXPECT_EQ(ret, UMF_RESULT_ERROR_INVALID_CTL_PATH);
Copy link
Preview

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buffer size is too small (1 byte) for a size_t value. This should be sizeof(arg) to match the expected data type size.

Copilot uses AI. Check for mistakes.


// no bucket id
ret = umfCtlGet("umf.pool.by_handle.{}.stats.buckets.alloc_num", &arg,
sizeof(arg), poolWrapper.get());
Copy link
Preview

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buffer size is inconsistent with other similar test cases. For consistency with the test pattern, this should use 1 as the buffer size to test the invalid path scenario.

Suggested change
sizeof(arg), poolWrapper.get());
1, poolWrapper.get());

Copilot uses AI. Check for mistakes.


// bucked id + count
ret = umfCtlGet("umf.pool.by_handle.{}.stats.buckets.1.count", &arg,
sizeof(arg), poolWrapper.get());
Copy link
Preview

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buffer size is inconsistent with other similar test cases. For consistency with the test pattern, this should use 1 as the buffer size to test the invalid path scenario.

Suggested change
sizeof(arg), poolWrapper.get());
1, poolWrapper.get());

Copilot uses AI. Check for mistakes.

int a;
int b;
int c;
int m; // modulus value, optional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typedef struct ctl_provider_t {
    int a, b, c, m;
} ctl_provider_t;

PRIVATE
${
LIBHWLOC_LIBRARY_DIRS})
target_link_libraries(${ EXAMPLE_NAME} PRIVATE ${LIBUMF_LIBRARIES} hwloc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is needed to keep those spaces in brackets?
I mean:
${hereEXAMPLE_NAME}

void *provider, const void *ptr,
umf_memory_property_id_t memory_property_id, void *property_value);

///
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In memory_pool.h you removed such line :)

umf_ctl_query_type_t queryType) {
(void)source;
if (strstr(extra_name, "{}") != NULL) {
LOG_ERR("%s, default setting do not support wildcard parameters {}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not -> does not?

Comment on lines +10 to +11
#include "umf.h"
#include <gtest/gtest.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

different header groups

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants