未验证 提交 e011e34a 编写于 作者: Q Qiao Longfei 提交者: GitHub

Merge pull request #12310 from jacquesqiao/add-profiler-to-train-demo

add profiler for demo_trainer
1 合并请求!12383Port py3 syntax
......@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <time.h>
#include <fstream>
#include "paddle/fluid/framework/executor.h"
......@@ -21,6 +22,7 @@
#include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/platform/init.h"
#include "paddle/fluid/platform/place.h"
#include "paddle/fluid/platform/profiler.h"
namespace paddle {
namespace train {
......@@ -93,11 +95,21 @@ int main() {
auto loss_var = scope.Var(loss_name);
paddle::platform::ProfilerState pf_state;
pf_state = paddle::platform::ProfilerState::kCPU;
paddle::platform::EnableProfiler(pf_state);
clock_t t1 = clock();
for (int i = 0; i < 10; ++i) {
executor.Run(*train_program.get(), &scope, 0, false, true);
std::cout << "step: " << i << " loss: "
<< loss_var->Get<paddle::framework::LoDTensor>().data<float>()[0]
<< std::endl;
}
clock_t t2 = clock();
paddle::platform::DisableProfiler(paddle::platform::EventSortingKey::kTotal,
"run_paddle_op_profiler");
std::cout << "run_time = " << t2 - t1 << std::endl;
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
反馈
建议
客服 返回
顶部