graph.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Intel Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <algorithm>
18 #include <string>
19 #include <utility>
20 #include <vector>
21 #include <ros/console.h>
24 #include "movidius_ncs_lib/graph.h"
26 
27 namespace movidius_ncs_lib
28 {
29 
30 Graph::Graph(const std::shared_ptr<Device>& device,
31  const std::string& graph_buf,
32  int network_dimension)
33  : graph_buf_(graph_buf),
34  network_dimension_(network_dimension),
35  handle_(nullptr)
36 {
37  allocate(device->getHandle());
38 }
39 
41 {
42  try
43  {
44  deallocate();
45  }
46  catch (MvncException& e)
47  {
49  }
50 }
51 
52 std::string Graph::getDebugInfo()
53 {
54  assert(handle_ != nullptr);
55  char* debug_info;
56  unsigned int length;
57  int ret = mvncGetGraphOption(handle_,
58  MVNC_DEBUG_INFO,
59  reinterpret_cast<void**>(&debug_info),
60  &length);
62  std::string result(debug_info);
63  return result;
64 }
65 
67 {
68  assert(handle_ != nullptr);
69  float* time_taken;
70  unsigned int length;
71  int ret = mvncGetGraphOption(handle_,
72  MVNC_TIME_TAKEN,
73  reinterpret_cast<void**>(&time_taken),
74  &length);
76  length /= sizeof(*time_taken);
77  float sum = 0;
78 
79  for (unsigned int i = 0; i < length; ++i)
80  {
81  sum += time_taken[i];
82  }
83 
84  return sum;
85 }
86 
88 {
89  assert(handle_ != nullptr);
90  return handle_;
91 }
92 
93 void Graph::allocate(void* device_handle)
94 {
95  int ret = mvncAllocateGraph(device_handle,
96  &handle_,
97  graph_buf_.c_str(),
98  graph_buf_.size());
100 }
101 
103 {
104  int ret = mvncDeallocateGraph(handle_);
106 }
107 } // namespace movidius_ncs_lib
std::string graph_buf_
Definition: graph.h:54
static void tryToThrowMvncException(int code)
const char * what() const noexcept
Definition: exception.h:34
std::string getDebugInfo()
Definition: graph.cpp:52
void allocate(void *device_handle)
Definition: graph.cpp:93
#define ROS_ERROR_STREAM(args)
Graph(const Device::Ptr &device, const std::string &graph_file, int network_dimension)
Definition: graph.cpp:30


movidius_ncs_lib
Author(s): Xiaojun Huang
autogenerated on Mon Jun 10 2019 14:11:23