diff --git a/onnxruntime/core/providers/vitisai/imp/global_api.cc b/onnxruntime/core/providers/vitisai/imp/global_api.cc index 00fb8c1578ff4..a963e656c457b 100644 --- a/onnxruntime/core/providers/vitisai/imp/global_api.cc +++ b/onnxruntime/core/providers/vitisai/imp/global_api.cc @@ -356,10 +356,18 @@ vaip_core::OrtApiForVaip* create_org_api_hook() { the_global_api.tensor_proto_get_shape_unsafe = vaip::tensor_proto_get_shape; the_global_api.tensor_proto_data_type = [](const ONNX_NAMESPACE::TensorProto& t) -> int { return t.data_type(); }; the_global_api.tensor_proto_delete = [](ONNX_NAMESPACE::TensorProto* tp) { delete tp; }; - the_global_api.tensor_proto_new_floats = vaip::tensor_proto_new_floats; + the_global_api.tensor_proto_new_i8 = vaip::tensor_proto_new_i8; + the_global_api.tensor_proto_new_i16 = vaip::tensor_proto_new_i16; the_global_api.tensor_proto_new_i32 = vaip::tensor_proto_new_i32; the_global_api.tensor_proto_new_i64 = vaip::tensor_proto_new_i64; - the_global_api.tensor_proto_new_i8 = vaip::tensor_proto_new_i8; + the_global_api.tensor_proto_new_u8 = vaip::tensor_proto_new_u8; + the_global_api.tensor_proto_new_u16 = vaip::tensor_proto_new_u16; + the_global_api.tensor_proto_new_u32 = vaip::tensor_proto_new_u32; + the_global_api.tensor_proto_new_u64 = vaip::tensor_proto_new_u64; + the_global_api.tensor_proto_new_floats = vaip::tensor_proto_new_floats; + the_global_api.tensor_proto_new_doubles = vaip::tensor_proto_new_doubles; + the_global_api.tensor_proto_new_bf16 = vaip::tensor_proto_new_bf16; + the_global_api.tensor_proto_new_fp16 = vaip::tensor_proto_new_fp16; the_global_api.tensor_proto_raw_data_size = [](const auto& tensor) { return tensor.raw_data().size(); }; the_global_api.tensor_proto_as_raw = vaip::tensor_proto_as_raw; the_global_api.tensor_proto_get_name = [](const auto& tensor) -> const std::string& { return tensor.name(); }; diff --git a/onnxruntime/core/providers/vitisai/imp/tensor_proto.cc b/onnxruntime/core/providers/vitisai/imp/tensor_proto.cc index 671d852abb0d6..63aa1daf7e18f 100644 --- a/onnxruntime/core/providers/vitisai/imp/tensor_proto.cc +++ b/onnxruntime/core/providers/vitisai/imp/tensor_proto.cc @@ -50,28 +50,67 @@ static ONNX_NAMESPACE::TensorProto* tensor_proto_new(const std::string& name, co return tensor_proto.release(); } +ONNX_NAMESPACE::TensorProto* tensor_proto_new_i8(const std::string& name, const std::vector& shape, + const std::vector& data) { + return tensor_proto_new(name, shape, ONNX_NAMESPACE::TensorProto_DataType_INT8, + reinterpret_cast(&data[0]), data.size() * sizeof(data[0])); +} + +ONNX_NAMESPACE::TensorProto* tensor_proto_new_i16(const std::string& name, const std::vector& shape, + const std::vector& data) { + return tensor_proto_new(name, shape, ONNX_NAMESPACE::TensorProto_DataType_INT16, + reinterpret_cast(&data[0]), data.size() * sizeof(data[0])); +} ONNX_NAMESPACE::TensorProto* tensor_proto_new_i32(const std::string& name, const std::vector& shape, const std::vector& data) { return tensor_proto_new(name, shape, ONNX_NAMESPACE::TensorProto_DataType_INT32, - reinterpret_cast(&data[0]), data.size() * sizeof(int32_t)); + reinterpret_cast(&data[0]), data.size() * sizeof(data[0])); } - ONNX_NAMESPACE::TensorProto* tensor_proto_new_i64(const std::string& name, const std::vector& shape, const std::vector& data) { - return tensor_proto_new(name, shape, ONNX_NAMESPACE::TensorProto_DataType_INT64, - reinterpret_cast(&data[0]), data.size() * sizeof(int64_t)); + return tensor_proto_new(name, shape, ONNX_NAMESPACE::TensorProto_DataType_INT32, + reinterpret_cast(&data[0]), data.size() * sizeof(data[0])); } - -ONNX_NAMESPACE::TensorProto* tensor_proto_new_i8(const std::string& name, const std::vector& shape, - const std::vector& data) { - return tensor_proto_new(name, shape, ONNX_NAMESPACE::TensorProto_DataType_INT8, - reinterpret_cast(&data[0]), data.size() * sizeof(int8_t)); +ONNX_NAMESPACE::TensorProto* tensor_proto_new_u8(const std::string& name, const std::vector& shape, + const std::vector& data) { + return tensor_proto_new(name, shape, ONNX_NAMESPACE::TensorProto_DataType_UINT8, + reinterpret_cast(&data[0]), data.size() * sizeof(data[0])); +} +ONNX_NAMESPACE::TensorProto* tensor_proto_new_u16(const std::string& name, const std::vector& shape, + const std::vector& data) { + return tensor_proto_new(name, shape, ONNX_NAMESPACE::TensorProto_DataType_UINT16, + reinterpret_cast(&data[0]), data.size() * sizeof(data[0])); +} +ONNX_NAMESPACE::TensorProto* tensor_proto_new_u32(const std::string& name, const std::vector& shape, + const std::vector& data) { + return tensor_proto_new(name, shape, ONNX_NAMESPACE::TensorProto_DataType_UINT32, + reinterpret_cast(&data[0]), data.size() * sizeof(data[0])); +} +ONNX_NAMESPACE::TensorProto* tensor_proto_new_u64(const std::string& name, const std::vector& shape, + const std::vector& data) { + return tensor_proto_new(name, shape, ONNX_NAMESPACE::TensorProto_DataType_UINT32, + reinterpret_cast(&data[0]), data.size() * sizeof(data[0])); } ONNX_NAMESPACE::TensorProto* tensor_proto_new_floats(const std::string& name, const std::vector& shape, const std::vector& data) { return tensor_proto_new(name, shape, ONNX_NAMESPACE::TensorProto_DataType_FLOAT, - reinterpret_cast(&data[0]), data.size() * sizeof(float)); + reinterpret_cast(&data[0]), data.size() * sizeof(data[0])); +} +ONNX_NAMESPACE::TensorProto* tensor_proto_new_doubles(const std::string& name, const std::vector& shape, + const std::vector& data) { + return tensor_proto_new(name, shape, ONNX_NAMESPACE::TensorProto_DataType_DOUBLE, + reinterpret_cast(&data[0]), data.size() * sizeof(data[0])); } +ONNX_NAMESPACE::TensorProto* tensor_proto_new_bf16(const std::string& name, const std::vector& shape, + const std::vector& data) { + return tensor_proto_new(name, shape, ONNX_NAMESPACE::TensorProto_DataType_BFLOAT16, + reinterpret_cast(&data[0]), data.size() * sizeof(data[0])); +} +ONNX_NAMESPACE::TensorProto* tensor_proto_new_fp16(const std::string& name, const std::vector& shape, + const std::vector& data) { + return tensor_proto_new(name, shape, ONNX_NAMESPACE::TensorProto_DataType_FLOAT16, + reinterpret_cast(&data[0]), data.size() * sizeof(data[0])); +} } // namespace vaip diff --git a/onnxruntime/core/providers/vitisai/imp/tensor_proto.h b/onnxruntime/core/providers/vitisai/imp/tensor_proto.h index 292905ca734f1..417f9d2f4bf31 100644 --- a/onnxruntime/core/providers/vitisai/imp/tensor_proto.h +++ b/onnxruntime/core/providers/vitisai/imp/tensor_proto.h @@ -11,10 +11,26 @@ vaip_core::DllSafe> tensor_proto_get_shape(const ONNX_NAMES const std::string& tensor_proto_get_name(const ONNX_NAMESPACE::TensorProto& tensor); ONNX_NAMESPACE::TensorProto* tensor_proto_new_i8(const std::string& name, const std::vector& shape, const std::vector& data); +ONNX_NAMESPACE::TensorProto* tensor_proto_new_u8(const std::string& name, const std::vector& shape, + const std::vector& data); +ONNX_NAMESPACE::TensorProto* tensor_proto_new_i16(const std::string& name, const std::vector& shape, + const std::vector& data); +ONNX_NAMESPACE::TensorProto* tensor_proto_new_u16(const std::string& name, const std::vector& shape, + const std::vector& data); +ONNX_NAMESPACE::TensorProto* tensor_proto_new_u32(const std::string& name, const std::vector& shape, + const std::vector& data); ONNX_NAMESPACE::TensorProto* tensor_proto_new_i32(const std::string& name, const std::vector& shape, const std::vector& data); +ONNX_NAMESPACE::TensorProto* tensor_proto_new_u64(const std::string& name, const std::vector& shape, + const std::vector& data); ONNX_NAMESPACE::TensorProto* tensor_proto_new_i64(const std::string& name, const std::vector& shape, const std::vector& data); ONNX_NAMESPACE::TensorProto* tensor_proto_new_floats(const std::string& name, const std::vector& shape, const std::vector& data); +ONNX_NAMESPACE::TensorProto* tensor_proto_new_bf16(const std::string& name, const std::vector& shape, + const std::vector& data); +ONNX_NAMESPACE::TensorProto* tensor_proto_new_fp16(const std::string& name, const std::vector& shape, + const std::vector& data); +ONNX_NAMESPACE::TensorProto* tensor_proto_new_doubles(const std::string& name, const std::vector& shape, + const std::vector& data); } // namespace vaip diff --git a/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h b/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h index 2c12d26fd2c31..62a7bb602e7e8 100644 --- a/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h +++ b/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h @@ -12,7 +12,7 @@ struct OrtApi; namespace vaip_core { -#define VAIP_ORT_API_MAJOR (2u) +#define VAIP_ORT_API_MAJOR (3u) #define VAIP_ORT_API_MINOR (0u) #define VAIP_ORT_API_PATCH (0u) struct OrtApiForVaip { @@ -198,6 +198,31 @@ struct OrtApiForVaip { DllSafe (*get_lib_name)(); // [81] /** new API after 2.0 */ void (*graph_add_initialized_tensor)(Graph& graph, const TensorProto& tensor); // [82] + /** new API after 3.0 */ + TensorProto* (*tensor_proto_new_doubles)( + const std::string& name, const std::vector& shape, + const std::vector& data); // [83] + TensorProto* (*tensor_proto_new_i16)( + const std::string& name, const std::vector& shape, + const std::vector& data); // [84 + TensorProto* (*tensor_proto_new_u16)( + const std::string& name, const std::vector& shape, + const std::vector& data); // [84] + TensorProto* (*tensor_proto_new_u32)( + const std::string& name, const std::vector& shape, + const std::vector& data); // [85] + TensorProto* (*tensor_proto_new_u8)(const std::string& name, + const std::vector& shape, + const std::vector& data); // [86] + TensorProto* (*tensor_proto_new_u64)( + const std::string& name, const std::vector& shape, + const std::vector& data); // [87] + TensorProto* (*tensor_proto_new_fp16)( + const std::string& name, const std::vector& shape, + const std::vector& data); // [88] + TensorProto* (*tensor_proto_new_bf16)( + const std::string& name, const std::vector& shape, + const std::vector& data); // [89] }; #ifndef USE_VITISAI diff --git a/onnxruntime/python/onnxruntime_pybind_state.cc b/onnxruntime/python/onnxruntime_pybind_state.cc index 7f9a6e13d7864..b1784f700d1fa 100644 --- a/onnxruntime/python/onnxruntime_pybind_state.cc +++ b/onnxruntime/python/onnxruntime_pybind_state.cc @@ -1066,13 +1066,12 @@ std::unique_ptr CreateExecutionProviderInstance( #endif } else if (type == kVitisAIExecutionProvider) { #ifdef USE_VITISAI + ProviderOptions info{}; const auto it = provider_options_map.find(type); - if (it == provider_options_map.end()) { - LOGS_DEFAULT(FATAL) << "cannot find provider options for VitisAIExecutionProvider"; + if (it != provider_options_map.end()) { + info = it->second; } - const auto& vitis_option_map = it->second; - return onnxruntime::VitisAIProviderFactoryCreator::Create(vitis_option_map) - ->CreateProvider(); + return onnxruntime::VitisAIProviderFactoryCreator::Create(info)->CreateProvider(); #endif } else if (type == kAclExecutionProvider) { #ifdef USE_ACL