r''' Start profiler and enter the first profiler step(0). State transformed from CLOSED to self.current_state and trigger corresponding action. Examples: .. code-block:: pycon :name: code-example4 >>> # doctest: +REQUIRES(env:GPU)
(self)
| 592 | self.stop() |
| 593 | |
| 594 | def start(self) -> None: |
| 595 | r''' |
| 596 | Start profiler and enter the first profiler step(0). |
| 597 | State transformed from CLOSED to self.current_state and trigger corresponding action. |
| 598 | |
| 599 | Examples: |
| 600 | .. code-block:: pycon |
| 601 | :name: code-example4 |
| 602 | |
| 603 | >>> # doctest: +REQUIRES(env:GPU) |
| 604 | >>> import paddle.profiler as profiler |
| 605 | >>> import paddle |
| 606 | >>> paddle.device.set_device('gpu') |
| 607 | >>> prof = profiler.Profiler( |
| 608 | ... targets=[profiler.ProfilerTarget.CPU, profiler.ProfilerTarget.GPU], |
| 609 | ... scheduler=(1, 9), |
| 610 | ... on_trace_ready=profiler.export_chrome_tracing('./log'), |
| 611 | ... ) |
| 612 | >>> prof.start() |
| 613 | >>> for iter in range(10): |
| 614 | ... # train() |
| 615 | ... prof.step() |
| 616 | >>> prof.stop() |
| 617 | |
| 618 | ''' |
| 619 | # Timing only without profiling. |
| 620 | benchmark().begin() |
| 621 | if not self.timer_only or self.emit_nvtx: |
| 622 | utils._is_profiler_used = True |
| 623 | if self.timer_only: |
| 624 | return |
| 625 | if self.record_shapes or self.with_flops: |
| 626 | enable_op_info_recorder() |
| 627 | if self.profile_memory: |
| 628 | enable_memory_recorder() |
| 629 | # CLOSED -> self.current_state |
| 630 | if self.current_state == ProfilerState.READY: |
| 631 | self.profiler.prepare() |
| 632 | elif self.current_state == ProfilerState.RECORD: |
| 633 | self.profiler.prepare() |
| 634 | self.profiler.start() |
| 635 | elif self.current_state == ProfilerState.RECORD_AND_RETURN: |
| 636 | self.profiler.prepare() |
| 637 | self.profiler.start() |
| 638 | self.record_event = RecordEvent( |
| 639 | name=f"ProfileStep#{self.step_num}", |
| 640 | event_type=TracerEventType.ProfileStep, |
| 641 | ) |
| 642 | self.record_event.begin() |
| 643 | |
| 644 | def stop(self) -> None: |
| 645 | r''' |