program_translator_test.cc 2.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
// Copyright (c) 2023 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 <gtest/gtest.h>
#include <chrono>
#include <iostream>
#include <map>
#include <string>

#include "paddle/fluid/dialect/pd_dialect.h"
#include "paddle/fluid/framework/framework.pb.h"
#include "paddle/fluid/framework/operator.h"
#include "paddle/fluid/framework/program_desc.h"
#include "paddle/fluid/translator/translate.h"
#include "paddle/ir/builtin_dialect.h"
#include "paddle/ir/dialect.h"
#include "paddle/ir/ir_context.h"
#include "paddle/ir/program.h"

using PaddleDialect = paddle::dialect::PaddleDialect;
using ProgramDesc = paddle::framework::ProgramDesc;
using BlockDesc = paddle::framework::BlockDesc;
using OpDesc = paddle::framework::OpDesc;
using VarDesc = paddle::framework::VarDesc;
using VarType = paddle::framework::proto::VarType;

ProgramDesc load_from_file(const std::string &file_name) {
  std::ifstream fin(file_name, std::ios::in | std::ios::binary);
  fin.seekg(0, std::ios::end);

  std::string buffer(fin.tellg(), ' ');
  fin.seekg(0, std::ios::beg);
  fin.read(&buffer[0], buffer.size());
  fin.close();
  return ProgramDesc(buffer);
}

TEST(PaddleDialectTest, Translator) {
50 51 52
  LOG(WARNING) << "TODO";
  // auto p = load_from_file("restnet50_main.prog");
  // std::cout << p.Size() << std::endl;
53

54
  // EXPECT_EQ(p.Size(), 1u);
55

56 57 58 59
  // ir::IrContext *ctx = ir::IrContext::Instance();
  // ctx->GetOrRegisterDialect<PaddleDialect>();
  // ctx->GetOrRegisterDialect<ir::BuiltinDialect>();
  // auto program = paddle::TranslateLegacyProgramToProgram(p);
60

61
  // std::list<ir::Operation *> ops = program->ops();
62 63 64
  // ops.size() = op size in BlockDesc + get_parameter_op + combine op
  // EXPECT_EQ(ops.size(), p.Block(0).OpSize() + program->parameters_num() +
  // 20); std::cout << *program << std::endl;
65
}