Skip to content

Commit

Permalink
[ETHOSN] Removed support for 20.08 version of the driver stack.
Browse files Browse the repository at this point in the history
  - Replaced capabilities header file with api calls introduced by the 20.11 ethosn driver stack release.
  - Removed 20.08 driver stack support and updated all affected code.
  • Loading branch information
tristan-arm committed May 11, 2021
1 parent 58c3413 commit 1056dce
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 253 deletions.
138 changes: 0 additions & 138 deletions src/relay/backend/contrib/ethosn/capabilities.h

This file was deleted.

74 changes: 4 additions & 70 deletions src/relay/backend/contrib/ethosn/codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <tvm/relay/expr_functor.h>
#include <tvm/runtime/module.h>

#include "capabilities.h"
#include "codegen_ethosn.h"
#include "ethosn_api.h"

Expand Down Expand Up @@ -198,19 +197,14 @@ sl::TensorsAndId MakeOps(const sl::TensorAndId<sl::Operand>& op) {

NetworkWithIDs ConstructNetworkVisitor::Construct(const Function& func) {
// Initialise everything
#if _ETHOSN_API_VERSION_ >= 2011
auto ctx = transform::PassContext::Current();
auto cfg = ctx->GetConfig<EthosnCompilerConfig>("relay.ext.ethos-n.options");
if (!cfg.defined()) {
cfg = AttrsWithDefaultValues<EthosnCompilerConfig>();
}
#endif
NetworkWithIDs network_with_ids;
#if _ETHOSN_API_VERSION_ >= 2011
network_ = sl::CreateNetwork(variants[cfg.value()->variant]);
#else
network_ = sl::CreateNetwork();
#endif
network_ = sl::CreateNetwork(sl::GetFwAndHwCapabilities(
sl::EthosNVariantFromString(cfg.value()->variant.c_str()), cfg.value()->sram_size_bytes));
network_with_ids.network = network_;
operand_table_.clear();

Expand Down Expand Up @@ -572,11 +566,7 @@ sl::CompilationOptions EthosnCompiler::CreateOptions() {
cfg = AttrsWithDefaultValues<EthosnCompilerConfig>();
}

#if _ETHOSN_API_VERSION_ >= 2011
sl::CompilationOptions options;
#else
sl::CompilationOptions options(variants[cfg.value()->variant]);
#endif
options.m_Strategy0 = cfg.value()->strategy0;
options.m_Strategy1 = cfg.value()->strategy1;
options.m_Strategy3 = cfg.value()->strategy3;
Expand All @@ -590,9 +580,6 @@ sl::CompilationOptions EthosnCompiler::CreateOptions() {
options.m_BlockConfig8x32 = cfg.value()->block_config_8x32;
options.m_BlockConfig8x8 = cfg.value()->block_config_8x8;
options.m_EnableIntermediateCompression = cfg.value()->enable_intermediate_compression;
#if _ETHOSN_API_VERSION_ == 2008
options.m_DebugInfo.m_DumpDebugFiles = cfg.value()->dump_debug_files;
#endif
options.m_DisableWinograd = cfg.value()->disable_winograd;
options.m_DebugInfo.m_DebugDir = cfg.value()->debug_dir;
options.m_CompilerAlgorithm =
Expand All @@ -619,20 +606,18 @@ std::pair<std::vector<uint32_t>, std::vector<uint32_t>> EthosnCompiler::GetInput
return std::make_pair(input_order, output_order);
}

#if _ETHOSN_API_VERSION_ >= 2011
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(variants[cfg.value()->variant]);
#endif
auto m_Queries = sl::SupportQueries(sl::GetFwAndHwCapabilities(
sl::EthosNVariantFromString(cfg.value()->variant.c_str()), cfg.value()->sram_size_bytes));

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);
#if _ETHOSN_API_VERSION_ >= 2011
if (params.is_depthwise) {
*rv = !err &&
m_Queries.IsDepthwiseConvolutionSupported(params.bias_info, params.weights_info,
Expand All @@ -641,139 +626,88 @@ TVM_REGISTER_GLOBAL("relay.ethos-n.support.conv2d")
*rv = !err && m_Queries.IsConvolutionSupported(params.bias_info, params.weights_info,
params.conv_info, params.activation_info);
}
#else
if (params.is_depthwise) {
*rv = !err && sl::IsDepthwiseConvolutionSupported(params.bias_info, params.weights_info,
params.conv_info, params.activation_info);
} else {
*rv = !err && sl::IsConvolutionSupported(params.bias_info, params.weights_info,
params.conv_info, params.activation_info);
}
#endif
});

TVM_REGISTER_GLOBAL("relay.ethos-n.support.fc")
.set_body([](tvm::TVMArgs args, tvm::TVMRetValue* rv) {
Call call = args[0];
FullyConnectedParams params;
auto err = EthosnAPI::QnnFullyConnected(call, &params);
#if _ETHOSN_API_VERSION_ >= 2011
*rv = !err && m_Queries.IsFullyConnectedSupported(params.bias_info, params.weights_info,
params.fc_info, params.input_info);
#else
*rv = !err && sl::IsFullyConnectedSupported(params.bias_info, params.weights_info,
params.fc_info, params.input_info);
#endif
});

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);
#if _ETHOSN_API_VERSION_ >= 2011
*rv = !err && m_Queries.IsPoolingSupported(params.pool_info, params.input_info);
#else
*rv = !err && sl::IsPoolingSupported(params.pool_info, params.input_info);
#endif
});

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);
#if _ETHOSN_API_VERSION_ >= 2011
*rv = !err && m_Queries.IsPoolingSupported(params.pool_info, params.input_info);
#else
*rv = !err && sl::IsPoolingSupported(params.pool_info, params.input_info);
#endif
});

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);
#if _ETHOSN_API_VERSION_ >= 2011
*rv = !err && m_Queries.IsReshapeSupported(params.new_shape, params.input_info);
#else
*rv = !err && sl::IsReshapeSupported(params.new_shape, params.input_info);
#endif
});

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);
#if _ETHOSN_API_VERSION_ >= 2011
*rv = !err && m_Queries.IsAdditionSupported(params.lhs_info, params.rhs_info,
params.output_quantization_info);
#else
*rv = !err && sl::IsAdditionSupported(params.lhs_info, params.rhs_info,
params.output_quantization_info);
#endif
});

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);
#if _ETHOSN_API_VERSION_ >= 2011
*rv = !err && m_Queries.IsSigmoidSupported(params.input_info);
#else
*rv = !err && sl::IsSigmoidSupported(params.input_info);
#endif
});

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);
#if _ETHOSN_API_VERSION_ >= 2011
*rv = !err && m_Queries.IsConcatenationSupported(params.input_infos, params.concat_info);
#else
*rv = !err && sl::IsConcatenationSupported(params.input_infos, params.concat_info);
#endif
});

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);
#if _ETHOSN_API_VERSION_ >= 2011
*rv = !err && m_Queries.IsSplitSupported(params.input_info, params.split_info);
#else
*rv = !err && sl::IsSplitSupported(params.input_info, params.split_info);
#endif
});

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);
#if _ETHOSN_API_VERSION_ >= 2011
*rv = !err && m_Queries.IsDepthToSpaceSupported(params.input_info, params.depth_info);
#else
*rv = !err && sl::IsDepthToSpaceSupported(params.input_info, params.depth_info);
#endif
});

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);
#if _ETHOSN_API_VERSION_ >= 2011
*rv = !err && m_Queries.IsReluSupported(params.relu_info, params.input_info);
#else
*rv = !err && sl::IsReluSupported(params.relu_info, params.input_info);
#endif
});

TVM_REGISTER_GLOBAL("relay.ethos-n.query").set_body([](tvm::TVMArgs args, tvm::TVMRetValue* rv) {
Expand Down
16 changes: 5 additions & 11 deletions src/relay/backend/contrib/ethosn/codegen_ethosn.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ NetworkWithIDs ConstructNetwork(const IRModule& mod, const GlobalVar& var, const

/*! \brief Attributes to store the compiler options for Ethos-N */
struct EthosnCompilerConfigNode : public tvm::AttrsNode<EthosnCompilerConfigNode> {
int variant;
String variant;
int sram_size_bytes;
bool strategy0;
bool strategy1;
bool strategy3;
Expand All @@ -240,18 +241,14 @@ struct EthosnCompilerConfigNode : public tvm::AttrsNode<EthosnCompilerConfigNode
bool block_config_8x32;
bool block_config_8x8;
bool enable_intermediate_compression;
#if _ETHOSN_API_VERSION_ == 2008
bool dump_debug_files;
#endif
bool disable_winograd;
String debug_dir;
String compiler_algorithm;

TVM_DECLARE_ATTRS(EthosnCompilerConfigNode, "ext.attrs.EthosnCompilerConfigNode") {
TVM_ATTR_FIELD(variant)
.describe(
"0 for Ethos-N77, 1 for Ethos-N57, 2 for Ethos-N37,"
" 3 for Ethos-N78. See Ethos-N documentation.")
TVM_ATTR_FIELD(variant).describe("See Ethos-N documentation.").set_default("Ethos-N77");
TVM_ATTR_FIELD(sram_size_bytes)
.describe("Optionally override the default sram size. See Ethos-N documentation.")
.set_default(0);
TVM_ATTR_FIELD(strategy0).set_default(true);
TVM_ATTR_FIELD(strategy1).set_default(true);
Expand All @@ -266,9 +263,6 @@ struct EthosnCompilerConfigNode : public tvm::AttrsNode<EthosnCompilerConfigNode
TVM_ATTR_FIELD(block_config_8x32).set_default(true);
TVM_ATTR_FIELD(block_config_8x8).set_default(true);
TVM_ATTR_FIELD(enable_intermediate_compression).set_default(true);
#if _ETHOSN_API_VERSION_ == 2008
TVM_ATTR_FIELD(dump_debug_files).set_default(false);
#endif
TVM_ATTR_FIELD(disable_winograd).set_default(false);
TVM_ATTR_FIELD(debug_dir).set_default(".");
TVM_ATTR_FIELD(compiler_algorithm).set_default("NonCascadingOnly");
Expand Down
Loading

0 comments on commit 1056dce

Please sign in to comment.