All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] Add hsaKmtAvailableMemory available memory inquiry to libhsakmt
@ 2022-01-10 21:23 Daniel Phillips
  2022-01-10 23:40 ` Felix Kuehling
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Phillips @ 2022-01-10 21:23 UTC (permalink / raw)
  To: amd-gfx, dri-devel; +Cc: Daniel Phillips

Add a library call to inquire memory available for allocation per
node. Uses the AMDKFD_IOC_AVAILABLE_MEMORY ioctl available in KFD
ioctl version 1.7

Change-Id: Id770fc2261e9e076f2fbce7dcdac640a6354ddbe
---
 include/hsakmt.h          | 11 +++++++++++
 include/linux/kfd_ioctl.h | 18 ++++++++++++++++--
 src/memory.c              | 23 +++++++++++++++++++++++
 3 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/include/hsakmt.h b/include/hsakmt.h
index ff2d023..abc617f 100644
--- a/include/hsakmt.h
+++ b/include/hsakmt.h
@@ -374,6 +374,17 @@ hsaKmtFreeMemory(
     HSAuint64   SizeInBytes         //IN
     );
 
+/**
+  Inquires memory available for allocation as a memory buffer
+*/
+
+HSAKMT_STATUS
+HSAKMTAPI
+hsaKmtAvailableMemory(
+    HSAuint32 Node,
+    HSAuint64 *AvailableBytes
+    );
+
 /**
   Registers with KFD a memory buffer that may be accessed by the GPU
 */
diff --git a/include/linux/kfd_ioctl.h b/include/linux/kfd_ioctl.h
index 039b30b..a81ae37 100644
--- a/include/linux/kfd_ioctl.h
+++ b/include/linux/kfd_ioctl.h
@@ -32,9 +32,10 @@
  * - 1.4 - Indicate new SRAM EDC bit in device properties
  * - 1.5 - Add SVM API
  * - 1.6 - Query clear flags in SVM get_attr API
+ * - 1.7 - Add available_memory ioctl
  */
 #define KFD_IOCTL_MAJOR_VERSION 1
-#define KFD_IOCTL_MINOR_VERSION 6
+#define KFD_IOCTL_MINOR_VERSION 7
 
 /*
  * Debug revision change log
@@ -761,6 +762,16 @@ struct kfd_ioctl_free_memory_of_gpu_args {
 	__u64 handle;		/* to KFD */
 };
 
+/* Inquire available memory with kfd_ioctl_get_available_memory
+ *
+ * @available: memory available for alloc
+ */
+struct kfd_ioctl_get_available_memory_args {
+	__u64 available;	/* from KFD */
+	__u32 gpu_id;		/* to KFD */
+	__u32 pad;
+};
+
 /* Map memory to one or more GPUs
  *
  * @handle:                memory handle returned by alloc
@@ -1240,8 +1251,11 @@ struct kfd_ioctl_set_xnack_mode_args {
 #define AMDKFD_IOC_SET_XNACK_MODE		\
 		AMDKFD_IOWR(0x21, struct kfd_ioctl_set_xnack_mode_args)
 
+#define AMDKFD_IOC_AVAILABLE_MEMORY		\
+		AMDKFD_IOR(0x22, struct kfd_ioctl_get_available_memory_args)
+
 #define AMDKFD_COMMAND_START		0x01
-#define AMDKFD_COMMAND_END		0x22
+#define AMDKFD_COMMAND_END		0x23
 
 /* non-upstream ioctls */
 #define AMDKFD_IOC_IPC_IMPORT_HANDLE                                    \
diff --git a/src/memory.c b/src/memory.c
index 6d2a4f4..b2cd759 100644
--- a/src/memory.c
+++ b/src/memory.c
@@ -199,6 +199,29 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtFreeMemory(void *MemoryAddress,
 	return fmm_release(MemoryAddress);
 }
 
+HSAKMT_STATUS HSAKMTAPI hsaKmtAvailableMemory(HSAuint32 Node, HSAuint64 *AvailableBytes)
+{
+	struct kfd_ioctl_get_available_memory_args args = {};
+	HSAKMT_STATUS result;
+
+	CHECK_KFD_OPEN();
+	CHECK_KFD_MINOR_VERSION(7);
+
+	pr_debug("[%s] node %d\n", __func__, Node);
+
+	result = validate_nodeid(Node, &args.gpu_id);
+	if (result != HSAKMT_STATUS_SUCCESS) {
+		pr_err("[%s] invalid node ID: %d\n", __func__, Node);
+		return result;
+	}
+
+	if (kmtIoctl(kfd_fd, AMDKFD_IOC_AVAILABLE_MEMORY, &args))
+		return HSAKMT_STATUS_ERROR;
+
+	*AvailableBytes = args.available;
+	return HSAKMT_STATUS_SUCCESS;
+}
+
 HSAKMT_STATUS HSAKMTAPI hsaKmtRegisterMemory(void *MemoryAddress,
 					     HSAuint64 MemorySizeInBytes)
 {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] Add hsaKmtAvailableMemory available memory inquiry to libhsakmt
  2022-01-10 21:23 [PATCH 1/1] Add hsaKmtAvailableMemory available memory inquiry to libhsakmt Daniel Phillips
@ 2022-01-10 23:40 ` Felix Kuehling
  0 siblings, 0 replies; 2+ messages in thread
From: Felix Kuehling @ 2022-01-10 23:40 UTC (permalink / raw)
  To: amd-gfx

On 2022-01-10 4:23 p.m., Daniel Phillips wrote:
> Add a library call to inquire memory available for allocation per
> node. Uses the AMDKFD_IOC_AVAILABLE_MEMORY ioctl available in KFD
> ioctl version 1.7
>
> Change-Id: Id770fc2261e9e076f2fbce7dcdac640a6354ddbe

This patch is

Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>


> ---
>   include/hsakmt.h          | 11 +++++++++++
>   include/linux/kfd_ioctl.h | 18 ++++++++++++++++--
>   src/memory.c              | 23 +++++++++++++++++++++++
>   3 files changed, 50 insertions(+), 2 deletions(-)
>
> diff --git a/include/hsakmt.h b/include/hsakmt.h
> index ff2d023..abc617f 100644
> --- a/include/hsakmt.h
> +++ b/include/hsakmt.h
> @@ -374,6 +374,17 @@ hsaKmtFreeMemory(
>       HSAuint64   SizeInBytes         //IN
>       );
>   
> +/**
> +  Inquires memory available for allocation as a memory buffer
> +*/
> +
> +HSAKMT_STATUS
> +HSAKMTAPI
> +hsaKmtAvailableMemory(
> +    HSAuint32 Node,
> +    HSAuint64 *AvailableBytes
> +    );
> +
>   /**
>     Registers with KFD a memory buffer that may be accessed by the GPU
>   */
> diff --git a/include/linux/kfd_ioctl.h b/include/linux/kfd_ioctl.h
> index 039b30b..a81ae37 100644
> --- a/include/linux/kfd_ioctl.h
> +++ b/include/linux/kfd_ioctl.h
> @@ -32,9 +32,10 @@
>    * - 1.4 - Indicate new SRAM EDC bit in device properties
>    * - 1.5 - Add SVM API
>    * - 1.6 - Query clear flags in SVM get_attr API
> + * - 1.7 - Add available_memory ioctl
>    */
>   #define KFD_IOCTL_MAJOR_VERSION 1
> -#define KFD_IOCTL_MINOR_VERSION 6
> +#define KFD_IOCTL_MINOR_VERSION 7
>   
>   /*
>    * Debug revision change log
> @@ -761,6 +762,16 @@ struct kfd_ioctl_free_memory_of_gpu_args {
>   	__u64 handle;		/* to KFD */
>   };
>   
> +/* Inquire available memory with kfd_ioctl_get_available_memory
> + *
> + * @available: memory available for alloc
> + */
> +struct kfd_ioctl_get_available_memory_args {
> +	__u64 available;	/* from KFD */
> +	__u32 gpu_id;		/* to KFD */
> +	__u32 pad;
> +};
> +
>   /* Map memory to one or more GPUs
>    *
>    * @handle:                memory handle returned by alloc
> @@ -1240,8 +1251,11 @@ struct kfd_ioctl_set_xnack_mode_args {
>   #define AMDKFD_IOC_SET_XNACK_MODE		\
>   		AMDKFD_IOWR(0x21, struct kfd_ioctl_set_xnack_mode_args)
>   
> +#define AMDKFD_IOC_AVAILABLE_MEMORY		\
> +		AMDKFD_IOR(0x22, struct kfd_ioctl_get_available_memory_args)
> +
>   #define AMDKFD_COMMAND_START		0x01
> -#define AMDKFD_COMMAND_END		0x22
> +#define AMDKFD_COMMAND_END		0x23
>   
>   /* non-upstream ioctls */
>   #define AMDKFD_IOC_IPC_IMPORT_HANDLE                                    \
> diff --git a/src/memory.c b/src/memory.c
> index 6d2a4f4..b2cd759 100644
> --- a/src/memory.c
> +++ b/src/memory.c
> @@ -199,6 +199,29 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtFreeMemory(void *MemoryAddress,
>   	return fmm_release(MemoryAddress);
>   }
>   
> +HSAKMT_STATUS HSAKMTAPI hsaKmtAvailableMemory(HSAuint32 Node, HSAuint64 *AvailableBytes)
> +{
> +	struct kfd_ioctl_get_available_memory_args args = {};
> +	HSAKMT_STATUS result;
> +
> +	CHECK_KFD_OPEN();
> +	CHECK_KFD_MINOR_VERSION(7);
> +
> +	pr_debug("[%s] node %d\n", __func__, Node);
> +
> +	result = validate_nodeid(Node, &args.gpu_id);
> +	if (result != HSAKMT_STATUS_SUCCESS) {
> +		pr_err("[%s] invalid node ID: %d\n", __func__, Node);
> +		return result;
> +	}
> +
> +	if (kmtIoctl(kfd_fd, AMDKFD_IOC_AVAILABLE_MEMORY, &args))
> +		return HSAKMT_STATUS_ERROR;
> +
> +	*AvailableBytes = args.available;
> +	return HSAKMT_STATUS_SUCCESS;
> +}
> +
>   HSAKMT_STATUS HSAKMTAPI hsaKmtRegisterMemory(void *MemoryAddress,
>   					     HSAuint64 MemorySizeInBytes)
>   {

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-10 23:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-10 21:23 [PATCH 1/1] Add hsaKmtAvailableMemory available memory inquiry to libhsakmt Daniel Phillips
2022-01-10 23:40 ` Felix Kuehling

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.