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

Generated by: LCOV version 2.0-1