Skip to content

feat: add direct CCU runtime support#52

Open
Kur0x wants to merge 2 commits into
mainfrom
codex/direct-ccu-rebased
Open

feat: add direct CCU runtime support#52
Kur0x wants to merge 2 commits into
mainfrom
codex/direct-ccu-rebased

Conversation

@Kur0x

@Kur0x Kur0x commented Jul 6, 2026

Copy link
Copy Markdown
Member

Summary

  • Add TileXR-owned direct CCU runtime, install/orchestrator, HCCP loader, repository, microcode, and resource allocation components under src/comm/ccu.
  • Expose direct CCU prepare/submit/destroy APIs through tilexr_api.h and comm_wrap.cpp.
  • Add CCU handoff documentation plus host/unit smoke coverage under tests/ccu.

Test plan

  • git diff --cached --check before commit
  • PATH="/tmp/tilexr-python-bin:$PATH" python3 -m unittest tests.ccu.test_tilexr_ccu_direct_smoke_probe tests.ccu.test_tilexr_ccu_public_comm_api tests.ccu.test_tilexr_ccu_direct_smoke_runner tests.ccu.test_tilexr_ccu_direct_orchestrator tests.ccu.test_tilexr_ccu_memory_program tests.ccu.test_tilexr_ccu_microcode
  • python3 -m unittest discover tests/ccu is not clean on this macOS host; failures are local environment/platform gaps: missing 3rdparty/hcomm reference source, Apple linker handling of -Wl,--gc-sections, and Linux dynamic-library behavior differences.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 217dbddb85

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

remote.memoryTokenId = peerWindow.tokenId;
remote.rawMemoryTokenId = peerWindow.rawTokenId;
remote.memoryTokenValue = peerWindow.tokenValue;
remote.remoteEid = ReverseEndpointEid(peerWindow.remoteEid);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve peer EIDs in exported-route mode

When peer-route import is unavailable or disabled (for example env/provider/collector routes or TILEXR_CCU_DIRECT_ENDPOINT_ROUTE_EXCHANGE_MODE=exported_peer), peerWindow.remoteEid is already the peer's exported endpoint EID and this fallback value is passed on to lower-layer channel construction. Reversing it here byte-swaps verified routes before TileXRCcuBuildLowerLayerTransportTemplate consumes them, so the generated channel specs address the wrong endpoint; only transform the EID on the path that actually requires the imported-route byte order.

Useful? React with 👍 / 👎.

class TileXRCcuDirectRuntime {
public:
int Init(const TileXRCcuDirectRuntimeOptions& options, TileXRCcuDirectRuntimeReport* report);
void Shutdown();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Release direct runtime resources on destruction

When RA-ctx resource-window registration or RA-ctx endpoint collection has created local memory registrations, QPs, CQs, or imported peer QPs, destroying TileXRComm only destroys the unique_ptr and this class has no destructor that calls Shutdown(). That means ReleaseRegisteredResourceWindow()/ReleaseLocalEndpointRoute() never run before the loader unloads, leaking RA resources until process exit and potentially exhausting handles across communicator lifetimes.

Useful? React with 👍 / 👎.

Comment thread src/comm/tilexr_comm.cpp
static_cast<uint32_t>(channelBoundRemoteXnId) <
static_cast<uint32_t>(peerResources.remoteXnStartId) + peerResources.remoteXnCount &&
routeIndex < allocation.channels.num &&
peerResources.channelStartId != 0 &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Accept zero-based channel allocations

When the allocated channel window starts at 0, which TileXRCcuResourceAllocator::Init accepts and zero-initialized public options naturally request, this extra nonzero check marks channelResourceOwnerVerified false even though the peer channel range check succeeds. The install provider later rejects those proofs as an unverified channel owner, so valid zero-based channel allocations can never become submitReady.

Useful? React with 👍 / 👎.

Comment on lines +117 to +121
((spec.doorbellTokenValue >> 20U) & 0xfffU) |
((static_cast<uint32_t>(Log2PowerOfTwo(wqeBasicBlocks)) & 0xfU) << 12U)));
Store16(ctx->raw, 22, static_cast<uint16_t>(
(static_cast<uint32_t>(spec.wqeBasicBlockStartId) & 0xfU) << 12U));
Store16(ctx->raw, 24, static_cast<uint16_t>((spec.wqeBasicBlockStartId >> 4U) & 0xffU));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject local-jetty values that exceed encoded bit fields

When an endpoint provider/env route supplies a large sqDepth whose sqDepth * 4 needs more than the 4 encoded bits, or hcomm_cap mode creates wqeBasicBlockStartId >= 4096 (for example 17+ routes at stride 256), these stores mask/truncate the values while returning success. The emitted local-jetty context then points at the wrong SQ/WQE window; validate those ranges before packing.

Useful? React with 👍 / 👎.

Comment thread src/comm/tilexr_comm.cpp
Comment on lines +1008 to +1010
uint16_t remoteNotifyCke =
static_cast<uint16_t>(static_cast<uint32_t>(peerResources.localWaitCkeStartId) +
peerLocalWaitCkeOffset);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Use peer-local CKE offsets for remote notify

When there are more than two ranks, this uses the local route index as an offset into the peer's localWaitCke window, but each peer orders its wait CKEs by that peer's own peer list. For example rank 0 targeting rank 2 chooses rank 2's wait CKE slot 1 even though rank 2's slot for rank 0 is 0; the proof is still marked verified, so the installed barrier can notify the wrong CKE and hang.

Useful? React with 👍 / 👎.

# Conflicts:
#	tests/comm/unit/test_tilexr_source_guards.cpp

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8e63d9e1e3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/comm/tilexr_comm.cpp
<< ", raInitialized " << (runtimeReport.raInitialized ? 1 : 0)
<< ", ccuTlvInitialized " << (runtimeReport.ccuTlvInitialized ? 1 : 0)
<< ", " << runtimeReport.message << ", direct CCU disabled";
g_ccuDirectRuntimeUnavailable = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Propagate direct CCU init failure across ranks

When one rank hits this init-failure path, the unavailable state is recorded only in that process; other ranks in other processes can still enter PrepareDirectCcuInstallAttempt and proceed to the socket allgathers in ExportRemoteCcuRmaBuffers, while the failed rank returns before participating. In a multi-process job where CCU runtime init fails on just one rank/device, prepare can hang instead of failing collectively, so exchange the availability/error state across ranks before any rank skips the direct-CCU collectives.

Useful? React with 👍 / 👎.

TileXRCcuEndpointTpHandleExchange localTpHandles {};
std::vector<TileXRCcuEndpointTpHandleExchange> allTpHandles;
bool peerTpHandlesReady = false;
if (canImportPeerRoutes) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep TP-handle exchange collective on all ranks

When canImportPeerRoutes differs by rank (for example one rank lacks a verified endpoint route/QP key or has a different exchange-mode env), only ranks that evaluate true enter this options_.allGather; ranks that skip it continue to later exchanges, so the socket allgather sequence diverges and can block or consume the wrong payload. Make this exchange unconditional with an explicit capability/empty handle, or collectively decide import availability before any rank skips the TP-handle allgather.

Useful? React with 👍 / 👎.

program->sqeLoad.clear();
program->sync.clear();
if (plan.taskWindows.size() > 1) {
if (AppendSqeLoadProgram(plan, TILEXR_CCU_SQE_ARGS_LEN, &program->sqeLoad, report) != TILEXR_SUCCESS) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Build SQE-load microcode for the requested arg count

When callers request a partial SQE load (sqeArgCount from 1 to 12), the allocator accepts it and sizes the SQE task window to that count, but this always emits 13 load instructions. The repository builder then rejects the otherwise valid plan because the SQE task window no longer matches the generated microcode, so use the requested task-window count here or reject partial counts before allocation.

Useful? React with 👍 / 👎.

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.

1 participant