Skip to content

Commit

Permalink
inline functions, fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Brookhart committed Jul 13, 2020
1 parent c61ac20 commit e64ee53
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
50 changes: 27 additions & 23 deletions src/relay/op/nn/convolution_make.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ namespace tvm {
namespace relay {

template <typename T>
Expr MakeConv(Expr data, Expr weight, Array<IndexExpr> strides, Array<IndexExpr> padding,
Array<IndexExpr> dilation, int groups, IndexExpr channels,
Array<IndexExpr> kernel_size, std::string data_layout, std::string kernel_layout,
std::string out_layout, DataType out_dtype, std::string op_name) {
inline Expr MakeConv(Expr data, Expr weight, Array<IndexExpr> strides, Array<IndexExpr> padding,
Array<IndexExpr> dilation, int groups, IndexExpr channels,
Array<IndexExpr> kernel_size, std::string data_layout,
std::string kernel_layout, std::string out_layout, DataType out_dtype,
std::string op_name) {
auto attrs = make_object<T>();
attrs->strides = std::move(strides);
attrs->padding = std::move(padding);
Expand All @@ -55,11 +56,11 @@ Expr MakeConv(Expr data, Expr weight, Array<IndexExpr> strides, Array<IndexExpr>
}

template <typename T>
Expr MakeConvWinograd(Expr data, Expr weight, int tile_size, Array<IndexExpr> strides,
Array<IndexExpr> padding, Array<IndexExpr> dilation, int groups,
IndexExpr channels, Array<IndexExpr> kernel_size, std::string data_layout,
std::string kernel_layout, std::string out_layout, DataType out_dtype,
std::string op_name) {
inline Expr MakeConvWinograd(Expr data, Expr weight, int tile_size, Array<IndexExpr> strides,
Array<IndexExpr> padding, Array<IndexExpr> dilation, int groups,
IndexExpr channels, Array<IndexExpr> kernel_size,
std::string data_layout, std::string kernel_layout,
std::string out_layout, DataType out_dtype, std::string op_name) {
auto attrs = make_object<T>();
attrs->tile_size = tile_size;
attrs->strides = std::move(strides);
Expand All @@ -77,10 +78,11 @@ Expr MakeConvWinograd(Expr data, Expr weight, int tile_size, Array<IndexExpr> st
}

template <typename T>
Expr MakeConvGemm(Expr data, Expr weight, Array<IndexExpr> strides, Array<IndexExpr> padding,
Array<IndexExpr> dilation, int groups, IndexExpr channels,
Array<IndexExpr> kernel_size, std::string data_layout, std::string kernel_layout,
std::string out_layout, DataType out_dtype, std::string op_name) {
inline Expr MakeConvGemm(Expr data, Expr weight, Array<IndexExpr> strides, Array<IndexExpr> padding,
Array<IndexExpr> dilation, int groups, IndexExpr channels,
Array<IndexExpr> kernel_size, std::string data_layout,
std::string kernel_layout, std::string out_layout, DataType out_dtype,
std::string op_name) {
auto attrs = make_object<T>();
attrs->strides = std::move(strides);
attrs->padding = std::move(padding);
Expand All @@ -97,11 +99,12 @@ Expr MakeConvGemm(Expr data, Expr weight, Array<IndexExpr> strides, Array<IndexE
}

template <typename T>
Expr MakeConvTranspose(Expr data, Expr weight, Array<IndexExpr> strides, Array<IndexExpr> padding,
Array<IndexExpr> dilation, int groups, IndexExpr channels,
Array<IndexExpr> kernel_size, std::string data_layout,
std::string kernel_layout, std::string out_layout,
Array<IndexExpr> output_padding, DataType out_dtype, std::string op_name) {
inline Expr MakeConvTranspose(Expr data, Expr weight, Array<IndexExpr> strides,
Array<IndexExpr> padding, Array<IndexExpr> dilation, int groups,
IndexExpr channels, Array<IndexExpr> kernel_size,
std::string data_layout, std::string kernel_layout,
std::string out_layout, Array<IndexExpr> output_padding,
DataType out_dtype, std::string op_name) {
auto attrs = make_object<T>();
attrs->strides = std::move(strides);
attrs->padding = std::move(padding);
Expand All @@ -119,11 +122,12 @@ Expr MakeConvTranspose(Expr data, Expr weight, Array<IndexExpr> strides, Array<I
}

template <typename T>
Expr MakeDeformableConv(Expr data, Expr offset, Expr weight, Array<IndexExpr> strides,
Array<IndexExpr> padding, Array<IndexExpr> dilation, int deformable_groups,
int groups, int channels, Array<IndexExpr> kernel_size,
std::string data_layout, std::string kernel_layout, std::string out_layout,
DataType out_dtype, std::string op_name) {
inline Expr MakeDeformableConv(Expr data, Expr offset, Expr weight, Array<IndexExpr> strides,
Array<IndexExpr> padding, Array<IndexExpr> dilation,
int deformable_groups, int groups, int channels,
Array<IndexExpr> kernel_size, std::string data_layout,
std::string kernel_layout, std::string out_layout,
DataType out_dtype, std::string op_name) {
auto attrs = make_object<T>();
attrs->strides = strides;
attrs->padding = padding;
Expand Down
10 changes: 5 additions & 5 deletions src/relay/op/nn/pooling.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ namespace tvm {
namespace relay {

template <typename T>
Expr MakeMaxPool(Expr data, Array<IndexExpr> pool_size, Array<IndexExpr> strides,
Array<IndexExpr> padding, String layout, bool ceil_mode, String op_name) {
inline Expr MakeMaxPool(Expr data, Array<IndexExpr> pool_size, Array<IndexExpr> strides,
Array<IndexExpr> padding, String layout, bool ceil_mode, String op_name) {
auto attrs = make_object<T>();
attrs->pool_size = std::move(pool_size);
attrs->strides = std::move(strides);
Expand All @@ -46,9 +46,9 @@ Expr MakeMaxPool(Expr data, Array<IndexExpr> pool_size, Array<IndexExpr> strides
}

template <typename T>
Expr MakeAvgPool(Expr data, Array<IndexExpr> pool_size, Array<IndexExpr> strides,
Array<IndexExpr> padding, String layout, bool ceil_mode, bool count_include_pad,
String op_name) {
inline Expr MakeAvgPool(Expr data, Array<IndexExpr> pool_size, Array<IndexExpr> strides,
Array<IndexExpr> padding, String layout, bool ceil_mode,
bool count_include_pad, String op_name) {
auto attrs = make_object<T>();
attrs->pool_size = std::move(pool_size);
attrs->strides = std::move(strides);
Expand Down
4 changes: 2 additions & 2 deletions src/relay/op/tensor/reduce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,12 @@ bool ReduceRel(const Array<Type>& types, int num_inputs, const Attrs& attrs,
}

Expr MakeReduce(Expr data, Array<Integer> axis, bool keepdims, bool exclude, String op_name) {
std::cout << "making " << op_name << std::endl;
auto attrs = make_object<ReduceAttrs>();
attrs->axis = std::move(axis);
attrs->keepdims = keepdims;
attrs->exclude = exclude;
static const Op& op = Op::Get(op_name);
return Call(op, {data}, Attrs(attrs), {});
return Call(Op::Get(op_name), {data}, Attrs(attrs), {});
}

#define RELAY_REGISTER_REDUCE_OP(OpName) \
Expand Down
2 changes: 1 addition & 1 deletion src/relay/transforms/pattern_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ static inline Expr Dense(Expr data, Expr weight, IndexExpr units, DataType out_d
}

static inline Expr Sum(Expr data, Array<Integer> axis, bool keepdims, bool exclude) {
return MakeReduce(data, axis, keepdims, exclude, "mean");
return MakeReduce(data, axis, keepdims, exclude, "sum");
}

static inline Expr Reshape(Expr data, Array<Integer> newshape) {
Expand Down

0 comments on commit e64ee53

Please sign in to comment.