/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include "framework/operator.h" #include "operators/op_param.h" namespace paddle_mobile { namespace framework { template vector OperatorBase::GetOutKeys() const { auto it = op_input_output_key.find(type_); if (it == op_input_output_key.end()) { DLOG << type_ << " has no outputs"; return {}; } return it->second.second; } template vector OperatorBase::GetInputKeys() const { auto it = op_input_output_key.find(type_); if (it == op_input_output_key.end()) { DLOG << type_ << " has no outputs"; return {}; } return it->second.first; } template OperatorBase::OperatorBase(const std::string &type, const VariableNameMap &inputs, const VariableNameMap &outputs, const AttributeMap &attrs, std::shared_ptr scope) : type_(type), inputs_(inputs), outputs_(outputs), attrs_(attrs), scope_(scope) { CheckAllInputOutputSet(); } template void OperatorBase::CheckAllInputOutputSet() const {} template void OperatorBase::Run() { DLOG << " begin run " << type_; RunImpl(); DLOG << " end run " << type_; return; #ifdef PADDLE_MOBILE_DEBUG DLOG << "-------------" << type_ << "----------------------------"; vector input_keys = GetInputKeys(); for (const auto key : input_keys) { auto var_vec_in = inputs_.at(key); for (int i = 0; i < var_vec_in.size(); ++i) { auto vari = scope_->FindVar(var_vec_in[i]); if (vari->IsInitialized()) { #ifdef PADDLE_MOBILE_CL if (type_ == "feed") { Tensor *tensor = vari->template GetMutable(); if (tensor) DLOG << type_ << " input- " << key << "=" << *tensor; } else { CLImage *cl_image = vari->template GetMutable(); // cl_command_queue commandQueue = // scope_->GetCLScpoe()->CommandQueue(); Tensor // *tmp ; // CLImageToTensor(cl_image,tmp,commandQueue); // tmp->Resize(cl_image->dims()); const float *input = cl_image->data(); if (cl_image) { DLOG << type_ << " input- " << key << "=" << cl_image->dims(); // if(input) // DLOG<template GetMutable(); if (tensor) { DLOG << type_ << " output- " << key << "=" << tensor->dims(); } } else { CLImage *cl_image = vari->template GetMutable(); // cl_command_queue commandQueue = // scope_->GetCLScpoe()->CommandQueue(); Tensor *tmp ; // CLImageToTensor(cl_image,tmp,commandQueue); // tmp->Resize(cl_image->dims()); if (cl_image) { const float *output = cl_image->data(); DLOG << type_ << " output- " << key << "=" << cl_image->dims(); // if(output) // DLOG<