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

[onert] Apply nodiscard attribute #14711

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion runtime/onert/api/nnfw/src/CustomKernelRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CustomKernelRegistry
void registerKernel(const std::string &id, nnfw_custom_eval evalFunction);

std::shared_ptr<backend::custom::IKernelBuilder> getBuilder();
std::unique_ptr<CustomKernel> buildKernelForOp(const std::string &id);
[[nodiscard]] std::unique_ptr<CustomKernel> buildKernelForOp(const std::string &id);

private:
std::unordered_map<std::string, nnfw_custom_eval> _storage;
Expand Down
120 changes: 62 additions & 58 deletions runtime/onert/api/nnfw/src/nnfw_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,102 +98,106 @@ struct nnfw_session
*
* @note Use factory instead of constructor to get status
*/
static NNFW_STATUS create(nnfw_session **session);
[[nodiscard]] static NNFW_STATUS create(nnfw_session **session);

private:
nnfw_session();

public:
~nnfw_session();
NNFW_STATUS load_model_from_path(const char *path);
NNFW_STATUS prepare();
NNFW_STATUS run();
[[nodiscard]] NNFW_STATUS load_model_from_path(const char *path);
[[nodiscard]] NNFW_STATUS prepare();
[[nodiscard]] NNFW_STATUS run();

NNFW_STATUS run_async();
NNFW_STATUS await();
[[nodiscard]] NNFW_STATUS run_async();
[[nodiscard]] NNFW_STATUS await();

NNFW_STATUS set_input(uint32_t index, NNFW_TYPE type, const void *buffer, size_t length);
NNFW_STATUS set_output(uint32_t index, NNFW_TYPE type, void *buffer, size_t length);
[[nodiscard]] NNFW_STATUS set_input(uint32_t index, NNFW_TYPE type, const void *buffer,
size_t length);
[[nodiscard]] NNFW_STATUS set_output(uint32_t index, NNFW_TYPE type, void *buffer, size_t length);

NNFW_STATUS input_size(uint32_t *number);
NNFW_STATUS output_size(uint32_t *number);
[[nodiscard]] NNFW_STATUS input_size(uint32_t *number);
[[nodiscard]] NNFW_STATUS output_size(uint32_t *number);

NNFW_STATUS set_input_layout(uint32_t index, NNFW_LAYOUT layout);
NNFW_STATUS set_output_layout(uint32_t index, NNFW_LAYOUT layout);
[[nodiscard]] NNFW_STATUS set_input_layout(uint32_t index, NNFW_LAYOUT layout);
[[nodiscard]] NNFW_STATUS set_output_layout(uint32_t index, NNFW_LAYOUT layout);

NNFW_STATUS set_input_tensorinfo(uint32_t index, const nnfw_tensorinfo *ti);
[[nodiscard]] NNFW_STATUS set_input_tensorinfo(uint32_t index, const nnfw_tensorinfo *ti);

NNFW_STATUS input_tensorinfo(uint32_t index, nnfw_tensorinfo *ti);
NNFW_STATUS output_tensorinfo(uint32_t index, nnfw_tensorinfo *ti);
[[nodiscard]] NNFW_STATUS input_tensorinfo(uint32_t index, nnfw_tensorinfo *ti);
[[nodiscard]] NNFW_STATUS output_tensorinfo(uint32_t index, nnfw_tensorinfo *ti);

NNFW_STATUS set_available_backends(const char *backends);
[[nodiscard]] NNFW_STATUS set_available_backends(const char *backends);

NNFW_STATUS set_workspace(const char *dir);
[[nodiscard]] NNFW_STATUS set_workspace(const char *dir);

static NNFW_STATUS deprecated(const char *msg);
[[nodiscard]] static NNFW_STATUS deprecated(const char *msg);

//
// Internal-only API
//

NNFW_STATUS set_config(const char *key, const char *value);
NNFW_STATUS get_config(const char *key, char *value, size_t value_size);
NNFW_STATUS load_circle_from_buffer(uint8_t *buffer, size_t size);
[[nodiscard]] NNFW_STATUS set_config(const char *key, const char *value);
[[nodiscard]] NNFW_STATUS get_config(const char *key, char *value, size_t value_size);
[[nodiscard]] NNFW_STATUS load_circle_from_buffer(uint8_t *buffer, size_t size);

//
// Experimental API
//
NNFW_STATUS register_custom_operation(const std::string &id, nnfw_custom_eval eval_func);
NNFW_STATUS input_tensorindex(const char *tensorname, uint32_t *index);
NNFW_STATUS output_tensorindex(const char *tensorname, uint32_t *index);
[[nodiscard]] NNFW_STATUS register_custom_operation(const std::string &id,
nnfw_custom_eval eval_func);
[[nodiscard]] NNFW_STATUS input_tensorindex(const char *tensorname, uint32_t *index);
[[nodiscard]] NNFW_STATUS output_tensorindex(const char *tensorname, uint32_t *index);

// Run inference with auto compilation
NNFW_STATUS run_with_auto_compilation(const char *target, NNFW_CODEGEN_PREF pref);
[[nodiscard]] NNFW_STATUS run_with_auto_compilation(const char *target, NNFW_CODEGEN_PREF pref);
// Set odc parameter: minmax_records_count for quantization in auto compilation mode
NNFW_STATUS set_odc_param_minmax_records_count(int minmax_records_count);
[[nodiscard]] NNFW_STATUS set_odc_param_minmax_records_count(int minmax_records_count);
// delete MinMax File of on-device compiler
NNFW_STATUS delete_odc_minmax_file();
[[nodiscard]] NNFW_STATUS delete_odc_minmax_file();

/**
* @brief Set backends with string-encoded mapping from operation index to backend type
* (cpu, acl_cl)
*/
NNFW_STATUS set_backends_per_operation(const char *backend_settings);

NNFW_STATUS train_get_traininfo(nnfw_train_info *info);
NNFW_STATUS train_set_traininfo(const nnfw_train_info *info);
NNFW_STATUS train_prepare();
NNFW_STATUS train_input_tensorinfo(uint32_t index, nnfw_tensorinfo *ti);
NNFW_STATUS train_expected_tensorinfo(uint32_t index, nnfw_tensorinfo *ti);
NNFW_STATUS train_set_input(uint32_t index, const void *input,
const nnfw_tensorinfo *input_tensorinfo);
NNFW_STATUS train_set_expected(uint32_t index, const void *expected,
const nnfw_tensorinfo *expected_tensorinfo);
NNFW_STATUS train_set_output(uint32_t index, NNFW_TYPE type, void *buffer, size_t length);
NNFW_STATUS train_run(bool update_weights);
NNFW_STATUS train_get_loss(uint32_t index, float *loss);
NNFW_STATUS train_export_circle(const char *path);
NNFW_STATUS train_export_circleplus(const char *path);
NNFW_STATUS train_import_checkpoint(const char *path);
NNFW_STATUS train_export_checkpoint(const char *path);

NNFW_STATUS set_quantization_type(NNFW_QUANTIZE_TYPE qtype);
NNFW_STATUS set_quantized_model_path(const char *path);
NNFW_STATUS quantize();

NNFW_STATUS set_codegen_model_path(const char *path);
NNFW_STATUS codegen(const char *target, NNFW_CODEGEN_PREF pref);

NNFW_STATUS set_prepare_config(const NNFW_PREPARE_CONFIG key, const char *value);
NNFW_STATUS reset_prepare_config();
NNFW_STATUS set_execute_config(const NNFW_RUN_CONFIG key, const char *value);
NNFW_STATUS reset_execute_config();
[[nodiscard]] NNFW_STATUS set_backends_per_operation(const char *backend_settings);

[[nodiscard]] NNFW_STATUS train_get_traininfo(nnfw_train_info *info);
[[nodiscard]] NNFW_STATUS train_set_traininfo(const nnfw_train_info *info);
[[nodiscard]] NNFW_STATUS train_prepare();
[[nodiscard]] NNFW_STATUS train_input_tensorinfo(uint32_t index, nnfw_tensorinfo *ti);
[[nodiscard]] NNFW_STATUS train_expected_tensorinfo(uint32_t index, nnfw_tensorinfo *ti);
[[nodiscard]] NNFW_STATUS train_set_input(uint32_t index, const void *input,
const nnfw_tensorinfo *input_tensorinfo);
[[nodiscard]] NNFW_STATUS train_set_expected(uint32_t index, const void *expected,
const nnfw_tensorinfo *expected_tensorinfo);
[[nodiscard]] NNFW_STATUS train_set_output(uint32_t index, NNFW_TYPE type, void *buffer,
size_t length);
[[nodiscard]] NNFW_STATUS train_run(bool update_weights);
[[nodiscard]] NNFW_STATUS train_get_loss(uint32_t index, float *loss);
[[nodiscard]] NNFW_STATUS train_export_circle(const char *path);
[[nodiscard]] NNFW_STATUS train_export_circleplus(const char *path);
[[nodiscard]] NNFW_STATUS train_import_checkpoint(const char *path);
[[nodiscard]] NNFW_STATUS train_export_checkpoint(const char *path);

[[nodiscard]] NNFW_STATUS set_quantization_type(NNFW_QUANTIZE_TYPE qtype);
[[nodiscard]] NNFW_STATUS set_quantized_model_path(const char *path);
[[nodiscard]] NNFW_STATUS quantize();

[[nodiscard]] NNFW_STATUS set_codegen_model_path(const char *path);
[[nodiscard]] NNFW_STATUS codegen(const char *target, NNFW_CODEGEN_PREF pref);

[[nodiscard]] NNFW_STATUS set_prepare_config(const NNFW_PREPARE_CONFIG key, const char *value);
[[nodiscard]] NNFW_STATUS reset_prepare_config();
[[nodiscard]] NNFW_STATUS set_execute_config(const NNFW_RUN_CONFIG key, const char *value);
[[nodiscard]] NNFW_STATUS reset_execute_config();

private:
const onert::ir::IGraph *primary_subgraph();
uint32_t getInputSize();
uint32_t getOutputSize();
NNFW_STATUS loadModelFile(const std::string &model_file_path, const std::string &model_type);
[[nodiscard]] NNFW_STATUS loadModelFile(const std::string &model_file_path,
const std::string &model_type);

bool isStateInitialized();
bool isStateModelLoaded();
Expand Down
3 changes: 2 additions & 1 deletion runtime/onert/backend/acl_cl/Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class Backend : public ::onert::backend::Backend

std::shared_ptr<IConfig> config() const override { return _config; }

std::unique_ptr<backend::BackendContext> newContext(ContextData &&data) const override
[[nodiscard]] std::unique_ptr<backend::BackendContext>
newContext(ContextData &&data) const override
{
const auto &graph = *data.graph;
const auto &operands = data.graph->operands();
Expand Down
5 changes: 4 additions & 1 deletion runtime/onert/backend/acl_cl/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ class Config : public IConfig
bool supportFP16() override { return true; }
void sync() const override { arm_compute::CLScheduler::get().sync(); }

std::unique_ptr<util::ITimer> timer() override { return std::make_unique<CLTimer>(); }
[[nodiscard]] std::unique_ptr<util::ITimer> timer() override
{
return std::make_unique<CLTimer>();
}
};

} // namespace onert::backend::acl_cl
Expand Down
2 changes: 1 addition & 1 deletion runtime/onert/backend/acl_cl/KernelGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class KernelGenerator : public basic::KernelGeneratorBase
KernelGenerator(const ir::Graph &graph, const std::shared_ptr<TensorBuilder> &tensor_builder,
const std::shared_ptr<acl_common::AclTensorRegistry<TensorManager>> &_tensor_reg);

std::unique_ptr<exec::FunctionSequence> generate(ir::OperationIndex ind) override;
[[nodiscard]] std::unique_ptr<exec::FunctionSequence> generate(ir::OperationIndex ind) override;

private:
void visit(const ir::operation::ArgMinMax &) override;
Expand Down
14 changes: 7 additions & 7 deletions runtime/onert/backend/acl_common/AclActivationBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ template <typename T_Tensor, typename T_ActivationLayer, typename T_ExecFunction
class AclActivationBuilder
{
private:
static std::unique_ptr<exec::IFunction> generateReLU(T_Tensor *ifm_alloc);
static std::unique_ptr<exec::IFunction> generateReLU1(T_Tensor *ifm_alloc);
static std::unique_ptr<exec::IFunction> generateReLU6(T_Tensor *ifm_alloc);
[[nodiscard]] static std::unique_ptr<exec::IFunction> generateReLU(T_Tensor *ifm_alloc);
[[nodiscard]] static std::unique_ptr<exec::IFunction> generateReLU1(T_Tensor *ifm_alloc);
[[nodiscard]] static std::unique_ptr<exec::IFunction> generateReLU6(T_Tensor *ifm_alloc);

public:
static std::unique_ptr<exec::IFunction> generate(ir::Activation code, T_Tensor *ifm_alloc);
};

template <typename T_Tensor, typename T_ActivationLayer, typename T_ExecFunction>
std::unique_ptr<exec::IFunction>
[[nodiscard]] std::unique_ptr<exec::IFunction>
AclActivationBuilder<T_Tensor, T_ActivationLayer, T_ExecFunction>::generateReLU(T_Tensor *ifm_alloc)
{
const ::arm_compute::ActivationLayerInfo act_info{
Expand All @@ -55,7 +55,7 @@ AclActivationBuilder<T_Tensor, T_ActivationLayer, T_ExecFunction>::generateReLU(
}

template <typename T_Tensor, typename T_ActivationLayer, typename T_ExecFunction>
std::unique_ptr<exec::IFunction>
[[nodiscard]] std::unique_ptr<exec::IFunction>
AclActivationBuilder<T_Tensor, T_ActivationLayer, T_ExecFunction>::generateReLU1(
T_Tensor *ifm_alloc)
{
Expand All @@ -70,7 +70,7 @@ AclActivationBuilder<T_Tensor, T_ActivationLayer, T_ExecFunction>::generateReLU1
}

template <typename T_Tensor, typename T_ActivationLayer, typename T_ExecFunction>
std::unique_ptr<exec::IFunction>
[[nodiscard]] std::unique_ptr<exec::IFunction>
AclActivationBuilder<T_Tensor, T_ActivationLayer, T_ExecFunction>::generateReLU6(
T_Tensor *ifm_alloc)
{
Expand All @@ -85,7 +85,7 @@ AclActivationBuilder<T_Tensor, T_ActivationLayer, T_ExecFunction>::generateReLU6
}

template <typename T_Tensor, typename T_ActivationLayer, typename T_ExecFunction>
std::unique_ptr<exec::IFunction>
[[nodiscard]] std::unique_ptr<exec::IFunction>
AclActivationBuilder<T_Tensor, T_ActivationLayer, T_ExecFunction>::generate(ir::Activation code,
T_Tensor *ifm_alloc)
{
Expand Down
3 changes: 2 additions & 1 deletion runtime/onert/backend/acl_neon/Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class Backend : public ::onert::backend::Backend

std::shared_ptr<IConfig> config() const override { return _config; }

std::unique_ptr<backend::BackendContext> newContext(ContextData &&data) const override
[[nodiscard]] std::unique_ptr<backend::BackendContext>
newContext(ContextData &&data) const override
{
const auto &graph = *data.graph;
const auto &operands = data.graph->operands();
Expand Down
5 changes: 4 additions & 1 deletion runtime/onert/backend/acl_neon/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ class Config : public IConfig
bool supportDynamicTensor() override { return false; }
bool supportFP16() override { return false; }

std::unique_ptr<util::ITimer> timer() override { return std::make_unique<util::CPUTimer>(); }
[[nodiscard]] std::unique_ptr<util::ITimer> timer() override
{
return std::make_unique<util::CPUTimer>();
}
};

} // namespace onert::backend::acl_neon
Expand Down
2 changes: 1 addition & 1 deletion runtime/onert/backend/acl_neon/KernelGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class KernelGenerator : public basic::KernelGeneratorBase
KernelGenerator(const ir::Graph &graph, const std::shared_ptr<TensorBuilder> &tensor_builder,
const std::shared_ptr<acl_common::AclTensorRegistry<TensorManager>> &_tensor_reg);

std::unique_ptr<exec::FunctionSequence> generate(ir::OperationIndex ind) override;
[[nodiscard]] std::unique_ptr<exec::FunctionSequence> generate(ir::OperationIndex ind) override;

private:
void visit(const ir::operation::ArgMinMax &) override;
Expand Down
3 changes: 2 additions & 1 deletion runtime/onert/backend/cpu/Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class Backend : public ::onert::backend::Backend

std::shared_ptr<IConfig> config() const override { return _config; }

std::unique_ptr<onert::backend::BackendContext> newContext(ContextData &&data) const override
[[nodiscard]] std::unique_ptr<onert::backend::BackendContext>
newContext(ContextData &&data) const override
{
auto custom_kernel_builder = data.custom_kernel_builder;
auto &graph = *data.graph;
Expand Down
5 changes: 4 additions & 1 deletion runtime/onert/backend/cpu/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ class Config : public IConfig
bool supportDynamicTensor() override { return true; }
bool supportFP16() override { return false; }

std::unique_ptr<util::ITimer> timer() override { return std::make_unique<util::CPUTimer>(); }
[[nodiscard]] std::unique_ptr<util::ITimer> timer() override
{
return std::make_unique<util::CPUTimer>();
}
};

} // namespace onert::backend::cpu
Expand Down
3 changes: 2 additions & 1 deletion runtime/onert/backend/cpu/KernelGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class KernelGenerator : public basic::KernelGeneratorBase
const std::shared_ptr<custom::IKernelBuilder> &kernel_builder,
const std::shared_ptr<ExternalContext> &external_context);

std::unique_ptr<exec::FunctionSequence> generate(ir::OperationIndex op_ind) override;
[[nodiscard]] std::unique_ptr<exec::FunctionSequence>
generate(ir::OperationIndex op_ind) override;

void visit(const ir::operation::AddN &) override;
void visit(const ir::operation::ArgMinMax &) override;
Expand Down
3 changes: 2 additions & 1 deletion runtime/onert/backend/ruy/Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class Backend : public ::onert::backend::Backend

std::shared_ptr<IConfig> config() const override { return _config; }

std::unique_ptr<onert::backend::BackendContext> newContext(ContextData &&data) const override
[[nodiscard]] std::unique_ptr<onert::backend::BackendContext>
newContext(ContextData &&data) const override
{
auto custom_kernel_builder = data.custom_kernel_builder;
auto &graph = *data.graph;
Expand Down
5 changes: 4 additions & 1 deletion runtime/onert/backend/ruy/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ class Config : public IConfig
bool supportDynamicTensor() override { return true; }
bool supportFP16() override { return false; }

std::unique_ptr<util::ITimer> timer() override { return std::make_unique<util::CPUTimer>(); }
[[nodiscard]] std::unique_ptr<util::ITimer> timer() override
{
return std::make_unique<util::CPUTimer>();
}
};

} // namespace onert::backend::ruy
Expand Down
2 changes: 1 addition & 1 deletion runtime/onert/backend/ruy/KernelGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class KernelGenerator : public basic::KernelGeneratorBase
const std::shared_ptr<custom::IKernelBuilder> &kernel_builder,
const std::shared_ptr<ExternalContext> &external_context);

std::unique_ptr<exec::FunctionSequence> generate(ir::OperationIndex ind) override;
[[nodiscard]] std::unique_ptr<exec::FunctionSequence> generate(ir::OperationIndex ind) override;

private:
void visit(const ir::operation::Conv2D &) override;
Expand Down
5 changes: 3 additions & 2 deletions runtime/onert/backend/train/Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ class Backend : public ::onert::backend::Backend, public backend::train::ITraina

std::shared_ptr<IConfig> config() const override { return _config; }

std::unique_ptr<onert::backend::BackendContext> newContext(ContextData &&data) const override
[[nodiscard]] std::unique_ptr<onert::backend::BackendContext>
newContext(ContextData &&data) const override
{
return std::make_unique<DummyBackendContext>(this, std::move(data));
}

std::unique_ptr<backend::train::TrainableBackendContext>
[[nodiscard]] std::unique_ptr<backend::train::TrainableBackendContext>
newContext(backend::train::TrainableContextData &&tdata) const override
{
const auto &tgraph = *tdata.tgraph;
Expand Down
5 changes: 4 additions & 1 deletion runtime/onert/backend/train/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ class Config : public IConfig
bool supportDynamicTensor() override { return false; }
bool supportFP16() override { return false; }

std::unique_ptr<util::ITimer> timer() override { return std::make_unique<util::CPUTimer>(); }
[[nodiscard]] std::unique_ptr<util::ITimer> timer() override
{
return std::make_unique<util::CPUTimer>();
}
};

} // namespace onert::backend::train
Expand Down
3 changes: 2 additions & 1 deletion runtime/onert/backend/trix/Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class Backend : public ::onert::backend::Backend

std::shared_ptr<IConfig> config() const override { return _config; }

std::unique_ptr<onert::backend::BackendContext> newContext(ContextData &&data) const override
[[nodiscard]] std::unique_ptr<onert::backend::BackendContext>
newContext(ContextData &&data) const override
{
auto &graph = *data.graph;
auto context = std::make_unique<BackendContext>(this, std::move(data));
Expand Down
5 changes: 4 additions & 1 deletion runtime/onert/backend/trix/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ class Config : public IConfig
bool supportDynamicTensor() override { return false; }
bool supportFP16() override { return false; }

std::unique_ptr<util::ITimer> timer() override { return std::make_unique<util::CPUTimer>(); }
[[nodiscard]] std::unique_ptr<util::ITimer> timer() override
{
return std::make_unique<util::CPUTimer>();
}
};

} // namespace onert::backend::trix
Expand Down
Loading
Loading