| 37 | using namespace egr_utils_api; // NOLINT |
| 38 | |
| 39 | TEST(Benchmark, EagerScaleCPU) { |
| 40 | // Prepare Device Contexts |
| 41 | eager_test::InitEnv(phi::CPUPlace()); |
| 42 | |
| 43 | for (const std::string mode : {"Accuracy", "Performance"}) { |
| 44 | phi::DDim ddim = common::make_ddim({2, 4, 4, 4}); |
| 45 | paddle::Tensor tensor = |
| 46 | eager_test::CreateTensorWithValue(ddim, |
| 47 | phi::CPUPlace(), |
| 48 | phi::DataType::FLOAT32, |
| 49 | phi::DataLayout::NCHW, |
| 50 | 5.0, |
| 51 | true); |
| 52 | RetainGradForTensor(tensor); |
| 53 | |
| 54 | if (mode == "Accuracy") { |
| 55 | benchmark_eager_scale(tensor, true /* accuracy_check*/); |
| 56 | |
| 57 | } else if (mode == "Performance") { |
| 58 | auto t_start = std::chrono::high_resolution_clock::now(); |
| 59 | #ifdef WITH_GPERFTOOLS |
| 60 | ProfilerStart("eager_scale_cpu.out"); |
| 61 | #endif |
| 62 | benchmark_eager_scale(tensor); |
| 63 | |
| 64 | #ifdef WITH_GPERFTOOLS |
| 65 | ProfilerStop(); |
| 66 | #endif |
| 67 | auto t_end = std::chrono::high_resolution_clock::now(); |
| 68 | double elapsed_time_ms = |
| 69 | std::chrono::duration<double, std::milli>(t_end - t_start).count(); |
| 70 | |
| 71 | std::cout << "Duration: " << elapsed_time_ms << " ms" << std::endl; |
| 72 | |
| 73 | } else { |
| 74 | PADDLE_THROW(common::errors::Fatal("Unknown benchmark mode")); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | TEST(Benchmark, EagerMatmulCPU) { |
| 80 | // Prepare Device Contexts |
nothing calls this directly
no test coverage detected