diff --git a/runtime/hsa-runtime/core/runtime/runtime.cpp b/runtime/hsa-runtime/core/runtime/runtime.cpp index 51dcb75694..b3e30a8b46 100644 --- a/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -1869,7 +1869,11 @@ hsa_status_t Runtime::GetSvmAttrib(void* ptr, size_t size, } } - if (getFlags) attribs.push_back(kmtPair(HSA_SVM_ATTR_SET_FLAGS, 0)); + if (getFlags) { + // Order is important to later code. + attribs.push_back(kmtPair(HSA_SVM_ATTR_CLR_FLAGS, 0)); + attribs.push_back(kmtPair(HSA_SVM_ATTR_SET_FLAGS, 0)); + } uint8_t* base = AlignDown((uint8_t*)ptr, 4096); uint8_t* end = AlignUp((uint8_t*)ptr + size, 4096); @@ -1888,8 +1892,10 @@ hsa_status_t Runtime::GetSvmAttrib(void* ptr, size_t size, case HSA_AMD_SVM_ATTRIB_GLOBAL_FLAG: { if (attribs[attribs.size() - 1].value & HSA_SVM_FLAG_COHERENT) value = HSA_AMD_SVM_GLOBAL_FLAG_FINE_GRAINED; - else + if (attribs[attribs.size() - 2].value & HSA_SVM_FLAG_COHERENT) value = HSA_AMD_SVM_GLOBAL_FLAG_COARSE_GRAINED; + else + value = HSA_AMD_SVM_GLOBAL_FLAG_INDETERMINATE; break; } case HSA_AMD_SVM_ATTRIB_READ_ONLY: { diff --git a/runtime/hsa-runtime/inc/hsa_ext_amd.h b/runtime/hsa-runtime/inc/hsa_ext_amd.h index 7c1fc16af2..bfecc8ed67 100644 --- a/runtime/hsa-runtime/inc/hsa_ext_amd.h +++ b/runtime/hsa-runtime/inc/hsa_ext_amd.h @@ -2170,13 +2170,25 @@ hsa_status_t HSA_API hsa_amd_deregister_deallocation_callback(void* ptr, typedef enum hsa_amd_svm_model_s { /** - * Updates to memory with this attribute conform to HSA memory consistency model. + * Updates to memory with this attribute conform to HSA memory consistency + * model. */ HSA_AMD_SVM_GLOBAL_FLAG_FINE_GRAINED = 0, /** - * Writes to memory with this attribute can be performed by a single agent at a time. + * Writes to memory with this attribute can be performed by a single agent + * at a time. */ - HSA_AMD_SVM_GLOBAL_FLAG_COARSE_GRAINED = 1 + HSA_AMD_SVM_GLOBAL_FLAG_COARSE_GRAINED = 1, + /** + * Memory region queried contains subregions with both + * HSA_AMD_SVM_GLOBAL_FLAG_COARSE_GRAINED and + * HSA_AMD_SVM_GLOBAL_FLAG_FINE_GRAINED attributes. + * + * This attribute can not be used in hsa_amd_svm_attributes_set. It is a + * possible return from hsa_amd_svm_attributes_get indicating that the query + * region contains both coarse and fine grained memory. + */ + HSA_AMD_SVM_GLOBAL_FLAG_INDETERMINATE = 2 } hsa_amd_svm_model_t; typedef enum hsa_amd_svm_attribute_s {