From a2cacf8c27b723890391ea6224aa62e86459a25d Mon Sep 17 00:00:00 2001 From: Satyanvesh Dittakavi <53337087+satyanveshd@users.noreply.github.com> Date: Thu, 2 Dec 2021 11:47:10 +0530 Subject: [PATCH] SWDEV-292714 - Add support for hipPointerGetAttribute (#2425) Change-Id: I9062ab2ef88d835a35fd4c9251d03f469677fa4e [ROCm/hip commit: 610565fe68d619a1f0e56e06517cef5f3ee5e6ea] --- projects/hip/include/hip/driver_types.h | 36 ++++++++++++++++++- projects/hip/include/hip/hip_runtime_api.h | 41 +++++++++++++++++++--- 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/projects/hip/include/hip/driver_types.h b/projects/hip/include/hip/driver_types.h index ec15687492..fb02516354 100644 --- a/projects/hip/include/hip/driver_types.h +++ b/projects/hip/include/hip/driver_types.h @@ -436,7 +436,41 @@ typedef enum hipFunction_attribute { HIP_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES, HIP_FUNC_ATTRIBUTE_PREFERRED_SHARED_MEMORY_CARVEOUT, HIP_FUNC_ATTRIBUTE_MAX -}hipFunction_attribute; +} hipFunction_attribute; + +typedef enum hipPointer_attribute { + HIP_POINTER_ATTRIBUTE_CONTEXT = 1, ///< The context on which a pointer was allocated + ///< @warning - not supported in HIP + HIP_POINTER_ATTRIBUTE_MEMORY_TYPE, ///< memory type describing location of a pointer + HIP_POINTER_ATTRIBUTE_DEVICE_POINTER,///< address at which the pointer is allocated on device + HIP_POINTER_ATTRIBUTE_HOST_POINTER, ///< address at which the pointer is allocated on host + HIP_POINTER_ATTRIBUTE_P2P_TOKENS, ///< A pair of tokens for use with linux kernel interface + ///< @warning - not supported in HIP + HIP_POINTER_ATTRIBUTE_SYNC_MEMOPS, ///< Synchronize every synchronous memory operation + ///< initiated on this region + HIP_POINTER_ATTRIBUTE_BUFFER_ID, ///< Unique ID for an allocated memory region + HIP_POINTER_ATTRIBUTE_IS_MANAGED, ///< Indicates if the pointer points to managed memory + HIP_POINTER_ATTRIBUTE_DEVICE_ORDINAL,///< device ordinal of a device on which a pointer + ///< was allocated or registered + HIP_POINTER_ATTRIBUTE_IS_LEGACY_HIP_IPC_CAPABLE, ///< if this pointer maps to an allocation + ///< that is suitable for hipIpcGetMemHandle + ///< @warning - not supported in HIP + HIP_POINTER_ATTRIBUTE_RANGE_START_ADDR,///< Starting address for this requested pointer + HIP_POINTER_ATTRIBUTE_RANGE_SIZE, ///< Size of the address range for this requested pointer + HIP_POINTER_ATTRIBUTE_MAPPED, ///< tells if this pointer is in a valid address range + ///< that is mapped to a backing allocation + HIP_POINTER_ATTRIBUTE_ALLOWED_HANDLE_TYPES,///< Bitmask of allowed hipmemAllocationHandleType + ///< for this allocation @warning - not supported in HIP + HIP_POINTER_ATTRIBUTE_IS_GPU_DIRECT_RDMA_CAPABLE, ///< returns if the memory referenced by + ///< this pointer can be used with the GPUDirect RDMA API + ///< @warning - not supported in HIP + HIP_POINTER_ATTRIBUTE_ACCESS_FLAGS, ///< Returns the access flags the device associated with + ///< for the corresponding memory referenced by the ptr + HIP_POINTER_ATTRIBUTE_MEMPOOL_HANDLE ///< Returns the mempool handle for the allocation if + ///< it was allocated from a mempool + ///< @warning - not supported in HIP +} hipPointer_attribute; + #endif // !defined(__HIPCC_RTC__) #else #error("Must define exactly one of __HIP_PLATFORM_AMD__ or __HIP_PLATFORM_NVIDIA__"); diff --git a/projects/hip/include/hip/hip_runtime_api.h b/projects/hip/include/hip/hip_runtime_api.h index 235a6d810a..6fb56a0325 100644 --- a/projects/hip/include/hip/hip_runtime_api.h +++ b/projects/hip/include/hip/hip_runtime_api.h @@ -1977,15 +1977,48 @@ hipError_t hipEventQuery(hipEvent_t event); /** * @brief Return attributes for the specified pointer * - * @param[out] attributes for the specified pointer - * @param[in] pointer to get attributes for + * @param [out] attributes attributes for the specified pointer + * @param [in] ptr pointer to get attributes for * * @return #hipSuccess, #hipErrorInvalidDevice, #hipErrorInvalidValue * - * @see hipGetDeviceCount, hipGetDevice, hipSetDevice, hipChooseDevice + * @see hipPointerGetAttribute */ hipError_t hipPointerGetAttributes(hipPointerAttribute_t* attributes, const void* ptr); - +/** + * @brief Returns information about the specified pointer.[BETA] + * + * @param [in, out] data returned pointer attribute value + * @param [in] atribute attribute to query for + * @param [in] ptr pointer to get attributes for + * + * @return #hipSuccess, #hipErrorInvalidDevice, #hipErrorInvalidValue + * + * @beta This API is marked as beta, meaning, while this is feature complete, + * it is still open to changes and may have outstanding issues. + * + * @see hipPointerGetAttributes + */ +hipError_t hipPointerGetAttribute(void* data, hipPointer_attribute attribute, + hipDeviceptr_t ptr); +/** + * @brief Returns information about the specified pointer.[BETA] + * + * @param [in] numAttributes number of attributes to query for + * @param [in] attributes attributes to query for + * @param [in, out] data a two-dimensional containing pointers to memory locations + * where the result of each attribute query will be written to + * @param [in] ptr pointer to get attributes for + * + * @return #hipSuccess, #hipErrorInvalidDevice, #hipErrorInvalidValue + * + * @beta This API is marked as beta, meaning, while this is feature complete, + * it is still open to changes and may have outstanding issues. + * + * @see hipPointerGetAttribute + */ +hipError_t hipDrvPointerGetAttributes(unsigned int numAttributes, hipPointer_attribute* attributes, + void** data, hipDeviceptr_t ptr); /** * @brief Imports an external semaphore. *