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 <sstream>
12 : #include "data_buffer_internal.h"
13 : #include "common/resource_statistics.h"
14 : #include "common/log_inner.h"
15 : #include "common/prof_reporter.h"
16 : #include "acl_rt_impl.h"
17 :
18 : #ifdef __cplusplus
19 : extern "C" {
20 : #endif
21 :
22 0 : size_t aclDataTypeSizeImpl(aclDataType dataType)
23 : {
24 0 : switch (dataType) {
25 0 : case ACL_STRING:
26 : case ACL_DT_UNDEFINED:
27 0 : return 0U;
28 0 : case ACL_UINT1:
29 : case ACL_INT4:
30 0 : return 1U;
31 0 : case ACL_BOOL:
32 : case ACL_INT8:
33 : case ACL_UINT8:
34 : case ACL_HIFLOAT8:
35 : case ACL_FLOAT8_E5M2:
36 : case ACL_FLOAT8_E4M3FN:
37 : case ACL_FLOAT8_E8M0:
38 0 : return sizeof(int8_t);
39 0 : case ACL_FLOAT16:
40 : case ACL_INT16:
41 : case ACL_UINT16:
42 : case ACL_BF16:
43 0 : return sizeof(int16_t);
44 0 : case ACL_FLOAT:
45 : case ACL_INT32:
46 : case ACL_UINT32:
47 : case ACL_COMPLEX32:
48 0 : return sizeof(int32_t);
49 0 : case ACL_COMPLEX128:
50 0 : return 2U * sizeof(int64_t);
51 0 : case ACL_INT64:
52 : case ACL_UINT64:
53 : case ACL_DOUBLE:
54 : case ACL_COMPLEX64:
55 : default:
56 0 : return sizeof(int64_t);
57 : }
58 : }
59 :
60 0 : aclDataBuffer* aclCreateDataBufferImpl(void* data, size_t size)
61 : {
62 0 : ACL_PROFILING_REG(acl::AclProfType::AclCreateDataBuffer);
63 0 : ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_DATA_BUFFER);
64 0 : ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_DATA_BUFFER);
65 0 : return new (std::nothrow) aclDataBuffer(data, size);
66 0 : }
67 :
68 0 : aclError aclDestroyDataBufferImpl(const aclDataBuffer* dataBuffer)
69 : {
70 0 : ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_DATA_BUFFER);
71 0 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(dataBuffer);
72 :
73 0 : ACL_DELETE_AND_SET_NULL(dataBuffer);
74 0 : ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_DATA_BUFFER);
75 0 : return ACL_SUCCESS;
76 : }
77 :
78 0 : aclError aclUpdateDataBufferImpl(aclDataBuffer* dataBuffer, void* data, size_t size)
79 : {
80 0 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(dataBuffer);
81 0 : dataBuffer->data = data;
82 0 : dataBuffer->length = size;
83 0 : return ACL_SUCCESS;
84 : }
85 :
86 0 : void* aclGetDataBufferAddrImpl(const aclDataBuffer* dataBuffer)
87 : {
88 0 : if (dataBuffer == nullptr) {
89 0 : return nullptr;
90 : }
91 :
92 0 : return dataBuffer->data;
93 : }
94 :
95 0 : uint32_t aclGetDataBufferSizeImpl(const aclDataBuffer* dataBuffer)
96 : {
97 0 : if (dataBuffer == nullptr) {
98 0 : return 0U;
99 : }
100 :
101 0 : return static_cast<uint32_t>(dataBuffer->length);
102 : }
103 :
104 0 : size_t aclGetDataBufferSizeV2Impl(const aclDataBuffer* dataBuffer)
105 : {
106 0 : if (dataBuffer == nullptr) {
107 0 : return 0U;
108 : }
109 :
110 0 : return static_cast<size_t>(dataBuffer->length);
111 : }
112 : #ifdef __cplusplus
113 : }
114 : #endif
|