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 "exception_util.h"
12 : #include "ccu_api_exception.h"
13 : #include "hcomm_c_adpt.h"
14 : #include "../../../../endpoint_pairs/channels/ccu/ccu_urma_channel.h"
15 : #include "ccu_ins_generator_base.h"
16 :
17 : namespace hcomm {
18 : namespace CcuRep {
19 :
20 6 : CcuRepBufRead::CcuRepBufRead(
21 : CcuInsGeneratorBase* insGenPtr, const ChannelHandle channel, RemoteAddr src, CcuBuf dst, Variable len,
22 6 : CompletedEvent sem, uint32_t mask)
23 6 : : insGenPtr(insGenPtr),
24 6 : channel(channel),
25 6 : src(src),
26 6 : dst(dst),
27 6 : len(len),
28 6 : sem(sem),
29 6 : mask(mask)
30 : {
31 6 : type = CcuRepType::BUF_READ;
32 6 : instrCount = insGenPtr->GetInstrCount(type);
33 6 : }
34 :
35 1 : bool CcuRepBufRead::Translate(CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& instrId, const TransDep& dep)
36 : {
37 1 : this->instrId = instrId;
38 1 : translated = true;
39 :
40 1 : CHK_PRT_THROW(
41 : insGenPtr->CcuRepBufReadTranslate(ccuKernel, instr, this, dep) != HcclResult::HCCL_SUCCESS,
42 : HCCL_ERROR("[CcuRepBufRead][Translate] failed to translate for instrId[%u]", instrId),
43 : Hccl::CcuApiException, "CcuRepBufRead translate failed");
44 1 : instrId += instrCount;
45 :
46 1 : return translated;
47 : }
48 :
49 1 : std::string CcuRepBufRead::Describe()
50 : {
51 1 : void* channelPtr{nullptr};
52 1 : auto ret = HcommChannelGet(channel, &channelPtr);
53 1 : if (ret != HcclResult::HCCL_SUCCESS) {
54 0 : Hccl::THROW<Hccl::CcuApiException>("failed to get ccu channel, type[%d]", type);
55 : }
56 :
57 1 : auto* channelImpl = dynamic_cast<CcuUrmaChannel*>(static_cast<Channel*>(channelPtr));
58 1 : if (channelImpl == nullptr) {
59 0 : Hccl::THROW<Hccl::CcuApiException>(
60 : "[%s] failed to cast channel[0x%llx] to CcuUrmaChannel", __func__, channel);
61 : }
62 : return Hccl::StringFormat(
63 3 : "Read Rmt Mem[%u] To CcuBuf[%u], len[%u], ChannalId[%u], sem[%u], mask[%04x]", src.addr.Id(), dst.Id(),
64 2 : len.Id(), channelImpl->GetChannelId(), sem.Id(), mask);
65 : }
66 :
67 : }; // namespace CcuRep
68 : }; // namespace hcomm
|