LCOV - code coverage report
Current view: top level - acl/acl_tdt_channel - tensor_data_transfer.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 35 35
Test Date: 2026-07-28 10:53:01 Functions: 100.0 % 8 8

            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 ACL_TENSOR_DATA_TRANSFER_H
      12              : #define ACL_TENSOR_DATA_TRANSFER_H
      13              : #include <string.h>
      14              : #include <string>
      15              : #include <vector>
      16              : #include <memory>
      17              : 
      18              : #include "acl/acl_tdt.h"
      19              : 
      20              : enum datasetMemType { MEM_UNKNOWN = 0, MEM_HOST, MEM_DEVICE };
      21              : 
      22              : struct acltdtDataItem {
      23           32 :     acltdtDataItem(
      24              :         acltdtTensorType tdtType, const int64_t* dims, size_t dimNum, const std::string& dimsStr, aclDataType type,
      25              :         const std::string& typeStr, std::shared_ptr<void> tensorData, size_t size)
      26           32 :     {
      27           32 :         this->tdtType = tdtType;
      28          118 :         for (size_t i = 0; i < dimNum; ++i) {
      29           86 :             this->dims.push_back(dims[i]);
      30              :         }
      31           32 :         this->dimsStr = dimsStr;
      32           32 :         this->dataType = type;
      33           32 :         this->dataTypeStr = typeStr;
      34           32 :         this->dataLen = size;
      35           32 :         this->dataPtr = tensorData;
      36           32 :         this->priorityData_ = nullptr;
      37           32 :         this->sliceNum = 0;
      38           32 :         this->sliceId = 0;
      39           32 :     }
      40            2 :     acltdtDataItem() = default;
      41           33 :     ~acltdtDataItem() = default;
      42              :     acltdtTensorType tdtType;
      43              :     std::vector<int64_t> dims;
      44              :     std::string dimsStr;
      45              :     aclDataType dataType;
      46              :     std::string dataTypeStr;
      47              :     size_t dataLen;
      48              :     std::shared_ptr<void> dataPtr;
      49              :     void* priorityData_; // this addr can not be free because it is passed by outside
      50              :     uint16_t sliceNum;
      51              :     uint16_t sliceId;
      52              : };
      53              : 
      54              : struct acltdtDataset {
      55           39 :     acltdtDataset() : freeSelf(false){};
      56           38 :     ~acltdtDataset()
      57              :     {
      58           38 :         if (freeSelf) {
      59           12 :             for (auto iter = blobs.begin(); iter != blobs.end(); ++iter) {
      60            3 :                 (void)acltdtDestroyDataItem(*iter);
      61              :             }
      62              :         }
      63           38 :     }
      64              :     std::string name;
      65              :     std::vector<acltdtDataItem*> blobs;
      66              :     datasetMemType memType = MEM_UNKNOWN;
      67              :     bool freeSelf;
      68              :     // mem reuse for performance optimization, used in acltdtReceiveTensor process
      69              :     size_t sharedMemSize_ = 0U;
      70              :     std::shared_ptr<void> sharedMem_;
      71              : };
      72              : 
      73              : struct acltdtChannelHandle {
      74           26 :     acltdtChannelHandle(uint32_t deviceId, const char* channelName)
      75           26 :     {
      76           26 :         devId = deviceId;
      77           26 :         isTdtProcess = true;
      78           26 :         qid = 0U;
      79           26 :         if (channelName != nullptr) {
      80           26 :             name = channelName;
      81           26 :             size_t prefixLen = sizeof("TF_RECEIVE_") - 1;
      82           26 :             if (strncmp(channelName, "TF_RECEIVE_", prefixLen) == 0) {
      83            3 :                 recvName = channelName + prefixLen;
      84              :             }
      85              :         }
      86           26 :     }
      87            1 :     acltdtChannelHandle() = default;
      88           27 :     ~acltdtChannelHandle() = default;
      89              :     std::string name;
      90              :     std::string recvName;
      91              :     uint32_t devId;
      92              :     uint32_t qid;
      93              :     bool isTdtProcess;
      94              :     std::shared_ptr<void> ctx_;
      95              : };
      96              : 
      97              : namespace acl {
      98              : constexpr size_t RESERVED_SIZE = 24U;
      99              : aclError acltdtSendTensorV2(const acltdtChannelHandle* handle, const acltdtDataset* dataset, int32_t timeout);
     100              : 
     101              : aclError acltdtReceiveTensorV2(const acltdtChannelHandle* handle, acltdtDataset* dataset, int32_t timeout);
     102              : 
     103              : aclError GetOrMallocHostMem(const acltdtChannelHandle* handle, acltdtDataset* dataset, size_t bufLen, void*& hostPtr);
     104              : 
     105              : #pragma pack(push, 1)
     106              : struct ItemInfo {
     107              :     int32_t version = 0;
     108              :     int32_t dataType = 0;
     109              :     uint32_t curCnt = 0U;
     110              :     uint32_t cnt = 0U;
     111              :     int32_t tensorType = 0;
     112              :     uint32_t dimNum = 0U;
     113              :     uint32_t dynamicBitSize = 0U;
     114              :     uint16_t sliceNum = 0;
     115              :     uint16_t sliceId = 0;
     116              :     char reserved[RESERVED_SIZE] = {0};
     117              :     uint64_t dataLen = 0LU;
     118              : };
     119              : #pragma pack(pop)
     120              : 
     121              : struct aclTdtDataItemInfo {
     122              :     ItemInfo ctrlInfo;
     123              :     std::vector<int64_t> dims;
     124              :     std::shared_ptr<void> dataPtr;
     125              :     void* priorityDataPtr_ = nullptr;
     126              : };
     127              : } // namespace acl
     128              : #endif // ACL_TENSOR_DATA_TRANSFER_H
        

Generated by: LCOV version 2.0-1