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

[ETHOSN] Match config for is-supported with compilation target #9160

Merged
merged 1 commit into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
73 changes: 51 additions & 22 deletions src/relay/backend/contrib/ethosn/codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -606,25 +606,37 @@ std::pair<std::vector<uint32_t>, std::vector<uint32_t>> EthosnCompiler::GetInput
return std::make_pair(input_order, output_order);
}

auto ctx = transform::PassContext::Current();
auto cfg = ctx -> GetConfig<EthosnCompilerConfig>("relay.ext.ethos-n.options").defined()
? ctx -> GetConfig<EthosnCompilerConfig>("relay.ext.ethos-n.options")
: AttrsWithDefaultValues<EthosnCompilerConfig>();
auto m_Queries = sl::SupportQueries(sl::GetFwAndHwCapabilities(
sl::EthosNVariantFromString(cfg.value()->variant.c_str()), cfg.value()->sram_size_bytes));
std::unique_ptr<sl::SupportQueries> EthosnCompiler::m_Queries;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit : Do we need this line ?


EthosnError EthosnCompiler::SupportedSetup() {
if (m_Queries == nullptr) {
auto ctx = transform::PassContext::Current();
auto cfg = ctx->GetConfig<EthosnCompilerConfig>("relay.ext.ethos-n.options").defined()
? ctx->GetConfig<EthosnCompilerConfig>("relay.ext.ethos-n.options")
: AttrsWithDefaultValues<EthosnCompilerConfig>();
m_Queries = std::make_unique<sl::SupportQueries>(sl::GetFwAndHwCapabilities(
sl::EthosNVariantFromString(cfg.value()->variant.c_str()), cfg.value()->sram_size_bytes));
if (m_Queries == nullptr) {
return EthosnError("Could not initialise Ethos-N compiler isSupported");
}
}
return EthosnError();
}

TVM_REGISTER_GLOBAL("relay.ethos-n.support.conv2d")
.set_body([](tvm::TVMArgs args, tvm::TVMRetValue* rv) {
Call call = args[0];
ConvolutionParams params;
auto err = EthosnAPI::QnnConv2d(call, &params);
err += EthosnCompiler::SupportedSetup();
if (params.is_depthwise) {
*rv = !err &&
m_Queries.IsDepthwiseConvolutionSupported(params.bias_info, params.weights_info,
params.conv_info, params.activation_info);
EthosnCompiler::GetSupported()->IsDepthwiseConvolutionSupported(
params.bias_info, params.weights_info, params.conv_info, params.activation_info);
} else {
*rv = !err && m_Queries.IsConvolutionSupported(params.bias_info, params.weights_info,
params.conv_info, params.activation_info);
*rv = !err &&
EthosnCompiler::GetSupported()->IsConvolutionSupported(
params.bias_info, params.weights_info, params.conv_info, params.activation_info);
}
});

Expand All @@ -633,81 +645,98 @@ TVM_REGISTER_GLOBAL("relay.ethos-n.support.fc")
Call call = args[0];
FullyConnectedParams params;
auto err = EthosnAPI::QnnFullyConnected(call, &params);
*rv = !err && m_Queries.IsFullyConnectedSupported(params.bias_info, params.weights_info,
params.fc_info, params.input_info);
err += EthosnCompiler::SupportedSetup();
*rv = !err && EthosnCompiler::GetSupported()->IsFullyConnectedSupported(
params.bias_info, params.weights_info, params.fc_info, params.input_info);
});

TVM_REGISTER_GLOBAL("relay.ethos-n.support.max_pool2d")
.set_body([](tvm::TVMArgs args, tvm::TVMRetValue* rv) {
Call call = args[0];
MaxPool2DParams params;
auto err = EthosnAPI::MaxPool2D(call, &params);
*rv = !err && m_Queries.IsPoolingSupported(params.pool_info, params.input_info);
err += EthosnCompiler::SupportedSetup();
*rv = !err &&
EthosnCompiler::GetSupported()->IsPoolingSupported(params.pool_info, params.input_info);
});

TVM_REGISTER_GLOBAL("relay.ethos-n.support.avg_pool2d")
.set_body([](tvm::TVMArgs args, tvm::TVMRetValue* rv) {
Call call = args[0];
AvgPool2DParams params;
auto err = EthosnAPI::AvgPool2D(call, &params);
*rv = !err && m_Queries.IsPoolingSupported(params.pool_info, params.input_info);
err += EthosnCompiler::SupportedSetup();
*rv = !err &&
EthosnCompiler::GetSupported()->IsPoolingSupported(params.pool_info, params.input_info);
});

TVM_REGISTER_GLOBAL("relay.ethos-n.support.reshape")
.set_body([](tvm::TVMArgs args, tvm::TVMRetValue* rv) {
Call call = args[0];
ReshapeParams params;
auto err = EthosnAPI::Reshape(call, &params);
*rv = !err && m_Queries.IsReshapeSupported(params.new_shape, params.input_info);
err += EthosnCompiler::SupportedSetup();
*rv = !err &&
EthosnCompiler::GetSupported()->IsReshapeSupported(params.new_shape, params.input_info);
});

TVM_REGISTER_GLOBAL("relay.ethos-n.support.addition")
.set_body([](tvm::TVMArgs args, tvm::TVMRetValue* rv) {
Call call = args[0];
AdditionParams params;
auto err = EthosnAPI::Addition(call, &params);
*rv = !err && m_Queries.IsAdditionSupported(params.lhs_info, params.rhs_info,
params.output_quantization_info);
err += EthosnCompiler::SupportedSetup();
*rv = !err && EthosnCompiler::GetSupported()->IsAdditionSupported(
params.lhs_info, params.rhs_info, params.output_quantization_info);
});

TVM_REGISTER_GLOBAL("relay.ethos-n.support.sigmoid")
.set_body([](tvm::TVMArgs args, tvm::TVMRetValue* rv) {
Call call = args[0];
SigmoidParams params;
auto err = EthosnAPI::Sigmoid(call, &params);
*rv = !err && m_Queries.IsSigmoidSupported(params.input_info);
err += EthosnCompiler::SupportedSetup();
*rv = !err && EthosnCompiler::GetSupported()->IsSigmoidSupported(params.input_info);
});

TVM_REGISTER_GLOBAL("relay.ethos-n.support.concatenate")
.set_body([](tvm::TVMArgs args, tvm::TVMRetValue* rv) {
Call call = args[0];
ConcatenateParams params;
auto err = EthosnAPI::Concatenate(call, &params);
*rv = !err && m_Queries.IsConcatenationSupported(params.input_infos, params.concat_info);
err += EthosnCompiler::SupportedSetup();
*rv = !err && EthosnCompiler::GetSupported()->IsConcatenationSupported(params.input_infos,
params.concat_info);
});

TVM_REGISTER_GLOBAL("relay.ethos-n.support.split")
.set_body([](tvm::TVMArgs args, tvm::TVMRetValue* rv) {
Call call = args[0];
SplitParams params;
auto err = EthosnAPI::Split(call, &params);
*rv = !err && m_Queries.IsSplitSupported(params.input_info, params.split_info);
err += EthosnCompiler::SupportedSetup();
*rv = !err &&
EthosnCompiler::GetSupported()->IsSplitSupported(params.input_info, params.split_info);
});

TVM_REGISTER_GLOBAL("relay.ethos-n.support.depth_to_space")
.set_body([](tvm::TVMArgs args, tvm::TVMRetValue* rv) {
Call call = args[0];
DepthToSpaceParams params;
auto err = EthosnAPI::DepthToSpace(call, &params);
*rv = !err && m_Queries.IsDepthToSpaceSupported(params.input_info, params.depth_info);
err += EthosnCompiler::SupportedSetup();
*rv = !err && EthosnCompiler::GetSupported()->IsDepthToSpaceSupported(params.input_info,
params.depth_info);
});

TVM_REGISTER_GLOBAL("relay.ethos-n.support.relu")
.set_body([](tvm::TVMArgs args, tvm::TVMRetValue* rv) {
Call call = args[0];
ReluParams params;
auto err = EthosnAPI::Relu(call, &params);
*rv = !err && m_Queries.IsReluSupported(params.relu_info, params.input_info);
err += EthosnCompiler::SupportedSetup();
*rv = !err &&
EthosnCompiler::GetSupported()->IsReluSupported(params.relu_info, params.input_info);
});

TVM_REGISTER_GLOBAL("relay.ethos-n.query").set_body([](tvm::TVMArgs args, tvm::TVMRetValue* rv) {
Expand Down
18 changes: 18 additions & 0 deletions src/relay/backend/contrib/ethosn/codegen_ethosn.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,22 @@ class EthosnCompiler {
*/
static runtime::Module CreateRuntimeModule(const ObjectRef& ref);

/*!
* \brief Initialise the is-supported functionality of the Ethos-N support library
* with the target variant.
* \return Error object
*/
static EthosnError SupportedSetup();

/*!
* \brief Return the is-supported API of the Support Library
* \return A reference to the API.
*/
static std::unique_ptr<sl::SupportQueries>& GetSupported() {
ICHECK(m_Queries != nullptr);
return m_Queries;
}

private:
/*!
* \brief Compile a single Relay Ethos-N function into an ordered compiled network.
Expand Down Expand Up @@ -322,6 +338,8 @@ class EthosnCompiler {
*/
static std::pair<std::vector<uint32_t>, std::vector<uint32_t>> GetInputOutputOrder(
NetworkWithIDs network, const std::unique_ptr<sl::CompiledNetwork>& compiled_network);

static std::unique_ptr<sl::SupportQueries> m_Queries;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add docs.

};

runtime::Module CompileEthosn(const ObjectRef& ref) {
Expand Down