4444 */
4545aclDataType ggml_cann_type_mapping (ggml_type type);
4646
47+ // Deleter for aclTensor.
4748struct acl_tensor_deleter {
4849 void operator ()(aclTensor * ptr) const noexcept {
4950 if (ptr != nullptr ) {
@@ -52,8 +53,7 @@ struct acl_tensor_deleter {
5253 }
5354};
5455
55- using acl_tensor_ptr = std::unique_ptr<aclTensor, acl_tensor_deleter>;
56-
56+ // Deleter for aclIntArray.
5757struct acl_int_array_deleter {
5858 void operator ()(aclIntArray * ptr) const noexcept {
5959 if (ptr != nullptr ) {
@@ -62,8 +62,7 @@ struct acl_int_array_deleter {
6262 }
6363};
6464
65- using acl_int_array_ptr = std::unique_ptr<aclIntArray, acl_int_array_deleter>;
66-
65+ // Deleter for aclScalar.
6766struct acl_scalar_deleter {
6867 void operator ()(aclScalar * ptr) const noexcept {
6968 if (ptr != nullptr ) {
@@ -72,8 +71,7 @@ struct acl_scalar_deleter {
7271 }
7372};
7473
75- using acl_scalar_ptr = std::unique_ptr<aclScalar, acl_scalar_deleter>;
76-
74+ // Deleter for aclTensorList.
7775struct acl_tensor_list_deleter {
7876 void operator ()(aclTensorList * ptr) const noexcept {
7977 if (ptr != nullptr ) {
@@ -82,6 +80,9 @@ struct acl_tensor_list_deleter {
8280 }
8381};
8482
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>;
8586using acl_tensor_list_ptr = std::unique_ptr<aclTensorList, acl_tensor_list_deleter>;
8687
8788/* *
@@ -161,9 +162,61 @@ acl_tensor_ptr ggml_cann_create_tensor(void * data_ptr,
161162 return acl_tensor_ptr (raw);
162163}
163164
165+ /* *
166+ * @brief Create an ACL int array resource wrapped in a smart pointer.
167+ *
168+ * This function constructs an aclIntArray from the provided int64_t values
169+ * and returns it as an acl_int_array_ptr (a std::unique_ptr with a custom
170+ * deleter). The returned pointer owns the ACL resource and will automatically
171+ * destroy it via aclDestroyIntArray().
172+ *
173+ * @param value Pointer to the int64_t elements.
174+ * @param size Number of elements in value.
175+ *
176+ * @return A smart pointer managing the created ACL int array.
177+ */
164178acl_int_array_ptr ggml_cann_create_int_array (const int64_t * value, uint64_t size);
165- acl_scalar_ptr ggml_cann_create_scalar (void * value, aclDataType dataType);
166179
180+ /* *
181+ * @brief Create an ACL scalar resource wrapped in a smart pointer.
182+ *
183+ * This function constructs an aclScalar from the raw value pointer and ACL
184+ * data type, then returns it as an acl_scalar_ptr (a std::unique_ptr with
185+ * a custom deleter). The returned pointer owns the ACL scalar and will
186+ * automatically destroy it via aclDestroyScalar().
187+ *
188+ * @param value Pointer to the raw scalar memory.
189+ * @param dataType ACL data type of the scalar.
190+ *
191+ * @return A smart pointer managing the created ACL scalar.
192+ */
193+ acl_scalar_ptr ggml_cann_create_scalar (void * value, aclDataType dataType);
194+
195+ /* *
196+ * @brief Create an ACL tensor list from multiple tensor smart pointers.
197+ *
198+ * This function accepts a variadic list of acl_tensor_ptr (a unique_ptr with
199+ * custom deleter) and produces an aclTensorList using aclCreateTensorList().
200+ *
201+ * The lifecycle management of the tensor objects changes as follows:
202+ * - aclCreateTensorList() takes ownership of the tensors
203+ * - Each input smart pointer releases ownership using release()
204+ * - As a result, the tensors will NOT be destroyed by unique_ptr
205+ * - Instead, they will be destroyed when aclDestroyTensorList() is called
206+ *
207+ * This ensures correct ownership transfer and prevents double-free situations.
208+ *
209+ * @param acl_tensor_ptr Variadic template parameter; each argument must be
210+ * a unique_ptr-like type supporting get() and release().
211+ *
212+ * @param tensors Variadic list of acl_tensor_ptr objects. Ownership of
213+ * each tensor is transferred away from these smart pointers.
214+ *
215+ * @return A smart pointer (acl_tensor_list_ptr) owning the created ACL tensor list.
216+ *
217+ * @note This implementation is C++11 compatible. The ownership-release process is
218+ * executed using a pack expansion inside an initializer list.
219+ */
167220template <typename ... acl_tensor_ptr> acl_tensor_list_ptr ggml_cann_create_tensor_list (acl_tensor_ptr &&... tensors) {
168221 aclTensor * raw_tensors[] = { tensors.get ()... };
169222 aclTensorList * raw = aclCreateTensorList (raw_tensors, sizeof ...(tensors));
0 commit comments