-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix InferCorrectLayout for dynamic upsampling and add a regression te…
…st (#6712) * add a regression test * fix dyn upsampling infer layout * fix lint
- Loading branch information
Matthew Brookhart
authored
Oct 21, 2020
1 parent
9ae386c
commit f65e320
Showing
3 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* 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 src/relay/op/dyn/nn/upsampling.h | ||
* \brief implementation of the InferCorrectLayout pass for dynamic upsampling | ||
*/ | ||
|
||
#ifndef TVM_RELAY_OP_DYN_NN_UPSAMPLING_H_ | ||
#define TVM_RELAY_OP_DYN_NN_UPSAMPLING_H_ | ||
|
||
#include <tvm/relay/attrs/nn.h> | ||
#include <tvm/tir/data_layout.h> | ||
|
||
#include "../../op_common.h" | ||
|
||
namespace tvm { | ||
namespace relay { | ||
namespace dyn { | ||
|
||
template <typename T> | ||
Array<Array<Layout> > UpsamplingInferCorrectLayout(const Attrs& attrs, | ||
const Array<Layout>& new_in_layouts, | ||
const Array<Layout>& old_in_layouts, | ||
const Array<tvm::relay::Type>& old_in_types) { | ||
// NOTE: Discard "const" qualifier here. | ||
T* params = const_cast<T*>(attrs.as<T>()); | ||
if (new_in_layouts.defined()) { | ||
CHECK_GT(new_in_layouts.size(), 0); | ||
|
||
Layout raw_layout(params->layout); | ||
Layout input = new_in_layouts[0]; | ||
if (input.IndexOf(LayoutAxis::Get('W')) == raw_layout.IndexOf(LayoutAxis::Get('W')) && | ||
input.IndexOf(LayoutAxis::Get('H')) == raw_layout.IndexOf(LayoutAxis::Get('H')) && | ||
!input.Contains(LayoutAxis::Get('w')) && !input.Contains(LayoutAxis::Get('h')) && | ||
(input.IndexOf(LayoutAxis::Get('D')) == -1 || | ||
(input.IndexOf(LayoutAxis::Get('D')) == raw_layout.IndexOf(LayoutAxis::Get('D')) && | ||
!input.Contains(LayoutAxis::Get('d'))))) { | ||
params->layout = input.name(); // modify self to follow the input layout | ||
} | ||
} | ||
|
||
Layout inferred_layout(params->layout); | ||
Layout param_layout("NCHW"); | ||
return Array<Array<Layout> >{{inferred_layout, param_layout, param_layout}, {inferred_layout}}; | ||
} | ||
|
||
} // namespace dyn | ||
} // namespace relay | ||
} // namespace tvm | ||
|
||
#endif // TVM_RELAY_OP_DYN_NN_UPSAMPLING_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters