tvm
measure_record.h
Go to the documentation of this file.
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 
25 #ifndef TVM_AUTO_SCHEDULER_MEASURE_RECORD_H_
26 #define TVM_AUTO_SCHEDULER_MEASURE_RECORD_H_
27 
29 
30 #include <fstream>
31 #include <string>
32 #include <utility>
33 
34 namespace tvm {
35 namespace auto_scheduler {
36 
37 const std::string AUTO_SCHEDULER_LOG_VERSION = "v0.6"; // NOLINT(*)
38 
41  public:
44 
45  void Callback(const SearchPolicy& policy, const Array<MeasureInput>& inputs,
46  const Array<MeasureResult>& results) final;
47 
48  static constexpr const char* _type_key = "auto_scheduler.RecordToFile";
50 };
51 
56 class RecordToFile : public MeasureCallback {
57  public:
62  explicit RecordToFile(String filename);
63 
65 };
66 
68 class RecordReaderNode : public Object {
69  public:
73  std::ifstream infile;
74 
76 
83 
90  std::pair<Array<MeasureInput>, Array<MeasureResult>> ReadLines(int max_size = -1,
91  int skip_size = 0);
92 
93  static constexpr const char* _type_key = "auto_scheduler.RecordReader";
95 
96  private:
98  std::string cur_line_;
99 };
100 
105 class RecordReader : public ObjectRef {
106  public:
111  explicit RecordReader(String filename);
112 
114 };
115 
123 void WriteMeasureRecords(std::ostream* os, const Array<MeasureInput>& inputs,
124  const Array<MeasureResult>& results,
125  const std::string log_version = AUTO_SCHEDULER_LOG_VERSION);
126 
134 void ReadMeasureRecord(const std::string& str, MeasureInputNode* inp, MeasureResultNode* res,
135  std::string* log_version);
136 
137 } // namespace auto_scheduler
138 } // namespace tvm
139 
140 #endif // TVM_AUTO_SCHEDULER_MEASURE_RECORD_H_
Bass class of measurement callbacks.
Definition: measure.h:211
Managed reference to MeasureCallbackNode.
Definition: measure.h:230
Store the input of a measurement.
Definition: measure.h:81
Store the results of a measurement.
Definition: measure.h:162
Log reader to load step logs from a file.
Definition: measure_record.h:68
bool ReadNext(MeasureInputNode *inp, MeasureResultNode *res)
Read next line in the log file.
static constexpr const char * _type_key
Definition: measure_record.h:93
TVM_DECLARE_FINAL_OBJECT_INFO(RecordReaderNode, Object)
std::pair< Array< MeasureInput >, Array< MeasureResult > > ReadLines(int max_size=-1, int skip_size=0)
Read multiple lines from the log file.
std::ifstream infile
The reading file stream.
Definition: measure_record.h:73
String filename
The name of input file.
Definition: measure_record.h:71
Managed reference to RecordReaderNode.
Definition: measure_record.h:105
RecordReader(String filename)
The constructor.
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(RecordReader, ObjectRef, RecordReaderNode)
Callback for logging the input and results of measurements to file.
Definition: measure_record.h:40
String filename
The name of output file.
Definition: measure_record.h:43
static constexpr const char * _type_key
Definition: measure_record.h:48
void Callback(const SearchPolicy &policy, const Array< MeasureInput > &inputs, const Array< MeasureResult > &results) final
Callback function that will be called on measurement input/result pairs after each measurement batch.
TVM_DECLARE_FINAL_OBJECT_INFO(RecordToFileNode, MeasureCallbackNode)
Managed reference to RecordToFileNode.
Definition: measure_record.h:56
RecordToFile(String filename)
The constructor.
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(RecordToFile, MeasureCallback, RecordToFileNode)
Managed reference to SearchPolicyNode.
Definition: search_policy.h:198
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Base class of all object reference.
Definition: object.h:519
base class of all object containers.
Definition: object.h:171
Reference to string objects.
Definition: string.h:98
Distributed measurement infrastructure to measure the runtime costs of tensor programs....
const std::string AUTO_SCHEDULER_LOG_VERSION
Definition: measure_record.h:37
void ReadMeasureRecord(const std::string &str, MeasureInputNode *inp, MeasureResultNode *res, std::string *log_version)
Read one measure record from a string.
void WriteMeasureRecords(std::ostream *os, const Array< MeasureInput > &inputs, const Array< MeasureResult > &results, const std::string log_version=AUTO_SCHEDULER_LOG_VERSION)
Append measure records to an output stream.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36