layer.cc 1.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Copyright (c) 2022 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 "paddle/fluid/jit/layer.h"

17 18 19 20 21 22
#include "paddle/fluid/framework/variable.h"

#include "paddle/fluid/jit/base_function.h"
#include "paddle/fluid/jit/compilation_unit.h"
#include "paddle/fluid/jit/function_schema.h"

23 24
namespace paddle {
namespace jit {
25
Layer::Layer(const Name2VariableMap& params_dict, const phi::Place& place)
26
    : params_dict_(params_dict) {
27
  unit_.reset(new CompilationUnit());
28 29
}

30
std::shared_ptr<BaseFunction> Layer::Function(const std::string& name) const {
31
  return unit_->Function(name);
32 33
}

34 35 36 37 38 39 40
std::vector<Tensor> Layer::forward(const std::vector<Tensor>& inputs) {
  auto func = Function("forward");
  return (*func)(inputs);
}

std::vector<DenseTensor> Layer::forward(
    const std::vector<DenseTensor>& inputs) {
41
  auto func = Function("forward");
42 43 44
  return (*func)(inputs);
}

45 46 47 48
void Layer::to(const phi::Place& place) {}

void Layer::SetFunction(const std::string& name,
                        const std::shared_ptr<BaseFunction>& function) {
49
  unit_->SetFunction(name, function);
50 51
}

52
std::vector<std::string> Layer::FunctionNames() const {
53
  return unit_->FunctionNames();
54 55 56
}

const Name2FunctionMap& Layer::FunctionMap() const {
57
  return unit_->FunctionMap();
58 59
}

60 61
}  // namespace jit
}  // namespace paddle