Skip to contentSkip to conversation

drm/amdkfd: fix missing L2 cache info in topology

PATCH In review Eric Huang 3 participants 9 messages Jan 29, 2025 – Feb 7, 2025

Subsystems (3)
lore
Share & tools
lore

Eric Huang

author
#0 lore raw

PATCH 1/1 drm/amdkfd: fix missing L2 cache info in topology

In some ASICs L2 cache info may miss in kfd topology, because the first bitmap may be empty, that means the first cu may be inactive, so to find the first active cu will solve the issue.

---
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +16 -2
index 4936697e6fc2..73d95041a388 100644
@@ -1665,17 +1665,31 @@ static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext,
 				int cache_type, unsigned int cu_processor_id,
 				struct kfd_node *knode)
 {
-	unsigned int cu_sibling_map_mask;
+	unsigned int cu_sibling_map_mask = 0;
 	int first_active_cu;
 	int i, j, k, xcc, start, end;
 	int num_xcc = NUM_XCC(knode->xcc_mask);
 	struct kfd_cache_properties *pcache = NULL;
 	enum amdgpu_memory_partition mode;
 	struct amdgpu_device *adev = knode->adev;
+	bool found = false;
 
 	start = ffs(knode->xcc_mask) - 1;
 	end = start + num_xcc;
-	cu_sibling_map_mask = cu_info->bitmap[start][0][0];
+
+	/* To find the bitmap in the first active cu */
+	for (xcc = start; xcc < end && !found; xcc++) {
+		for (i = 0; i < gfx_info->max_shader_engines && !found; i++) {
+			for (j = 0; j < gfx_info->max_sh_per_se && !found; j++) {
+				if (cu_info->bitmap[xcc][i % 4][j % 4]) {
+					cu_sibling_map_mask =
+						cu_info->bitmap[xcc][i % 4][j % 4];
+					found = true;
+				}
+			}
+		}
+	}
+
 	cu_sibling_map_mask &=
 		((1 << pcache_info[cache_type].num_cu_shared) - 1);
 	first_active_cu = ffs(cu_sibling_map_mask);
Signature · 1 line
2.34.1
author
#1 lore raw

Ping ......

Quoted 48 lines · Eric Huang

In some ASICs L2 cache info may miss in kfd topology, because the first bitmap may be empty, that means the first cu may be inactive, so to find the first active cu will solve the issue.

---
  drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 18 ++++++++++++++++--
  1 file changed, 16 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +16 -2
index 4936697e6fc2..73d95041a388 100644
@@ -1665,17 +1665,31 @@ static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext,
  				int cache_type, unsigned int cu_processor_id,
  				struct kfd_node *knode)
  {
-	unsigned int cu_sibling_map_mask;
+	unsigned int cu_sibling_map_mask = 0;
  	int first_active_cu;
  	int i, j, k, xcc, start, end;
  	int num_xcc = NUM_XCC(knode->xcc_mask);
  	struct kfd_cache_properties *pcache = NULL;
  	enum amdgpu_memory_partition mode;
  	struct amdgpu_device *adev = knode->adev;
+	bool found = false;
 
  	start = ffs(knode->xcc_mask) - 1;
  	end = start + num_xcc;
-	cu_sibling_map_mask = cu_info->bitmap[start][0][0];
+
+	/* To find the bitmap in the first active cu */
+	for (xcc = start; xcc < end && !found; xcc++) {
+		for (i = 0; i < gfx_info->max_shader_engines && !found; i++) {
+			for (j = 0; j < gfx_info->max_sh_per_se && !found; j++) {
+				if (cu_info->bitmap[xcc][i % 4][j % 4]) {
+					cu_sibling_map_mask =
+						cu_info->bitmap[xcc][i % 4][j % 4];
+					found = true;
+				}
+			}
+		}
+	}
+
  	cu_sibling_map_mask &=
  		((1 << pcache_info[cache_type].num_cu_shared) - 1);
  	first_active_cu = ffs(cu_sibling_map_mask);
#2 lore raw
In reply to Eric Huang
Quoted 24 lines · Eric Huang

In some ASICs L2 cache info may miss in kfd topology, because the first bitmap may be empty, that means the first cu may be inactive, so to find the first active cu will solve the issue.

---
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1 -1
index 4936697e6fc2..73d95041a388 100644
@@ -1665,17 +1665,31 @@ static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext,
 				int cache_type, unsigned int cu_processor_id,
 				struct kfd_node *knode)
 {
-	unsigned int cu_sibling_map_mask;
+	unsigned int cu_sibling_map_mask = 0;
 	int first_active_cu;
 	int i, j, k, xcc, start, end;
 	int num_xcc = NUM_XCC(knode->xcc_mask);
 	struct kfd_cache_properties *pcache = NULL;

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext, · line 1681

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +4 -1
 	enum amdgpu_memory_partition mode;
 	struct amdgpu_device *adev = knode->adev;
+	bool found = false;
 
 	start = ffs(knode->xcc_mask) - 1;
 	end = start + num_xcc;
-	cu_sibling_map_mask = cu_info->bitmap[start][0][0];
+
+	/* To find the bitmap in the first active cu */
+	for (xcc = start; xcc < end && !found; xcc++) {

It seems there is an assumption made here that a CU in one XCC could share this cache with CU in another XCC. This is not true for GFX 9.4.3 SOCs. In those, a CU in XCC0 doesn't share L2 with CU in XCC1.

Thanks,
Lijo

Quoted 14 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +11 -0
+		for (i = 0; i < gfx_info->max_shader_engines && !found; i++) {
+			for (j = 0; j < gfx_info->max_sh_per_se && !found; j++) {
+				if (cu_info->bitmap[xcc][i % 4][j % 4]) {
+					cu_sibling_map_mask =
+						cu_info->bitmap[xcc][i % 4][j % 4];
+					found = true;
+				}
+			}
+		}
+	}
+
 	cu_sibling_map_mask &=
 		((1 << pcache_info[cache_type].num_cu_shared) - 1);
 	first_active_cu = ffs(cu_sibling_map_mask);
author
#3 lore raw
Quoted 30 lines · Lijo
Quoted 28 lines · Eric Huang

In some ASICs L2 cache info may miss in kfd topology, because the first bitmap may be empty, that means the first cu may be inactive, so to find the first active cu will solve the issue.

---
  drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 18 ++++++++++++++++--
  1 file changed, 16 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +2 -1
index 4936697e6fc2..73d95041a388 100644
@@ -1665,17 +1665,31 @@ static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext,
  				int cache_type, unsigned int cu_processor_id,
  				struct kfd_node *knode)
  {
-	unsigned int cu_sibling_map_mask;
+	unsigned int cu_sibling_map_mask = 0;
  	int first_active_cu;
  	int i, j, k, xcc, start, end;
  	int num_xcc = NUM_XCC(knode->xcc_mask);
  	struct kfd_cache_properties *pcache = NULL;
  	enum amdgpu_memory_partition mode;
  	struct amdgpu_device *adev = knode->adev;
+	bool found = false;
 
Quoted 9 lines

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext, · line 1681

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +3 -1
  	start = ffs(knode->xcc_mask) - 1;
  	end = start + num_xcc;
-	cu_sibling_map_mask = cu_info->bitmap[start][0][0];
+
+	/* To find the bitmap in the first active cu */
+	for (xcc = start; xcc < end && !found; xcc++) {

It seems there is an assumption made here that a CU in one XCC could share this cache with CU in another XCC. This is not true for GFX 9.4.3 SOCs. In those, a CU in XCC0 doesn't share L2 with CU in XCC1.

In KFD topology we only report L2 cache info of the first active cu in A XCC, which could be XCC0 or XCC1. It is generic for L2 info in the certain XCP/kfd node, and not specific for every XCC, so it doesn't mean the L2 cache found in XCC0 can be shared with XCC1, it only means there is L2 cache in this kfd node.

Regards,
Eric

Quoted 18 lines

Thanks,
Lijo

Quoted 14 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +11 -0
+		for (i = 0; i < gfx_info->max_shader_engines && !found; i++) {
+			for (j = 0; j < gfx_info->max_sh_per_se && !found; j++) {
+				if (cu_info->bitmap[xcc][i % 4][j % 4]) {
+					cu_sibling_map_mask =
+						cu_info->bitmap[xcc][i % 4][j % 4];
+					found = true;
+				}
+			}
+		}
+	}
+
  	cu_sibling_map_mask &=
  		((1 << pcache_info[cache_type].num_cu_shared) - 1);
  	first_active_cu = ffs(cu_sibling_map_mask);
#4 lore raw

[Public]

Yes, the problem is that. If a node has 2 XCCs, it should report the L2 of each separately with the number of CUs sharing each L2.

In this, it appears to loop through and find the first non-zero of all XCCs of a node and not based on the first non-zero per XCC basis. It makes a difference in number of L2 instances available.

Thanks,
Lijo
________________________________
From: Huang, JinHuiEric <[email protected]>
Sent: Thursday, February 6, 2025 10:00:38 PM
To: Lazar, Lijo <[email protected]>; [email protected] <[email protected]>
Subject: Re: [PATCH] drm/amdkfd: fix missing L2 cache info in topology

Quoted 30 lines · Lijo
Quoted 28 lines · Eric Huang

In some ASICs L2 cache info may miss in kfd topology, because the first bitmap may be empty, that means the first cu may be inactive, so to find the first active cu will solve the issue.

---
  drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 18 ++++++++++++++++--
  1 file changed, 16 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +2 -1
index 4936697e6fc2..73d95041a388 100644
@@ -1665,17 +1665,31 @@ static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext,
                              int cache_type, unsigned int cu_processor_id,
                              struct kfd_node *knode)
  {
-    unsigned int cu_sibling_map_mask;
+    unsigned int cu_sibling_map_mask = 0;
      int first_active_cu;
      int i, j, k, xcc, start, end;
      int num_xcc = NUM_XCC(knode->xcc_mask);
      struct kfd_cache_properties *pcache = NULL;
      enum amdgpu_memory_partition mode;
      struct amdgpu_device *adev = knode->adev;
+    bool found = false;
 
Quoted 9 lines

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext, · line 1681

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +3 -1
      start = ffs(knode->xcc_mask) - 1;
      end = start + num_xcc;
-    cu_sibling_map_mask = cu_info->bitmap[start][0][0];
+
+    /* To find the bitmap in the first active cu */
+    for (xcc = start; xcc < end && !found; xcc++) {

It seems there is an assumption made here that a CU in one XCC could share this cache with CU in another XCC. This is not true for GFX 9.4.3 SOCs. In those, a CU in XCC0 doesn't share L2 with CU in XCC1.

In KFD topology we only report L2 cache info of the first active cu in A XCC, which could be XCC0 or XCC1. It is generic for L2 info in the certain XCP/kfd node, and not specific for every XCC, so it doesn't mean the L2 cache found in XCC0 can be shared with XCC1, it only means there is L2 cache in this kfd node.

Regards,
Eric

Quoted 18 lines

Thanks,
Lijo

Quoted 14 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +11 -0
+            for (i = 0; i < gfx_info->max_shader_engines && !found; i++) {
+                    for (j = 0; j < gfx_info->max_sh_per_se && !found; j++) {
+                            if (cu_info->bitmap[xcc][i % 4][j % 4]) {
+                                    cu_sibling_map_mask =
+                                            cu_info->bitmap[xcc][i % 4][j % 4];
+                                    found = true;
+                            }
+                    }
+            }
+    }
+
      cu_sibling_map_mask &=
              ((1 << pcache_info[cache_type].num_cu_shared) - 1);
      first_active_cu = ffs(cu_sibling_map_mask);
author
#5 lore raw

I understand your concern. KFD currently only reports one L2 instance, but not every L2 instance. If customers want to have more detail in all available L2 info, we probably can change the logic in this function, but it is not related to my change. My change is based on current kfd logic and fixes missing L2 issue.

Thanks,
Eric

Quoted 89 lines · Lijo

[Public]

Yes, the problem is that. If a node has 2 XCCs, it should report the L2 of each separately with the number of CUs sharing each L2.

In this, it appears to loop through and find the first non-zero of all XCCs of a node and not based on the first non-zero per XCC basis. It makes a difference in number of L2 instances available.

Thanks,
Lijo
------------------------------------------------------------------------
*From:* Huang, JinHuiEric <[email protected]>
*Sent:* Thursday, February 6, 2025 10:00:38 PM
*To:* Lazar, Lijo <[email protected]>; [email protected] <[email protected]> *Subject:* Re: [PATCH] drm/amdkfd: fix missing L2 cache info in topology

Quoted 7 lines · Lijo
Quoted 5 lines · Eric Huang

In some ASICs L2 cache info may miss in kfd topology, because the first bitmap may be empty, that means the first cu may be inactive, so to find the first active cu will solve the issue.

Quoted 6 lines

Review

Quoted 6 lines

---
   drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 18 ++++++++++++++++--

   1 file changed, 16 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c

Quoted 4 lines

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int fill_in_l2_l3_pcache(struct

Quoted 4 lines

index 4936697e6fc2..73d95041a388 100644

drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -0
@@ -1665,17 +1665,31 @@ static int fill_in_l2_l3_pcache(struct 

kfd_cache_properties **props_ext,

Quoted 1 line
Quoted 1 line

                               int cache_type, unsigned int

cu_processor_id,

Quoted 18 lines
Quoted 12 lines

                               struct kfd_node *knode) {
-    unsigned int cu_sibling_map_mask;
+    unsigned int cu_sibling_map_mask = 0; int first_active_cu;
       int i, j, k, xcc, start, end;
       int num_xcc = NUM_XCC(knode->xcc_mask); struct kfd_cache_properties *pcache = NULL; enum amdgpu_memory_partition mode; struct amdgpu_device *adev = knode->adev; +    bool found = false;

Quoted 6 lines

       start = ffs(knode->xcc_mask) - 1;
       end = start + num_xcc;
-    cu_sibling_map_mask = cu_info->bitmap[start][0][0]; +
+    /* To find the bitmap in the first active cu */ +    for (xcc = start; xcc < end && !found; xcc++) {

Quoted 3 lines

It seems there is an assumption made here that a CU in one XCC could share this cache with CU in another XCC. This is not true for GFX 9.4.3 SOCs. In those, a CU in XCC0 doesn't share L2 with CU in XCC1.

In KFD topology we only report L2 cache info of the first active cu in A XCC, which could be XCC0 or XCC1. It is generic for L2 info in the certain XCP/kfd node, and not specific for every XCC, so it doesn't mean the L2 cache found in XCC0 can be shared with XCC1, it only means there is L2 cache in this kfd node.

Regards,
Eric

Quoted 5 lines

Thanks,
Lijo

Quoted 1 line

+            for (i = 0; i < gfx_info->max_shader_engines &&

!found; i++) {

Quoted 1 line
Quoted 1 line

+                    for (j = 0; j < gfx_info->max_sh_per_se &&

!found; j++) {

Quoted 12 lines
Quoted 12 lines

+                            if (cu_info->bitmap[xcc][i % 4][j % 4]) {
+ cu_sibling_map_mask =
+ cu_info->bitmap[xcc][i % 4][j % 4];
+                                    found = true;
+                            }
+                    }
+            }
+    }
+
       cu_sibling_map_mask &=
               ((1 << pcache_info[cache_type].num_cu_shared) - 1); first_active_cu = ffs(cu_sibling_map_mask);

#6 lore raw
Quoted 6 lines · Eric Huang

I understand your concern. KFD currently only reports one L2 instance, but not every L2 instance. If customers want to have more detail in all available L2 info, we probably can change the logic in this function, but it is not related to my change. My change is based on current kfd logic and fixes missing L2 issue.

Even for that case, do you need to loop through all xccs? Expectation is there are some set of active CUs in any XCC (in general, XCC without an active CU is not expected to part of KFD node).

Thanks,
Lijo

Quoted 100 lines

Thanks,
Eric

Quoted 95 lines · Lijo

[Public]

Yes, the problem is that. If a node has 2 XCCs, it should report the L2 of each separately with the number of CUs sharing each L2.

In this, it appears to loop through and find the first non-zero of all XCCs of a node and not based on the first non-zero per XCC basis. It makes a difference in number of L2 instances available.

Thanks,
Lijo
------------------------------------------------------------------------
*From:* Huang, JinHuiEric <[email protected]>
*Sent:* Thursday, February 6, 2025 10:00:38 PM
*To:* Lazar, Lijo <[email protected]>; [email protected] <[email protected]>
*Subject:* Re: [PATCH] drm/amdkfd: fix missing L2 cache info in topology

Quoted 7 lines · Lijo
Quoted 5 lines · Eric Huang

In some ASICs L2 cache info may miss in kfd topology, because the first bitmap may be empty, that means the first cu may be inactive, so to find the first active cu will solve the issue.

Quoted 6 lines

drivers/

Quoted 6 lines

---
   drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 18 ++++++++++++++++--

   1 file changed, 16 insertions(+), 2 deletions(-)
drivers/ renamed from drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -0

gpu/drm/amd/amdkfd/kfd_topology.c

Quoted 4 lines

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int fill_in_l2_l3_pcache(struct

Quoted 4 lines

index 4936697e6fc2..73d95041a388 100644

drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -0
@@ -1665,17 +1665,31 @@ static int fill_in_l2_l3_pcache(struct

kfd_cache_properties **props_ext,

Quoted 1 line
Quoted 1 line

                               int cache_type, unsigned int

cu_processor_id,

Quoted 18 lines
Quoted 10 lines

                               struct kfd_node *knode) {
-    unsigned int cu_sibling_map_mask;
+    unsigned int cu_sibling_map_mask = 0; int first_active_cu;
       int i, j, k, xcc, start, end;
       int num_xcc = NUM_XCC(knode->xcc_mask); struct kfd_cache_properties *pcache = NULL; enum amdgpu_memory_partition mode; struct amdgpu_device *adev = knode->adev;

Quoted 8 lines

+    bool found = false;

       start = ffs(knode->xcc_mask) - 1;
       end = start + num_xcc;
-    cu_sibling_map_mask = cu_info->bitmap[start][0][0]; +
+    /* To find the bitmap in the first active cu */ +    for (xcc = start; xcc < end && !found; xcc++) {

Quoted 3 lines

It seems there is an assumption made here that a CU in one XCC could share this cache with CU in another XCC. This is not true for GFX 9.4.3 SOCs. In those, a CU in XCC0 doesn't share L2 with CU in XCC1.

In KFD topology we only report L2 cache info of the first active cu in A XCC, which could be XCC0 or XCC1. It is generic for L2 info in the certain XCP/kfd node, and not specific for every XCC, so it doesn't mean the L2 cache found in XCC0 can be shared with XCC1, it only means there is L2 cache in this kfd node.

Regards,
Eric

Quoted 5 lines

Thanks,
Lijo

Quoted 1 line

+            for (i = 0; i < gfx_info->max_shader_engines && !

found; i++) {

Quoted 1 line
Quoted 1 line

+                    for (j = 0; j < gfx_info->max_sh_per_se && !

found; j++) {

Quoted 3 lines
Quoted 3 lines

+                            if (cu_info->bitmap[xcc][i % 4][j % 4]) { +                                    cu_sibling_map_mask = +                                            cu_info->bitmap[xcc][i

% 4][j % 4];

Quoted 9 lines
Quoted 9 lines

+                                    found = true;
+                            }
+                    }
+            }
+    }
+
       cu_sibling_map_mask &=
               ((1 << pcache_info[cache_type].num_cu_shared) - 1); first_active_cu = ffs(cu_sibling_map_mask);

author
#7 lore raw
Quoted 11 lines · Lijo
Quoted 6 lines · Eric Huang

I understand your concern. KFD currently only reports one L2 instance, but not every L2 instance. If customers want to have more detail in all available L2 info, we probably can change the logic in this function, but it is not related to my change. My change is based on current kfd logic and fixes missing L2 issue.

Even for that case, do you need to loop through all xccs? Expectation is there are some set of active CUs in any XCC (in general, XCC without an active CU is not expected to part of KFD node).

Good point. I will send out another patch accordingly.

Thanks,
Eric

Quoted 99 lines

Thanks,
Lijo

Quoted 95 lines

Thanks,
Eric

Quoted 91 lines · Lijo

[Public]

Yes, the problem is that. If a node has 2 XCCs, it should report the L2 of each separately with the number of CUs sharing each L2.

In this, it appears to loop through and find the first non-zero of all XCCs of a node and not based on the first non-zero per XCC basis. It makes a difference in number of L2 instances available.

Thanks,
Lijo
------------------------------------------------------------------------
*From:* Huang, JinHuiEric <[email protected]>
*Sent:* Thursday, February 6, 2025 10:00:38 PM
*To:* Lazar, Lijo <[email protected]>; [email protected] <[email protected]>
*Subject:* Re: [PATCH] drm/amdkfd: fix missing L2 cache info in topology

Quoted 6 lines · Lijo
Quoted 5 lines · Eric Huang

In some ASICs L2 cache info may miss in kfd topology, because the first bitmap may be empty, that means the first cu may be inactive, so to find the first active cu will solve the issue.

Quoted 6 lines

drivers/

Quoted 6 lines
---
    drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 18 ++++++++++++++++--
    1 file changed, 16 insertions(+), 2 deletions(-)
drivers/ renamed from drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -0

gpu/drm/amd/amdkfd/kfd_topology.c

Quoted 4 lines

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int fill_in_l2_l3_pcache(struct

Quoted 4 lines

index 4936697e6fc2..73d95041a388 100644

drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -0
@@ -1665,17 +1665,31 @@ static int fill_in_l2_l3_pcache(struct

kfd_cache_properties **props_ext,

Quoted 1 line

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int fill_in_l2_l3_pcache(struct · line 1665

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -0
                                int cache_type, unsigned int

cu_processor_id,

Quoted 18 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1 -1
                                struct kfd_node *knode)
    {
-    unsigned int cu_sibling_map_mask;
+    unsigned int cu_sibling_map_mask = 0;
        int first_active_cu;
        int i, j, k, xcc, start, end;
        int num_xcc = NUM_XCC(knode->xcc_mask);
        struct kfd_cache_properties *pcache = NULL;

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext, · line 1681

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +4 -1
        enum amdgpu_memory_partition mode;
        struct amdgpu_device *adev = knode->adev;
+    bool found = false;
 
        start = ffs(knode->xcc_mask) - 1;
        end = start + num_xcc;
-    cu_sibling_map_mask = cu_info->bitmap[start][0][0];
+
+    /* To find the bitmap in the first active cu */
+    for (xcc = start; xcc < end && !found; xcc++) {
Quoted 3 lines

It seems there is an assumption made here that a CU in one XCC could share this cache with CU in another XCC. This is not true for GFX 9.4.3 SOCs. In those, a CU in XCC0 doesn't share L2 with CU in XCC1.

In KFD topology we only report L2 cache info of the first active cu in A XCC, which could be XCC0 or XCC1. It is generic for L2 info in the certain XCP/kfd node, and not specific for every XCC, so it doesn't mean the L2 cache found in XCC0 can be shared with XCC1, it only means there is L2 cache in this kfd node.

Regards,
Eric

Quoted 4 lines

Thanks,
Lijo

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1 -0
+            for (i = 0; i < gfx_info->max_shader_engines && !

found; i++) {

Quoted 1 line

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int fill_in_l2_l3_pcache(struct · line 1683

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1 -0
+                    for (j = 0; j < gfx_info->max_sh_per_se && !

found; j++) {

Quoted 3 lines

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext,

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +3 -0
+                            if (cu_info->bitmap[xcc][i % 4][j % 4]) {
+                                    cu_sibling_map_mask =
+                                            cu_info->bitmap[xcc][i

% 4][j % 4];

Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +6 -0
+                                    found = true;
+                            }
+                    }
+            }
+    }
+
        cu_sibling_map_mask &=
                ((1 << pcache_info[cache_type].num_cu_shared) - 1);
        first_active_cu = ffs(cu_sibling_map_mask);
Acked-by on v1 1/1
#8 lore raw
In reply to Eric Huang
Quoted 52 lines · Eric Huang

In some ASICs L2 cache info may miss in kfd topology, because the first bitmap may be empty, that means the first cu may be inactive, so to find the first active cu will solve the issue.

---
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +16 -3
index 4936697e6fc2..73d95041a388 100644
@@ -1665,17 +1665,31 @@ static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext,
                                int cache_type, unsigned int cu_processor_id,
                                struct kfd_node *knode)
 {
-       unsigned int cu_sibling_map_mask;
+       unsigned int cu_sibling_map_mask = 0;
        int first_active_cu;
        int i, j, k, xcc, start, end;
        int num_xcc = NUM_XCC(knode->xcc_mask);
        struct kfd_cache_properties *pcache = NULL;
        enum amdgpu_memory_partition mode;
        struct amdgpu_device *adev = knode->adev;
+       bool found = false;
 
        start = ffs(knode->xcc_mask) - 1;
        end = start + num_xcc;
-       cu_sibling_map_mask = cu_info->bitmap[start][0][0];
+
+       /* To find the bitmap in the first active cu */
+       for (xcc = start; xcc < end && !found; xcc++) {
+               for (i = 0; i < gfx_info->max_shader_engines && !found; i++) {
+                       for (j = 0; j < gfx_info->max_sh_per_se && !found; j++) {
+                               if (cu_info->bitmap[xcc][i % 4][j % 4]) {
+                                       cu_sibling_map_mask =
+                                               cu_info->bitmap[xcc][i % 4][j % 4];
+                                       found = true;
+                               }
+                       }
+               }
+       }
+
        cu_sibling_map_mask &=
                ((1 << pcache_info[cache_type].num_cu_shared) - 1);
        first_active_cu = ffs(cu_sibling_map_mask);
--

2.34.1