|
44 | 44 | */ |
45 | 45 | aclDataType ggml_cann_type_mapping(ggml_type type); |
46 | 46 |
|
47 | | -// Deleter for aclTensor. |
48 | | -struct acl_tensor_deleter { |
49 | | - void operator()(aclTensor * ptr) const noexcept { |
50 | | - if (ptr != nullptr) { |
51 | | - ACL_CHECK(aclDestroyTensor(ptr)); |
| 47 | +// Deleter for acl objects. |
| 48 | +template <typename T, aclError (*DestroyFunc)(const T *)> struct acl_deleter { |
| 49 | + void operator()(T * ptr) const noexcept { |
| 50 | + if (ptr) { |
| 51 | + ACL_CHECK(DestroyFunc(ptr)); |
52 | 52 | } |
53 | 53 | } |
54 | 54 | }; |
55 | 55 |
|
56 | | -// Deleter for aclIntArray. |
57 | | -struct acl_int_array_deleter { |
58 | | - void operator()(aclIntArray * ptr) const noexcept { |
59 | | - if (ptr != nullptr) { |
60 | | - ACL_CHECK(aclDestroyIntArray(ptr)); |
61 | | - } |
62 | | - } |
63 | | -}; |
64 | | - |
65 | | -// Deleter for aclScalar. |
66 | | -struct acl_scalar_deleter { |
67 | | - void operator()(aclScalar * ptr) const noexcept { |
68 | | - if (ptr != nullptr) { |
69 | | - ACL_CHECK(aclDestroyScalar(ptr)); |
70 | | - } |
71 | | - } |
72 | | -}; |
73 | | - |
74 | | -// Deleter for aclTensorList. |
75 | | -struct acl_tensor_list_deleter { |
76 | | - void operator()(aclTensorList * ptr) const noexcept { |
77 | | - if (ptr != nullptr) { |
78 | | - ACL_CHECK(aclDestroyTensorList(ptr)); |
79 | | - } |
80 | | - } |
81 | | -}; |
82 | | - |
83 | | -using acl_tensor_ptr = std::unique_ptr<aclTensor, acl_tensor_deleter>; |
84 | | -using acl_int_array_ptr = std::unique_ptr<aclIntArray, acl_int_array_deleter>; |
85 | | -using acl_scalar_ptr = std::unique_ptr<aclScalar, acl_scalar_deleter>; |
86 | | -using acl_tensor_list_ptr = std::unique_ptr<aclTensorList, acl_tensor_list_deleter>; |
| 56 | +using acl_tensor_ptr = std::unique_ptr<aclTensor, acl_deleter<aclTensor, aclDestroyTensor>>; |
| 57 | +using acl_int_array_ptr = std::unique_ptr<aclIntArray, acl_deleter<aclIntArray, aclDestroyIntArray>>; |
| 58 | +using acl_scalar_ptr = std::unique_ptr<aclScalar, acl_deleter<aclScalar, aclDestroyScalar>>; |
| 59 | +using acl_tensor_list_ptr = std::unique_ptr<aclTensorList, acl_deleter<aclTensorList, aclDestroyTensorList>>; |
87 | 60 |
|
88 | 61 | /** |
89 | 62 | * @brief Creates an ACL tensor from a ggml_tensor with optional shape. |
|
0 commit comments