Skip to content

Conversation

evgeny-leksikov
Copy link
Contributor

What?

Fix Rust query_xfer_backend API

Why?

return a string, as rest of the API doesn't return the raw pointer

How?

  • add nixl_capi_query_xfer_backend_type and use it in Rust implementation
  • add C++ Agent::getBackendType helper API and use it in C wrapper

Copy link

👋 Hi evgeny-leksikov! Thank you for contributing to ai-dynamo/nixl.

Your PR reviewers will review your contribution then trigger the CI to test your changes.

🚀

 - return string instead of raw handle
 - add nixl_capi_query_xfer_backend_type and use it in Rust
   implementation
 - add C++ Agent::getBackendType helper API and use it in C wrapper
Copy link
Contributor

@mkhazraee mkhazraee Sep 25, 2025

Choose a reason for hiding this comment

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

We should not add APIs to nixl just for this. I don't understand why in our cpp wrapper we can't call getType on the nixlBackendH.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because nixl API defines nixlBackendH as an opaque type.
Dependency of the wrapper on internal core/agent_data.h may help here but IMO "get backend type" public API looks useful.

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 @evgeny-leksikov is right here, I don't see how it can be done w/o adding a new API, because of the opaque handle type.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, let's ignore this one API then for now, as it's not used by users we know of as of today. Adding an API to C++ and Python just to handle Rust doesn't sound the best, while they can easily handle it. Also we might do a large refactor and add methods to the xferReqH object itself, will see, and we can decide on it then.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mkhazraee do you have any users of this API?
Otherwise we'll close this PR..

* @return nixl_status_t Error code if call was not successful
*/
nixl_status_t
getBackendType(const nixlBackendH *backend, nixl_backend_t &type) const;
Copy link
Contributor

Choose a reason for hiding this comment

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

Line break

* @brief Get the type of a backend
*
* @param backend Backend handle
* @param type [out] Backend type
Copy link
Contributor

Choose a reason for hiding this comment

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

Alignment

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 @evgeny-leksikov is right here, I don't see how it can be done w/o adding a new API, because of the opaque handle type.

return NIXL_ERR_INVALID_PARAM;
}

try {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove the try.
It is doesn't exist anywhere else in this file.
And it is never used for getType()..

nixl_capi_backend_t *backend);

nixl_capi_status_t
nixl_capi_query_xfer_backend_type(nixl_capi_agent_t agent,
Copy link
Contributor

Choose a reason for hiding this comment

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

query -> get?

}

static thread_local nixl_backend_t type;
auto nixl_ret = agent->inner->getBackendType(backend_handle->backend, type);
Copy link
Contributor

Choose a reason for hiding this comment

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

try { ... here

return ret;
}

static thread_local nixl_backend_t type;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is static thread_local really needed? It doesn't appear anywhere else in this file..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's needed to avoid memory management in rust layer and thread safety in wrapper

assert!(result.is_ok(), "query_xfer_backend failed with error: {:?}", result.err());
let backend = result.unwrap();
println!("Transfer will use backend: {:?}", backend);
let backend_name = result.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

name -> type? (consistency)

///
/// # Returns
/// A handle to the backend used for the transfer
/// Name of the backend used for the transfer
Copy link
Contributor

Choose a reason for hiding this comment

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

Type?


// Extract the backend type string from the binary data
let backend_type = unsafe {
let slice = std::slice::from_raw_parts(
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe

CStr::from_ptr(backend_type_ptr as *const 8)
                        .to_string_lossy()
                        .into_owned()
```?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

c-str may lose data because it's null-teminated. Need to keep c++ like string with length

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

Successfully merging this pull request may close these issues.

3 participants