Skip to content

Conversation

lslusarczyk
Copy link
Contributor

@lslusarczyk lslusarczyk commented Sep 11, 2025

@lslusarczyk lslusarczyk requested a review from a team as a code owner September 11, 2025 12:30
@bratpiorka bratpiorka requested review from lplewa and ldorau September 11, 2025 12:53
Copy link
Contributor

@ldorau ldorau left a comment

Choose a reason for hiding this comment

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

14 / 16 files reviewed (will be continued)

@lslusarczyk
Copy link
Contributor Author

@lukaszstolarczuk , @bratpiorka , @ldorau ,
CI passed, please check if I applied your comments correctly, resolve discussions which can be resolved and give approve if there is nothing left to do with respect to your comments

@lplewa , please do the same wrt your comments when you're back


uint32_t existing_peer_index = 0;
utils_write_lock(&ze_provider->resident_device_rwlock);
while (existing_peer_index < ze_provider->resident_device_count &&
Copy link
Contributor

Choose a reason for hiding this comment

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

you do the incrementation within the while loop and have extra && to mark the stop, I believe I agree with Łukasz - this would look better as for.

// you obviously don't have to init anything in for (e.g. for(; index < count; index++)

add_umf_library(
NAME umf_ze_loopback
TYPE SHARED
SRCS ze_loopback.h ze_loopback.cpp
Copy link
Contributor

Choose a reason for hiding this comment

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

.h is not needed?


#include "umf/providers/provider_level_zero.h"
#include "utils_load_library.h"
#include <cstdlib>
Copy link
Contributor

Choose a reason for hiding this comment

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

#include <cstdlib>

#include <umf/providers/provider_level_zero.h>

#include "level_zero_mocks.h"
#include "utils_load_library.h"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, applied

#ifndef UMF_TEST_PROVIDER_LEVEL_ZERO_MOCKS_H
#define UMF_TEST_PROVIDER_LEVEL_ZERO_MOCKS_H

#include "utils_log.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

#include <vector>
#include <gmock/gmock.h>

#include "utils_log.h"
#include "ze_loopback.h"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, applied

*
*/

#include "ze_loopback.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

#include <cstdlib>
#include <iostream>

#include "ze_loopback.h"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, applied

// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "../common/level_zero_mocks.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

#include <umf/pools/pool_disjoint.h>
#include <umf/providers/provider_level_zero.h>

#include "gtest/gtest.h"
#include "../common/level_zero_mocks.h"
#include "pool.hpp"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, applied

Copy link
Contributor

@lplewa lplewa left a comment

Choose a reason for hiding this comment

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

Please refactor commits structure.

commits in PR should be split to functional parts, with proper commit message.
Each commit should work (at least it should build - but we do not check it so exception happens). You should not split implementation, tests, documentation to separate commits.

If i were you i would create(This list is an inspiration for proper commits structure, you do not have split your PR to exactly this commits) : commit for adding iterate over critnib, commit for changes in asserts, maybe commit for this mock library, commit for allowing ovveride lib_name, commit for change in setResidentDevides, commit for main functionality of this PR....

void critnib_iter(critnib *c, uintptr_t min, uintptr_t max,
int (*func)(uintptr_t key, void *value, void *privdata),
void *privdata) {
bool wasIterating = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

move lock inside if - then you can just add else to if instead extra variable. This will make it a lite bit easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, because I want to access root in if (c->root) under the lock too


uint32_t existing_peer_index = 0;
utils_write_lock(&ze_provider->resident_device_rwlock);
while (existing_peer_index < ze_provider->resident_device_count &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes i noticed that you need it outside of loop - this is why i write
for(index = 0; index < count; index++) if (device[index] == index) break;
not
for (int index = 0; index < count; index++) if (device[index] == index) break;

If something is for loop we should use for not while. If you need access to loop counter outside of function you can declare it before loop - this is a standard approach which should not confuse reader.

LOG_ERR("umfMemoryTrackerIterateAll did not manage to do some change "
"numFailed: %d, numSuccess: %d",
privData.success_changes, privData.failed_changes);
return UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;
Copy link
Contributor

Choose a reason for hiding this comment

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

When returining this error code get_last_native_error function should be able to return more precise error message - please add support for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, added store_last_native_error(result); in ze_memory_provider_resident_device_change_helper

.failed_changes = 0,
};

umf_result_t result = umfMemoryTrackerIterateAll(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we miss communicated - I will follow up on this later on.

return 0;
}

umf_result_t umfLevelZeroMemoryProviderResidentDeviceChange(
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer to have add and remove function - i recall pbalcer already suggested it too.

I will split it to 3 functions - add, delete, and helper function to iterate over existing allocations (so we limit code duplication)

@lslusarczyk
Copy link
Contributor Author

Please refactor commits structure.

commits in PR should be split to functional parts, with proper commit message. Each commit should work (at least it should build - but we do not check it so exception happens). You should not split implementation, tests, documentation to separate commits.

If i were you i would create(This list is an inspiration for proper commits structure, you do not have split your PR to exactly this commits) : commit for adding iterate over critnib, commit for changes in asserts, maybe commit for this mock library, commit for allowing ovveride lib_name, commit for change in setResidentDevides, commit for main functionality of this PR....

Refactor will be squashing all commits to one during merge.
Each commit will be working :)

@lplewa
Copy link
Contributor

lplewa commented Oct 6, 2025

Please refactor commits structure.
commits in PR should be split to functional parts, with proper commit message. Each commit should work (at least it should build - but we do not check it so exception happens). You should not split implementation, tests, documentation to separate commits.
If i were you i would create(This list is an inspiration for proper commits structure, you do not have split your PR to exactly this commits) : commit for adding iterate over critnib, commit for changes in asserts, maybe commit for this mock library, commit for allowing ovveride lib_name, commit for change in setResidentDevides, commit for main functionality of this PR....

Refactor will be squashing all commits to one during merge. Each commit will be working :)

We do not do squash merge in this project

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.

6 participants