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 : #ifndef HCCLV2_HDC_LITE_H
11 : #define HCCLV2_HDC_LITE_H
12 :
13 : #include <mutex>
14 : #include <memory>
15 : #include "hdc_param.h"
16 : #include "buffer.h"
17 : #include "types.h"
18 :
19 : namespace Hccl {
20 : // HDCommunicateLite为device侧提供host和device之间的单向通道;如接收端未及时读取buffer中的数据,可能会导致数据丢失,需要使用者自行确保收发两端的应答确认机制。
21 :
22 : class HDCommunicateLite {
23 : public:
24 168 : HDCommunicateLite() = default;
25 :
26 : HcclResult Init(const struct HDCommunicateParams ¶ms);
27 :
28 : HcclResult Put(u32 offset, u32 length, u8 *value);
29 :
30 : HcclResult Get(u32 offset, u32 length, u8 *value);
31 :
32 : private:
33 : HcclResult Write(u32 offset, u32 length, u8 *value);
34 : HcclResult Read(u32 offset, u32 length, u8 *value);
35 : HcclResult UpdateCache(u32 timeoutSec);
36 :
37 : std::unique_ptr<Buffer> devMem;
38 : u32 deviceLogicId{ 0xFFFFFFFF };
39 : u32 flag{ HCCLV2_HDC_TYPE_D2H };
40 : u32 buffLen{ 0 };
41 :
42 : void *readCacheAddr{ nullptr };
43 : u32 *headCntAddr{ nullptr };
44 : u32 *tailCntAddr{ nullptr };
45 : u32 *devHeadCntAddr{ nullptr };
46 : u32 *devTailCntAddr{ nullptr };
47 : std::mutex shmLock;
48 : };
49 : }
50 : #endif // HCCLV2_HDC_LITE_H
|