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/relay/collage/custom_cost_estimator.cc |
22 | * \brief A custom CostEstimator to support target-specific cost functions. |
23 | */ |
24 | |
25 | #ifndef TVM_RELAY_COLLAGE_CUSTOM_COST_ESTIMATOR_H_ |
26 | #define TVM_RELAY_COLLAGE_CUSTOM_COST_ESTIMATOR_H_ |
27 | |
28 | #include <tvm/relay/function.h> |
29 | |
30 | #include "./cost.h" |
31 | #include "./cost_estimator.h" |
32 | |
33 | namespace tvm { |
34 | namespace relay { |
35 | namespace collage { |
36 | |
37 | /*! |
38 | * \brief A cost estimator that uses a target-specific cost function. |
39 | */ |
40 | class CustomCostEstimatorNode : public CostEstimatorNode { |
41 | public: |
42 | Cost Estimate(const IRModule& mod, const Target& target) const override; |
43 | |
44 | static constexpr const char* _type_key = "relay.collage.CustomCostEstimator" ; |
45 | TVM_DECLARE_FINAL_OBJECT_INFO(CustomCostEstimatorNode, CostEstimatorNode); |
46 | |
47 | protected: |
48 | /*! |
49 | * \brief Python implemented cost function name. |
50 | */ |
51 | String py_fn_estimator_; |
52 | |
53 | friend class CustomCostEstimator; |
54 | }; |
55 | |
56 | class CustomCostEstimator : public CostEstimator { |
57 | public: |
58 | explicit CustomCostEstimator(String py_fn_estimator); |
59 | |
60 | TVM_DEFINE_OBJECT_REF_METHODS(CustomCostEstimator, CostEstimator, CustomCostEstimatorNode); |
61 | }; |
62 | |
63 | } // namespace collage |
64 | } // namespace relay |
65 | } // namespace tvm |
66 | |
67 | #endif // TVM_RELAY_COLLAGE_CUSTOM_COST_ESTIMATOR_H_ |
68 | |