* Copyright (c) 2026 Huawei Technologies Co., Ltd.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*/
* \file handle.cpp
* \brief Handle 管理实现
*/
#include "handle.hpp"
#include <cstring>
#include "securec.h"
#include "acl/acl.h"
#include "tiling/platform/platform_ascendc.h"
#include "platform/soc_spec.h"
#include "cann_ops_tensor.h"
namespace acltensor {
AscendDevice::AscendDevice()
{
aclError aclRet = aclrtGetDevice(&deviceId_);
if (aclRet != ACL_SUCCESS)
{
deviceId_ = 0;
}
auto ascendcPlatform = platform_ascendc::PlatformAscendCManager::GetInstance();
coreNum_ = ascendcPlatform->GetCoreNumAiv();
ascendcPlatform->GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize_);
auto npuArch = ascendcPlatform->GetCurNpuArch();
const char* socNameStr = nullptr;
switch (npuArch)
{
case NpuArch::DAV_3510:
socNameStr = "Ascend950";
socType_ = SocType::ASCEND950;
break;
default:
socNameStr = "Unknown";
socType_ = SocType::UNKNOWN;
break;
}
if (socNameStr != nullptr) {
int ret = memcpy_s(socName_, sizeof(socName_), socNameStr, strlen(socNameStr) + 1);
if (ret != EOK) {
socName_[0] = '\0';
}
}
}
}
acltensorStatus_t acltensorCreate(acltensorHandle_t* handle)
{
if (handle == nullptr)
{
return ACLTENSOR_STATUS_INVALID_VALUE;
}
acltensorHandle* h = new (std::nothrow) acltensorHandle();
if (h == nullptr)
{
return ACLTENSOR_STATUS_ALLOC_FAILED;
}
*handle = h;
return ACLTENSOR_STATUS_SUCCESS;
}
acltensorStatus_t acltensorDestroy(acltensorHandle_t handle)
{
if (handle == nullptr)
{
return ACLTENSOR_STATUS_SUCCESS;
}
delete handle;
return ACLTENSOR_STATUS_SUCCESS;
}