diff --git a/include/onnxruntime/core/session/onnxruntime_c_api.h b/include/onnxruntime/core/session/onnxruntime_c_api.h index b6c51baa90..49b924f0a6 100644 --- a/include/onnxruntime/core/session/onnxruntime_c_api.h +++ b/include/onnxruntime/core/session/onnxruntime_c_api.h @@ -373,7 +373,8 @@ typedef enum OrtAllocatorType { } OrtAllocatorType; /** - memory types for allocator, exec provider specific types should be extended in each provider + * memory types for allocator, exec provider specific types should be extended in each provider + * Whenever this struct is updated, please also update the MakeKey function in onnxruntime/core/framework/execution_provider.cc */ typedef enum OrtMemType { OrtMemTypeCPUInput = -2, // Any CPU memory used by non-CPU execution provider diff --git a/onnxruntime/core/framework/execution_provider.cc b/onnxruntime/core/framework/execution_provider.cc index b3be350c2c..a0bd30bae1 100644 --- a/onnxruntime/core/framework/execution_provider.cc +++ b/onnxruntime/core/framework/execution_provider.cc @@ -11,8 +11,9 @@ namespace onnxruntime { namespace { +//It assumes max(OrtMemType) <= 1, min(OrtMemType) = -2 inline int MakeKey(int id, OrtMemType mem_type) { - return id << 2 | mem_type; + return id << 2 | (mem_type + 2); } } // namespace