cutlass icon indicating copy to clipboard operation
cutlass copied to clipboard

[QST]Why cp.async.ca will influence bank conflcit of Shared Store From Global Load ?

Open liuqi123123 opened this issue 1 year ago • 9 comments

when I rewrite cutlass conv with cute api, I encountered an interesting phenomena: During global to smem stage,I can't reduce the bank conflict using cute swizzle.After some research, I find the reason is the instruction cp.async.ca when I copy element in Activation to smem. In cutlass, Activation g2s copy will use cp.async.ca, Filter g2s use cp.async.cg, I can understand this. And I do some experiment below to find out why bank conflict can't decrease:

Image

when I always use cp.async.cg in Activation g2s copy and Filter g2s copy with cute swizzle, bank conflict will decrease as i thought. but why cp.async.ca will block this bank conflict reduction?What happens to the hardware?

liuqi123123 avatar Apr 02 '25 05:04 liuqi123123

cg and ca has nothing to do with bank conflicts. cg will bypass L1, ca will not. conv usually can benefit from L1, but to a specific problem size, you may want to choose the best one for you.

hwu36 avatar Apr 30 '25 02:04 hwu36

cg and ca has nothing to do with bank conflicts. cg will bypass L1, ca will not. conv usually can benefit from L1, but to a specific problem size, you may want to choose the best one for you.

but in my experiment, I change nothing other than cp.async mode, it do real influence bank conflict num. Is any other ideas applied to figure out what's really going on? thanks very much!

liuqi123123 avatar Apr 30 '25 03:04 liuqi123123

This issue has been labeled inactive-30d due to no recent activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be labeled inactive-90d if there is no activity in the next 60 days.

github-actions[bot] avatar May 30 '25 04:05 github-actions[bot]

This issue has been labeled inactive-90d due to no recent activity in the past 90 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed.

github-actions[bot] avatar Aug 28 '25 05:08 github-actions[bot]

@liuqi123123 Do you solve it? I encounter same question.

wukong1992 avatar Sep 11 '25 11:09 wukong1992

No😃

------------------ Original ------------------ From: wukong1992 @.> Date: Thu,Sep 11,2025 7:52 PM To: NVIDIA/cutlass @.> Cc: M @.>, Mention @.> Subject: Re: [NVIDIA/cutlass] [QST]Why cp.async.ca will influence bankconflcit of Shared Store From Global Load ? (Issue #2212)

wukong1992 left a comment (NVIDIA/cutlass#2212)

@liuqi123123 Do you solve it? I encounter same question.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

liuqi123123 avatar Sep 11 '25 12:09 liuqi123123

我遇到过类似的问题。以RTX3060(SM86架构)为例,cp.async.ca要求连续的128byte访问模式,才不会导致出现bank conflict。你可以看一下t0-t31的访存模式,看看相邻的几个线程是否可以构成连续的128byte。

下面是猜测内容:

之所以要求连续128byte,是因为L1的更新粒度是128byte。如果不连续,会拆分为多个transaction。L1向shared memory写的数据的时候,可能是乱序的,这导致了bank conflict的出现。

.cg不存在bank conflict大概率是因为做了数据的聚合。L2的数据宽度为32B,32B的数据在某个buffer上做了聚合。

diantaowang avatar Oct 31 '25 08:10 diantaowang

我遇到过类似的问题。以RTX3060(SM86架构)为例,cp.async.ca要求连续的128byte访问模式,才不会导致出现bank conflict。你可以看一下t0-t31的访存模式,看看相邻的几个线程是否可以构成连续的128byte。

下面是猜测内容:

之所以要求连续128byte,是因为L1的更新粒度是128byte。如果不连续,会拆分为多个transaction。L1向shared memory写的数据的时候,可能是乱序的,这导致了bank conflict的出现。

.cg不存在bank conflict大概率是因为做了数据的聚合。L2的数据宽度为32B,32B的数据在某个buffer上做了聚合。

你好,想问下cp.async.ca要求连续的128byte访问模式这个有依据(来源)吗?我在RTX4060Ti(SM89架构)上似乎使用cp.async.cg也需要连续的128B访存模式

pikkali avatar Jan 29 '26 14:01 pikkali

我遇到过类似的问题。以RTX3060(SM86架构)为例,cp.async.ca要求连续的128byte访问模式,才不会导致出现bank conflict。你可以看一下t0-t31的访存模式,看看相邻的几个线程是否可以构成连续的128byte。

下面是猜测内容:

之所以要求连续128byte,是因为L1的更新粒度是128byte。如果不连续,会拆分为多个transaction。L1向shared memory写的数据的时候,可能是乱序的,这导致了bank conflict的出现。

.cg不存在bank conflict大概率是因为做了数据的聚合。L2的数据宽度为32B,32B的数据在某个buffer上做了聚合。

@diantaowang 不好意思打扰一下,以下是我的测试代码:

#include <thrust/device_vector.h>

__global__ 
void ldgsts(int* src) {
  int lane_id = threadIdx.x;
  __shared__ int dst[512];

  int group_id = lane_id / 4; 
  int sub_id   = lane_id % 4;
  int src_offset_int = group_id * 32 + sub_id * 4;
  int dst_offset_int = lane_id * 4; 

  for (int offset = 0; offset < 1024; offset += 256) {
    void *ptr = (void *)(dst + dst_offset_int + offset / 2);
    uint32_t smem_ptr;

    asm(
      "{ .reg .u64 smem_ptr; cvta.to.shared.u64 smem_ptr, %1; cvt.u32.u64 %0, smem_ptr; }\n"
      : "=r"(smem_ptr)
      : "l"(ptr)); 
    asm volatile("cp.async.cg.shared.global [%0], [%1], %2;\n" 
      ::"r"(smem_ptr),
        "l"(&src[offset + src_offset_int]), 
        "n"(16));
  }
  asm volatile("cp.async.commit_group;\n" ::);
}

__global__ 
void ldg_sts(int* src) {
  int lane_id = threadIdx.x;
  __shared__ int dst[512];

  int group_id = lane_id / 4; 
  int sub_id   = lane_id % 4;
  int src_offset_int = group_id * 32 + sub_id * 4;
  int dst_offset_int = lane_id * 4; 

  for (int offset = 0; offset < 1024; offset += 256) {
    void *ptr = (void *)(dst + dst_offset_int + offset / 2);
    uint32_t smem_ptr;

    asm(
      "{ .reg .u64 smem_ptr; cvta.to.shared.u64 smem_ptr, %1; cvt.u32.u64 %0, smem_ptr; }\n"
      : "=r"(smem_ptr)
      : "l"(ptr)); 

    int4 data;
    
    int* src_ptr = &src[offset + src_offset_int];
    asm volatile("ld.global.v4.u32 {%0, %1, %2, %3}, [%4];" 
      : "=r"(data.x), "=r"(data.y), "=r"(data.z), "=r"(data.w) 
      : "l"(src_ptr));

    asm volatile("st.shared.v4.u32 [%0], {%1, %2, %3, %4};" 
      : : "r"(smem_ptr), "r"(data.x), "r"(data.y), "r"(data.z), "r"(data.w));
  }
}


int main(){
	thrust::device_vector<int> input(1024);

	ldgsts<<<1, 32>>>(input.data().get());
	ldg_sts<<<1, 32>>>(input.data().get());
	cudaDeviceSynchronize();
}

其中T0-T3访问连续的64B(0-63,起始地址与128B对齐),T4-T7访问另一组连续的64B(128-191,起始地址与128B对齐),T0-T7构成了对Share Memory的128B访问. 但我在 SM89, SM87 上测试,无论使用cp.async.cg还是cp.async.ca都存在 Bank Conflict, 而使用ld.global+st.shared则不存在 Bank Conflict. 请问你能帮忙测试下代码吗(非常感谢)?还是说我的理解可能存在问题.

pikkali avatar Jan 30 '26 02:01 pikkali