LCOV - code coverage report
Current view: top level - legacy/ascend950/framework/communicator/hostdpu - dpu_kernel_entrance.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 26.3 % 38 10
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 1 1

            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              : #include "dpu_kernel_entrance.h"
      12              : #include "log.h"
      13              : #include "acl/acl_rt.h"
      14              : 
      15              : using namespace Hccl;
      16              : using u64 = unsigned long long;
      17              : std::unordered_map<std::string, std::unordered_map<uint32_t, std::unique_ptr<Hccl::TaskService>>> g_taskServiceMap;
      18              : std::unordered_map<std::string, std::unordered_map<uint32_t, void*>> g_taskExpMemMap;
      19              : std::mutex g_serMapMutex;
      20              : extern "C" {
      21            1 : __attribute__((visibility("default"))) uint32_t RunDpuRpcSrvLaunch(const uint64_t args)
      22              : {
      23            3 :     HCCL_INFO("[%s] Launch Dpu Kernel: 0x%lx", __func__, args);
      24            1 :     if (args == 0) {
      25            0 :         HCCL_ERROR("[%s] args is null.", __func__);
      26            0 :         return HCCL_E_PARA;
      27              :     }
      28              : 
      29            1 :     if (reinterpret_cast<uint64_t>(args) + sizeof(DpuKernelLaunchParam) < reinterpret_cast<uint64_t>(args)) {
      30            0 :         HCCL_ERROR("[%s] Invalid args address.", __func__);
      31            0 :         return HCCL_E_PARA;
      32              :     }
      33              :     // 解析参数信息
      34            1 :     DpuKernelLaunchParam* params = reinterpret_cast<DpuKernelLaunchParam*>(args);
      35              : 
      36            3 :     HCCL_RUN_INFO(
      37              :         "[%s] DpuKernelLaunchParam{commId:%s; memorySize:%lu; deviceMem:%p; hostMem:%p, taskExpMem:%p; devId:%u}",
      38              :         __func__, params->commId.c_str(), params->memorySize, params->deviceMem, params->hostMem, params->taskExpMem,
      39              :         params->deviceId);
      40              : 
      41            1 :     if (params->memorySize == 0) {
      42            0 :         HCCL_ERROR("[%s] memorySize is 0.", __func__);
      43            0 :         return HCCL_E_PARA;
      44              :     }
      45            1 :     if (params->deviceMem == nullptr || params->hostMem == nullptr || params->taskExpMem == nullptr) {
      46            3 :         HCCL_ERROR(
      47              :             "[%s] deviceMem[%p] or hostMem[%p] or taskExpMem[%p] is nullptr.", __func__, params->deviceMem,
      48              :             params->hostMem, params->taskExpMem);
      49            1 :         return HCCL_E_PARA;
      50              :     }
      51              : 
      52              :     // 实例化TaskService
      53              :     std::unique_ptr<Hccl::TaskService> taskService = std::make_unique<Hccl::TaskService>(
      54            0 :         params->deviceMem, params->memorySize, params->hostMem, params->memorySize, params->commId, params->deviceId);
      55              : 
      56            0 :     aclError ret = aclrtSetDevice(params->deviceId);
      57            0 :     if (ret != ACL_SUCCESS) {
      58            0 :         HCCL_ERROR("[%s] set device fail. DeviceId: %u.", __func__, params->deviceId);
      59            0 :         return HCCL_E_RUNTIME;
      60              :     }
      61              : 
      62              :     // 设置到通信域中保存 map<commId, map<devid, TaskService>>与map<commId, map<devid,taskExpMem>>
      63            0 :     HCCL_INFO("[%s] save TaskService", __func__);
      64            0 :     Hccl::TaskService* svcPtr = nullptr;
      65              :     {
      66            0 :         std::lock_guard<std::mutex> lock(g_serMapMutex);
      67            0 :         g_taskServiceMap[params->commId][params->deviceId] = std::move(taskService);
      68            0 :         g_taskExpMemMap[params->commId][params->deviceId] = params->taskExpMem;
      69            0 :         svcPtr = g_taskServiceMap[params->commId][params->deviceId].get();
      70            0 :     }
      71              : 
      72              :     // Run
      73            0 :     HCCL_INFO("[%s] start to TaskRun", __func__);
      74            0 :     HcclResult hcclRet = svcPtr->TaskRun();
      75            0 :     if (hcclRet != HCCL_SUCCESS) {
      76            0 :         uint8_t newFlag = TASK_TERMINATE_RESPONSE;
      77            0 :         errno_t cpyRet = memcpy_s(static_cast<uint8_t*>(params->deviceMem), sizeof(newFlag), &newFlag, sizeof(newFlag));
      78            0 :         if (cpyRet != EOK) {
      79            0 :             HCCL_ERROR("set eixt flag failed: %d", cpyRet);
      80            0 :             return HCCL_E_INTERNAL;
      81              :         }
      82              :     }
      83              : 
      84              :     // End
      85            0 :     return hcclRet;
      86            0 : }
      87              : }
        

Generated by: LCOV version 2.0-1