Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph Model #18

Open
wants to merge 189 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
7ec10f2
Porting from Ansor graph branch
liaopeiyuan Aug 1, 2021
8cfc7c4
adapting to newest TVM
liaopeiyuan Aug 1, 2021
258856c
more API changes
liaopeiyuan Aug 1, 2021
1bd1afb
include
liaopeiyuan Aug 1, 2021
ccc0464
Update graph_feature.cc
liaopeiyuan Aug 1, 2021
51e93c7
update
liaopeiyuan Aug 1, 2021
1d2e7bd
Update graph_feature.h
liaopeiyuan Aug 1, 2021
5768b81
Update graph_feature.h
liaopeiyuan Aug 1, 2021
75f3ce7
Update graph_feature.cc
liaopeiyuan Aug 1, 2021
2c0a8e7
header
liaopeiyuan Aug 1, 2021
e622637
Update graph_feature.h
liaopeiyuan Aug 1, 2021
19f09d2
Update feature.h
liaopeiyuan Aug 1, 2021
7fb25ce
class in header
liaopeiyuan Aug 1, 2021
b844f0d
header
liaopeiyuan Aug 1, 2021
b1587fe
header
liaopeiyuan Aug 1, 2021
9696358
Update feature.cc
liaopeiyuan Aug 1, 2021
c71137f
Update feature.cc
liaopeiyuan Aug 1, 2021
d7a1e36
Update feature.h
liaopeiyuan Aug 1, 2021
afbc0d6
header
liaopeiyuan Aug 1, 2021
af9c05e
header inheritance
liaopeiyuan Aug 1, 2021
685d4ea
Update feature.h
liaopeiyuan Aug 1, 2021
6d70223
Update feature.cc
liaopeiyuan Aug 1, 2021
ee6ff06
header
liaopeiyuan Aug 1, 2021
e48deae
header
liaopeiyuan Aug 1, 2021
fe5ecfa
Update feature.h
liaopeiyuan Aug 1, 2021
cef2f68
Update feature.h
liaopeiyuan Aug 1, 2021
a0ce1e6
introduce min_cost
liaopeiyuan Aug 1, 2021
2865d3e
graph dataset
liaopeiyuan Aug 1, 2021
6b4cd1d
make graph dataset & initial commit on graph model
liaopeiyuan Aug 1, 2021
e10c900
Update graph_model.py
liaopeiyuan Aug 1, 2021
1391748
Update make_graph_dataset.py
liaopeiyuan Aug 1, 2021
9b97248
Update graph_feature.cc
liaopeiyuan Aug 1, 2021
43fb2cd
Update feature.h
liaopeiyuan Aug 1, 2021
d820905
Update feature.h
liaopeiyuan Aug 1, 2021
e39a498
Update graph_feature.py
liaopeiyuan Aug 1, 2021
6ff311a
Update graph_feature.py
liaopeiyuan Aug 1, 2021
f608f0e
Update graph_feature.py
liaopeiyuan Aug 1, 2021
ddb3cab
debug deserialize
liaopeiyuan Aug 1, 2021
f73e478
Update graph_feature.cc
liaopeiyuan Aug 1, 2021
840cc31
fix bug in graph deserialization
liaopeiyuan Aug 1, 2021
4fb002f
Update graph_feature.py
liaopeiyuan Aug 1, 2021
28e3a63
Update graph_feature.cc
liaopeiyuan Aug 1, 2021
77a6523
Update graph_feature.py
liaopeiyuan Aug 1, 2021
12016c0
Update graph_dataset.py
liaopeiyuan Aug 1, 2021
2bcdf2f
Update graph_dataset.py
liaopeiyuan Aug 1, 2021
130a086
Update graph_dataset.py
liaopeiyuan Aug 1, 2021
c556dec
Update graph_feature.py
liaopeiyuan Aug 1, 2021
6271808
Update graph_feature.py
liaopeiyuan Aug 1, 2021
659deb1
update
liaopeiyuan Aug 1, 2021
fa3fa79
update build pipeline
liaopeiyuan Aug 2, 2021
2b486b1
error ct
liaopeiyuan Aug 2, 2021
7cc097f
Update graph_feature.cc
liaopeiyuan Aug 2, 2021
272f330
debug
liaopeiyuan Aug 2, 2021
527e120
Update feature.cc
liaopeiyuan Aug 2, 2021
6a06c58
Update feature.cc
liaopeiyuan Aug 2, 2021
fa28f60
Update graph_feature.py
liaopeiyuan Aug 2, 2021
616b974
remove parallel for to debug
liaopeiyuan Aug 2, 2021
39a78c7
debug
liaopeiyuan Aug 2, 2021
7822564
Update graph_feature.cc
liaopeiyuan Aug 2, 2021
768ff01
Update graph_feature.cc
liaopeiyuan Aug 2, 2021
42fd00a
Update graph_feature.cc
liaopeiyuan Aug 2, 2021
342c862
Update graph_feature.cc
liaopeiyuan Aug 2, 2021
15fb01f
Update graph_feature.cc
liaopeiyuan Aug 2, 2021
91d60b8
Update graph_feature.cc
liaopeiyuan Aug 2, 2021
1a41f8e
Update graph_feature.cc
liaopeiyuan Aug 2, 2021
70b91cf
Update graph_feature.cc
liaopeiyuan Aug 2, 2021
5d4ae74
Update graph_feature.cc
liaopeiyuan Aug 2, 2021
6d75a49
Update graph_feature.cc
liaopeiyuan Aug 2, 2021
8521f90
Update schedule_ops.cc
liaopeiyuan Aug 2, 2021
959e17a
Update schedule_ops.cc
liaopeiyuan Aug 2, 2021
cc8a321
Update schedule_ops.cc
liaopeiyuan Aug 2, 2021
18fa054
Update schedule_ops.cc
liaopeiyuan Aug 2, 2021
cbb726b
catch schedule ops error
liaopeiyuan Aug 2, 2021
cae8d0c
Update graph_feature.cc
liaopeiyuan Aug 2, 2021
a6c846a
Update graph_feature.cc
liaopeiyuan Aug 2, 2021
f0a222a
clean-up
liaopeiyuan Aug 2, 2021
0253754
Update graph_model.py
liaopeiyuan Aug 2, 2021
5b4fb1a
python interface for graph model
liaopeiyuan Aug 2, 2021
86248c8
name
liaopeiyuan Aug 2, 2021
26dbe85
Update train_graph_model.py
liaopeiyuan Aug 2, 2021
1dcfed7
Update graph_model.py
liaopeiyuan Aug 2, 2021
71bc30d
Update graph_model.py
liaopeiyuan Aug 2, 2021
0328797
Update graph_model.py
liaopeiyuan Aug 2, 2021
000f73d
Update graph_model.py
liaopeiyuan Aug 2, 2021
2ecf391
Update graph_model.py
liaopeiyuan Aug 2, 2021
b51f8c3
Update graph_model.py
liaopeiyuan Aug 2, 2021
4e48dc7
Update graph_model.py
liaopeiyuan Aug 2, 2021
cdcb1a2
Update train_graph_model.py
liaopeiyuan Aug 2, 2021
7e8412e
tuple
liaopeiyuan Aug 2, 2021
103d0ee
training & validation
liaopeiyuan Aug 2, 2021
7801ba9
Update graph_model.py
liaopeiyuan Aug 2, 2021
33f8af1
Update graph_model.py
liaopeiyuan Aug 2, 2021
7a61be0
Update graph_model.py
liaopeiyuan Aug 2, 2021
3d79604
Update graph_model.py
liaopeiyuan Aug 2, 2021
a6a152d
Update graph_model.py
liaopeiyuan Aug 2, 2021
e882158
cuda
liaopeiyuan Aug 2, 2021
f355d37
Update graph_model.py
liaopeiyuan Aug 2, 2021
a5fdef8
Update graph_model.py
liaopeiyuan Aug 2, 2021
1779073
Update graph_model.py
liaopeiyuan Aug 2, 2021
b883315
Update graph_model.py
liaopeiyuan Aug 2, 2021
16d3905
Update graph_model.py
liaopeiyuan Aug 2, 2021
db8ba7a
Update graph_model.py
liaopeiyuan Aug 2, 2021
2a38135
Update graph_model.py
liaopeiyuan Aug 2, 2021
4151cb7
Update graph_model.py
liaopeiyuan Aug 2, 2021
96acc52
Update graph_model.py
liaopeiyuan Aug 2, 2021
4de6091
trying out exponential
liaopeiyuan Aug 2, 2021
24c06da
Update graph_feature.cc
liaopeiyuan Aug 2, 2021
fe1f67d
Update graph_model.py
liaopeiyuan Aug 2, 2021
0936556
Update graph_feature.cc
liaopeiyuan Aug 4, 2021
ee5f04a
integrating buffer feature
Aug 19, 2021
4dd0984
update with new features
Aug 19, 2021
742bf82
pad features
Aug 20, 2021
b86762f
Update graph_feature.cc
Aug 20, 2021
713af14
Update graph_feature.cc
Aug 20, 2021
0f60b43
Update graph_feature.cc
Aug 20, 2021
0452258
Update graph_feature.cc
Aug 20, 2021
ca145d4
Update graph_feature.cc
Aug 20, 2021
9dd0718
Update graph_feature.cc
Aug 20, 2021
9388558
update
Aug 20, 2021
f66563e
Update graph_model.py
Aug 20, 2021
4dcd635
Update graph_model.py
Aug 20, 2021
e277f5e
Update graph_model.py
Aug 20, 2021
697c9ef
SAGEConv
Aug 20, 2021
5105cf8
Update graph_model.py
Aug 20, 2021
142e4ac
Update graph_model.py
Aug 20, 2021
2166bec
Update graph_model.py
Aug 20, 2021
449a46a
Update graph_model.py
Aug 20, 2021
452c8c8
Update graph_model.py
Aug 20, 2021
bf69ff7
Update graph_model.py
Aug 20, 2021
5f5d940
Update graph_model.py
Aug 20, 2021
e9af37f
Update graph_model.py
Aug 20, 2021
0835ffb
Update graph_model.py
Aug 20, 2021
e3ee402
Update graph_model.py
Aug 20, 2021
40dee22
Update graph_model.py
Aug 20, 2021
9ca7e34
Update graph_model.py
Aug 20, 2021
4ef35a6
Update graph_feature.cc
Aug 20, 2021
3c94a8f
Update graph_feature.cc
Aug 20, 2021
2d12163
Update graph_model.py
Aug 20, 2021
2f8be2d
Update graph_model.py
Aug 20, 2021
d77c2d1
Update graph_model.py
Aug 20, 2021
3aff3b4
Update graph_feature.cc
Aug 20, 2021
f45d73d
Update graph_model.py
Aug 20, 2021
61dab1a
Update graph_feature.cc
Aug 20, 2021
f2d5848
update
Aug 20, 2021
9bb6e53
-1 feature
Aug 20, 2021
0111ac1
update
Aug 20, 2021
462b27f
Update graph_feature.cc
Aug 20, 2021
15d18bd
Update graph_feature.cc
Aug 20, 2021
9443617
update
Aug 20, 2021
9e8ac7f
Update graph_model.py
Aug 20, 2021
ed8608f
GNN
Aug 21, 2021
59accc3
Update graph_model.py
Aug 21, 2021
ad341bc
Update graph_model.py
Aug 21, 2021
ada4152
Update graph_model.py
Aug 21, 2021
64ca02d
gnn
Aug 24, 2021
b0a8614
lambda rank loss
Aug 31, 2021
eba32db
Merge branch 'main' into graph-model
Aug 31, 2021
0afd2e4
Update graph_model.py
Aug 31, 2021
5aa2cbc
Merge branch 'graph-model' of https://github.com/liaopeiyuan/tenset i…
Aug 31, 2021
d528cc3
Update graph_model.py
Aug 31, 2021
e6b1524
Update graph_model.py
Aug 31, 2021
bb1b517
Update graph_model.py
Aug 31, 2021
b7a64c4
Update graph_model.py
Aug 31, 2021
1c20679
Update graph_model.py
Aug 31, 2021
2a8d069
Update graph_model.py
Aug 31, 2021
d0ed93f
Update graph_model.py
Aug 31, 2021
38f1826
Update graph_model.py
Aug 31, 2021
7a358a4
Update graph_model.py
Aug 31, 2021
6b7db0e
Update graph_model.py
Aug 31, 2021
5cf4a39
Update graph_model.py
Aug 31, 2021
7b5a791
Update graph_model.py
Aug 31, 2021
ac05021
Update graph_model.py
Aug 31, 2021
694dd26
Update graph_model.py
Aug 31, 2021
f36b71e
Update graph_model.py
Aug 31, 2021
5c00fe4
Update graph_model.py
Aug 31, 2021
6f93909
Update graph_model.py
Aug 31, 2021
2524803
Update graph_model.py
Aug 31, 2021
1172161
Update graph_model.py
Aug 31, 2021
81c27d4
Update graph_model.py
Aug 31, 2021
5d84eeb
Update graph_model.py
Aug 31, 2021
cc56856
Update graph_model.py
Aug 31, 2021
e5e8e4c
Update graph_model.py
Aug 31, 2021
3698a2c
Update graph_model.py
Aug 31, 2021
2b8bf80
Update graph_model.py
Aug 31, 2021
4f481bc
Update graph_model.py
Aug 31, 2021
b996ed5
Update graph_model.py
Aug 31, 2021
f3f16fe
Update graph_model.py
Aug 31, 2021
6bce708
Update graph_model.py
Aug 31, 2021
c93dde2
Update graph_model.py
Aug 31, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions include/tvm/auto_scheduler/feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@

#include <tvm/auto_scheduler/compute_dag.h>
#include <tvm/auto_scheduler/measure.h>
#include <tvm/tir/op_attr_types.h>
#include <tvm/tir/stmt_functor.h>

#include <string>
#include <vector>
#include <unordered_map>

namespace tvm {
namespace auto_scheduler {
Expand Down Expand Up @@ -116,6 +119,125 @@ void GetPerStoreFeaturesFromMeasurePairs(const Array<MeasureInput>& inputs,
std::vector<float>* normalized_throughputs,
std::vector<int>* task_ids);

template <class T>
using BufferMap = std::unordered_map<Buffer, T, ObjectHash, ObjectEqual>;

// Data reuse type
enum class ReuseType : int { kLoopMultipleRead = 0, kSerialMultipleReadWrite = 1, kNoReuse = 2 };

// Buffer access type
enum class BufferAccessType : int { kRead = 0, kWrite = 1, kReadWrite = 2, kUnknownRW = 3 };

struct BufferAccess {
// data reuse type
BufferAccessType acc_type{BufferAccessType::kUnknownRW};
// Use a two-dimensional array to store multiple multi-dimensional accesses.
// The innermost vector stores the multi-dimensional indices of one access.
std::vector<std::vector<PrimExpr>> indices;
};

struct BufferAccessFeature {
std::string buffer_name; // The name of the buffer
BufferAccessType acc_type; // The type of the access
float bytes; // The touched memory in bytes
float unique_bytes; // The touched unique memory in bytes
float lines; // The number of touched cache lines
float unique_lines; // The number touched unique cache lines
ReuseType reuse_type; // Tye type of data reuse
float reuse_dis_iter; // The reuse distance in iterator number
float reuse_dis_bytes; // The reuse distance in total touched bytes
float reuse_ct; // The reuse ratio
float bytes_d_reuse_ct; // bytes / reuse_ct
float unique_bytes_d_reuse_ct; // unique_bytes / reuse_ct
float lines_d_reuse_ct; // lines / reuse_ct
float unique_lines_d_reuse_ct; // unique_lines / reuse_ct
float stride; // The stride in access
};

inline float slog(float x);

int64_t GetLoopExtent(const ForNode* node);

std::tuple<ReuseType, float, float, float> ComputeReuse(
const Buffer& buf,
const std::vector<std::vector<PrimExpr> >& indices,
const std::vector<const ForNode*>& for_loop_stack,
const std::unordered_map<const ForNode*, BufferMap<std::vector<
std::tuple<BufferAccessType, int64_t, int> > > >& for_touch_regions);

void ComputeRegion(
const std::vector<std::vector<PrimExpr> > &indices,
arith::Analyzer* ana,
std::vector<int>* region);

int64_t ComputeStride(const std::vector<std::vector<PrimExpr> >& indices,
const std::vector<int>& shape,
const VarNode* stride_var);

// Extract all buffer accesses in an expr
class BufferAccessExtractor : public StmtExprVisitor {
public:
void ExtractReads(const PrimExpr& expr);

void InsertAccess(const Buffer& buf, BufferAccessType acc_type, const Array<PrimExpr>& indices);

void VisitExpr_(const BufferLoadNode* op) final;

BufferMap<BufferAccess> buf_accesses;
};

// Count math ops in an expr
class MathOpCounter : public StmtExprVisitor {
public:
#define VisitBinary(Type, float_ct, int_ct) \
void VisitExpr_(const Type* op) final;

VisitBinary(AddNode, float_addsub, int_addsub);
VisitBinary(SubNode, float_addsub, int_addsub);
VisitBinary(MulNode, float_mul, int_mul);
VisitBinary(DivNode, float_divmod, int_divmod);
VisitBinary(ModNode, float_divmod, int_divmod);
VisitBinary(FloorDivNode, float_divmod, int_divmod);
VisitBinary(FloorModNode, float_divmod, int_divmod);
VisitBinary(MaxNode, float_cmp, int_cmp);
VisitBinary(MinNode, float_cmp, int_cmp);
VisitBinary(EQNode, float_cmp, int_cmp);
VisitBinary(NENode, float_cmp, int_cmp);
VisitBinary(LTNode, float_cmp, int_cmp);
VisitBinary(LENode, float_cmp, int_cmp);
VisitBinary(GTNode, float_cmp, int_cmp);
VisitBinary(GENode, float_cmp, int_cmp);

#undef VisitBinary

void VisitExpr_(const AndNode* op) final;
void VisitExpr_(const OrNode* op) final;
void VisitExpr_(const NotNode* op) final;
void VisitExpr_(const SelectNode* op) final;
void VisitExpr_(const CallNode* op) final;

// todo(merrymercy): Detect MAD (Multiply–add)
size_t float_mad{0}; // The number of float MAD (Multiply–add) ops
size_t float_addsub{0}; // The number of float add and sub ops
size_t float_mul{0}; // The number of float multiply ops
size_t float_divmod{0}; // The number of float div and mod ops
size_t float_cmp{0}; // The number of float comparison ops
size_t float_math_func{0}; // The number of float math func calls
size_t float_other_func{0}; // The number of other float func calls
size_t int_mad{0}; // The number of integer MAD (Multiply–add) ops
size_t int_addsub{0}; // The number of integer add and sub ops
size_t int_mul{0}; // The number of float multiply ops
size_t int_divmod{0}; // The number of float div and mod ops
size_t int_cmp{0}; // The number of float comparison ops
size_t int_math_func{0}; // The number of float math func calls
size_t int_other_func{0}; // The number of other float func calls
size_t bool_op{0}; // The number of bool ops
size_t select_op{0}; // The number of select ops

OpAttrMap<TCallEffectKind> op_call_effect_ = Op::GetAttrMap<TCallEffectKind>("TCallEffectKind");
};


} // namespace auto_scheduler
} // namespace tvm

Expand Down
98 changes: 98 additions & 0 deletions include/tvm/auto_scheduler/graph_feature.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*!
* \file auto_scheduler/graph_feature.h
* \brief Feature extraction for the graph cost model
*/

#ifndef TVM_AUTO_GRAPH_FEATURE_H_
#define TVM_AUTO_GRAPH_FEATURE_H_

#include <string>
#include <vector>
#include <tvm/auto_scheduler/compute_dag.h>
#include <tvm/auto_scheduler/measure.h>

namespace tvm {
namespace auto_scheduler {

static const int NODE_FEATURE_LENGTH = 142;
static const int EDGE_FEATURE_LENGTH = 4;
struct Edge {
int src;
int dst;
float feature[EDGE_FEATURE_LENGTH];
};

// {"stmtnode": 0, ""}
struct Node {
int node_type;
int id;
float feature[NODE_FEATURE_LENGTH];
};

void GetGraph(const State& state,
const SearchTask& task,
int max_n_bufs,
std::vector<Node>* node_list,
std::vector<Edge>* edge_list);


/*! \brief Get PerStmt feature from states and different tasks */
void GetGraphFromStates(const Array<State>& states,
const std::vector<SearchTask>& tasks,
int max_n_bufs,
std::vector<std::vector<Node> >* node_list,
std::vector<std::vector<Edge> >* edge_list);


/*! \brief Get graph from states and the same task */
void GetGraphFromStates(const Array<State>& states,
const SearchTask task,
int max_n_bufs,
std::vector<std::vector<Node> >* node_list,
std::vector<std::vector<Edge> >* edge_list);


/*! \brief Get graph from a log file */
void GetGraphFromFile(const std::string& filename,
int n_lines,
int max_n_bufs,
std::vector<std::vector<Node> >* node_list,
std::vector<std::vector<Edge> >* edge_list,
std::vector<float>* normalized_throughputs,
std::vector<int>* task_ids);


/*! \brief Get graph from measure pairs */
void GetGraphFromMeasurePairs(const Array<MeasureInput>& inputs,
const Array<MeasureResult>& results,
int skip_first_n_feature_extraction,
int max_n_bufs,
std::vector<std::vector<Node> >* node_list,
std::vector<std::vector<Edge> >* edge_list,
std::vector<float>* normalized_throughputs,
std::vector<int>* task_ids);


} // namespace auto_scheduler
} // namespace tvm

#endif // TVM_AUTO_GRAPH_FEATURE_H_
1 change: 1 addition & 0 deletions python/tvm/auto_scheduler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from . import compute_dag
from . import dataset
from . import graph_dataset
from . import dispatcher
from . import feature
from . import loop_state
Expand Down
1 change: 1 addition & 0 deletions python/tvm/auto_scheduler/cost_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
from .cost_model import RandomModel, RandomModelInternal
from .xgb_model import XGBModel
from .mlp_model import MLPModel
from .graph_model import GraphModel
from .lgbm_model import LGBModel
from .tabnet_model import TabNetModel
Loading