Line data Source code
1 : /**
2 : * Copyright (c) 2025 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 "rts_cnt_notify.h"
12 : #include "exception_util.h"
13 : #include "task.h"
14 : #include "dev_capability.h"
15 :
16 : namespace Hccl {
17 :
18 70 : RtsCntNotify::RtsCntNotify()
19 70 : : deviceId(HrtGetDevice()),
20 70 : devPhyId(HrtGetDevicePhyIdByIndex(HrtGetDevice())),
21 70 : handle(HrtCntNotifyCreate(deviceId)),
22 70 : id(HrtGetCntNotifyId(handle))
23 : {
24 70 : HrtDevResInfo devResInfo;
25 70 : devResInfo.dieId = 0;
26 70 : devResInfo.procType = HrtDevResProcType::PROCESS_HCCP;
27 70 : devResInfo.resType = HrtDevResType::RES_TYPE_STARS_CNT_NOTIFY_BIT_WR;
28 70 : devResInfo.resId = id;
29 70 : devResInfo.flag = 0;
30 70 : auto resAddrInfo = HrtGetDevResAddress(devResInfo);
31 70 : addr = resAddrInfo.address;
32 70 : size = DevCapability::GetInstance().GetNotifySize();
33 70 : }
34 :
35 70 : RtsCntNotify::~RtsCntNotify()
36 : {
37 70 : HrtDevResInfo devResInfo;
38 70 : devResInfo.dieId = 0;
39 70 : devResInfo.procType = HrtDevResProcType::PROCESS_HCCP;
40 70 : devResInfo.resType = HrtDevResType::RES_TYPE_STARS_CNT_NOTIFY_BIT_WR;
41 70 : devResInfo.resId = id;
42 70 : devResInfo.flag = 0;
43 70 : DECTOR_TRY_CATCH("RtsCntNotify", HrtReleaseDevResAddress(devResInfo));
44 70 : DECTOR_TRY_CATCH("RtsCntNotify", HrtCntNotifyDestroy(handle));
45 70 : }
46 :
47 0 : std::unique_ptr<BaseTask> RtsCntNotify::PostBits(u32 bitValue)
48 : {
49 0 : return std::make_unique<TaskPostBits>(this, bitValue);
50 : }
51 :
52 0 : std::unique_ptr<BaseTask> RtsCntNotify::WaitValue(u32 value) { return std::make_unique<TaskWaitValue>(this, value); }
53 :
54 12 : void RtsCntNotify::PostBits(u32 bitValue, const Stream& stream) const
55 : {
56 12 : HrtCntNotifyRecord(handle, stream.GetPtr(), HrtCntNotifyRecordMode::WRITE_BIT, bitValue);
57 12 : }
58 :
59 7 : void RtsCntNotify::WaitValue(u32 value, u32 timeout, const aclrtStream& rtStream) const
60 : {
61 7 : HrtCntNotifyWaitWithTimeOut(handle, rtStream, HrtCntNotifyWaitMode::EQUAL, value, timeout);
62 7 : }
63 :
64 4 : void RtsCntNotify::WaitValue(u32 value, u32 timeout, const Stream& stream) const
65 : {
66 4 : WaitValue(value, timeout, stream.GetPtr());
67 4 : }
68 :
69 1 : std::string RtsCntNotify::Describe() const
70 : {
71 1 : return StringFormat("RtsCntNotify[handle=%p, id=%u, addr=0x%llx, size=%u]", handle, id, addr, size);
72 : }
73 :
74 5 : std::vector<char> RtsCntNotify::GetUniqueId() const
75 : {
76 5 : BinaryStream binaryStream;
77 5 : binaryStream << id;
78 5 : binaryStream << devPhyId;
79 5 : std::vector<char> result;
80 5 : binaryStream.Dump(result);
81 5 : return result;
82 5 : }
83 :
84 : } // namespace Hccl
|