1 | /* |
2 | * Licensed to the Apache Software Foundation (ASF) under one |
3 | * or more contributor license agreements. See the NOTICE file |
4 | * distributed with this work for additional information |
5 | * regarding copyright ownership. The ASF licenses this file |
6 | * to you under the Apache License, Version 2.0 (the |
7 | * "License"); you may not use this file except in compliance |
8 | * with the License. You may obtain a copy of the License at |
9 | * |
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * |
12 | * Unless required by applicable law or agreed to in writing, |
13 | * software distributed under the License is distributed on an |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
15 | * KIND, either express or implied. See the License for the |
16 | * specific language governing permissions and limitations |
17 | * under the License. |
18 | */ |
19 | |
20 | /*! |
21 | * \file src/runtime/vm/profiler/vm.h |
22 | * \brief The Relay debug virtual machine. |
23 | */ |
24 | |
25 | #ifndef TVM_RUNTIME_VM_PROFILER_VM_H_ |
26 | #define TVM_RUNTIME_VM_PROFILER_VM_H_ |
27 | |
28 | #include <tvm/runtime/profiling.h> |
29 | #include <tvm/runtime/vm/vm.h> |
30 | |
31 | #include <memory> |
32 | #include <optional> |
33 | #include <string> |
34 | #include <unordered_map> |
35 | #include <vector> |
36 | |
37 | namespace tvm { |
38 | namespace runtime { |
39 | namespace vm { |
40 | |
41 | class VirtualMachineDebug : public VirtualMachine { |
42 | public: |
43 | VirtualMachineDebug() : VirtualMachine(), prof_({}) {} |
44 | |
45 | PackedFunc GetFunction(const std::string& name, const ObjectPtr<Object>& sptr_to_self) final; |
46 | |
47 | void LoadExecutable(const ObjectPtr<Executable>& exec) final; |
48 | |
49 | ~VirtualMachineDebug() {} |
50 | |
51 | private: |
52 | void InvokePacked(Index packed_index, const PackedFunc& func, Index arg_count, Index output_size, |
53 | const std::vector<ObjectRef>& args) final; |
54 | void OpStartHook(Instruction instr) final; |
55 | void OpStopHook() final; |
56 | |
57 | std::unordered_map<Index, std::string> packed_index_map_; |
58 | std::optional<profiling::Profiler> prof_; |
59 | }; |
60 | |
61 | } // namespace vm |
62 | } // namespace runtime |
63 | } // namespace tvm |
64 | |
65 | #endif // TVM_RUNTIME_VM_PROFILER_VM_H_ |
66 | |