1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
7 #include "gna-api-dumper.h"
8 #include "gna-api-instrumentation.h"
16 * holds gna - style handle in RAII way
18 class GNADeviceHelper {
19 intel_gna_status_t nGNAStatus = GNA_NOERROR;
20 intel_gna_handle_t nGNAHandle = 0;
21 intel_gna_proc_t nGNAProcType = GNA_AUTO;
22 intel_gna_perf_t nGNAPerfResults;
23 intel_gna_perf_t nGNAPerfResultsTotal;
24 const uint32_t GNA_TIMEOUT = MAX_TIMEOUT;
25 bool isPerformanceMeasuring;
28 explicit GNADeviceHelper(intel_gna_proc_t proc_type = GNA_AUTO,
29 uint8_t lib_async_n_threads = 1,
30 bool use_openmp = false,
31 bool isPerformanceMeasuring = false) :
32 nGNAProcType(proc_type),
33 isPerformanceMeasuring(isPerformanceMeasuring) {
34 initGnaPerfCounters();
35 open(lib_async_n_threads);
38 uint8_t num_cores = std::thread::hardware_concurrency();
39 setOMPThreads((num_cores != 0) ? num_cores : 1);
47 uint8_t *alloc(uint32_t size_requested, uint32_t *size_granted);
49 void propagateSync(const intel_nnet_type_t *pNeuralNetwork,
50 const uint32_t *pActiveIndices,
51 uint32_t nActiveIndices);
53 uint32_t propagate(const intel_nnet_type_t *pNeuralNetwork,
54 const uint32_t *pActiveIndices,
55 uint32_t nActiveIndices);
57 void wait(uint32_t id);
61 intel_gna_model_header header;
62 std::shared_ptr<void> model;
65 DumpResult dumpXnn(const intel_nnet_type_t *pNeuralNetwork,
66 const uint32_t *pActiveIndices,
67 uint32_t nActiveIndices);
73 void updateGnaPerfCounters();
74 void getGnaPerfCounters(std::map<std::string,
75 InferenceEngine::InferenceEngineProfileInfo>& retPerfCounters);
78 void open(uint8_t const n_threads);
82 void checkStatus() const;
84 void setOMPThreads(uint8_t const n_threads);
86 void initGnaPerfCounters() {
87 nGNAPerfResults = {{0, 0, 0, 0, 0, 0, 0}, {0, 0}, {0, 0, 0}, {0, 0}};
88 nGNAPerfResultsTotal = {{0, 0, 0, 0, 0, 0, 0}, {0, 0}, {0, 0, 0}, {0, 0}};