Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/plugins/ucx/ucx_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "common/nixl_log.h"
#include "serdes/serdes.h"
#include "common/nixl_log.h"
#include "ucx/device_mem_list.h"
#include "ucx/gpu_xfer_req_h.h"

#include <optional>
#include <limits>
Expand Down Expand Up @@ -1666,10 +1666,7 @@ nixlUcxEngine::createGpuXferReq(const nixlBackendReqH &req_hndl,
}

try {
auto device_mem_list =
std::make_unique<nixl::ucx::deviceMemList>(*ep, local_mems, remote_rkeys);
gpu_req_hndl = device_mem_list->get();
device_mem_list.release();
gpu_req_hndl = nixl::ucx::createGpuXferReq(*ep, local_mems, remote_rkeys);
return NIXL_SUCCESS;
}
catch (const std::exception &e) {
Expand All @@ -1680,8 +1677,7 @@ nixlUcxEngine::createGpuXferReq(const nixlBackendReqH &req_hndl,

void
nixlUcxEngine::releaseGpuXferReq(nixlGpuXferReqH gpu_req_hndl) const {
nixl::ucx::deviceMemList device_mem_list{gpu_req_hndl};
gpu_req_hndl = nullptr;
nixl::ucx::releaseGpuXferReq(gpu_req_hndl);
}

nixl_status_t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,26 @@
* limitations under the License.
*/

#include "device_mem_list.h"

#include <stdexcept>

#include "gpu_xfer_req_h.h"
#include "common/nixl_log.h"
#include "ucx_utils.h"
#include "rkey.h"
#include "config.h"

namespace nixl::ucx {

extern "C" {
#ifdef HAVE_UCX_GPU_DEVICE_API
#include <ucp/api/device/ucp_host.h>
#endif
}

deviceMemList::deviceMemList(const nixlUcxEp &ep,
const std::vector<nixlUcxMem> &local_mems,
const std::vector<const nixl::ucx::rkey *> &remote_rkeys)
: deviceMemList_{createDeviceMemList(ep, local_mems, remote_rkeys),
&ucp_device_mem_list_release} {}
namespace nixl::ucx {

deviceMemList::deviceMemList(const nixlGpuXferReqH gpu_req) noexcept
: deviceMemList_{reinterpret_cast<ucp_device_mem_list_handle_h>(gpu_req),
&ucp_device_mem_list_release} {}
#ifdef HAVE_UCX_GPU_DEVICE_API

nixlGpuXferReqH
deviceMemList::get() const noexcept {
return reinterpret_cast<nixlGpuXferReqH>(deviceMemList_.get());
}

ucp_device_mem_list_handle_h
deviceMemList::createDeviceMemList(const nixlUcxEp &ep,
const std::vector<nixlUcxMem> &local_mems,
const std::vector<const nixl::ucx::rkey *> &remote_rkeys) {
createGpuXferReq(const nixlUcxEp &ep,
const std::vector<nixlUcxMem> &local_mems,
const std::vector<const nixl::ucx::rkey *> &remote_rkeys) {
nixl_status_t status = ep.checkTxState();
if (status != NIXL_SUCCESS) {
throw std::runtime_error("Endpoint not in valid state for creating memory list");
Expand Down Expand Up @@ -88,25 +76,28 @@ deviceMemList::createDeviceMemList(const nixlUcxEp &ep,
}

NIXL_DEBUG << "Created device memory list handle with " << local_mems.size() << " elements";
return ucx_handle;
return reinterpret_cast<nixlGpuXferReqH>(ucx_handle);
}

void
releaseGpuXferReq(nixlGpuXferReqH gpu_req) noexcept {
auto ucx_handle = reinterpret_cast<ucp_device_mem_list_handle_h>(gpu_req);
ucp_device_mem_list_release(ucx_handle);
}

#else

deviceMemList::deviceMemList(const nixlUcxEp &ep,
const std::vector<nixlUcxMem> &local_mems,
const std::vector<const nixl::ucx::rkey *> &remote_rkeys) {
nixlGpuXferReqH
createGpuXferReq(const nixlUcxEp &ep,
const std::vector<nixlUcxMem> &local_mems,
const std::vector<const nixl::ucx::rkey *> &remote_rkeys) {
NIXL_ERROR << "UCX GPU device API not supported";
throw std::runtime_error("UCX GPU device API not available");
}

deviceMemList::deviceMemList(const nixlGpuXferReqH gpu_req) noexcept {
NIXL_WARN << "UCX GPU device API not supported - cannot create device memory list from handle";
}

nixlGpuXferReqH
deviceMemList::get() const noexcept {
return nullptr;
void
releaseGpuXferReq(nixlGpuXferReqH gpu_req) noexcept {
NIXL_WARN << "UCX GPU device API not supported - cannot release GPU transfer request handle";
}

#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,8 @@
#ifndef NIXL_SRC_UTILS_UCX_GPU_XFER_REQ_H_H
#define NIXL_SRC_UTILS_UCX_GPU_XFER_REQ_H_H

#include <memory>
#include <vector>

extern "C" {
#ifdef HAVE_UCX_GPU_DEVICE_API
#include <ucp/api/device/ucp_host.h>
#endif
}

#include "nixl_types.h"

class nixlUcxEp;
Expand All @@ -35,28 +28,13 @@ class nixlUcxMem;
namespace nixl::ucx {
class rkey;

class deviceMemList {
public:
deviceMemList() = delete;
deviceMemList(const nixlUcxEp &ep,
const std::vector<nixlUcxMem> &local_mems,
const std::vector<const nixl::ucx::rkey *> &remote_rkeys);
explicit deviceMemList(const nixlGpuXferReqH) noexcept;

[[nodiscard]] nixlGpuXferReqH
get() const noexcept;

#ifdef HAVE_UCX_GPU_DEVICE_API
private:
[[nodiscard]] static ucp_device_mem_list_handle_h
createDeviceMemList(const nixlUcxEp &ep,
const std::vector<nixlUcxMem> &local_mems,
const std::vector<const nixl::ucx::rkey *> &remote_rkeys);

const std::unique_ptr<ucp_device_mem_list_handle, void (*)(ucp_device_mem_list_handle_h)>
deviceMemList_;
#endif
};
nixlGpuXferReqH
createGpuXferReq(const nixlUcxEp &,
const std::vector<nixlUcxMem> &,
const std::vector<const nixl::ucx::rkey *> &);

void
releaseGpuXferReq(nixlGpuXferReqH gpu_req) noexcept;
} // namespace nixl::ucx

#endif
2 changes: 1 addition & 1 deletion src/utils/ucx/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ endif

ucx_utils_inc_dirs = include_directories('.')

ucx_utils_sources = ['ucx_utils.cpp', 'ucx_utils.h', 'config.h', 'config.cpp', 'rkey.cpp', 'rkey.h', 'device_mem_list.cpp', 'device_mem_list.h']
ucx_utils_sources = ['ucx_utils.cpp', 'ucx_utils.h', 'config.h', 'config.cpp', 'rkey.cpp', 'rkey.h', 'gpu_xfer_req_h.cpp', 'gpu_xfer_req_h.h']

ucx_utils_lib = library('ucx_utils',
ucx_utils_sources,
Expand Down