| 1 | # Licensed to the Apache Software Foundation (ASF) under one | ||
| 2 | # or more contributor license agreements. See the NOTICE file | ||
| 3 | # distributed with this work for additional information | ||
| 4 | # regarding copyright ownership. The ASF licenses this file | ||
| 5 | # to you under the Apache License, Version 2.0 (the | ||
| 6 | # "License"); you may not use this file except in compliance | ||
| 7 | # with the License. You may obtain a copy of the License at | ||
| 8 | # | ||
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 10 | # | ||
| 11 | # Unless required by applicable law or agreed to in writing, | ||
| 12 | # software distributed under the License is distributed on an | ||
| 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| 14 | # KIND, either express or implied. See the License for the | ||
| 15 | # specific language governing permissions and limitations | ||
| 16 | # under the License. | ||
| 17 | |||
| 18 | package AI::MXNet::Profiler; | ||
| 19 | use strict; | ||
| 20 | use warnings; | ||
| 21 | use AI::MXNet::Base; | ||
| 22 | use AI::MXNet::Function::Parameters; | ||
| 23 | |||
| 24 | =head1 NAME | ||
| 25 | |||
| 26 | AI::MXNet::Profiler - Optional profiler feature. | ||
| 27 | =cut | ||
| 28 | |||
| 29 | =head1 DESCRIPTION | ||
| 30 | |||
| 31 | Optional profirer. | ||
| 32 | =cut | ||
| 33 | |||
| 34 | =head2 profiler_set_config | ||
| 35 | |||
| 36 | Set up the configure of profiler. | ||
| 37 | |||
| 38 | Parameters | ||
| 39 | ---------- | ||
| 40 | kwargs : hash ref | ||
| 41 | Indicates configuration parameters with key/value pairs, listed below | ||
| 42 | profile_symbolic : boolean, whether to profile symbolic operators | ||
| 43 | profile_imperative : boolean, whether to profile imperative operators | ||
| 44 | profile_memory : boolean, whether to profile memory usage | ||
| 45 | profile_api : boolean, whether to profile the C API | ||
| 46 | file_name : string, output file for profile data | ||
| 47 | continuous_dump : boolean, whether to periodically dump profiling data to file | ||
| 48 | dump_period : float, seconds between profile data dumps | ||
| 49 | =cut | ||
| 50 | |||
| 51 | method profiler_set_config(HashRef[Str] $kwargs) | ||
| 52 | { | ||
| 53 | check_call(AI::MXNet::SetProfilerConfig(scalar(keys %{ $kwargs }), $kwargs)); | ||
| 54 | } | ||
| 55 | |||
| 56 | =head2 profiler_set_state | ||
| 57 | |||
| 58 | Set up the profiler state to record operator. | ||
| 59 | |||
| 60 | Parameters | ||
| 61 | ---------- | ||
| 62 | state : int, optional | ||
| 63 | Indicting whether to run the profiler, can | ||
| 64 | be 'stop' - 0 or 'run' - 1. Default is `stop`. | ||
| 65 | =cut | ||
| 66 | |||
| 67 | method profiler_set_state(Int $state) | ||
| 68 | { | ||
| 69 | check_call(AI::MXNet::SetProfilerState($state)); | ||
| 70 | } | ||
| 71 | |||
| 72 | =head2 dump_profile | ||
| 73 | |||
| 74 | Dump profile and stop profiler. Use this to save profile | ||
| 75 | in advance in case your program cannot exit normally | ||
| 76 | =cut | ||
| 77 | |||
| 78 | method dump_profile() | ||
| 79 | { | ||
| 80 | check_call(AI::MXNetCAPI::DumpProfile()); | ||
| 81 | } | ||
| 82 | |||
| 83 | 1; |