| 22 | PD_DECLARE_KERNEL(load_sr, CPU, ALL_LAYOUT); |
| 23 | |
| 24 | TEST(SaveLoadOp, CPU) { |
| 25 | paddle::framework::Scope scope; |
| 26 | phi::CPUPlace place; |
| 27 | |
| 28 | auto var = scope.Var("test_var"); |
| 29 | auto tensor = var->GetMutable<phi::DenseTensor>(); |
| 30 | tensor->Resize({3, 10}); |
| 31 | phi::LegacyLoD expect_lod; |
| 32 | expect_lod.resize(1); |
| 33 | expect_lod[0].push_back(0); |
| 34 | expect_lod[0].push_back(1); |
| 35 | expect_lod[0].push_back(2); |
| 36 | expect_lod[0].push_back(3); |
| 37 | |
| 38 | tensor->set_lod(expect_lod); |
| 39 | int* expect = tensor->mutable_data<int>(place); |
| 40 | for (int64_t i = 0; i < tensor->numel(); ++i) { |
| 41 | expect[i] = static_cast<int>(i); |
| 42 | } |
| 43 | paddle::framework::AttributeMap attrs; |
| 44 | attrs.insert({"file_path", std::string("tensor.save")}); |
| 45 | |
| 46 | auto save_op = paddle::framework::OpRegistry::CreateOp( |
| 47 | "save", {{"X", {"test_var"}}}, {}, attrs); |
| 48 | save_op->Run(scope, place); |
| 49 | |
| 50 | auto load_var = scope.Var("out_var"); |
| 51 | auto target = load_var->GetMutable<phi::DenseTensor>(); |
| 52 | auto load_op = paddle::framework::OpRegistry::CreateOp( |
| 53 | "load", {}, {{"Out", {"out_var"}}}, attrs); |
| 54 | load_op->Run(scope, place); |
| 55 | int* actual = target->data<int>(); |
| 56 | for (int64_t i = 0; i < tensor->numel(); ++i) { |
| 57 | EXPECT_EQ(expect[i], actual[i]); |
| 58 | } |
| 59 | auto& actual_lod = target->lod(); |
| 60 | EXPECT_EQ(expect_lod.size(), actual_lod.size()); |
| 61 | for (size_t i = 0; i < expect_lod.size(); ++i) { // NOLINT |
| 62 | for (size_t j = 0; j < expect_lod[i].size(); ++j) { |
| 63 | EXPECT_EQ(expect_lod[i][j], actual_lod[i][j]); |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | TEST(SaveLoadOpSelectedRows, CPU) { |
| 69 | paddle::framework::Scope scope; |
nothing calls this directly
no test coverage detected