Yanchen/nuphar/clip 11 (#4737)

* [WIP] log unsupported ops in Nuphar

* [Nuphar] added support for clip-11

also added some log information for unsupported ops in Nuphar
This commit is contained in:
Yang Chen 2020-08-10 15:45:21 -07:00 committed by GitHub
parent 3530ce541c
commit f51385fd1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 7 deletions

View file

@ -30,7 +30,7 @@ tvm::Tensor Ceil(const tvm::Tensor& X, const std::string& name) {
return topi::ceil(X, name);
}
tvm::Tensor Clip(const tvm::Tensor& X, float min_value, float max_value, const std::string& name) {
tvm::Tensor Clip(const tvm::Tensor& X, tvm::Expr min_value, tvm::Expr max_value, const std::string& name) {
auto Y = tvm::compute(
X->shape,
[&](const tvm::Array<tvm::Var>& indices) {

View file

@ -11,7 +11,7 @@ namespace tvm_codegen {
tvm::Tensor Abs(const tvm::Tensor& X, const std::string& name = "abs");
tvm::Tensor Affine(const tvm::Tensor& X, float alpha, float beta, const std::string& name = "affine");
tvm::Tensor Ceil(const tvm::Tensor& X, const std::string& name = "ceil");
tvm::Tensor Clip(const tvm::Tensor& X, float min_value, float max_value, const std::string& name = "clip");
tvm::Tensor Clip(const tvm::Tensor& X, tvm::Expr min_value, tvm::Expr max_value, const std::string& name = "clip");
tvm::Tensor Elu(const tvm::Tensor& X, float alpha, const std::string& name = "elu");
tvm::Tensor Exp(const tvm::Tensor& X, const std::string& name = "exp");
tvm::Tensor Floor(const tvm::Tensor& X, const std::string& name = "floor");

View file

@ -13,14 +13,31 @@ namespace tvm_codegen {
Status GENERIC_OP_IR_CREATOR_CLASS(Clip)::Evaluate(
const tvm::Array<tvm::Tensor>& inputs,
const Node& node,
CodeGenContext&,
CodeGenContext& ctx_codegen,
tvm::Array<tvm::Tensor>& outputs) {
ProtoHelperNodeContext ctx(node);
OpNodeProtoHelper<ProtoHelperNodeContext> info(&ctx);
float max_value, min_value;
ORT_RETURN_IF_ERROR(info.GetAttr<float>("max", &max_value));
ORT_RETURN_IF_ERROR(info.GetAttr<float>("min", &min_value));
int version = ctx_codegen.GetCodeGenHandle()->domain_version_lookup_func(node.Domain());
tvm::Expr min_value, max_value;
if (version < 11) {
float max_v, min_v;
info.GetAttrOrDefault("min", &min_v, std::numeric_limits<float>::lowest());
info.GetAttrOrDefault("max", &max_v, std::numeric_limits<float>::max());
min_value = tvm::make_const(tvm::Float(32), min_v);
max_value = tvm::make_const(tvm::Float(32), max_v);
} else {
// for op_version >= 11, max and min are optional inputs
min_value = tvm::make_const(tvm::Float(32), std::numeric_limits<float>::lowest());
max_value = tvm::make_const(tvm::Float(32), std::numeric_limits<float>::max());
auto num_inputs = inputs.size();
if (num_inputs >= 2) {
min_value = inputs[1]();
}
if (num_inputs == 3) {
max_value = inputs[2]();
}
}
tvm::Tensor Y = Clip(inputs[0], min_value, max_value, node.Name() + "_Clip");
outputs.push_back(Y);

View file

@ -83,7 +83,8 @@ class NupharKernelState {
NUPHAR_OP(AveragePool, 10, DataTypeImpl::AllIEEEFloatTensorExceptHalfTypes()) \
NUPHAR_OP(AveragePool, 11, DataTypeImpl::AllIEEEFloatTensorExceptHalfTypes()) \
NUPHAR_OP(Ceil, 6, DataTypeImpl::AllIEEEFloatTensorTypes()) \
NUPHAR_OP(Clip, 6, DataTypeImpl::AllIEEEFloatTensorTypes()) \
NUPHAR_VERSIONED_OP(Clip, 6, 10, DataTypeImpl::AllIEEEFloatTensorTypes()) \
NUPHAR_VERSIONED_OP(Clip, 11, 11, DataTypeImpl::AllIEEEFloatTensorTypes()) \
NUPHAR_VERSIONED_OP(Concat, 4, 10, DataTypeImpl::AllFixedSizeTensorTypes()) \
NUPHAR_OP(Concat, 11, DataTypeImpl::AllFixedSizeTensorTypes()) \
DISABLE_MACRO(NUPHAR_OP(Conv, 1, DataTypeImpl::AllIEEEFloatTensorExceptHalfTypes())) \

View file

@ -256,6 +256,7 @@ Status Partitioner::Evaluate(const onnxruntime::GraphViewer& graph, bool disting
if (IsNodeSupported(*node)) {
AcceptNode(graph, node_idx);
} else {
LOGS_DEFAULT(INFO) << "unsupported node (" << node->Name() << ") in nuphar provider";
RejectNode(graph, node_idx);
}
}