Line data Source code
1 : /**
2 : * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "ccu_rep_v1.h"
12 : #include "string_util.h"
13 : #include "exception_util.h"
14 : #include "ccu_api_exception.h"
15 : #include "hcomm_c_adpt.h"
16 : #include "ccu_ins_generator_v1.h"
17 : #include "../../../../endpoint_pairs/channels/ccu/ccu_urma_channel.h"
18 : #include "ccu_ins_generator_base.h"
19 : #include "ccu_kernel.h"
20 :
21 : namespace hcomm {
22 : namespace CcuRep {
23 :
24 6 : CcuRepBufWrite::CcuRepBufWrite(
25 : CcuInsGeneratorBase* insGenPtr, const ChannelHandle channel, CcuBuf src, RemoteAddr dst, Variable len,
26 6 : CompletedEvent sem, uint16_t mask)
27 6 : : insGenPtr(insGenPtr),
28 6 : channel(channel),
29 6 : src(src),
30 6 : dst(dst),
31 6 : len(len),
32 6 : sem(sem),
33 6 : mask(mask)
34 : {
35 6 : type = CcuRepType::BUF_WRITE;
36 6 : instrCount = insGenPtr->GetInstrCount(type);
37 6 : }
38 :
39 1 : bool CcuRepBufWrite::Translate(CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& instrId, const TransDep& dep)
40 : {
41 1 : this->instrId = instrId;
42 1 : translated = true;
43 :
44 1 : instrCount = insGenPtr->GetInstrCount(type);
45 1 : CHK_PRT_THROW(
46 : insGenPtr->CcuRepBufWriteTranslate(ccuKernel, instr, this, dep) != HcclResult::HCCL_SUCCESS,
47 : HCCL_ERROR("[CcuRepBufWrite][Translate] failed to translate for instrId[%u]", instrId),
48 : Hccl::CcuApiException, "CcuRepBufWrite translate failed");
49 1 : instrId += instrCount;
50 :
51 1 : return translated;
52 : }
53 :
54 1 : std::string CcuRepBufWrite::Describe()
55 : {
56 1 : void* channelPtr{nullptr};
57 1 : auto ret = HcommChannelGet(channel, &channelPtr);
58 1 : if (ret != HcclResult::HCCL_SUCCESS) {
59 0 : Hccl::THROW<Hccl::CcuApiException>("failed to get ccu channel, type[%d]", type);
60 : }
61 :
62 1 : auto* channelImpl = dynamic_cast<CcuUrmaChannel*>(static_cast<Channel*>(channelPtr));
63 1 : if (channelImpl == nullptr) {
64 0 : Hccl::THROW<Hccl::CcuApiException>(
65 : "[%s] failed to cast channel[0x%llx] to CcuUrmaChannel", __func__, channel);
66 : }
67 : return Hccl::StringFormat(
68 3 : "Write CcuBuf[%u] To Rmt Mem[%u], len[%u], ChannalId[%u], sem[%u], mask[%04x]", src.Id(), dst.addr.Id(),
69 2 : len.Id(), channelImpl->GetChannelId(), sem.Id(), mask);
70 : }
71 :
72 : }; // namespace CcuRep
73 : }; // namespace hcomm
|