while_op_helper.h 2.0 KB
Newer Older
S
sneaxiy 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// Copyright (c) 2019 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.

#pragma once

#include <memory>
#include <string>
#include <vector>
W
wanghuancoder 已提交
20

S
sneaxiy 已提交
21
#include "paddle/fluid/framework/operator.h"
22
#include "paddle/fluid/operators/controlflow/op_variant.h"
S
sneaxiy 已提交
23 24
#include "paddle/fluid/platform/variant.h"

W
wanghuancoder 已提交
25 26 27 28 29 30 31
namespace paddle {
namespace framework {
class LoDTensor;
class ProgramDesc;
}  // namespace framework
}  // namespace paddle

S
sneaxiy 已提交
32 33 34 35 36 37 38 39 40 41
namespace paddle {
namespace operators {

static constexpr char kStepBlock[] = "sub_block";
static constexpr char kCondition[] = "Condition";
static constexpr char kStepScopes[] = "StepScopes";
static constexpr char kX[] = "X";
static constexpr char kXGRAD[] = "X@GRAD";
static constexpr char kOutputs[] = "Out";
static constexpr char kSkipEagerDeletionVars[] = "skip_eager_deletion_vars";
42
static constexpr char kSuffix[] = "@TMP_COPY";
S
sneaxiy 已提交
43 44

void PrepareSafeEagerDeletionOnWhileOpAndWhileGradOp(
45
    const framework::ProgramDesc &program, int block_id,
S
sneaxiy 已提交
46 47 48
    const std::vector<std::unique_ptr<framework::OperatorBase>> &all_ops);

void PrepareSafeEagerDeletionOnWhileOpAndWhileGradOp(
49
    const framework::ProgramDesc &program,
50 51
    const std::vector<OpVariant> &while_ops,
    const std::vector<OpVariant> &while_grad_ops);
S
sneaxiy 已提交
52

53 54
bool GetCondData(const framework::LoDTensor &cond);

55 56 57
bool StrInVaraiableNameMap(const std::string &,
                           const framework::VariableNameMap &);

S
sneaxiy 已提交
58 59
}  // namespace operators
}  // namespace paddle