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 : #ifndef HCCL_CCU_CTX_SIGNATURE_H
12 : #define HCCL_CCU_CTX_SIGNATURE_H
13 :
14 : #include <sstream>
15 : #include <iostream>
16 : #include <string>
17 : #include <ios>
18 : #include "hash_utils.h"
19 : #include "string_util.h"
20 :
21 : namespace Hccl {
22 :
23 : class CcuCtxSignature {
24 : public:
25 104 : CcuCtxSignature() = default;
26 124 : ~CcuCtxSignature() = default;
27 20 : CcuCtxSignature(const CcuCtxSignature& other)
28 20 : {
29 : // 实现复制构造函数
30 20 : data << other.data.str();
31 20 : }
32 :
33 8 : void operator=(const CcuCtxSignature& other)
34 : {
35 : // 实现赋值操作
36 8 : data << other.data.str();
37 8 : }
38 :
39 20 : bool operator==(const CcuCtxSignature& rhs) const { return this == &rhs || data.str() == rhs.data.str(); }
40 :
41 : // 用法Append<T>(t)
42 : template <typename T>
43 114 : void Append(T t)
44 : {
45 114 : data << t;
46 114 : }
47 :
48 2 : void Append(const CcuCtxSignature& other) { data << other.data.str(); }
49 :
50 49 : std::string Describe() const { return StringFormat("CcuCtxSignature[data=%s]", data.str().c_str()); }
51 :
52 : // 下掉CcuContext GetSignatrue
53 73 : std::string GetData() const { return data.str(); }
54 :
55 : friend class std::hash<Hccl::CcuCtxSignature>;
56 :
57 : private:
58 : std::ostringstream data;
59 : };
60 :
61 : } // namespace Hccl
62 :
63 : namespace std {
64 :
65 : template <>
66 : class hash<Hccl::CcuCtxSignature> {
67 : public:
68 24 : size_t operator()(const Hccl::CcuCtxSignature& signature) const
69 : {
70 24 : auto dataHash = hash<string>{}(signature.GetData());
71 24 : return Hccl::HashCombine({dataHash});
72 : }
73 : };
74 :
75 : } // namespace std
76 :
77 : #endif // HCCL_CCU_CTX_SIGNATURE_H
|