From 818c023535cf854071121137ff1ea11697c9e771 Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Mon, 22 Jul 2019 23:25:53 -0700 Subject: [PATCH] Add/correct missing SAL annotations + avoid using unsigned types (except where counts are involved). (#1451) * Add/correct missing SAL annotations + other cosmetic changes. * Add Outptr * Don't use unsigned types --- .../onnxruntime/core/framework/run_options.h | 4 +- .../core/optimizer/graph_transformer_level.h | 2 +- .../core/session/onnxruntime_c_api.h | 91 ++++++++++--------- .../core/session/onnxruntime_cxx_api.h | 10 +- .../core/session/onnxruntime_cxx_inline.h | 8 +- onnxruntime/core/framework/run_options.cc | 13 ++- .../core/session/abi_session_options.cc | 10 +- onnxruntime/core/session/inference_session.h | 2 +- onnxruntime/core/session/onnxruntime_c_api.cc | 36 ++++---- onnxruntime/server/executor.cc | 2 +- .../test/shared_lib/test_run_options.cc | 2 +- 11 files changed, 93 insertions(+), 87 deletions(-) diff --git a/include/onnxruntime/core/framework/run_options.h b/include/onnxruntime/core/framework/run_options.h index 52285311e5..b666078538 100644 --- a/include/onnxruntime/core/framework/run_options.h +++ b/include/onnxruntime/core/framework/run_options.h @@ -14,8 +14,8 @@ struct OrtRunOptions { /// Log severity. See https://github.com/microsoft/onnxruntime/blob/master/include/onnxruntime/core/common/logging/severity.h /// Default = -1 (use the log severity from the InferenceSession that the Run is for). int run_log_severity_level = -1; - unsigned run_log_verbosity_level = 0; ///< VLOG level if debug build and run_log_severity_level is 0 (VERBOSE). - std::string run_tag; ///< A tag for the Run() calls using this. + int run_log_verbosity_level = 0; ///< VLOG level if debug build and run_log_severity_level is 0 (VERBOSE). + std::string run_tag; ///< A tag for the Run() calls using this. // Set to 'true' to ensure the termination of all the outstanding Run() calls // that use this OrtRunOptions instance. Some of the outstanding Run() calls may diff --git a/include/onnxruntime/core/optimizer/graph_transformer_level.h b/include/onnxruntime/core/optimizer/graph_transformer_level.h index 5c8ca23a17..4f2d5b305c 100644 --- a/include/onnxruntime/core/optimizer/graph_transformer_level.h +++ b/include/onnxruntime/core/optimizer/graph_transformer_level.h @@ -7,7 +7,7 @@ namespace onnxruntime { -enum class TransformerLevel : uint32_t { +enum class TransformerLevel : int { Default = 0, Level1, Level2, diff --git a/include/onnxruntime/core/session/onnxruntime_c_api.h b/include/onnxruntime/core/session/onnxruntime_c_api.h index c0c5cb8ef2..1b14ae61f3 100644 --- a/include/onnxruntime/core/session/onnxruntime_c_api.h +++ b/include/onnxruntime/core/session/onnxruntime_c_api.h @@ -18,6 +18,7 @@ extern "C" { #define _In_ #define _In_opt_ #define _Out_ +#define _Outptr_ #define _Out_opt_ #define _Inout_ #define _Inout_opt_ @@ -58,7 +59,6 @@ extern "C" { #ifdef __cplusplus // Windows users should use unicode paths when possible to bypass the MAX_PATH limitation -// Every type name starting with 'P' is a pointer type, an opaque handler // Every pointer marked with _In_ or _Out_, cannot be NULL. Caller should ensure that. // for ReleaseXXX(...) functions, they can accept NULL pointer. #define NO_EXCEPTION noexcept @@ -152,6 +152,7 @@ ORT_RUNTIME_CLASS(TensorTypeAndShapeInfo); ORT_RUNTIME_CLASS(SessionOptions); ORT_RUNTIME_CLASS(Callback); ORT_RUNTIME_CLASS(CustomOpDomain); +ORT_RUNTIME_CLASS(Allocator); // When passing in an allocator to any ORT function, be sure that the allocator object // is not destroyed until the last allocated object using it is freed. @@ -169,16 +170,16 @@ typedef void(ORT_API_CALL* OrtLoggingFunction)( /** * \param out Should be freed by `OrtReleaseEnv` after use */ -ORT_API_STATUS(OrtCreateEnv, OrtLoggingLevel default_warning_level, _In_ const char* logid, _Out_ OrtEnv** out) +ORT_API_STATUS(OrtCreateEnv, OrtLoggingLevel default_logging_level, _In_ const char* logid, _Outptr_ OrtEnv** out) ORT_ALL_ARGS_NONNULL; /** * \param out Should be freed by `OrtReleaseEnv` after use */ ORT_API_STATUS(OrtCreateEnvWithCustomLogger, OrtLoggingFunction logging_function, - _In_opt_ void* logger_param, OrtLoggingLevel default_warning_level, + _In_opt_ void* logger_param, OrtLoggingLevel default_logging_level, _In_ const char* logid, - _Out_ OrtEnv** out); + _Outptr_ OrtEnv** out); // TODO: document the path separator convention? '/' vs '\' // TODO: should specify the access characteristics of model_path. Is this read only during the @@ -186,23 +187,23 @@ ORT_API_STATUS(OrtCreateEnvWithCustomLogger, OrtLoggingFunction logging_function // and continue to access throughout the OrtSession lifetime? // What sort of access is needed to model_path : read or read/write? ORT_API_STATUS(OrtCreateSession, _In_ OrtEnv* env, _In_ const ORTCHAR_T* model_path, - _In_ const OrtSessionOptions* options, _Out_ OrtSession** out); + _In_ const OrtSessionOptions* options, _Outptr_ OrtSession** out); ORT_API_STATUS(OrtCreateSessionFromArray, _In_ OrtEnv* env, _In_ const void* model_data, size_t model_data_length, - _In_ const OrtSessionOptions* options, _Out_ OrtSession** out); + _In_ const OrtSessionOptions* options, _Outptr_ OrtSession** out); ORT_API_STATUS(OrtRun, _Inout_ OrtSession* sess, _In_opt_ const OrtRunOptions* run_options, _In_ const char* const* input_names, _In_ const OrtValue* const* input, size_t input_len, - _In_ const char* const* output_names, size_t output_names_len, _Out_ OrtValue** output); + _In_ const char* const* output_names, size_t output_names_len, _Outptr_ OrtValue** out); /** * \return A pointer of the newly created object. The pointer should be freed by OrtReleaseSessionOptions after use */ -ORT_API_STATUS(OrtCreateSessionOptions, _Out_ OrtSessionOptions** output); +ORT_API_STATUS(OrtCreateSessionOptions, _Outptr_ OrtSessionOptions** options); // create a copy of an existing OrtSessionOptions -ORT_API_STATUS(OrtCloneSessionOptions, _In_ OrtSessionOptions* in, _Out_ OrtSessionOptions** output); +ORT_API_STATUS(OrtCloneSessionOptions, _In_ OrtSessionOptions* in_options, _Outptr_ OrtSessionOptions** out_options); ORT_API_STATUS(OrtEnableSequentialExecution, _In_ OrtSessionOptions* options); ORT_API_STATUS(OrtDisableSequentialExecution, _In_ OrtSessionOptions* options); @@ -228,14 +229,14 @@ ORT_API_STATUS(OrtDisableCpuMemArena, _In_ OrtSessionOptions* options); ORT_API_STATUS(OrtSetSessionLogId, _In_ OrtSessionOptions* options, const char* logid); // < applies to session load, initialization, etc -ORT_API_STATUS(OrtSetSessionLogVerbosityLevel, _In_ OrtSessionOptions* options, uint32_t session_log_verbosity_level); +ORT_API_STATUS(OrtSetSessionLogVerbosityLevel, _In_ OrtSessionOptions* options, int session_log_verbosity_level); // Set Graph optimization level. // Available options are : 0, 1, 2. // 0 -> Disable all optimizations // 1 -> Enable basic optimizations // 2 -> Enable all optimizations -ORT_API_STATUS(OrtSetSessionGraphOptimizationLevel, _In_ OrtSessionOptions* options, uint32_t graph_optimization_level); +ORT_API_STATUS(OrtSetSessionGraphOptimizationLevel, _In_ OrtSessionOptions* options, int graph_optimization_level); // How many threads in the session thread pool. ORT_API_STATUS(OrtSetSessionThreadPoolSize, _In_ OrtSessionOptions* options, int session_thread_pool_size); @@ -257,35 +258,36 @@ ORT_API_STATUS(OrtSessionGetOutputCount, _In_ const OrtSession* sess, _Out_ size /** * \param out should be freed by OrtReleaseTypeInfo after use */ -ORT_API_STATUS(OrtSessionGetInputTypeInfo, _In_ const OrtSession* sess, size_t index, _Out_ OrtTypeInfo** out); +ORT_API_STATUS(OrtSessionGetInputTypeInfo, _In_ const OrtSession* sess, size_t index, _Outptr_ OrtTypeInfo** type_info); /** * \param out should be freed by OrtReleaseTypeInfo after use */ -ORT_API_STATUS(OrtSessionGetOutputTypeInfo, _In_ const OrtSession* sess, size_t index, _Out_ OrtTypeInfo** out); +ORT_API_STATUS(OrtSessionGetOutputTypeInfo, _In_ const OrtSession* sess, size_t index, _Outptr_ OrtTypeInfo** type_info); /** * \param value is set to a null terminated string allocated using 'allocator'. The caller is responsible in freeing it. */ ORT_API_STATUS(OrtSessionGetInputName, _In_ const OrtSession* sess, size_t index, - _Inout_ OrtAllocator* allocator, _Out_ char** value); + _Inout_ OrtAllocator* allocator, _Outptr_ char** value); ORT_API_STATUS(OrtSessionGetOutputName, _In_ const OrtSession* sess, size_t index, - _Inout_ OrtAllocator* allocator, _Out_ char** value); + _Inout_ OrtAllocator* allocator, _Outptr_ char** value); /** * \return A pointer to the newly created object. The pointer should be freed by OrtReleaseRunOptions after use */ -ORT_API_STATUS(OrtCreateRunOptions, _Out_ OrtRunOptions** out); +ORT_API_STATUS(OrtCreateRunOptions, _Outptr_ OrtRunOptions** out); -ORT_API_STATUS(OrtRunOptionsSetRunLogVerbosityLevel, _In_ OrtRunOptions*, unsigned int); +ORT_API_STATUS(OrtRunOptionsSetRunLogVerbosityLevel, _In_ OrtRunOptions* options, int value); ORT_API_STATUS(OrtRunOptionsSetRunTag, _In_ OrtRunOptions*, _In_ const char* run_tag); -ORT_API_STATUS(OrtRunOptionsGetRunLogVerbosityLevel, _In_ OrtRunOptions*, _Out_ unsigned int* out); -ORT_API_STATUS(OrtRunOptionsGetRunTag, _In_ OrtRunOptions*, _Out_ const char** out); +ORT_API_STATUS(OrtRunOptionsGetRunLogVerbosityLevel, _In_ const OrtRunOptions* options, _Out_ int* out); +ORT_API_STATUS(OrtRunOptionsGetRunTag, _In_ const OrtRunOptions*, _Out_ const char** out); // Set a flag so that any running OrtRun* calls that are using this instance of OrtRunOptions // will exit as soon as possible if the flag is true. -ORT_API_STATUS(OrtRunOptionsSetTerminate, _In_ OrtRunOptions*, _In_ int flag); +// flag can be either 1 (true) or 0 (false) +ORT_API_STATUS(OrtRunOptionsSetTerminate, _In_ OrtRunOptions* options, _In_ int flag); /** * Create a tensor from an allocator. OrtReleaseValue will also release the buffer inside the output value @@ -294,7 +296,7 @@ ORT_API_STATUS(OrtRunOptionsSetTerminate, _In_ OrtRunOptions*, _In_ int flag); */ ORT_API_STATUS(OrtCreateTensorAsOrtValue, _Inout_ OrtAllocator* allocator, _In_ const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type, - _Out_ OrtValue** out); + _Outptr_ OrtValue** out); /** * Create a tensor with user's buffer. You can fill the buffer either before calling this function or after. @@ -303,11 +305,11 @@ ORT_API_STATUS(OrtCreateTensorAsOrtValue, _Inout_ OrtAllocator* allocator, */ ORT_API_STATUS(OrtCreateTensorWithDataAsOrtValue, _In_ const OrtAllocatorInfo* info, _Inout_ void* p_data, size_t p_data_len, _In_ const int64_t* shape, size_t shape_len, - ONNXTensorElementDataType type, _Out_ OrtValue** out); + ONNXTensorElementDataType type, _Outptr_ OrtValue** out); // This function doesn't work with string tensor // this is a no-copy method whose pointer is only valid until the backing OrtValue is free'd. -ORT_API_STATUS(OrtGetTensorMutableData, _Inout_ OrtValue* value, _Out_ void** out); +ORT_API_STATUS(OrtGetTensorMutableData, _Inout_ OrtValue* value, _Outptr_ void** out); /** * \Sets *out to 1 iff an OrtValue is a tensor, 0 otherwise @@ -350,7 +352,7 @@ ORT_API_STATUS(OrtGetStringTensorContent, _In_ const OrtValue* value, _Out_ void */ ORT_API_STATUS(OrtTensorProtoToOrtValue, _In_ const void* input, int input_len, _In_opt_ const ORTCHAR_T* input_file_path, _Inout_ void* preallocated, size_t preallocated_size, - _Out_ OrtValue** out, _Out_ OrtCallback** deleter); + _Outptr_ OrtValue** out, _Outptr_ OrtCallback** deleter); /** * f will be freed in this call @@ -376,7 +378,7 @@ ORT_API_STATUS(OrtOnnxTypeFromTypeInfo, _In_ const OrtTypeInfo*, _Out_ enum ONNX /** * The 'out' value should be released by calling OrtReleaseTensorTypeAndShapeInfo */ -ORT_API_STATUS(OrtCreateTensorTypeAndShapeInfo, OrtTensorTypeAndShapeInfo** out); +ORT_API_STATUS(OrtCreateTensorTypeAndShapeInfo, _Outptr_ OrtTensorTypeAndShapeInfo** out); ORT_API_STATUS(OrtSetTensorElementType, _In_ OrtTensorTypeAndShapeInfo*, enum ONNXTensorElementDataType type); @@ -405,14 +407,14 @@ ORT_API_STATUS(OrtGetTensorShapeElementCount, _In_ const OrtTensorTypeAndShapeIn /** * \param out Should be freed by OrtReleaseTensorTypeAndShapeInfo after use */ -ORT_API_STATUS(OrtGetTensorTypeAndShape, _In_ const OrtValue* value, _Out_ OrtTensorTypeAndShapeInfo** out); +ORT_API_STATUS(OrtGetTensorTypeAndShape, _In_ const OrtValue* value, _Outptr_ OrtTensorTypeAndShapeInfo** out); /** * Get the type information of an OrtValue * \param value * \param out The returned value should be freed by OrtReleaseTypeInfo after use */ -ORT_API_STATUS(OrtGetTypeInfo, _In_ const OrtValue* value, OrtTypeInfo** out); +ORT_API_STATUS(OrtGetTypeInfo, _In_ const OrtValue* value, _Outptr_ OrtTypeInfo** out); ORT_API_STATUS(OrtGetValueType, _In_ const OrtValue* value, _Out_ enum ONNXType* out); @@ -432,12 +434,12 @@ typedef enum OrtMemType { OrtMemTypeDefault = 0, // the default allocator for execution provider } OrtMemType; -ORT_API_STATUS(OrtCreateAllocatorInfo, _In_ const char* name1, enum OrtAllocatorType type, int id1, enum OrtMemType mem_type1, _Out_ OrtAllocatorInfo** out); +ORT_API_STATUS(OrtCreateAllocatorInfo, _In_ const char* name1, enum OrtAllocatorType type, int id1, enum OrtMemType mem_type1, _Outptr_ OrtAllocatorInfo** out); /** * Convenience function for special case of OrtCreateAllocatorInfo, for the CPU allocator. Uses name = "Cpu" and id = 0. */ -ORT_API_STATUS(OrtCreateCpuAllocatorInfo, enum OrtAllocatorType type, enum OrtMemType mem_type1, _Out_ OrtAllocatorInfo** out) +ORT_API_STATUS(OrtCreateCpuAllocatorInfo, enum OrtAllocatorType type, enum OrtMemType mem_type1, _Outptr_ OrtAllocatorInfo** out) ORT_ALL_ARGS_NONNULL; /** @@ -450,17 +452,16 @@ ORT_ALL_ARGS_NONNULL; /** * Do not free the returned value */ -ORT_API_STATUS(OrtAllocatorInfoGetName, _In_ OrtAllocatorInfo* ptr, _Out_ const char** out); -ORT_API_STATUS(OrtAllocatorInfoGetId, _In_ OrtAllocatorInfo* ptr, _Out_ int* out); -ORT_API_STATUS(OrtAllocatorInfoGetMemType, _In_ OrtAllocatorInfo* ptr, _Out_ OrtMemType* out); -ORT_API_STATUS(OrtAllocatorInfoGetType, _In_ OrtAllocatorInfo* ptr, _Out_ OrtAllocatorType* out); +ORT_API_STATUS(OrtAllocatorInfoGetName, _In_ const OrtAllocatorInfo* ptr, _Out_ const char** out); +ORT_API_STATUS(OrtAllocatorInfoGetId, _In_ const OrtAllocatorInfo* ptr, _Out_ int* out); +ORT_API_STATUS(OrtAllocatorInfoGetMemType, _In_ const OrtAllocatorInfo* ptr, _Out_ OrtMemType* out); +ORT_API_STATUS(OrtAllocatorInfoGetType, _In_ const OrtAllocatorInfo* ptr, _Out_ OrtAllocatorType* out); -ORT_API_STATUS(OrtAllocatorAlloc, _Inout_ OrtAllocator* ptr, size_t size, _Out_ void** out); +ORT_API_STATUS(OrtAllocatorAlloc, _Inout_ OrtAllocator* ptr, size_t size, _Outptr_ void** out); ORT_API_STATUS(OrtAllocatorFree, _Inout_ OrtAllocator* ptr, void* p); ORT_API_STATUS(OrtAllocatorGetInfo, _In_ const OrtAllocator* ptr, _Out_ const OrtAllocatorInfo** out); -ORT_API_STATUS(OrtCreateDefaultAllocator, _Out_ OrtAllocator** out); -ORT_API(void, OrtReleaseAllocator, _In_ OrtAllocator* allocator); +ORT_API_STATUS(OrtCreateDefaultAllocator, _Outptr_ OrtAllocator** out); ORT_API(const char*, OrtGetVersionString); /** @@ -509,13 +510,13 @@ ORT_ALL_ARGS_NONNULL; * If input OrtValue represents a sequence, use index to retrieve the index'th element * of the sequence. */ -ORT_API_STATUS(OrtGetValue, const OrtValue* value, int index, OrtAllocator* allocator, OrtValue** out); +ORT_API_STATUS(OrtGetValue, _In_ const OrtValue* value, int index, _Inout_ OrtAllocator* allocator, _Outptr_ OrtValue** out); /** * Returns 2 for type map and N for sequence where N is the number of elements * in the sequence. */ -ORT_API_STATUS(OrtGetValueCount, const OrtValue* value, size_t* out); +ORT_API_STATUS(OrtGetValueCount, _In_ const OrtValue* value, _Out_ size_t* out); /** * To construct a map, use num_values = 2 and 'in' should be an arrary of 2 OrtValues @@ -524,8 +525,8 @@ ORT_API_STATUS(OrtGetValueCount, const OrtValue* value, size_t* out); * sequence. 'in' should be an arrary of N OrtValues. * \value_type should be either map or sequence. */ -ORT_API_STATUS(OrtCreateValue, OrtValue** in, size_t num_values, enum ONNXType value_type, - OrtValue** out); +ORT_API_STATUS(OrtCreateValue, _In_ OrtValue** in, size_t num_values, enum ONNXType value_type, + _Outptr_ OrtValue** out); /* * EXPERIMENTAL APIS - Subject to change. Released as a preview to get feedback and enable early testing @@ -550,7 +551,7 @@ struct OrtCustomOpApi { OrtStatus*(ORT_API_CALL* KernelInfoGetAttribute_int64)(_In_ const OrtKernelInfo* info, _In_ const char* name, _Out_ int64_t* out); OrtStatus*(ORT_API_CALL* KernelInfoGetAttribute_string)(_In_ const OrtKernelInfo* info, _In_ const char* name, _Out_ char* out, _Inout_ size_t* size); - OrtStatus*(ORT_API_CALL* GetTensorTypeAndShape)(_In_ const OrtValue* value, _Out_ OrtTensorTypeAndShapeInfo** out); + OrtStatus*(ORT_API_CALL* GetTensorTypeAndShape)(_In_ const OrtValue* value, _Outptr_ OrtTensorTypeAndShapeInfo** out); OrtStatus*(ORT_API_CALL* GetTensorShapeElementCount)(_In_ const OrtTensorTypeAndShapeInfo* info, _Out_ size_t* out); OrtStatus*(ORT_API_CALL* GetTensorElementType)(_In_ const OrtTensorTypeAndShapeInfo*, _Out_ enum ONNXTensorElementDataType* out); @@ -558,14 +559,14 @@ struct OrtCustomOpApi { OrtStatus*(ORT_API_CALL* GetDimensionCount)(_In_ const OrtTensorTypeAndShapeInfo* info, _Out_ size_t* out); OrtStatus*(ORT_API_CALL* GetDimensions)(_In_ const OrtTensorTypeAndShapeInfo* info, _Out_ int64_t* dim_values, size_t dim_values_length); OrtStatus*(ORT_API_CALL* SetDimensions)(OrtTensorTypeAndShapeInfo* info, _In_ const int64_t* dim_values, size_t dim_count); - OrtStatus*(ORT_API_CALL* GetTensorMutableData)(_Inout_ OrtValue* value, _Out_ void** data); + OrtStatus*(ORT_API_CALL* GetTensorMutableData)(_Inout_ OrtValue* value, _Outptr_ void** data); void(ORT_API_CALL* ReleaseTensorTypeAndShapeInfo)(OrtTensorTypeAndShapeInfo* input); OrtStatus*(ORT_API_CALL* KernelContext_GetInputCount)(const OrtKernelContext* context, _Out_ size_t* out); OrtStatus*(ORT_API_CALL* KernelContext_GetInput)(const OrtKernelContext* context, _In_ size_t index, _Out_ const OrtValue** out); OrtStatus*(ORT_API_CALL* KernelContext_GetOutputCount)(const OrtKernelContext* context, _Out_ size_t* out); - OrtStatus*(ORT_API_CALL* KernelContext_GetOutput)(OrtKernelContext* context, _In_ size_t index, _In_ const int64_t* dim_values, size_t dim_count, _Out_ OrtValue** out); + OrtStatus*(ORT_API_CALL* KernelContext_GetOutput)(OrtKernelContext* context, _In_ size_t index, _In_ const int64_t* dim_values, size_t dim_count, _Outptr_ OrtValue** out); }; typedef struct OrtCustomOpApi OrtCustomOpApi; @@ -600,7 +601,7 @@ typedef struct OrtCustomOp OrtCustomOp; /* * Create a custom op domain. After all sessions using it are released, call OrtReleaseCustomOpDomain */ -ORT_API_STATUS(OrtCreateCustomOpDomain, _In_ const char* domain, _Out_ OrtCustomOpDomain** out); +ORT_API_STATUS(OrtCreateCustomOpDomain, _In_ const char* domain, _Outptr_ OrtCustomOpDomain** out); /* * Add custom ops to the OrtCustomOpDomain @@ -612,7 +613,7 @@ ORT_API_STATUS(OrtCustomOpDomain_Add, _In_ OrtCustomOpDomain* custom_op_domain, * Add a custom op domain to the OrtSessionOptions * Note: The OrtCustomOpDomain* must not be deleted until the sessions using it are released */ -ORT_API_STATUS(OrtAddCustomOpDomain, _In_ OrtSessionOptions* options, OrtCustomOpDomain* custom_op_domain); +ORT_API_STATUS(OrtAddCustomOpDomain, _In_ OrtSessionOptions* options, _In_ OrtCustomOpDomain* custom_op_domain); /* * END EXPERIMENTAL */ diff --git a/include/onnxruntime/core/session/onnxruntime_cxx_api.h b/include/onnxruntime/core/session/onnxruntime_cxx_api.h index 8cd8dea637..dc10322a01 100644 --- a/include/onnxruntime/core/session/onnxruntime_cxx_api.h +++ b/include/onnxruntime/core/session/onnxruntime_cxx_api.h @@ -101,8 +101,8 @@ struct Value; struct Env : Base { Env(nullptr_t) {} - Env(OrtLoggingLevel default_warning_level, _In_ const char* logid); - Env(OrtLoggingLevel default_warning_level, const char* logid, OrtLoggingFunction logging_function, void* logger_param); + Env(OrtLoggingLevel default_logging_level, _In_ const char* logid); + Env(OrtLoggingLevel default_logging_level, const char* logid, OrtLoggingFunction logging_function, void* logger_param); explicit Env(OrtEnv* p) : Base{p} {} }; @@ -117,8 +117,8 @@ struct RunOptions : Base { RunOptions(nullptr_t) {} RunOptions(); - RunOptions& SetRunLogVerbosityLevel(unsigned int); - unsigned int GetRunLogVerbosityLevel() const; + RunOptions& SetRunLogVerbosityLevel(int); + int GetRunLogVerbosityLevel() const; RunOptions& SetRunTag(const char* run_tag); const char* GetRunTag() const; @@ -134,7 +134,7 @@ struct SessionOptions : Base { SessionOptions Clone() const; SessionOptions& SetThreadPoolSize(int session_thread_pool_size); - SessionOptions& SetGraphOptimizationLevel(uint32_t graph_optimization_level); + SessionOptions& SetGraphOptimizationLevel(int graph_optimization_level); SessionOptions& EnableCpuMemArena(); SessionOptions& DisableCpuMemArena(); diff --git a/include/onnxruntime/core/session/onnxruntime_cxx_inline.h b/include/onnxruntime/core/session/onnxruntime_cxx_inline.h index ccb7af2616..dfbf5029ed 100644 --- a/include/onnxruntime/core/session/onnxruntime_cxx_inline.h +++ b/include/onnxruntime/core/session/onnxruntime_cxx_inline.h @@ -90,13 +90,13 @@ inline RunOptions::RunOptions() { ORT_THROW_ON_ERROR(OrtCreateRunOptions(&p_)); } -inline RunOptions& RunOptions::SetRunLogVerbosityLevel(unsigned int level) { +inline RunOptions& RunOptions::SetRunLogVerbosityLevel(int level) { ORT_THROW_ON_ERROR(OrtRunOptionsSetRunLogVerbosityLevel(p_, level)); return *this; } -inline unsigned int RunOptions::GetRunLogVerbosityLevel() const { - unsigned int out; +inline int RunOptions::GetRunLogVerbosityLevel() const { + int out; ORT_THROW_ON_ERROR(OrtRunOptionsGetRunLogVerbosityLevel(p_, &out)); return out; } @@ -132,7 +132,7 @@ inline SessionOptions& SessionOptions::SetThreadPoolSize(int session_thread_pool return *this; } -inline SessionOptions& SessionOptions::SetGraphOptimizationLevel(uint32_t graph_optimization_level) { +inline SessionOptions& SessionOptions::SetGraphOptimizationLevel(int graph_optimization_level) { ORT_THROW_ON_ERROR(OrtSetSessionGraphOptimizationLevel(p_, graph_optimization_level)); return *this; } diff --git a/onnxruntime/core/framework/run_options.cc b/onnxruntime/core/framework/run_options.cc index add62db9da..d446dc42ca 100644 --- a/onnxruntime/core/framework/run_options.cc +++ b/onnxruntime/core/framework/run_options.cc @@ -12,7 +12,7 @@ ORT_API_STATUS_IMPL(OrtCreateRunOptions, OrtRunOptions** out) { API_IMPL_END } -ORT_API_STATUS_IMPL(OrtRunOptionsSetRunLogVerbosityLevel, _In_ OrtRunOptions* options, unsigned int value) { +ORT_API_STATUS_IMPL(OrtRunOptionsSetRunLogVerbosityLevel, _In_ OrtRunOptions* options, int value) { options->run_log_verbosity_level = value; return nullptr; } @@ -23,17 +23,20 @@ ORT_API_STATUS_IMPL(OrtRunOptionsSetRunTag, _In_ OrtRunOptions* options, _In_ co return nullptr; } -ORT_API_STATUS_IMPL(OrtRunOptionsGetRunLogVerbosityLevel, _In_ OrtRunOptions* options, unsigned int* out) { +ORT_API_STATUS_IMPL(OrtRunOptionsGetRunLogVerbosityLevel, _In_ const OrtRunOptions* options, int* out) { *out = options->run_log_verbosity_level; return nullptr; } -ORT_API_STATUS_IMPL(OrtRunOptionsGetRunTag, _In_ OrtRunOptions* options, const char** out) { +ORT_API_STATUS_IMPL(OrtRunOptionsGetRunTag, _In_ const OrtRunOptions* options, const char** out) { *out = options->run_tag.c_str(); return nullptr; } -ORT_API_STATUS_IMPL(OrtRunOptionsSetTerminate, _In_ OrtRunOptions* options, bool value) { - options->terminate = value; +ORT_API_STATUS_IMPL(OrtRunOptionsSetTerminate, _In_ OrtRunOptions* options, int flag) { + if (!(flag == 0 || flag == 1)) { + return OrtCreateStatus(ORT_INVALID_ARGUMENT, "Invalid value for flag. Should be either 0 or 1"); + } + options->terminate = flag; return nullptr; } diff --git a/onnxruntime/core/session/abi_session_options.cc b/onnxruntime/core/session/abi_session_options.cc index aeaab0b248..fadb56745a 100644 --- a/onnxruntime/core/session/abi_session_options.cc +++ b/onnxruntime/core/session/abi_session_options.cc @@ -89,16 +89,18 @@ ORT_API_STATUS_IMPL(OrtSetSessionLogId, _In_ OrtSessionOptions* options, const c } ///< applies to session load, initialization, etc -ORT_API_STATUS_IMPL(OrtSetSessionLogVerbosityLevel, _In_ OrtSessionOptions* options, uint32_t session_log_verbosity_level) { +ORT_API_STATUS_IMPL(OrtSetSessionLogVerbosityLevel, _In_ OrtSessionOptions* options, int session_log_verbosity_level) { options->value.session_log_verbosity_level = session_log_verbosity_level; return nullptr; } // Set Graph optimization level. -// Returns 0 on success and -1 otherwise // Available options are : 0, 1, 2. -ORT_API_STATUS_IMPL(OrtSetSessionGraphOptimizationLevel, _In_ OrtSessionOptions* options, uint32_t graph_optimization_level) { - if (graph_optimization_level >= static_cast(onnxruntime::TransformerLevel::MaxTransformerLevel)) +ORT_API_STATUS_IMPL(OrtSetSessionGraphOptimizationLevel, _In_ OrtSessionOptions* options, int graph_optimization_level) { + if (graph_optimization_level < 0) { + return OrtCreateStatus(ORT_INVALID_ARGUMENT, "graph_optimization_level is not valid"); + } + if (graph_optimization_level >= static_cast(onnxruntime::TransformerLevel::MaxTransformerLevel)) return OrtCreateStatus(ORT_INVALID_ARGUMENT, "graph_optimization_level is not valid"); options->value.graph_optimization_level = static_cast(graph_optimization_level); return nullptr; diff --git a/onnxruntime/core/session/inference_session.h b/onnxruntime/core/session/inference_session.h index fe428006b4..761c121e95 100644 --- a/onnxruntime/core/session/inference_session.h +++ b/onnxruntime/core/session/inference_session.h @@ -77,7 +77,7 @@ struct SessionOptions { /// See https://github.com/microsoft/onnxruntime/blob/master/include/onnxruntime/core/common/logging/severity.h /// Default = -1 (use default logger severity) int session_log_severity_level = -1; - unsigned session_log_verbosity_level = 0; ///< VLOG level if debug build and session_log_severity_level is 0 (VERBOSE). + int session_log_verbosity_level = 0; ///< VLOG level if debug build and session_log_severity_level is 0 (VERBOSE). unsigned max_num_graph_transformation_steps = 5; // TODO choose a good default here? diff --git a/onnxruntime/core/session/onnxruntime_c_api.cc b/onnxruntime/core/session/onnxruntime_c_api.cc index 2a4cf1c948..84e3b2a02d 100644 --- a/onnxruntime/core/session/onnxruntime_c_api.cc +++ b/onnxruntime/core/session/onnxruntime_c_api.cc @@ -92,7 +92,7 @@ class LoggingWrapper : public ISink { ORT_API_STATUS_IMPL(OrtCreateEnvWithCustomLogger, OrtLoggingFunction logging_function, _In_opt_ void* logger_param, OrtLoggingLevel default_warning_level, _In_ const char* logid, - _Out_ OrtEnv** out) { + _Outptr_ OrtEnv** out) { API_IMPL_BEGIN std::string name = logid; std::unique_ptr logger = std::make_unique(logging_function, logger_param); @@ -113,7 +113,7 @@ ORT_API(const char*, OrtGetVersionString) { } ORT_API_STATUS_IMPL(OrtCreateEnv, OrtLoggingLevel default_warning_level, - _In_ const char* logid, _Out_ OrtEnv** out) { + _In_ const char* logid, _Outptr_ OrtEnv** out) { API_IMPL_BEGIN std::string name = logid; auto default_logging_manager = std::make_unique(std::unique_ptr{new CLogSink{}}, @@ -206,7 +206,7 @@ OrtStatus* CreateTensorImpl(const int64_t* shape, size_t shape_len, const OrtAll */ ORT_API_STATUS_IMPL(OrtCreateTensorWithDataAsOrtValue, _In_ const OrtAllocatorInfo* info, _Inout_ void* p_data, size_t p_data_len, _In_ const int64_t* shape, size_t shape_len, - ONNXTensorElementDataType type, _Out_ OrtValue** out) { + ONNXTensorElementDataType type, _Outptr_ OrtValue** out) { API_IMPL_BEGIN std::unique_ptr tensor; switch (type) { @@ -272,7 +272,7 @@ ORT_API_STATUS_IMPL(OrtCreateTensorWithDataAsOrtValue, _In_ const OrtAllocatorIn ORT_API_STATUS_IMPL(OrtCreateTensorAsOrtValue, _Inout_ OrtAllocator* allocator, _In_ const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type, - _Out_ OrtValue** out) { + _Outptr_ OrtValue** out) { API_IMPL_BEGIN std::unique_ptr tensor; switch (type) { @@ -336,7 +336,7 @@ ORT_API_STATUS_IMPL(OrtCreateTensorAsOrtValue, _Inout_ OrtAllocator* allocator, API_IMPL_END } -ORT_API_STATUS_IMPL(OrtCreateCustomOpDomain, _In_ const char* domain, _Out_ OrtCustomOpDomain** out) { +ORT_API_STATUS_IMPL(OrtCreateCustomOpDomain, _In_ const char* domain, _Outptr_ OrtCustomOpDomain** out) { API_IMPL_BEGIN auto custom_op_domain = std::make_unique(); custom_op_domain->domain_ = domain; @@ -366,7 +366,7 @@ ORT_API_STATUS_IMPL(OrtAddCustomOpDomain, _In_ OrtSessionOptions* options, OrtCu namespace { template OrtStatus* CreateSessionImpl(_In_ OrtEnv* env, _In_ const OrtSessionOptions* options, - Loader loader, _Out_ OrtSession** out) { + Loader loader, _Outptr_ OrtSession** out) { auto sess = std::make_unique<::onnxruntime::InferenceSession>( options == nullptr ? onnxruntime::SessionOptions() : options->value, env->loggingManager); Status status; @@ -396,7 +396,7 @@ OrtStatus* CreateSessionImpl(_In_ OrtEnv* env, _In_ const OrtSessionOptions* opt } // namespace ORT_API_STATUS_IMPL(OrtCreateSession, _In_ OrtEnv* env, _In_ const ORTCHAR_T* model_path, - _In_ const OrtSessionOptions* options, _Out_ OrtSession** out) { + _In_ const OrtSessionOptions* options, _Outptr_ OrtSession** out) { API_IMPL_BEGIN const auto loader = [model_path](InferenceSession& sess) { return sess.Load(model_path); @@ -406,7 +406,7 @@ ORT_API_STATUS_IMPL(OrtCreateSession, _In_ OrtEnv* env, _In_ const ORTCHAR_T* mo } ORT_API_STATUS_IMPL(OrtCreateSessionFromArray, _In_ OrtEnv* env, _In_ const void* model_data, size_t model_data_length, - _In_ const OrtSessionOptions* options, _Out_ OrtSession** out) { + _In_ const OrtSessionOptions* options, _Outptr_ OrtSession** out) { API_IMPL_BEGIN const auto loader = [model_data, model_data_length](InferenceSession& sess) { return sess.Load(model_data, static_cast(model_data_length)); @@ -418,7 +418,7 @@ ORT_API_STATUS_IMPL(OrtCreateSessionFromArray, _In_ OrtEnv* env, _In_ const void ORT_API_STATUS_IMPL(OrtRun, _In_ OrtSession* sess, _In_ const OrtRunOptions* run_options, _In_ const char* const* input_names, _In_ const OrtValue* const* input, size_t input_len, - _In_ const char* const* output_names1, size_t output_names_len, _Out_ OrtValue** output) { + _In_ const char* const* output_names1, size_t output_names_len, _Outptr_ OrtValue** output) { API_IMPL_BEGIN auto session = reinterpret_cast<::onnxruntime::InferenceSession*>(sess); const int queue_id = 0; @@ -477,7 +477,7 @@ ORT_API_STATUS_IMPL(OrtRun, _In_ OrtSession* sess, API_IMPL_END } -ORT_API_STATUS_IMPL(OrtGetTensorMutableData, _In_ OrtValue* value, _Out_ void** output) { +ORT_API_STATUS_IMPL(OrtGetTensorMutableData, _In_ OrtValue* value, _Outptr_ void** output) { TENSOR_READWRITE_API_BEGIN //TODO: test if it's a string tensor *output = tensor->MutableDataRaw(); @@ -522,7 +522,7 @@ ORT_API_STATUS_IMPL(OrtGetStringTensorContent, _In_ const OrtValue* value, ORT_API_STATUS_IMPL(OrtTensorProtoToOrtValue, _In_ const void* input, int input_len, _In_opt_ const ORTCHAR_T* input_file_path, _Inout_ void* preallocated, size_t preallocated_size, - _Out_ OrtValue** out, _Out_ OrtCallback** deleter) { + _Outptr_ OrtValue** out, _Outptr_ OrtCallback** deleter) { API_IMPL_BEGIN OrtAllocatorInfo* cpuAllocatorInfo; auto st = OrtCreateCpuAllocatorInfo(OrtDeviceAllocator, OrtMemTypeDefault, &cpuAllocatorInfo); @@ -596,7 +596,7 @@ ORT_API_STATUS_IMPL(OrtSessionGetOutputCount, _In_ const OrtSession* sess, _Out_ API_IMPL_END } -ORT_API_STATUS_IMPL(OrtSessionGetInputTypeInfo, _In_ const OrtSession* sess, size_t index, _Out_ struct OrtTypeInfo** out) { +ORT_API_STATUS_IMPL(OrtSessionGetInputTypeInfo, _In_ const OrtSession* sess, size_t index, _Outptr_ struct OrtTypeInfo** out) { API_IMPL_BEGIN auto session = reinterpret_cast(sess); std::pair p = session->GetModelInputs(); @@ -608,7 +608,7 @@ ORT_API_STATUS_IMPL(OrtSessionGetInputTypeInfo, _In_ const OrtSession* sess, siz return OrtTypeInfo::FromDataTypeImpl(type_proto, out); API_IMPL_END } -ORT_API_STATUS_IMPL(OrtSessionGetOutputTypeInfo, _In_ const OrtSession* sess, size_t index, _Out_ struct OrtTypeInfo** out) { +ORT_API_STATUS_IMPL(OrtSessionGetOutputTypeInfo, _In_ const OrtSession* sess, size_t index, _Outptr_ struct OrtTypeInfo** out) { API_IMPL_BEGIN auto session = reinterpret_cast(sess); std::pair p = session->GetModelOutputs(); @@ -630,7 +630,7 @@ static char* StrDup(const std::string& str, OrtAllocator* allocator) { static OrtStatus* GetInputOutputNameImpl(_In_ const OrtSession* sess, size_t index, _Inout_ OrtAllocator* allocator, bool is_input, - _Out_ char** output) { + _Outptr_ char** output) { auto session = reinterpret_cast(sess); std::pair p = is_input ? session->GetModelInputs() : session->GetModelOutputs(); if (!p.first.IsOK()) @@ -650,7 +650,7 @@ ORT_API_STATUS_IMPL(OrtIsTensor, _In_ const OrtValue* value, int* out) { return nullptr; } -ORT_API_STATUS_IMPL(OrtAllocatorAlloc, _Inout_ OrtAllocator* ptr, size_t size, _Out_ void** out) { +ORT_API_STATUS_IMPL(OrtAllocatorAlloc, _Inout_ OrtAllocator* ptr, size_t size, _Outptr_ void** out) { API_IMPL_BEGIN *out = ptr->Alloc(ptr, size); return nullptr; @@ -664,7 +664,7 @@ ORT_API_STATUS_IMPL(OrtAllocatorFree, _Inout_ OrtAllocator* ptr, void* p) { API_IMPL_END } -ORT_API_STATUS_IMPL(OrtAllocatorGetInfo, _In_ const OrtAllocator* ptr, _Out_ const struct OrtAllocatorInfo** out) { +ORT_API_STATUS_IMPL(OrtAllocatorGetInfo, _In_ const OrtAllocator* ptr, _Outptr_ const struct OrtAllocatorInfo** out) { API_IMPL_BEGIN *out = ptr->Info(ptr); return nullptr; @@ -672,14 +672,14 @@ ORT_API_STATUS_IMPL(OrtAllocatorGetInfo, _In_ const OrtAllocator* ptr, _Out_ con } ORT_API_STATUS_IMPL(OrtSessionGetInputName, _In_ const OrtSession* sess, size_t index, - _Inout_ OrtAllocator* allocator, _Out_ char** output) { + _Inout_ OrtAllocator* allocator, _Outptr_ char** output) { API_IMPL_BEGIN return GetInputOutputNameImpl(sess, index, allocator, true, output); API_IMPL_END } ORT_API_STATUS_IMPL(OrtSessionGetOutputName, _In_ const OrtSession* sess, size_t index, - _Inout_ OrtAllocator* allocator, _Out_ char** output) { + _Inout_ OrtAllocator* allocator, _Outptr_ char** output) { API_IMPL_BEGIN return GetInputOutputNameImpl(sess, index, allocator, false, output); API_IMPL_END diff --git a/onnxruntime/server/executor.cc b/onnxruntime/server/executor.cc index b2c2b3e1a6..e7cae666f4 100644 --- a/onnxruntime/server/executor.cc +++ b/onnxruntime/server/executor.cc @@ -120,7 +120,7 @@ protobufutil::Status Executor::Predict(const std::string& model_name, } Ort::RunOptions run_options{}; - run_options.SetRunLogVerbosityLevel(static_cast(env_->GetLogSeverity())); + run_options.SetRunLogVerbosityLevel(static_cast(env_->GetLogSeverity())); run_options.SetRunTag(request_id_.c_str()); // Prepare the output names diff --git a/onnxruntime/test/shared_lib/test_run_options.cc b/onnxruntime/test/shared_lib/test_run_options.cc index 5a07d66354..f1f05bb6cc 100644 --- a/onnxruntime/test/shared_lib/test_run_options.cc +++ b/onnxruntime/test/shared_lib/test_run_options.cc @@ -10,5 +10,5 @@ TEST_F(CApiTest, run_options) { options.SetRunLogVerbosityLevel(1); options.SetRunTag("abc"); ASSERT_STREQ(options.GetRunTag(), "abc"); - ASSERT_EQ(options.GetRunLogVerbosityLevel(), unsigned(1)); + ASSERT_EQ(options.GetRunLogVerbosityLevel(), 1); }