diff --git a/include/onnxruntime/core/session/onnxruntime_c_api.h b/include/onnxruntime/core/session/onnxruntime_c_api.h index 8af8c820bb..54085a2c08 100644 --- a/include/onnxruntime/core/session/onnxruntime_c_api.h +++ b/include/onnxruntime/core/session/onnxruntime_c_api.h @@ -289,7 +289,7 @@ ORT_API(void, OrtRunOptionsSetTerminate, _In_ OrtRunOptions*, _In_ int flag); * \param type must be one of TENSOR_ELEMENT_DATA_TYPE_xxxx */ ORT_API_STATUS(OrtCreateTensorAsOrtValue, _Inout_ OrtAllocator* allocator, - _In_ const size_t* shape, size_t shape_len, ONNXTensorElementDataType type, + _In_ const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type, _Out_ OrtValue** out); /** @@ -298,7 +298,7 @@ ORT_API_STATUS(OrtCreateTensorAsOrtValue, _Inout_ OrtAllocator* allocator, * \param out Should be freed by calling OrtReleaseValue */ ORT_API_STATUS(OrtCreateTensorWithDataAsOrtValue, _In_ const OrtAllocatorInfo* info, - _Inout_ void* p_data, size_t p_data_len, _In_ const size_t* shape, size_t shape_len, + _Inout_ void* p_data, size_t p_data_len, _In_ const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type, _Out_ OrtValue** out); // This function doesn't work with string tensor diff --git a/include/onnxruntime/core/session/onnxruntime_cxx_api.h b/include/onnxruntime/core/session/onnxruntime_cxx_api.h index dffd51e764..0d6ce33c6b 100644 --- a/include/onnxruntime/core/session/onnxruntime_cxx_api.h +++ b/include/onnxruntime/core/session/onnxruntime_cxx_api.h @@ -129,13 +129,13 @@ class SessionOptionsWrapper { } #endif }; -inline OrtValue* OrtCreateTensorAsOrtValue(_Inout_ OrtAllocator* env, const std::vector& shape, ONNXTensorElementDataType type) { +inline OrtValue* OrtCreateTensorAsOrtValue(_Inout_ OrtAllocator* env, const std::vector& shape, ONNXTensorElementDataType type) { OrtValue* ret; ORT_THROW_ON_ERROR(::OrtCreateTensorAsOrtValue(env, shape.data(), shape.size(), type, &ret)); return ret; } -inline OrtValue* OrtCreateTensorWithDataAsOrtValue(_In_ const OrtAllocatorInfo* info, _In_ void* p_data, size_t p_data_len, const std::vector& shape, ONNXTensorElementDataType type) { +inline OrtValue* OrtCreateTensorWithDataAsOrtValue(_In_ const OrtAllocatorInfo* info, _In_ void* p_data, size_t p_data_len, const std::vector& shape, ONNXTensorElementDataType type) { OrtValue* ret; ORT_THROW_ON_ERROR(::OrtCreateTensorWithDataAsOrtValue(info, p_data, p_data_len, shape.data(), shape.size(), type, &ret)); return ret; diff --git a/onnxruntime/core/session/onnxruntime_c_api.cc b/onnxruntime/core/session/onnxruntime_c_api.cc index 4f881da3c6..bfc4e1d85a 100644 --- a/onnxruntime/core/session/onnxruntime_c_api.cc +++ b/onnxruntime/core/session/onnxruntime_c_api.cc @@ -167,7 +167,7 @@ ORT_API_STATUS_IMPL(OrtFillStringTensor, _In_ OrtValue* value, _In_ const char* } template -OrtStatus* CreateTensorImpl(const size_t* shape, size_t shape_len, OrtAllocator* allocator, +OrtStatus* CreateTensorImpl(const int64_t* shape, size_t shape_len, OrtAllocator* allocator, std::unique_ptr* out) { std::vector shapes(shape_len); for (size_t i = 0; i != shape_len; ++i) { @@ -183,7 +183,7 @@ OrtStatus* CreateTensorImpl(const size_t* shape, size_t shape_len, OrtAllocator* * this function will create a copy of the allocator info */ template -OrtStatus* CreateTensorImpl(const size_t* shape, size_t shape_len, const OrtAllocatorInfo* info, +OrtStatus* CreateTensorImpl(const int64_t* shape, size_t shape_len, const OrtAllocatorInfo* info, void* p_data, size_t p_data_len, std::unique_ptr* out) { size_t elem_count = 1; std::vector shapes(shape_len); @@ -209,7 +209,7 @@ OrtStatus* CreateTensorImpl(const size_t* shape, size_t shape_len, const OrtAllo * this function will create a copy of the allocator info */ ORT_API_STATUS_IMPL(OrtCreateTensorWithDataAsOrtValue, _In_ const OrtAllocatorInfo* info, - _Inout_ void* p_data, size_t p_data_len, _In_ const size_t* shape, size_t shape_len, + _Inout_ void* p_data, size_t p_data_len, _In_ const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type, _Out_ OrtValue** out) { API_IMPL_BEGIN std::unique_ptr tensor; @@ -275,7 +275,7 @@ ORT_API_STATUS_IMPL(OrtCreateTensorWithDataAsOrtValue, _In_ const OrtAllocatorIn } ORT_API_STATUS_IMPL(OrtCreateTensorAsOrtValue, _Inout_ OrtAllocator* allocator, - _In_ const size_t* shape, size_t shape_len, ONNXTensorElementDataType type, + _In_ const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type, _Out_ OrtValue** out) { API_IMPL_BEGIN std::unique_ptr tensor; @@ -796,7 +796,7 @@ OrtStatus* OrtGetValueImplSeqOfPrimitives(const MLValue* p_ml_value, int index, using ElemType = typename T::value_type; auto& data = p_ml_value->Get(); auto& data_elem = data.at(index); - std::vector dims = {1}; + std::vector dims = {1}; OrtStatus* st = OrtCreateTensorAsOrtValue(allocator, dims.data(), dims.size(), GetONNXTensorElementDataType(), out); return st ? st : PopulateTensorWithData(*out, &data_elem, 1); @@ -830,7 +830,7 @@ static OrtStatus* OrtGetValueImplMapHelper(const MLValue* p_ml_value, int index, using TKey = typename T::key_type; using TVal = typename T::mapped_type; auto& data = p_ml_value->Get(); - size_t num_kv_pairs = data.size(); + int64_t num_kv_pairs = data.size(); switch (index) { case 0: { // user is requesting keys std::vector vec; @@ -838,7 +838,7 @@ static OrtStatus* OrtGetValueImplMapHelper(const MLValue* p_ml_value, int index, for (const auto& kv : data) { vec.push_back(kv.first); } - std::vector dims{num_kv_pairs}; + std::vector dims{num_kv_pairs}; OrtStatus* st = OrtCreateTensorAsOrtValue(allocator, dims.data(), dims.size(), GetONNXTensorElementDataType(), out); return st ? st : PopulateTensorWithData(*out, vec.data(), num_kv_pairs); @@ -849,7 +849,7 @@ static OrtStatus* OrtGetValueImplMapHelper(const MLValue* p_ml_value, int index, for (const auto& kv : data) { vec.push_back(kv.second); } - std::vector dims{num_kv_pairs}; + std::vector dims{num_kv_pairs}; OrtStatus* st = OrtCreateTensorAsOrtValue(allocator, dims.data(), dims.size(), GetONNXTensorElementDataType(), out); return st ? st : PopulateTensorWithData(*out, vec.data(), num_kv_pairs); diff --git a/onnxruntime/test/shared_lib/fns_candy_style_transfer.c b/onnxruntime/test/shared_lib/fns_candy_style_transfer.c index de3d592ac6..a058268162 100644 --- a/onnxruntime/test/shared_lib/fns_candy_style_transfer.c +++ b/onnxruntime/test/shared_lib/fns_candy_style_transfer.c @@ -147,7 +147,7 @@ int run_inference(OrtSession* session, const char* input_file, const char* outpu } OrtAllocatorInfo* allocator_info; ORT_ABORT_ON_ERROR(OrtCreateCpuAllocatorInfo(OrtArenaAllocator, OrtMemTypeDefault, &allocator_info)); - const size_t input_shape[] = {1, 3, 720, 720}; + const int64_t input_shape[] = {1, 3, 720, 720}; const size_t input_shape_len = sizeof(input_shape) / sizeof(input_shape[0]); const size_t model_input_len = model_input_ele_count * sizeof(float); diff --git a/onnxruntime/test/shared_lib/test_inference.cc b/onnxruntime/test/shared_lib/test_inference.cc index 6475c34798..295c4abaaf 100644 --- a/onnxruntime/test/shared_lib/test_inference.cc +++ b/onnxruntime/test/shared_lib/test_inference.cc @@ -14,7 +14,7 @@ using namespace onnxruntime; void RunSession(OrtAllocator* env, OrtSession* session_object, - const std::vector& dims_x, + const std::vector& dims_x, const std::vector& values_x, const std::vector& dims_y, const std::vector& values_y, @@ -59,7 +59,7 @@ void RunSession(OrtAllocator* env, OrtSession* session_object, template void TestInference(OrtEnv* env, T model_uri, - const std::vector& dims_x, + const std::vector& dims_x, const std::vector& values_x, const std::vector& expected_dims_y, const std::vector& expected_values_y, @@ -110,9 +110,9 @@ void TestInference(OrtEnv* env, T model_uri, std::unique_ptr value_y(nullptr, OrtReleaseValue); { std::vector allocated_outputs(1); - std::vector dims_y(expected_dims_y.size()); + std::vector dims_y(expected_dims_y.size()); for (size_t i = 0; i != expected_dims_y.size(); ++i) { - dims_y[i] = static_cast(expected_dims_y[i]); + dims_y[i] = expected_dims_y[i]; } allocated_outputs[0] = @@ -141,7 +141,7 @@ class CApiTestWithProvider : public CApiTest, TEST_P(CApiTestWithProvider, simple) { // simple inference test // prepare inputs - std::vector dims_x = {3, 2}; + std::vector dims_x = {3, 2}; std::vector values_x = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f}; // prepare expected inputs and outputs @@ -227,7 +227,7 @@ struct MyCustomOp : OrtCustomOp { TEST_F(CApiTest, custom_op_handler) { std::cout << "Running custom op inference" << std::endl; - std::vector dims_x = {3, 2}; + std::vector dims_x = {3, 2}; std::vector values_x = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f}; // prepare expected inputs and outputs @@ -253,7 +253,7 @@ TEST_F(CApiTest, create_session_without_session_option) { #endif TEST_F(CApiTest, create_tensor) { const char* s[] = {"abc", "kmp"}; - size_t expected_len = 2; + int64_t expected_len = 2; std::unique_ptr default_allocator(std::make_unique()); { std::unique_ptr tensor( @@ -266,7 +266,7 @@ TEST_F(CApiTest, create_tensor) { ORT_THROW_ON_ERROR(OrtGetTensorShapeAndType(tensor.get(), &shape_info_ptr)); shape_info.reset(shape_info_ptr); } - size_t len = static_cast(OrtGetTensorShapeElementCount(shape_info.get())); + int64_t len = OrtGetTensorShapeElementCount(shape_info.get()); ASSERT_EQ(len, expected_len); std::vector shape_array(len); @@ -284,7 +284,7 @@ TEST_F(CApiTest, create_tensor_with_data) { constexpr size_t values_length = sizeof(values) / sizeof(values[0]); OrtAllocatorInfo* info; ORT_THROW_ON_ERROR(OrtCreateAllocatorInfo("Cpu", OrtDeviceAllocator, 0, OrtMemTypeDefault, &info)); - std::vector dims = {4}; + std::vector dims = {4}; std::unique_ptr tensor( OrtCreateTensorWithDataAsOrtValue(info, values, values_length * sizeof(float), dims, ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT), OrtReleaseValue); OrtReleaseAllocatorInfo(info); diff --git a/onnxruntime/test/shared_lib/test_nontensor_types.cc b/onnxruntime/test/shared_lib/test_nontensor_types.cc index 1611b1cfab..ca3cdc5cee 100644 --- a/onnxruntime/test/shared_lib/test_nontensor_types.cc +++ b/onnxruntime/test/shared_lib/test_nontensor_types.cc @@ -40,7 +40,7 @@ TEST_F(CApiTest, CreateGetVectorOfMapsInt64Float) { // support zipmap output ty const int NUM_KV_PAIRS = 4; std::vector in(N); std::vector keys{3, 1, 2, 0}; - std::vector dims = {4}; + std::vector dims = {4}; std::vector values{3.0f, 1.0f, 2.f, 0.f}; for (int i = 0; i < N; ++i) { // create key tensor @@ -147,11 +147,11 @@ TEST_F(CApiTest, CreateGetVectorOfMapsStringFloat) { // support zipmap output t RelAllocations rels(&OrtReleaseStatus); const int N = 3; - const size_t NUM_KV_PAIRS = 4; + const int64_t NUM_KV_PAIRS = 4; std::vector in(N); const char* keys_arr[NUM_KV_PAIRS] = {"abc", "def", "ghi", "jkl"}; std::vector keys{keys_arr, keys_arr + NUM_KV_PAIRS}; - std::vector dims = {NUM_KV_PAIRS}; + std::vector dims = {NUM_KV_PAIRS}; std::vector values{3.0f, 1.0f, 2.f, 0.f}; for (int i = 0; i < N; ++i) { // create key tensor