]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amdgpu: add an option to allow gpu partition allocate all available memory
authorXiaogang Chen <xiaogang.chen@amd.com>
Tue, 31 Mar 2026 18:24:17 +0000 (13:24 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 3 Apr 2026 17:50:29 +0000 (13:50 -0400)
Current driver reports and limits memory allocation for each partition equally
among partitions using same memory partition. Application may not be able to
use all available memory when run on a partitioned gpu though system still has
enough free memory.

Add an option that app can use to have gpu partition allocate all available
memory.

Signed-off-by: Xiaogang Chen <xiaogang.chen@amd.com>
Reviewed-by: Philip Yang <philip.yang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h

index 4f27c75abedb6f227ebe0e238b0334a3005c9fa5..d9e283f3b57d5b267baed3889d736152ff3f46e2 100644 (file)
@@ -805,7 +805,10 @@ u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int xcp_id)
                } else {
                        tmp = adev->gmc.mem_partitions[mem_id].size;
                }
-               do_div(tmp, adev->xcp_mgr->num_xcp_per_mem_partition);
+
+               if (adev->xcp_mgr->mem_alloc_mode == AMDGPU_PARTITION_MEM_CAPPING_EVEN)
+                       do_div(tmp, adev->xcp_mgr->num_xcp_per_mem_partition);
+
                return ALIGN_DOWN(tmp, PAGE_SIZE);
        } else if (adev->apu_prefer_gtt) {
                return (ttm_tt_pages_limit() << PAGE_SHIFT);
index cab3196a87fb1105833e46c09c7dfb388eadcfa2..2956e45c92549b68760d351c351b0315f6a6b07b 100644 (file)
@@ -1580,6 +1580,36 @@ static ssize_t amdgpu_gfx_set_compute_partition(struct device *dev,
        return count;
 }
 
+static ssize_t compute_partition_mem_alloc_mode_show(struct device *dev,
+                                               struct device_attribute *addr,
+                                               char *buf)
+{
+       struct drm_device *ddev = dev_get_drvdata(dev);
+       struct amdgpu_device *adev = drm_to_adev(ddev);
+       int mode = adev->xcp_mgr->mem_alloc_mode;
+
+       return sysfs_emit(buf, "%s\n",
+                         amdgpu_gfx_compute_mem_alloc_mode_desc(mode));
+}
+
+
+static ssize_t compute_partition_mem_alloc_mode_store(struct device *dev,
+                                               struct device_attribute *addr,
+                                               const char *buf, size_t count)
+{
+       struct drm_device *ddev = dev_get_drvdata(dev);
+       struct amdgpu_device *adev = drm_to_adev(ddev);
+
+       if (!strncasecmp("CAPPING", buf, strlen("CAPPING")))
+               adev->xcp_mgr->mem_alloc_mode = AMDGPU_PARTITION_MEM_CAPPING_EVEN;
+       else if (!strncasecmp("ALL", buf, strlen("ALL")))
+               adev->xcp_mgr->mem_alloc_mode = AMDGPU_PARTITION_MEM_ALLOC_ALL;
+       else
+               return -EINVAL;
+
+       return count;
+}
+
 static const char *xcp_desc[] = {
        [AMDGPU_SPX_PARTITION_MODE] = "SPX",
        [AMDGPU_DPX_PARTITION_MODE] = "DPX",
@@ -1935,6 +1965,10 @@ static DEVICE_ATTR(gfx_reset_mask, 0444,
 static DEVICE_ATTR(compute_reset_mask, 0444,
                   amdgpu_gfx_get_compute_reset_mask, NULL);
 
+static DEVICE_ATTR(compute_partition_mem_alloc_mode, 0644,
+                  compute_partition_mem_alloc_mode_show,
+                  compute_partition_mem_alloc_mode_store);
+
 static int amdgpu_gfx_sysfs_xcp_init(struct amdgpu_device *adev)
 {
        struct amdgpu_xcp_mgr *xcp_mgr = adev->xcp_mgr;
@@ -1955,6 +1989,11 @@ static int amdgpu_gfx_sysfs_xcp_init(struct amdgpu_device *adev)
        if (r)
                return r;
 
+       r = device_create_file(adev->dev,
+                              &dev_attr_compute_partition_mem_alloc_mode);
+       if (r)
+               return r;
+
        if (xcp_switch_supported)
                r = device_create_file(adev->dev,
                                       &dev_attr_available_compute_partition);
index 2785eda6fea52da9d0e8c74a8d8b70d7c27b6f25..a0cf0a3b41dafd9d39a2ef2569b4061d7ecf99c5 100644 (file)
@@ -71,6 +71,11 @@ enum amdgpu_gfx_partition {
        AMDGPU_AUTO_COMPUTE_PARTITION_MODE = -2,
 };
 
+enum amdgpu_gfx_partition_mem_alloc_mode {
+       AMDGPU_PARTITION_MEM_CAPPING_EVEN = 0,
+       AMDGPU_PARTITION_MEM_ALLOC_ALL  = 1,
+};
+
 #define NUM_XCC(x) hweight16(x)
 
 enum amdgpu_gfx_ras_mem_id_type {
@@ -677,4 +682,16 @@ static inline const char *amdgpu_gfx_compute_mode_desc(int mode)
        }
 }
 
+static inline const char *amdgpu_gfx_compute_mem_alloc_mode_desc(int mode)
+{
+       switch (mode) {
+       case AMDGPU_PARTITION_MEM_CAPPING_EVEN:
+                       return "CAPPING";
+       case AMDGPU_PARTITION_MEM_ALLOC_ALL:
+               return "ALL";
+       default:
+               return "UNKNOWN";
+       }
+}
+
 #endif
index cc5f4e01e38f42906d5372b943d7966030efc83c..42be8ee155dde010e6043f01806993ccc07fb28e 100644 (file)
@@ -181,6 +181,7 @@ int amdgpu_xcp_init(struct amdgpu_xcp_mgr *xcp_mgr, int num_xcps, int mode)
        }
 
        xcp_mgr->num_xcps = num_xcps;
+       xcp_mgr->mem_alloc_mode = AMDGPU_PARTITION_MEM_CAPPING_EVEN;
        amdgpu_xcp_update_partition_sched_list(adev);
 
        return 0;
index 8058e8f35d4149b4c10fd627ece3032cff42c70f..878c1c422893cf4b0688e70364461334fc21e6bb 100644 (file)
@@ -132,6 +132,8 @@ struct amdgpu_xcp_mgr {
        struct amdgpu_xcp_cfg *xcp_cfg;
        uint32_t supp_xcp_modes;
        uint32_t avail_xcp_modes;
+       /* used to determin KFD memory alloc mode for each partition */
+       uint32_t mem_alloc_mode;
 };
 
 struct amdgpu_xcp_mgr_funcs {