/* * Copyright (c) Qualcomm Innovation Center, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ #pragma once #include #include #include #include #include #include #include #include #include namespace executorch { namespace backends { namespace qnn { class OpWrapper final { public: explicit OpWrapper( std::string name, std::string package_name, std::string op_type) : name_(std::move(name)), package_name_(std::move(package_name)), op_type_(std::move(op_type)) {} OpWrapper(OpWrapper&& other) noexcept : name_(std::move(other.name_)), package_name_(std::move(other.package_name_)), op_type_(std::move(other.op_type_)), input_tensors_(std::move(other.input_tensors_)), output_tensors_(std::move(other.output_tensors_)), params_(std::move(other.params_)), input_tensor_structs_(std::move(other.input_tensor_structs_)), output_tensor_structs_(std::move(other.output_tensor_structs_)) {} OpWrapper(const OpWrapper& other) = delete; OpWrapper& operator=(const OpWrapper& other) = delete; OpWrapper& operator=(OpWrapper&& other) = delete; ~OpWrapper() = default; void AddInputTensors( const std::vector>& tensors) { input_tensors_ = tensors; } void AddOutputTensors( const std::vector>& tensors) { output_tensors_ = tensors; } void AddTensorParam( const std::string& name, Qnn_DataType_t data_type, std::uint32_t rank, const std::uint32_t dims[], const void* data, bool copy_data = false) { std::unique_ptr quantize_param_wrapper = std::make_unique(); constexpr std::uint32_t kBytes = 0; std::shared_ptr tensor_wrapper = CreateTensorWrapper( QNN_TENSOR_TYPE_STATIC, data_type, std::move(quantize_param_wrapper), rank, dims, kBytes, data, copy_data); params_.emplace_back( std::make_unique(name, tensor_wrapper)); } template void AddScalarParam(const std::string& name, Qnn_DataType_t data_type, T data) { params_.emplace_back( std::make_unique>(name, data_type, data)); } const std::vector>& GetParams() { return params_; } const std::vector>& GetInputTensors() { return input_tensors_; } const std::vector>& GetOutputTensors() { return output_tensors_; } const std::string GetOpType() { return op_type_; } Qnn_OpConfig_t GetOpConfig(); private: std::string name_; std::string package_name_; std::string op_type_; std::vector> input_tensors_; std::vector> output_tensors_; std::vector> params_; std::vector input_tensor_structs_; std::vector output_tensor_structs_; std::vector param_types_; }; } // namespace qnn } // namespace backends } // namespace executorch