1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
7 #include <gna-api-types-xnn.h>
8 #include "gna_plugin_log.hpp"
9 namespace GNAPluginNS {
12 * represent wrapper that capable to exception save pass c-objects
20 class CPPWrapper<intel_nnet_type_t> {
22 intel_nnet_type_t obj;
26 obj.pLayers = nullptr;
31 * creates nnet structure of n layers
32 * @param n - number of layers
34 explicit CPPWrapper(size_t n) {
36 THROW_GNA_EXCEPTION << "Can't allocate array of intel_nnet_layer_t objects of zero length";
38 obj.pLayers = reinterpret_cast<intel_nnet_layer_t *>(_mm_malloc(n * sizeof(intel_nnet_layer_t), 64));
39 if (obj.pLayers == nullptr) {
40 THROW_GNA_EXCEPTION << "out of memory in while allocating "<< n << " GNA layers";
43 for (int i = 0; i < obj.nLayers; i++) {
44 obj.pLayers[i].pLayerStruct = nullptr;
48 for (int i = 0; i < obj.nLayers; i++) {
49 if (obj.pLayers[i].pLayerStruct != nullptr) {
50 _mm_free(obj.pLayers[i].pLayerStruct);
53 _mm_free(obj.pLayers);
55 intel_nnet_type_t * operator ->() {
58 intel_nnet_type_t * operator *() {
61 operator intel_nnet_type_t &() {
66 } // namespace GNAPluginNS