* Copyright (c) 2025 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.
*/
#include <sstream>
#include "data_buffer_internal.h"
#include "common/resource_statistics.h"
#include "common/log_inner.h"
#include "common/prof_reporter.h"
#include "acl_rt_impl.h"
#ifdef __cplusplus
extern "C" {
#endif
size_t aclDataTypeSizeImpl(aclDataType dataType)
{
switch (dataType) {
case ACL_STRING:
case ACL_DT_UNDEFINED:
return 0U;
case ACL_UINT1:
case ACL_INT4:
return 1U;
case ACL_BOOL:
case ACL_INT8:
case ACL_UINT8:
case ACL_HIFLOAT8:
case ACL_FLOAT8_E5M2:
case ACL_FLOAT8_E4M3FN:
case ACL_FLOAT8_E8M0:
return sizeof(int8_t);
case ACL_FLOAT16:
case ACL_INT16:
case ACL_UINT16:
case ACL_BF16:
return sizeof(int16_t);
case ACL_FLOAT:
case ACL_INT32:
case ACL_UINT32:
case ACL_COMPLEX32:
return sizeof(int32_t);
case ACL_COMPLEX128:
return 2U * sizeof(int64_t);
case ACL_INT64:
case ACL_UINT64:
case ACL_DOUBLE:
case ACL_COMPLEX64:
default:
return sizeof(int64_t);
}
}
aclDataBuffer *aclCreateDataBufferImpl(void *data, size_t size)
{
ACL_PROFILING_REG(acl::AclProfType::AclCreateDataBuffer);
ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_DATA_BUFFER);
ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_DATA_BUFFER);
return new(std::nothrow) aclDataBuffer(data, size);
}
aclError aclDestroyDataBufferImpl(const aclDataBuffer *dataBuffer)
{
ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_DATA_BUFFER);
ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(dataBuffer);
ACL_DELETE_AND_SET_NULL(dataBuffer);
ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_DATA_BUFFER);
return ACL_SUCCESS;
}
aclError aclUpdateDataBufferImpl(aclDataBuffer *dataBuffer, void *data, size_t size)
{
ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(dataBuffer);
dataBuffer->data = data;
dataBuffer->length = size;
return ACL_SUCCESS;
}
void *aclGetDataBufferAddrImpl(const aclDataBuffer *dataBuffer)
{
if (dataBuffer == nullptr) {
return nullptr;
}
return dataBuffer->data;
}
uint32_t aclGetDataBufferSizeImpl(const aclDataBuffer *dataBuffer)
{
if (dataBuffer == nullptr) {
return 0U;
}
return static_cast<uint32_t>(dataBuffer->length);
}
size_t aclGetDataBufferSizeV2Impl(const aclDataBuffer *dataBuffer)
{
if (dataBuffer == nullptr) {
return 0U;
}
return static_cast<size_t>(dataBuffer->length);
}
#ifdef __cplusplus
}
#endif