-
Notifications
You must be signed in to change notification settings - Fork 8
feat(ccu): integrate internal collective backend #76
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
Draft
Kur0x
wants to merge
2
commits into
codex/ccu-stack-04-runtime
Choose a base branch
from
codex/ccu-stack-05-backend
base: codex/ccu-stack-04-runtime
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /* | ||
| * Copyright (c) 2024-2026 TileXR Project | ||
| * This file is a part of the CANN Open Software. | ||
| * Licensed under CANN Open Software License Agreement Version 1.0 (the "License"). | ||
| * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| * See LICENSE in the root of the software repository for the full text of the License. | ||
| */ | ||
| #include "collective_backend.h" | ||
|
|
||
| #include "../../comm/ccu/tilexr_ccu_backend.h" | ||
| #include "../../comm/tilexr_comm.h" | ||
|
|
||
| namespace TileXRCollectives { | ||
| namespace Host { | ||
| namespace { | ||
|
|
||
| BackendTestState g_testState {}; | ||
|
|
||
| int DispatchAiv(const CollectiveRequest &request) | ||
| { | ||
| (void)request; | ||
| return g_testState.enabled ? g_testState.aivReturn : TileXR::TILEXR_SUCCESS; | ||
| } | ||
|
|
||
| int DispatchUdma(const CollectiveRequest &request) | ||
| { | ||
| if (g_testState.enabled) { | ||
| if (!g_testState.udmaInitialized) { | ||
| return TileXR::TILEXR_ERROR_NOT_INITIALIZED; | ||
| } | ||
| return g_testState.udmaSupported ? g_testState.udmaReturn : TileXR::TILEXR_ERROR_NOT_SUPPORT; | ||
| } | ||
|
|
||
| auto *comm = static_cast<TileXR::TileXRComm *>(request.comm); | ||
| if (comm == nullptr || !comm->IsUdmaAvailableForCollectives()) { | ||
| return TileXR::TILEXR_ERROR_NOT_INITIALIZED; | ||
| } | ||
| return TileXR::TILEXR_ERROR_NOT_SUPPORT; | ||
| } | ||
|
|
||
| int DispatchCcu(const CollectiveRequest &request) | ||
| { | ||
| if (g_testState.enabled) { | ||
| if (!g_testState.ccuInitialized) { | ||
| return TileXR::TILEXR_ERROR_NOT_INITIALIZED; | ||
| } | ||
| return g_testState.ccuSupported ? g_testState.ccuReturn : TileXR::TILEXR_ERROR_NOT_SUPPORT; | ||
| } | ||
|
|
||
| auto *comm = static_cast<TileXR::TileXRComm *>(request.comm); | ||
| TileXR::TileXRCcuBackend *backend = comm->GetCcuBackendForCollectives(); | ||
| if (backend == nullptr || !backend->Available()) { | ||
| return TileXR::TILEXR_ERROR_NOT_INITIALIZED; | ||
| } | ||
| TileXR::TileXRCcuCollectiveRequest ccuRequest {}; | ||
| ccuRequest.type = request.type; | ||
| ccuRequest.sendBuf = request.sendBuf; | ||
| ccuRequest.recvBuf = request.recvBuf; | ||
| ccuRequest.count = request.count; | ||
| ccuRequest.dataType = request.dataType; | ||
| ccuRequest.reduceOp = request.reduceOp; | ||
| ccuRequest.root = request.root; | ||
| ccuRequest.stream = request.stream; | ||
| TileXR::TileXRCcuCollectivePlan plan {}; | ||
| const int ret = backend->PrepareCollective(ccuRequest, &plan); | ||
| if (ret != TileXR::TILEXR_SUCCESS) { | ||
| return ret; | ||
| } | ||
| return backend->SubmitCollective(plan, request.stream); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| int DispatchCollective(const CollectiveRequest &request, TileXRCollectiveBackend backend) | ||
| { | ||
| if (request.comm == nullptr || request.sendBuf == nullptr || request.recvBuf == nullptr || request.count <= 0) { | ||
| return TileXR::TILEXR_ERROR_PARA_CHECK_FAIL; | ||
| } | ||
|
|
||
| switch (backend) { | ||
| case TILEXR_COLLECTIVE_BACKEND_AIV: | ||
| return DispatchAiv(request); | ||
| case TILEXR_COLLECTIVE_BACKEND_UDMA: | ||
| return DispatchUdma(request); | ||
| case TILEXR_COLLECTIVE_BACKEND_CCU: | ||
| return DispatchCcu(request); | ||
| case TILEXR_COLLECTIVE_BACKEND_AUTO: | ||
| default: | ||
| if (g_testState.enabled && g_testState.ccuInitialized && g_testState.ccuSupported) { | ||
| return DispatchCcu(request); | ||
| } | ||
| if (g_testState.enabled && g_testState.udmaInitialized && g_testState.udmaSupported) { | ||
| return DispatchUdma(request); | ||
| } | ||
| return DispatchAiv(request); | ||
| } | ||
| } | ||
|
|
||
| void SetBackendTestState(const BackendTestState &state) | ||
| { | ||
| g_testState = state; | ||
| g_testState.enabled = true; | ||
| } | ||
|
|
||
| void ResetBackendTestState() | ||
| { | ||
| g_testState = BackendTestState {}; | ||
| } | ||
|
|
||
| } // namespace Host | ||
| } // namespace TileXRCollectives | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Copyright (c) 2024-2026 TileXR Project | ||
| * This file is a part of the CANN Open Software. | ||
| * Licensed under CANN Open Software License Agreement Version 1.0 (the "License"). | ||
| * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| * See LICENSE in the root of the software repository for the full text of the License. | ||
| */ | ||
| #ifndef TILEXR_COLLECTIVES_HOST_COLLECTIVE_BACKEND_H | ||
| #define TILEXR_COLLECTIVES_HOST_COLLECTIVE_BACKEND_H | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| #include "acl/acl_base.h" | ||
| #include "tilexr_collectives.h" | ||
| #include "tilexr_types.h" | ||
|
|
||
| namespace TileXRCollectives { | ||
| namespace Host { | ||
|
|
||
| struct CollectiveRequest { | ||
| TileXR::TileXRType type = TileXR::TileXRType::ALL_GATHER; | ||
| void *sendBuf = nullptr; | ||
| void *recvBuf = nullptr; | ||
| int64_t count = 0; | ||
| TileXR::TileXRDataType dataType = TileXR::TILEXR_DATA_TYPE_RESERVED; | ||
| TileXR::TileXRReduceOp reduceOp = TileXR::TILEXR_REDUCE_RESERVED; | ||
| int root = 0; | ||
| TileXRCommPtr comm = nullptr; | ||
| aclrtStream stream = nullptr; | ||
| }; | ||
|
|
||
| struct BackendTestState { | ||
| bool enabled = false; | ||
| bool udmaInitialized = false; | ||
| bool udmaSupported = false; | ||
| int udmaReturn = TileXR::TILEXR_ERROR_NOT_SUPPORT; | ||
| bool ccuInitialized = false; | ||
| bool ccuSupported = false; | ||
| int ccuReturn = TileXR::TILEXR_ERROR_NOT_SUPPORT; | ||
| int aivReturn = TileXR::TILEXR_SUCCESS; | ||
| }; | ||
|
|
||
| int DispatchCollective(const CollectiveRequest &request, TileXRCollectiveBackend backend); | ||
| void SetBackendTestState(const BackendTestState &state); | ||
| void ResetBackendTestState(); | ||
|
|
||
| } // namespace Host | ||
| } // namespace TileXRCollectives | ||
|
|
||
| #endif // TILEXR_COLLECTIVES_HOST_COLLECTIVE_BACKEND_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In production this condition is always true for a forced CCU request: none of the normal
TileXRComminitialization paths callInitCcuBackend; the only caller isEnableCcuBackendForTest. Consequently the newly publicTILEXR_COLLECTIVE_BACKEND_CCUoption always returnsTILEXR_ERROR_NOT_INITIALIZED. Please initialize the backend in the normal communicator lifecycle or lazily before dispatch.