onnxruntime/core/providers/ngraph/ngraph_custom_op.cc
//This method gets called in critical path of execution: Optimize
This method gets called in critical path of execution: Optimize
This method gets called in critical path of execution : Optimize
Status NGRAPHCustomOp::Compute(const ONNXRunTimeTensor* input_tensors, const size_t num_inputs, ONNXRunTimeTensor* const output_tensors, const size_t num_outputs) const {
  ORT_UNUSED_PARAMETER(num_outputs);
  std::lock_guard<std::mutex> lock(compute_lock_);
  Initialize(input_tensors, num_inputs);
  ORT_ENFORCE(ng_curr_exe_ != nullptr);
  std::vector<std::shared_ptr<ngraph::runtime::Tensor>> ng_inputs;
  std::vector<std::shared_ptr<ngraph::runtime::Tensor>> ng_outputs;
  try {
    auto& in_tensor = input_tensors;
    for (const auto& ng_param : ng_curr_exe_->get_parameters()) {
      ng_inputs.emplace_back(ng_backend_->create_tensor(ng_param->get_output_element_type(0), ng_param->get_output_shape(0), (in_tensor++)->data));
    }
  } catch (const std::exception& exp) {
    return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Exception while copying input data to nGraph: " + std::string(exp.what()));
  } catch (...) {
    return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Unknown exception while copying input data to nGraph");
  }
  try {
    auto onxr_output = output_tensors;
    for (auto& ng_result : ng_curr_exe_->get_results()) {
      const auto& dtype = ng_result->get_element_type();
      const auto& shape = ng_result->get_shape();
      onxr_output->dtype = GetDataType(dtype);
      onxr_output->ndim = shape.size();
      onxr_output->shape = new int64_t[onxr_output->ndim];
      size_t num_elements = 1;
      for (size_t dim = 0; dim < shape.size(); dim++) {
        num_elements *= shape[dim];
        onxr_output->shape[dim] = shape[dim];
      }
      onxr_output->data = (*(allocate_func_))(allocator_, 64, num_elements * sizeof(onxr_output->dtype));
      ng_outputs.emplace_back(ng_backend_->create_tensor(dtype, shape, onxr_output->data));
      ++onxr_output;
    }
  } catch (const std::exception& exp) {
    return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Exception while creating nGraph output Tensor: " + std::string(exp.what()));
  } catch (...) {
    return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Unknown exception while creating nGraph output Tensor");
  }
  try {
    if (!ng_curr_exe_->call(ng_outputs, ng_inputs))
      return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Error while executing nGraph computation");
  } catch (const std::exception& exp) {
    return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Exception while executing nGraph computation: " + std::string(exp.what()));
  } catch (...) {
    return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Unknown exception while executing nGraph computation");
  }
  return Status::OK();
}
Status NGRAPHCustomOp :: Compute ( const ONNXRunTimeTensor * input_tensors , const size_t num_inputs , ONNXRunTimeTensor * const output_tensors , const size_t num_outputs ) const { ORT_UNUSED_PARAMETER ( num_outputs ) ; std :: lock_guard < std :: mutex > lock ( compute_lock_ ) ; Initialize ( input_tensors , num_inputs ) ; ORT_ENFORCE ( ng_curr_exe_ != nullptr ) ; std :: vector < std :: shared_ptr < ngraph :: runtime :: Tensor > > ng_inputs ; std :: vector < std :: shared_ptr < ngraph :: runtime :: Tensor > > ng_outputs ; try { auto & in_tensor = input_tensors ; for ( const auto & ng_param : ng_curr_exe_ -> get_parameters ( ) ) { ng_inputs . emplace_back ( ng_backend_ -> create_tensor ( ng_param -> get_output_element_type ( 0 ) , ng_param -> get_output_shape ( 0 ) , ( in_tensor ++ ) -> data ) ) ; } } catch ( const std :: exception & exp ) { return ORT_MAKE_STATUS ( ONNXRUNTIME , FAIL , " " + std :: string ( exp . what ( ) ) ) ; } catch ( ... ) { return ORT_MAKE_STATUS ( ONNXRUNTIME , FAIL , " " ) ; } try { auto onxr_output = output_tensors ; for ( auto & ng_result : ng_curr_exe_ -> get_results ( ) ) { const auto & dtype = ng_result -> get_element_type ( ) ; const auto & shape = ng_result -> get_shape ( ) ; onxr_output -> dtype = GetDataType ( dtype ) ; onxr_output -> ndim = shape . size ( ) ; onxr_output -> shape = new int64_t [ onxr_output -> ndim ] ; size_t num_elements = 1 ; for ( size_t dim = 0 ; dim < shape . size ( ) ; dim ++ ) { num_elements *= shape [ dim ] ; onxr_output -> shape [ dim ] = shape [ dim ] ; } onxr_output -> data = ( * ( allocate_func_ ) ) ( allocator_ , 64 , num_elements * sizeof ( onxr_output -> dtype ) ) ; ng_outputs . emplace_back ( ng_backend_ -> create_tensor ( dtype , shape , onxr_output -> data ) ) ; ++ onxr_output ; } } catch ( const std :: exception & exp ) { return ORT_MAKE_STATUS ( ONNXRUNTIME , FAIL , " " + std :: string ( exp . what ( ) ) ) ; } catch ( ... ) { return ORT_MAKE_STATUS ( ONNXRUNTIME , FAIL , " " ) ; } try { if ( ! ng_curr_exe_ -> call ( ng_outputs , ng_inputs ) ) return ORT_MAKE_STATUS ( ONNXRUNTIME , FAIL , " " ) ; } catch ( const std :: exception & exp ) { return ORT_MAKE_STATUS ( ONNXRUNTIME , FAIL , " " + std :: string ( exp . what ( ) ) ) ; } catch ( ... ) { return ORT_MAKE_STATUS ( ONNXRUNTIME , FAIL , " " ) ; } return Status :: OK ( ) ; }
This method gets called in critical path of execution: Optimize
This method gets called in critical path of execution : Optimize
//TODO: Minimize locked region // Initialize nGraph function if it is not already initialized. // Write ONNXR input data to nGraph input tensors. // Initialize output tensors //TODO: Optimize // Run the graph through nGraph.