TODO(hongm): Convert `g` and `init` to using std::unique_ptr.
| 43 | |
| 44 | // TODO(hongm): Convert `g` and `init` to using std::unique_ptr. |
| 45 | Benchmark::Benchmark(const string& device, Graph* g, |
| 46 | const SessionOptions* options, Graph* init, |
| 47 | Rendezvous* rendez, const char* executor_type) { |
| 48 | SessionOptions default_options; |
| 49 | if (!options) { |
| 50 | options = &default_options; |
| 51 | } |
| 52 | |
| 53 | testing::StopTiming(); |
| 54 | string t = absl::AsciiStrToUpper(device); |
| 55 | // Allow NewDevice to allocate a new threadpool with different number of |
| 56 | // threads for each new benchmark. |
| 57 | LocalDevice::set_use_global_threadpool(false); |
| 58 | device_ = |
| 59 | DeviceFactory::NewDevice(t, *options, "/job:localhost/replica:0/task:0"); |
| 60 | CHECK(device_) << "Could not create a " << device << " device"; |
| 61 | |
| 62 | pool_ = |
| 63 | new thread::ThreadPool(options->env, "blocking", port::MaxParallelism()); |
| 64 | |
| 65 | auto runner = [this](std::function<void()> closure) { |
| 66 | pool_->Schedule(closure); |
| 67 | }; |
| 68 | auto cost_runner = [this](std::function<void()> closure, int64 cost) { |
| 69 | pool_->CostSchedule(closure, cost); |
| 70 | }; |
| 71 | |
| 72 | if (rendez == nullptr) { |
| 73 | rendez_ = NewLocalRendezvous(); |
| 74 | } else { |
| 75 | rendez_ = rendez; |
| 76 | } |
| 77 | |
| 78 | const int graph_def_version = g->versions().producer(); |
| 79 | |
| 80 | LocalExecutorParams params; |
| 81 | params.device = device_.get(); |
| 82 | params.function_library = nullptr; |
| 83 | params.create_kernel = [this, graph_def_version](const NodeDef& ndef, |
| 84 | OpKernel** kernel) { |
| 85 | return CreateNonCachedKernel(device_.get(), nullptr, ndef, |
| 86 | graph_def_version, kernel); |
| 87 | }; |
| 88 | params.delete_kernel = [](OpKernel* kernel) { |
| 89 | DeleteNonCachedKernel(kernel); |
| 90 | }; |
| 91 | |
| 92 | if (init) { |
| 93 | std::unique_ptr<Executor> init_exec; |
| 94 | TF_CHECK_OK(NewExecutor(executor_type, params, std::unique_ptr<Graph>(init), |
| 95 | &init_exec)); |
| 96 | Executor::Args args; |
| 97 | args.rendezvous = rendez_; |
| 98 | args.runner = runner; |
| 99 | args.cost_runner = cost_runner; |
| 100 | TF_CHECK_OK(init_exec->Run(args)); |
| 101 | } |
| 102 |
nothing calls this directly
no test coverage detected