Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add memspace filter functions #743

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

lplewa
Copy link
Contributor

@lplewa lplewa commented Sep 19, 2024

Description

Checklist

  • Code compiles without errors locally
  • All tests pass locally
  • CI workflows execute properly
  • CI workflows, not executed per PR (e.g. Nightly), execute properly
  • New tests added, especially if they will fail without my changes
  • Added/extended example(s) to cover this functionality
  • Extended the README/documentation
  • All newly added source files have a license
  • All newly added source files are referenced in CMake files
  • Logger (with debug/info/... messages) is used

@lplewa lplewa requested a review from a team as a code owner September 19, 2024 15:37
@lplewa lplewa force-pushed the filter branch 2 times, most recently from 12ab322 to 5bd462c Compare September 19, 2024 15:46
@@ -39,6 +39,13 @@ umf_result_t umfMemtargetGetType(umf_const_memtarget_handle_t hMemtarget,
umf_result_t umfMemtargetGetCapacity(umf_const_memtarget_handle_t hMemtarget,
size_t *capacity);

/// \brief Get ID of the memory target in bytes.
Copy link
Contributor

Choose a reason for hiding this comment

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

"id in bytes" - what does this mean?

@@ -426,3 +426,133 @@ umfMemspaceMemtargetRemove(umf_memspace_handle_t hMemspace,
hMemspace->size--;
return UMF_RESULT_SUCCESS;
}

static int MemspaceFilter(umf_memspace_handle_t memspace,
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't it be called "umfMemspaceFilter"?


for (size_t i = 0; i < memspace->size; i++) {
int r = filter(memspace, memspace->nodes[i], args);
if (r < 0) {
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 comment what it means to got r < 0. Also r->ret. Next - probably we could log here what happened

for (size_t i = 0; i < memspace->size; i++) {
int r = filter(memspace, memspace->nodes[i], args);
if (r < 0) {
return r;
Copy link
Contributor

Choose a reason for hiding this comment

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

shoulnd't we free the nodesToRemove ptr?

int r = filter(memspace, memspace->nodes[i], args);
if (r < 0) {
return r;
} else if (r == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what if r>0? assert?

for (; i < idx; i++) {
ret = umfMemspaceMemtargetRemove(memspace, nodesToRemove[i]);
if (ret != UMF_RESULT_SUCCESS) {
goto re_add;
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 why and what we want to do

int filterById(umf_const_memspace_handle_t memspace,
umf_const_memtarget_handle_t target, void *args) {
if (!memspace && !target && !args) {
return -UMF_RESULT_ERROR_INVALID_ARGUMENT;
Copy link
Contributor

Choose a reason for hiding this comment

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

negative return? please comment this function

return -UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

struct filter_by_id_args *filterArgs = args;
Copy link
Contributor

Choose a reason for hiding this comment

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

use typedef :)

struct filter_by_id_args args = {ids, size};
int ret = MemspaceFilter(memspace, &filterById, &args);

return ret < 0 ? -ret : ret;
Copy link
Contributor

Choose a reason for hiding this comment

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

please comment this :)

size_t size;
};

int filterById(umf_const_memspace_handle_t memspace,
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be 1000x better if you return only 0 or error code and set item id by output arg

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.

2 participants