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
2 changes: 2 additions & 0 deletions src/utils/device/proxy/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

device_proxy_lib = library('nixl_device_proxy',
['proxy_config.cpp', 'proxy_config.h',
'proxy_memview_manager.cpp', 'proxy_memview_manager.h', 'proxy_host_view.h',
'proxy_submission.cpp', 'proxy_submission.h',
'proxy_control_buffer.cpp', 'proxy_control_buffer.h',
'proxy_protocol.h', 'proxy_transport.h'],
include_directories: [nixl_inc_dirs, utils_inc_dirs],
Expand Down
54 changes: 54 additions & 0 deletions src/utils/device/proxy/proxy_host_view.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef NIXL_SRC_UTILS_DEVICE_PROXY_PROXY_HOST_VIEW_H
#define NIXL_SRC_UTILS_DEVICE_PROXY_PROXY_HOST_VIEW_H

#include <vector>

#include "backend_aux.h"
#include "device/device_ops.h"
#include "nixl_types.h"

namespace nixl {

/**
* The manager's device memview: kernels read the token and direct pointers through
* it. The same type as nixlMemViewH; the name says which of its meanings is meant.
*/
using proxy_view_handle_t = nixlMemViewH;

/**
* The host side of one prepared memory view. The manager creates and owns host views;
* a ring command names one by its address (the 64-bit host token), and
* resolveSubmission() reads it through that token without a lookup.
*/
struct proxyHostView {
struct storedDesc {
/** metadataP is borrowed and must outlive submissions. */
nixlMetaDesc desc;
bool usable = true;
};

proxy_view_handle_t proxy_memview = nullptr;
deviceMem proxy_memview_mem;
Comment on lines +46 to +47

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please use camelCase here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do in a follow-up PR after #2327, which rewrites this file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in dfab94b0 (#2465).

bool remote = false;
std::vector<storedDesc> descs;
};

} // namespace nixl

#endif // NIXL_SRC_UTILS_DEVICE_PROXY_PROXY_HOST_VIEW_H
144 changes: 144 additions & 0 deletions src/utils/device/proxy/proxy_memview_manager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "proxy_memview_manager.h"

#include <cstddef>
#include <cstdint>
#include <type_traits>
#include <utility>

#include "nixl_log.h"
#include "nixl_types.h"

namespace nixl {

proxyMemViewManager::proxyMemViewManager(deviceOps &allocator,
const nixlProxyDeviceContextData *device_context)
: allocator_(allocator),
device_context_(device_context) {}

template<typename DlistT>
nixl_status_t
proxyMemViewManager::createView(const DlistT &dlist,
const std::vector<void *> &direct_ptrs,
proxyHostView *&out) {
out = nullptr;

// CPU: the host view, and the device memview's contents, which name the host view by
// its address.
auto host_view = std::make_unique<proxyHostView>();
host_view->remote = std::is_same_v<DlistT, nixl_remote_meta_dlist_t>;
fillDescs(dlist, host_view->descs);
const nixlProxyDeviceMemView memview_contents{
static_cast<uint64_t>(reinterpret_cast<uintptr_t>(host_view.get())),
device_context_,
static_cast<uint32_t>(direct_ptrs.size())};

// GPU: allocate the device memview and copy the contents and direct pointers into it.
deviceMem device_memview_mem;
if (allocator_.allocDeviceMem(nixlProxyDeviceMemViewBytes(direct_ptrs.size()),
device_memview_mem) != NIXL_SUCCESS) {
NIXL_ERROR << "proxyMemViewManager: failed to allocate device memview";
return NIXL_ERR_BACKEND;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This code seems to negate the point of using statuses in the allocDeviceMem method. It seems that the status of allocDeviceMem should be returned here.

I'm still not sure if using statuses in deviceOps methods makes more sense than exceptions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed; the follow-up returns allocDeviceMem()'s status. The deviceOps question is in #2225 (comment).

}
auto *device_memview = static_cast<nixlProxyDeviceMemView *>(device_memview_mem.get());
nixl_status_t copy_status = allocator_.copy(device_memview,
&memview_contents,
sizeof(memview_contents),
deviceOps::copyDirection::HostToDevice);
if (copy_status == NIXL_SUCCESS && !direct_ptrs.empty()) {
copy_status = allocator_.copy(nixlProxyDeviceMemViewDirectPtrs(device_memview),
direct_ptrs.data(),
direct_ptrs.size() * sizeof(void *),
deviceOps::copyDirection::HostToDevice);
}
if (copy_status != NIXL_SUCCESS) {
NIXL_ERROR << "proxyMemViewManager: failed to initialize device memview";
return NIXL_ERR_BACKEND;
}

// Link: the host view owns its device memview, and the map owns the host view.
host_view->proxy_memview = device_memview;
host_view->proxy_memview_mem = std::move(device_memview_mem);
out = host_view.get();
views_.emplace(device_memview, std::move(host_view));
return NIXL_SUCCESS;
}

nixl_status_t
proxyMemViewManager::prepLocal(const nixl_meta_dlist_t &dlist, proxy_view_handle_t &out) {
proxyHostView *host_view = nullptr;
const nixl_status_t status = createView(dlist, {}, host_view);
if (status != NIXL_SUCCESS) {
return status;
}

out = host_view->proxy_memview;
NIXL_DEBUG << "proxyMemViewManager::prepLocal: host_view=" << host_view
<< " descs=" << dlist.descCount();
return NIXL_SUCCESS;
}

nixl_status_t
proxyMemViewManager::prepRemote(const nixl_remote_meta_dlist_t &dlist,
const std::vector<void *> &direct_ptrs,
proxy_view_handle_t &out) {
if (dlist.getType() != VRAM_SEG) {
NIXL_ERROR << "proxyMemViewManager::prepRemote: unsupported mem type " << dlist.getType();
return NIXL_ERR_INVALID_PARAM;
}

proxyHostView *host_view = nullptr;
const nixl_status_t status = createView(dlist, direct_ptrs, host_view);
if (status != NIXL_SUCCESS) {
return status;
}

out = host_view->proxy_memview;
NIXL_DEBUG << "proxyMemViewManager::prepRemote: host_view=" << host_view
<< " descs=" << dlist.descCount() << " direct_ptrs=" << direct_ptrs.size();
return NIXL_SUCCESS;
}

nixl_status_t
proxyMemViewManager::release(proxy_view_handle_t proxy_memview) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need a return status in a release method? I think issue a warning is enogh here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In #2327 the backend's releaseMemView() returns void and warns, like nixlBackend::releaseMemView(). The manager's release() still returns the status the runtime logs; I'll make it void too in the follow-up.

const auto it = views_.find(proxy_memview);
if (it == views_.end()) {
return NIXL_ERR_INVALID_PARAM;
}

views_.erase(it);
return NIXL_SUCCESS;
}

template<typename DlistT>
void
proxyMemViewManager::fillDescs(const DlistT &dlist, std::vector<proxyHostView::storedDesc> &out) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe just return std::vector<proxyHostView::storedDesc>?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do in a follow-up PR after #2327, which rewrites this file.

out.clear();
out.reserve(dlist.descCount());
for (const auto &desc : dlist) {
proxyHostView::storedDesc stored{desc};
if constexpr (std::is_same_v<DlistT, nixl_remote_meta_dlist_t>) {
// A hole (the null agent's descriptor) has no metadata, and nothing without metadata
// can be posted, so the metadata alone decides.
stored.usable = desc.metadataP != nullptr;
}
out.push_back(std::move(stored));
}
}

} // namespace nixl
74 changes: 74 additions & 0 deletions src/utils/device/proxy/proxy_memview_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef NIXL_SRC_UTILS_DEVICE_PROXY_PROXY_MEMVIEW_MANAGER_H
#define NIXL_SRC_UTILS_DEVICE_PROXY_PROXY_MEMVIEW_MANAGER_H

#include <memory>
#include <unordered_map>
#include <vector>

#include "backend_aux.h"
#include "device/device_ops.h"
#include "proxy_protocol.h"
#include "proxy_host_view.h"

namespace nixl {

/**
Comment thread
tomerdav marked this conversation as resolved.
Resolved
* Creates, owns and releases the proxy's prepared memory views. A view is a host view
* (its descriptors) plus a device memview that the GPU reads and that carries the host
* view's address as its token. Host views never move, so a token stays valid until its
* view is released. Not thread-safe: the caller serializes every call.
*/
class proxyMemViewManager {
public:
proxyMemViewManager(deviceOps &allocator, const nixlProxyDeviceContextData *device_context);

proxyMemViewManager(const proxyMemViewManager &) = delete;
proxyMemViewManager &
operator=(const proxyMemViewManager &) = delete;

[[nodiscard]] nixl_status_t
prepLocal(const nixl_meta_dlist_t &dlist, proxy_view_handle_t &out);

[[nodiscard]] nixl_status_t
prepRemote(const nixl_remote_meta_dlist_t &dlist,
const std::vector<void *> &direct_ptrs,
proxy_view_handle_t &out);

/** Releases the view after all GPU/CPU operations using it have completed. */
[[nodiscard]] nixl_status_t
release(proxy_view_handle_t proxy_memview);

private:
template<typename DlistT>
[[nodiscard]] nixl_status_t
createView(const DlistT &dlist, const std::vector<void *> &direct_ptrs, proxyHostView *&out);

template<typename DlistT>
static void
fillDescs(const DlistT &dlist, std::vector<proxyHostView::storedDesc> &out);

deviceOps &allocator_;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
deviceOps &allocator_;
deviceOps &deviceOps_;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do in a follow-up PR after #2327, which rewrites this file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 7cac37de (#2465).

const nixlProxyDeviceContextData *device_context_;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
const nixlProxyDeviceContextData *device_context_;
const nixlProxyDeviceContextData *deviceContext_;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do in a follow-up PR after #2327, which rewrites this file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 7cac37de (#2465).

/** Workers never access this ownership map. */
std::unordered_map<proxy_view_handle_t, std::unique_ptr<proxyHostView>> views_;
};

} // namespace nixl

#endif // NIXL_SRC_UTILS_DEVICE_PROXY_PROXY_MEMVIEW_MANAGER_H
Loading
Loading