xref: /aosp_15_r20/external/XNNPACK/src/operator-delete.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Copyright (c) Facebook, Inc. and its affiliates.
2 // All rights reserved.
3 //
4 // Copyright 2019 Google LLC
5 //
6 // This source code is licensed under the BSD-style license found in the
7 // LICENSE file in the root directory of this source tree.
8 
9 #include <stdlib.h>
10 
11 #include <xnnpack.h>
12 #include <xnnpack/allocator.h>
13 #include <xnnpack/log.h>
14 #include <xnnpack/operator.h>
15 #include <xnnpack/params.h>
16 
17 
xnn_delete_operator(xnn_operator_t op)18 enum xnn_status xnn_delete_operator(xnn_operator_t op)
19 {
20   if ((xnn_params.init_flags & XNN_INIT_FLAG_XNNPACK) == 0) {
21     xnn_log_error("failed to delete operator: XNNPACK is not initialized");
22     return xnn_status_uninitialized;
23   }
24 
25   if (op == NULL) {
26     return xnn_status_invalid_parameter;
27   }
28 
29   xnn_release_memory(op->indirection_buffer);
30   if (op->weights_cache == NULL) {
31     xnn_release_simd_memory(op->packed_weights.pointer);
32   }
33   if (op->num_post_operation_params != 0) {
34     xnn_release_memory(op->post_operation_params);
35   }
36   xnn_release_simd_memory(op->zero_buffer);
37   xnn_release_memory(op->pixelwise_buffer);
38   xnn_release_memory(op->subconvolution_buffer);
39   xnn_release_simd_memory(op->lookup_table);
40   xnn_release_simd_memory(op);
41   return xnn_status_success;
42 }
43