| 135 | } |
| 136 | |
| 137 | void TimeAdd(const std::vector<int64>& x_shape, |
| 138 | const std::vector<int64>& y_shape, int64 iterations) { |
| 139 | TestAddShape(x_shape, y_shape); |
| 140 | |
| 141 | Scope root = Scope::NewRootScope(); |
| 142 | |
| 143 | Tensor x_quantized_tensor(DT_QUINT8, TensorShape(x_shape)); |
| 144 | Output placeholder = Placeholder(root.WithOpName("placeholder"), DT_QUINT8); |
| 145 | Output x_min = Const(root.WithOpName("x_min"), 0.0f); |
| 146 | Output x_max = Const(root.WithOpName("x_max"), 1.0f); |
| 147 | |
| 148 | Tensor y_quantized_tensor(DT_QUINT8, TensorShape(y_shape)); |
| 149 | Output y = |
| 150 | Const(root.WithOpName("y"), Input::Initializer(y_quantized_tensor)); |
| 151 | Output y_min = Const(root.WithOpName("y_min"), 0.0f); |
| 152 | Output y_max = Const(root.WithOpName("y_max"), 1.0f); |
| 153 | |
| 154 | ops::QuantizedAdd add = ops::QuantizedAdd(root.WithOpName("add"), placeholder, |
| 155 | y, x_min, x_max, y_min, y_max); |
| 156 | |
| 157 | TF_EXPECT_OK(root.status()); |
| 158 | |
| 159 | ClientSession session(root); |
| 160 | std::vector<Tensor> outputs; |
| 161 | |
| 162 | int64 total_duration = 0; |
| 163 | for (int i = 0; i < iterations; ++i) { |
| 164 | const int64 start_time = Env::Default()->NowMicros(); |
| 165 | TF_EXPECT_OK(session.Run({{placeholder, x_quantized_tensor}}, |
| 166 | {add.z, add.min_z, add.max_z}, &outputs)); |
| 167 | const int64 end_time = Env::Default()->NowMicros(); |
| 168 | total_duration += end_time - start_time; |
| 169 | } |
| 170 | const int64 one_run_duration = total_duration / iterations; |
| 171 | |
| 172 | const int64 num_ops = outputs[0].NumElements(); |
| 173 | |
| 174 | const double million_ops_per_second = |
| 175 | (iterations * num_ops) / static_cast<double>(total_duration); |
| 176 | |
| 177 | LOG(INFO) << "TimeAdd: " << TensorShape(x_shape).DebugString() << " * " |
| 178 | << TensorShape(y_shape).DebugString() |
| 179 | << ": iterations=" << iterations |
| 180 | << ", MOps/s=" << million_ops_per_second |
| 181 | << ", one_run_duration=" << one_run_duration |
| 182 | << ", total_duration=" << total_duration; |
| 183 | } |
| 184 | |
| 185 | void TestManualScalar() { |
| 186 | TestAdd( |
no test coverage detected