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 HCCLV2_DATA_SLICE_H
12 : #define HCCLV2_DATA_SLICE_H
13 :
14 : #include <sstream>
15 : #include <memory>
16 : #include "buffer_type.h"
17 : #include "types/types.h"
18 : #include "string_util.h"
19 :
20 : namespace Hccl {
21 :
22 : class DataSlice {
23 : public:
24 2 : explicit DataSlice() : type(BufferType::INPUT), offset(0), size(0) {}
25 :
26 : explicit DataSlice(u64 size) : type(BufferType::INPUT), offset(0), size(size) {}
27 :
28 434 : DataSlice(BufferType bufferType, u64 offset, u64 size) : type(bufferType), offset(offset), size(size) {}
29 :
30 18 : bool operator==(const DataSlice& other) const
31 : {
32 18 : return (type == other.type && offset == other.offset && size == other.size);
33 : }
34 :
35 0 : bool operator!=(const DataSlice& other) const
36 : {
37 0 : return (type != other.type || offset != other.offset || size != other.size);
38 : }
39 :
40 264 : std::string Describe() const
41 : {
42 : return StringFormat(
43 792 : "DataSlice[%s, offset=%s, size=%s]", type.Describe().c_str(), Dec2hex(offset).c_str(),
44 1056 : Dec2hex(size).c_str());
45 : }
46 :
47 80 : inline BufferType GetType() const { return type; }
48 :
49 68 : inline u64 GetOffset() const { return offset; }
50 :
51 449 : inline u64 GetSize() const { return size; }
52 :
53 0 : void SetBufferType(const BufferType bufferType) { type = bufferType; }
54 :
55 0 : void SetOffset(u64 off) { offset = off; }
56 :
57 0 : void SetSize(u64 size) { this->size = size; }
58 :
59 : private:
60 : BufferType type;
61 : u64 offset;
62 : u64 size;
63 : };
64 :
65 : inline bool DataSliceSizeIsEqual(std::unique_ptr<DataSlice>& a, std::unique_ptr<DataSlice>& b)
66 : {
67 : return a->GetSize() == b->GetSize();
68 : }
69 :
70 : inline bool
71 : DataSliceSizeIsEqual(std::unique_ptr<DataSlice>& a, std::unique_ptr<DataSlice>& b, std::unique_ptr<DataSlice>& c)
72 : {
73 : return (a->GetSize() == b->GetSize()) && (b->GetSize() == c->GetSize());
74 : }
75 :
76 : } // namespace Hccl
77 : #endif
|