/******************************************
 * Compile:
 * nvcc 2.cu -o 2
 * Run:       
 * ./2
*******************************************/

#include <stdio.h>
#include <sys/time.h>

#define height 256
#define width 256
#define filter_size 3
#define stride 1
#define pad 1
#define channels 3

#define block_size_x 32
#define block_size_y 32

#define GET_TIME(now)                           \
    {                                           \
        struct timeval t;                       \
        gettimeofday(&t, NULL);                 \
        now = t.tv_sec + t.tv_usec / 1000000.0; \
    }

// 并行矩阵乘法函数
__global__ static void matMultCUDA(const float *a, const float *b, float *c, int M, int N, int K, int BLOCK_SIZE)
{
	//表示目前的 thread 的编号
	const int tid = threadIdx.x;
	//表示目前在第几个 block 中
	const int bid = blockIdx.x;
	//计算出当前的 row 和 column
	const int idx = bid * BLOCK_SIZE + tid;
	const int row = idx / M;
	int column = idx % M;
	do
	{
		//矩阵乘法
		if (row < M && column < K)
		{
			float t = 0;
			for (int i = 0; i < N; i++)
			{
				t += a[row * N + i] * b[i * K + column];
			}
			c[row * K + column] = t;
		}
		column += M;
	} while (column < K);
}

float im2col_get_data(float *im, int row, int col, int channel){ 
    row -= pad;
    col -= pad;    // padding补0
    if (row < 0 || col < 0 ||
        row >= height || col >= width) return 0;    
    // im[col + width*(row + height*channel)]=im[col+width*row+width*height*channel]
    return im[col + width*(row + height*channel)];
}
    

void im2col(float* data_im, float* data_col) {   
    int c,h,w;    // 计算卷积后的尺寸
    int height_col = (height + 2*pad - filter_size) / stride + 1;    
    int width_col = (width + 2*pad - filter_size) / stride + 1;
    int channels_col = channels * filter_size * filter_size;    
    // 获取对应的值
    for (c = 0; c < channels_col; ++c) {
        int w_offset = c % filter_size;        
        int h_offset = (c / filter_size) % filter_size;        
        int c_im = c / filter_size / filter_size;        
        for (h = 0; h < height_col; ++h) {
            for (w = 0; w < width_col; ++w) { 
                // 获取原图中对应的坐标
                int im_row = h_offset + h * stride;                
                int im_col = w_offset + w * stride;                
                // col_index为重排后图像中的索引
                int col_index = (c * height_col + h) * width_col + w;
                data_col[col_index] = im2col_get_data(data_im, im_row, im_col, c_im);
            }
        }
    }
}

int main()
{
    double start, finish, time;

    int height_col = (height + 2*pad - filter_size) / stride + 1;    
    int width_col = (width + 2*pad - filter_size) / stride + 1;    /// 卷积核大小：filter_size*filter_size是一个卷积核的大小，通道数channels
    int channels_col = channels * filter_size * filter_size;    
    
    // 动态分配内存
    float *im = (float *)malloc(height * width * channels * sizeof(float));
    float *col = (float *)malloc(channels_col * height_col * width_col * sizeof(float));
    float *filter = (float *)malloc(channels * filter_size * filter_size * sizeof(float));

    // 初始化input矩阵
    for (int i = 0; i < height * width * channels ; i++)
    {
        im[i] = (float)(rand() % 50)/100;
    }
    // 初始化filter
    for (int i = 0; i < filter_size * filter_size * channels; i++)
    {
        filter[i] = (float)(rand() % 50)/100;
    }

    GET_TIME(start);

    im2col(im, col);

    float *cuda_a, *cuda_b, *cuda_c;
    

    float *c = (float *)malloc(channels * (width_col * height_col) * sizeof(float));
    

	//cudaMalloc 分配空间
	cudaMalloc((void **)&cuda_a, sizeof(float) * channels * (filter_size * filter_size) );
	cudaMalloc((void **)&cuda_b, sizeof(float) * channels_col * (width_col * height_col));
	cudaMalloc((void **)&cuda_c, sizeof(float) * channels * (width_col * height_col));
    

	//cudaMemcpy 将矩阵复制到显存中
	cudaMemcpy(cuda_a, filter, sizeof(float) * channels * (filter_size * filter_size), cudaMemcpyHostToDevice);
	cudaMemcpy(cuda_b, col, sizeof(float) * channels_col * (width_col * height_col), cudaMemcpyHostToDevice);

    int BLOCK_SIZE = height;
    const int blocks_num = (channels * (width_col * height_col) + BLOCK_SIZE - 1) / BLOCK_SIZE;

	// 在CUDA 中执行 gemm 函数
	matMultCUDA<<<blocks_num, BLOCK_SIZE, 0>>>(cuda_a, cuda_b, cuda_c, channels, (filter_size * filter_size), (width_col * height_col), BLOCK_SIZE);

    //cudaMemcpy 将结果从显存中复制回内存
	cudaMemcpy(c, cuda_c, sizeof(float) * channels * (width_col * height_col), cudaMemcpyDeviceToHost);
    
	GET_TIME(finish);
	time = finish - start;
    
    // 输出结果到文件result.txt
    FILE *fp = fopen("result.txt", "w");
    for (int i = 0; i < channels * (width_col * height_col); i++)
    {
        fprintf(fp, "%f ", c[i]);
    }

	//Free
	cudaFree(cuda_a);
	cudaFree(cuda_b);
	cudaFree(cuda_c);
    free(c);
    free(im);
    free(col);

	printf("time: %f s\n\n", time);
    

    return 0;
}


	.file	"tmpxft_003af380_00000000-6_2.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.type	_ZL41__device_stub__Z11matMultCUDAPKfS0_PfiiiiPKfS0_Pfiiii, @function
_ZL41__device_stub__Z11matMultCUDAPKfS0_PfiiiiPKfS0_Pfiiii:
.LFB2054:
	.cfi_startproc
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	48(%rsp), %rdx
	movl	%ecx, 20(%rsp)
	leaq	56(%rsp), %rcx
	movl	%r8d, 16(%rsp)
	movl	%r9d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	192(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	56(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_ZL11matMultCUDAPKfS0_Pfiiii(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 208
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L2:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_ZL41__device_stub__Z11matMultCUDAPKfS0_PfiiiiPKfS0_Pfiiii, .-_ZL41__device_stub__Z11matMultCUDAPKfS0_PfiiiiPKfS0_Pfiiii
	.type	_ZL11matMultCUDAPKfS0_Pfiiii, @function
_ZL11matMultCUDAPKfS0_Pfiiii:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_ZL41__device_stub__Z11matMultCUDAPKfS0_PfiiiiPKfS0_Pfiiii
	.cfi_endproc
.LFE2055:
	.size	_ZL11matMultCUDAPKfS0_Pfiiii, .-_ZL11matMultCUDAPKfS0_Pfiiii
	.globl	_Z15im2col_get_dataPfiii
	.type	_Z15im2col_get_dataPfiii, @function
_Z15im2col_get_dataPfiii:
.LFB2027:
	.cfi_startproc
	endbr64
	decl	%esi
	cmpl	$255, %esi
	ja	.L10
	decl	%edx
	cmpl	$255, %edx
	ja	.L10
	sall	$8, %ecx
	leal	(%rcx,%rsi), %eax
	sall	$8, %eax
	addl	%edx, %eax
	cltq
	movss	(%rdi,%rax,4), %xmm0
	ret
.L10:
	xorps	%xmm0, %xmm0
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z15im2col_get_dataPfiii, .-_Z15im2col_get_dataPfiii
	.globl	_Z6im2colPfS_
	.type	_Z6im2colPfS_, @function
_Z6im2colPfS_:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rsi, %r11
	xorl	%r8d, %r8d
	movl	$3, %r10d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	$9, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	pushq	%rdx
	.cfi_def_cfa_offset 64
.L15:
	movl	%r8d, %eax
	movq	%r8, %rbp
	xorl	%r9d, %r9d
	cltd
	salq	$18, %rbp
	idivl	%r10d
	addq	%r11, %rbp
	movl	%edx, %r15d
	cltd
	idivl	%r10d
	movl	%r8d, %eax
	movl	%edx, %r14d
	cltd
	idivl	%r12d
	movl	%eax, (%rsp)
.L12:
	leal	(%r14,%r9), %eax
	movq	%r9, %rbx
	xorl	%r13d, %r13d
	movl	%eax, 4(%rsp)
	salq	$10, %rbx
	addq	%rbp, %rbx
.L13:
	movl	(%rsp), %ecx
	movl	4(%rsp), %esi
	leal	(%r15,%r13), %edx
	call	_Z15im2col_get_dataPfiii
	movss	%xmm0, (%rbx,%r13,4)
	incq	%r13
	cmpq	$256, %r13
	jne	.L13
	incq	%r9
	cmpq	$256, %r9
	jne	.L12
	incq	%r8
	cmpq	$27, %r8
	jne	.L15
	popq	%rax
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z6im2colPfS_, .-_Z6im2colPfS_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC3:
	.string	"w"
.LC4:
	.string	"result.txt"
.LC5:
	.string	"%f "
.LC6:
	.string	"time: %f s\n\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$786432, %edi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movl	$7077888, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	movl	$108, %edi
	movq	%rax, %rbx
	call	malloc@PLT
	movq	%rax, %r13
.L20:
	call	rand@PLT
	movl	$50, %ecx
	cltd
	idivl	%ecx
	cvtsi2ssl	%edx, %xmm0
	divss	.LC1(%rip), %xmm0
	movss	%xmm0, 0(%rbp,%r12,4)
	incq	%r12
	cmpq	$196608, %r12
	jne	.L20
	xorl	%r12d, %r12d
	movl	$50, %r14d
.L21:
	call	rand@PLT
	cltd
	idivl	%r14d
	cvtsi2ssl	%edx, %xmm0
	divss	.LC1(%rip), %xmm0
	movss	%xmm0, 0(%r13,%r12,4)
	incq	%r12
	cmpq	$27, %r12
	jne	.L21
	leaq	56(%rsp), %r14
	xorl	%esi, %esi
	movq	%r14, %rdi
	call	gettimeofday@PLT
	cvtsi2sdq	56(%rsp), %xmm1
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	cvtsi2sdq	64(%rsp), %xmm0
	divsd	.LC2(%rip), %xmm0
	addsd	%xmm1, %xmm0
	movsd	%xmm0, 8(%rsp)
	call	_Z6im2colPfS_
	movl	$786432, %edi
	call	malloc@PLT
	leaq	16(%rsp), %rdi
	movl	$108, %esi
	movq	%rax, %r12
	call	cudaMalloc@PLT
	leaq	24(%rsp), %rdi
	movl	$7077888, %esi
	call	cudaMalloc@PLT
	leaq	32(%rsp), %rdi
	movl	$786432, %esi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%r13, %rsi
	movl	$108, %edx
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$7077888, %edx
	call	cudaMemcpy@PLT
	movl	$16777217, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$16777219, %edi
	salq	$8, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	salq	$8, %rdi
	movq	%rdx, 56(%rsp)
	movl	$1, 64(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L22
	pushq	%rax
	.cfi_def_cfa_offset 152
	movl	$3, %ecx
	movl	$65536, %r9d
	movl	$9, %r8d
	pushq	$256
	.cfi_def_cfa_offset 160
	movq	48(%rsp), %rdx
	movq	40(%rsp), %rsi
	movq	32(%rsp), %rdi
	call	_ZL41__device_stub__Z11matMultCUDAPKfS0_PfiiiiPKfS0_Pfiiii
	popq	%rdx
	.cfi_def_cfa_offset 152
	popq	%rcx
	.cfi_def_cfa_offset 144
.L22:
	movq	32(%rsp), %rsi
	movl	$2, %ecx
	movq	%r12, %rdi
	xorl	%r15d, %r15d
	movl	$786432, %edx
	call	cudaMemcpy@PLT
	movq	%r14, %rdi
	xorl	%esi, %esi
	leaq	.LC5(%rip), %r14
	call	gettimeofday@PLT
	cvtsi2sdq	56(%rsp), %xmm1
	leaq	.LC3(%rip), %rsi
	cvtsi2sdq	64(%rsp), %xmm0
	divsd	.LC2(%rip), %xmm0
	leaq	.LC4(%rip), %rdi
	addsd	%xmm1, %xmm0
	subsd	8(%rsp), %xmm0
	movsd	%xmm0, 8(%rsp)
	call	fopen@PLT
	movq	%rax, %r13
.L23:
	cvtss2sd	(%r12,%r15,4), %xmm0
	movq	%r14, %rdx
	movl	$2, %esi
	movq	%r13, %rdi
	movb	$1, %al
	incq	%r15
	call	__fprintf_chk@PLT
	cmpq	$196608, %r15
	jne	.L23
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movsd	8(%rsp), %xmm0
	leaq	.LC6(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L24
	call	__stack_chk_fail@PLT
.L24:
	addq	$88, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	main, .-main
	.section	.rodata.str1.1
.LC7:
	.string	"_Z11matMultCUDAPKfS0_Pfiiii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2057:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC7(%rip), %rdx
	movq	%rax, %rdi
	leaq	_ZL11matMultCUDAPKfS0_Pfiiii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2057:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC1:
	.long	1120403456
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC2:
	.long	0
	.long	1093567616
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

/******************************************
 * Compile:
 * nvcc 2.cu -o 2
 * Run:       
 * ./2
*******************************************/


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <sys/time.h>

#define height 256
#define width 256
#define filter_size 3
#define stride 1
#define pad 1
#define channels 3

#define block_size_x 32
#define block_size_y 32

#define GET_TIME(now)                           \
    {                                           \
        struct timeval t;                       \
        gettimeofday(&t, NULL);                 \
        now = t.tv_sec + t.tv_usec / 1000000.0; \
    }

// 并行矩阵乘法函数
__global__ static void matMultCUDA(const float *a, const float *b, float *c, int M, int N, int K, int BLOCK_SIZE)
{
	//表示目前的 thread 的编号
	const int tid = threadIdx.x;
	//表示目前在第几个 block 中
	const int bid = blockIdx.x;
	//计算出当前的 row 和 column
	const int idx = bid * BLOCK_SIZE + tid;
	const int row = idx / M;
	int column = idx % M;
	do
	{
		//矩阵乘法
		if (row < M && column < K)
		{
			float t = 0;
			for (int i = 0; i < N; i++)
			{
				t += a[row * N + i] * b[i * K + column];
			}
			c[row * K + column] = t;
		}
		column += M;
	} while (column < K);
}

float im2col_get_data(float *im, int row, int col, int channel){ 
    row -= pad;
    col -= pad;    // padding补0
    if (row < 0 || col < 0 ||
        row >= height || col >= width) return 0;    
    // im[col + width*(row + height*channel)]=im[col+width*row+width*height*channel]
    return im[col + width*(row + height*channel)];
}
    

void im2col(float* data_im, float* data_col) {   
    int c,h,w;    // 计算卷积后的尺寸
    int height_col = (height + 2*pad - filter_size) / stride + 1;    
    int width_col = (width + 2*pad - filter_size) / stride + 1;
    int channels_col = channels * filter_size * filter_size;    
    // 获取对应的值
    for (c = 0; c < channels_col; ++c) {
        int w_offset = c % filter_size;        
        int h_offset = (c / filter_size) % filter_size;        
        int c_im = c / filter_size / filter_size;        
        for (h = 0; h < height_col; ++h) {
            for (w = 0; w < width_col; ++w) { 
                // 获取原图中对应的坐标
                int im_row = h_offset + h * stride;                
                int im_col = w_offset + w * stride;                
                // col_index为重排后图像中的索引
                int col_index = (c * height_col + h) * width_col + w;
                data_col[col_index] = im2col_get_data(data_im, im_row, im_col, c_im);
            }
        }
    }
}

int main()
{
    double start, finish, time;

    int height_col = (height + 2*pad - filter_size) / stride + 1;    
    int width_col = (width + 2*pad - filter_size) / stride + 1;    /// 卷积核大小：filter_size*filter_size是一个卷积核的大小，通道数channels
    int channels_col = channels * filter_size * filter_size;    
    
    // 动态分配内存
    float *im = (float *)malloc(height * width * channels * sizeof(float));
    float *col = (float *)malloc(channels_col * height_col * width_col * sizeof(float));
    float *filter = (float *)malloc(channels * filter_size * filter_size * sizeof(float));

    // 初始化input矩阵
    for (int i = 0; i < height * width * channels ; i++)
    {
        im[i] = (float)(rand() % 50)/100;
    }
    // 初始化filter
    for (int i = 0; i < filter_size * filter_size * channels; i++)
    {
        filter[i] = (float)(rand() % 50)/100;
    }

    GET_TIME(start);

    im2col(im, col);

    float *cuda_a, *cuda_b, *cuda_c;
    

    float *c = (float *)malloc(channels * (width_col * height_col) * sizeof(float));
    

	//cudaMalloc 分配空间
	hipMalloc((void **)&cuda_a, sizeof(float) * channels * (filter_size * filter_size) );
	hipMalloc((void **)&cuda_b, sizeof(float) * channels_col * (width_col * height_col));
	hipMalloc((void **)&cuda_c, sizeof(float) * channels * (width_col * height_col));
    

	//cudaMemcpy 将矩阵复制到显存中
	hipMemcpy(cuda_a, filter, sizeof(float) * channels * (filter_size * filter_size), hipMemcpyHostToDevice);
	hipMemcpy(cuda_b, col, sizeof(float) * channels_col * (width_col * height_col), hipMemcpyHostToDevice);

    int BLOCK_SIZE = height;
    const int blocks_num = (channels * (width_col * height_col) + BLOCK_SIZE - 1) / BLOCK_SIZE;

	// 在CUDA 中执行 gemm 函数
	matMultCUDA<<<blocks_num, BLOCK_SIZE, 0>>>(cuda_a, cuda_b, cuda_c, channels, (filter_size * filter_size), (width_col * height_col), BLOCK_SIZE);

    //cudaMemcpy 将结果从显存中复制回内存
	hipMemcpy(c, cuda_c, sizeof(float) * channels * (width_col * height_col), hipMemcpyDeviceToHost);
    
	GET_TIME(finish);
	time = finish - start;
    
    // 输出结果到文件result.txt
    FILE *fp = fopen("result.txt", "w");
    for (int i = 0; i < channels * (width_col * height_col); i++)
    {
        fprintf(fp, "%f ", c[i]);
    }

	//Free
	hipFree(cuda_a);
	hipFree(cuda_b);
	hipFree(cuda_c);
    free(c);
    free(im);
    free(col);

	printf("time: %f s\n\n", time);
    

    return 0;
}


	.text
	.file	"2.hip"
	.globl	_Z15im2col_get_dataPfiii        # -- Begin function _Z15im2col_get_dataPfiii
	.type	_Z15im2col_get_dataPfiii,@function
_Z15im2col_get_dataPfiii:               # @_Z15im2col_get_dataPfiii
	.cfi_startproc
# %bb.0:
                                        # kill: def $esi killed $esi def $rsi
	movl	$-257, %eax                     # imm = 0xFEFF
	leal	(%rsi,%rax), %r8d
	xorps	%xmm0, %xmm0
	cmpl	$-256, %r8d
	jb	.LBB0_3
# %bb.1:
	addl	%eax, %edx
	cmpl	$-256, %edx
	jb	.LBB0_3
# %bb.2:
	shll	$16, %ecx
	shll	$8, %esi
	addl	%ecx, %esi
	addl	%esi, %edx
	movslq	%edx, %rax
	movss	(%rdi,%rax,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
.LBB0_3:
	retq
.Lfunc_end0:
	.size	_Z15im2col_get_dataPfiii, .Lfunc_end0-_Z15im2col_get_dataPfiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z6im2colPfS_                   # -- Begin function _Z6im2colPfS_
	.type	_Z6im2colPfS_,@function
_Z6im2colPfS_:                          # @_Z6im2colPfS_
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$-257, %r9d                     # imm = 0xFEFF
	xorl	%r13d, %r13d
	movabsq	$-6148914691236517205, %r10     # imm = 0xAAAAAAAAAAAAAAAB
	movabsq	$-2049638230412172401, %r11     # imm = 0xE38E38E38E38E38F
	movl	$1024, %ebx                     # imm = 0x400
.LBB1_1:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_2 Depth 2
                                        #       Child Loop BB1_3 Depth 3
	movl	%r13d, %eax
	imulq	$954437177, %rax, %r14          # imm = 0x38E38E39
	shrq	$32, %r14
	andl	$-2, %r14d
	shll	$15, %r14d
	movq	%r13, %rax
	mulq	%r10
	movq	%rdx, %r8
	shrq	%r8
	imull	$253, %r8d, %ebp
	addl	%r9d, %ebp
	addl	%r14d, %ebp
	movq	%r13, %rax
	mulq	%r11
	andl	$-8, %edx
	shll	$5, %edx
	leal	(%rdx,%rdx,2), %eax
	subl	%eax, %ebp
	movslq	%ebp, %rax
	leaq	(%rdi,%rax,4), %rax
	leal	(%r8,%r8,2), %r8d
	movl	%r9d, %edx
	subl	%r8d, %edx
	movzbl	%r13b, %r8d
	imull	$171, %r8d, %r8d
	shrl	$9, %r8d
	imull	$86, %r8d, %ecx
	movzbl	%ch, %ecx
	leal	(%rcx,%rcx,2), %ecx
	subb	%cl, %r8b
	movzbl	%r8b, %r8d
	movq	%rsi, %r14
	xorl	%r15d, %r15d
.LBB1_2:                                # %.preheader
                                        #   Parent Loop BB1_1 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_3 Depth 3
	leal	(%r15,%r8), %ebp
	addl	$-257, %ebp                     # imm = 0xFEFF
	xorl	%r12d, %r12d
.LBB1_3:                                #   Parent Loop BB1_1 Depth=1
                                        #     Parent Loop BB1_2 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	xorps	%xmm0, %xmm0
	cmpl	$-256, %ebp
	jb	.LBB1_6
# %bb.4:                                #   in Loop: Header=BB1_3 Depth=3
	leal	(%rdx,%r12), %ecx
	cmpl	$-256, %ecx
	jb	.LBB1_6
# %bb.5:                                #   in Loop: Header=BB1_3 Depth=3
	movss	(%rax,%r12,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
.LBB1_6:                                # %_Z15im2col_get_dataPfiii.exit
                                        #   in Loop: Header=BB1_3 Depth=3
	movss	%xmm0, (%r14,%r12,4)
	incq	%r12
	cmpq	$256, %r12                      # imm = 0x100
	jne	.LBB1_3
# %bb.7:                                #   in Loop: Header=BB1_2 Depth=2
	incq	%r15
	addq	%rbx, %r14
	addq	%rbx, %rax
	cmpq	$256, %r15                      # imm = 0x100
	jne	.LBB1_2
# %bb.8:                                #   in Loop: Header=BB1_1 Depth=1
	incq	%r13
	addq	$262144, %rsi                   # imm = 0x40000
	incl	%r9d
	cmpq	$27, %r13
	jne	.LBB1_1
# %bb.9:
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z6im2colPfS_, .Lfunc_end1-_Z6im2colPfS_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI2_0:
	.long	0x42c80000                      # float 100
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI2_1:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$786432, %edi                   # imm = 0xC0000
	callq	malloc
	movq	%rax, %rbx
	movl	$7077888, %edi                  # imm = 0x6C0000
	callq	malloc
	movq	%rax, %r14
	movl	$108, %edi
	callq	malloc
	movq	%rax, %r12
	xorl	%r15d, %r15d
.LBB2_1:                                # =>This Inner Loop Header: Depth=1
	callq	rand
	movss	.LCPI2_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	cltq
	imulq	$1374389535, %rax, %rcx         # imm = 0x51EB851F
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$36, %rcx
	addl	%edx, %ecx
	imull	$50, %ecx, %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	divss	%xmm1, %xmm0
	movss	%xmm0, (%rbx,%r15,4)
	incq	%r15
	cmpq	$196608, %r15                   # imm = 0x30000
	jne	.LBB2_1
# %bb.2:                                # %.preheader.preheader
	xorl	%r15d, %r15d
.LBB2_3:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$1374389535, %rax, %rcx         # imm = 0x51EB851F
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$36, %rcx
	addl	%edx, %ecx
	imull	$50, %ecx, %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	divss	.LCPI2_0(%rip), %xmm0
	movss	%xmm0, (%r12,%r15,4)
	incq	%r15
	cmpq	$27, %r15
	jne	.LBB2_3
# %bb.4:
	leaq	56(%rsp), %r15
	movq	%r15, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%r15), %rax
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	movq	8(%r15), %rax
	movq	%rax, 40(%rsp)                  # 8-byte Spill
	movq	%rbx, %rdi
	movq	%r14, %rsi
	callq	_Z6im2colPfS_
	movl	$786432, %edi                   # imm = 0xC0000
	callq	malloc
	movq	%rax, %r15
	leaq	32(%rsp), %r13
	movl	$108, %esi
	movq	%r13, %rdi
	callq	hipMalloc
	leaq	24(%rsp), %rbp
	movl	$7077888, %esi                  # imm = 0x6C0000
	movq	%rbp, %rdi
	callq	hipMalloc
	leaq	16(%rsp), %rdi
	movl	$786432, %esi                   # imm = 0xC0000
	callq	hipMalloc
	movq	(%r13), %rdi
	movl	$108, %edx
	movq	%r12, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%rbp), %rdi
	movl	$7077888, %edx                  # imm = 0x6C0000
	movq	%r14, 48(%rsp)                  # 8-byte Spill
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movabsq	$4294967552, %rdx               # imm = 0x100000100
	leaq	512(%rdx), %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_6
# %bb.5:
	movq	32(%rsp), %rdi
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdx
	movl	$256, (%rsp)                    # imm = 0x100
	movl	$3, %ecx
	movl	$9, %r8d
	movl	$65536, %r9d                    # imm = 0x10000
	callq	_ZL26__device_stub__matMultCUDAPKfS0_Pfiiii
.LBB2_6:
	movq	16(%rsp), %rsi
	movl	$786432, %edx                   # imm = 0xC0000
	movq	%r15, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	xorl	%r13d, %r13d
	leaq	56(%rsp), %r12
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%r12), %rbp
	movq	8(%r12), %r14
	movl	$.L.str, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, %r12
.LBB2_7:                                # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r15,%r13,4), %xmm0
	movl	$.L.str.2, %esi
	movq	%r12, %rdi
	movb	$1, %al
	callq	fprintf
	incq	%r13
	cmpq	$196608, %r13                   # imm = 0x30000
	jne	.LBB2_7
# %bb.8:
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r14, %xmm0
	movsd	.LCPI2_1(%rip), %xmm1           # xmm1 = mem[0],zero
	divsd	%xmm1, %xmm0
	cvtsi2sd	%rbp, %xmm3
	addsd	%xmm0, %xmm3
	xorps	%xmm0, %xmm0
	cvtsi2sdq	40(%rsp), %xmm0         # 8-byte Folded Reload
	cvtsi2sdq	8(%rsp), %xmm2          # 8-byte Folded Reload
	divsd	%xmm1, %xmm0
	addsd	%xmm0, %xmm2
	subsd	%xmm2, %xmm3
	movsd	%xmm3, 8(%rsp)                  # 8-byte Spill
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	%r15, %rdi
	callq	free
	movq	%rbx, %rdi
	callq	free
	movq	48(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movl	$.L.str.3, %edi
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movb	$1, %al
	callq	printf
	xorl	%eax, %eax
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
                                        # -- End function
	.type	_ZL26__device_stub__matMultCUDAPKfS0_Pfiiii,@function # -- Begin function _ZL26__device_stub__matMultCUDAPKfS0_Pfiiii
_ZL26__device_stub__matMultCUDAPKfS0_Pfiiii: # @_ZL26__device_stub__matMultCUDAPKfS0_Pfiiii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$160, %rsp
	.cfi_def_cfa_offset 208
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	20(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	16(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	12(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	208(%rsp), %rax
	movq	%rax, 48(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_ZL11matMultCUDAPKfS0_Pfiiii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$176, %rsp
	.cfi_adjust_cfa_offset -176
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_ZL26__device_stub__matMultCUDAPKfS0_Pfiiii, .Lfunc_end3-_ZL26__device_stub__matMultCUDAPKfS0_Pfiiii
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_ZL11matMultCUDAPKfS0_Pfiiii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB5_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_ZL11matMultCUDAPKfS0_Pfiiii,@object # @_ZL11matMultCUDAPKfS0_Pfiiii
	.section	.rodata,"a",@progbits
	.p2align	3, 0x0
_ZL11matMultCUDAPKfS0_Pfiiii:
	.quad	_ZL26__device_stub__matMultCUDAPKfS0_Pfiiii
	.size	_ZL11matMultCUDAPKfS0_Pfiiii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"result.txt"
	.size	.L.str, 11

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"w"
	.size	.L.str.1, 2

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"%f "
	.size	.L.str.2, 4

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"time: %f s\n\n"
	.size	.L.str.3, 13

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_ZL11matMultCUDAPKfS0_Pfiiii"
	.size	.L__unnamed_1, 29

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _ZL26__device_stub__matMultCUDAPKfS0_Pfiiii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _ZL11matMultCUDAPKfS0_Pfiiii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.section	.text._ZL11matMultCUDAPKfS0_Pfiiii,"axG",@progbits,_ZL11matMultCUDAPKfS0_Pfiiii,comdat
	.globl	_ZL11matMultCUDAPKfS0_Pfiiii    ; -- Begin function _ZL11matMultCUDAPKfS0_Pfiiii
	.p2align	8
	.type	_ZL11matMultCUDAPKfS0_Pfiiii,@function
_ZL11matMultCUDAPKfS0_Pfiiii:           ; @_ZL11matMultCUDAPKfS0_Pfiiii
; %bb.0:
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x18
	s_load_b128 s[8:11], s[0:1], 0x0
	s_mov_b32 s12, 0
	s_waitcnt lgkmcnt(0)
	s_ashr_i32 s17, s4, 31
	s_mov_b32 s16, s4
	s_add_i32 s2, s4, s17
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_xor_b32 s2, s2, s17
	v_cvt_f32_u32_e32 v1, s2
	s_sub_i32 s3, 0, s2
	s_cmp_gt_i32 s5, 0
	s_cselect_b32 s13, -1, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v1, v1
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v1, 0x4f7ffffe, v1
	v_cvt_u32_f32_e32 v3, v1
	v_mad_u64_u32 v[1:2], null, s15, s7, v[0:1]
	s_ashr_i32 s7, s6, 31
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_lo_u32 v0, s3, v3
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_hi_u32 v0, v3, v0
	v_add_nc_u32_e32 v4, v1, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_xor_b32_e32 v4, v4, v2
	v_xor_b32_e32 v2, s17, v2
	v_add_nc_u32_e32 v0, v3, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_hi_u32 v0, v4, v0
	v_mul_lo_u32 v3, v0, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_sub_nc_u32_e32 v3, v4, v3
	v_add_nc_u32_e32 v4, 1, v0
	v_subrev_nc_u32_e32 v5, s2, v3
	v_cmp_le_u32_e32 vcc_lo, s2, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_cndmask_b32 v3, v3, v5 :: v_dual_cndmask_b32 v0, v0, v4
	v_cmp_le_u32_e32 vcc_lo, s2, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v4, 1, v0
	s_load_b64 s[2:3], s[0:1], 0x10
	v_cndmask_b32_e32 v0, v0, v4, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_xor_b32_e32 v0, v0, v2
	v_sub_nc_u32_e32 v4, v0, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_4)
	v_mul_lo_u32 v0, v4, s4
	v_mul_lo_u32 v2, v4, s5
	v_cmp_gt_i32_e64 s0, s4, v4
	v_mul_lo_u32 v9, v4, s6
	v_sub_nc_u32_e32 v0, v1, v0
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v3, 31, v2
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[2:3], 2, v[2:3]
	v_lshlrev_b64 v[4:5], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v1, vcc_lo, s8, v2
	v_add_co_ci_u32_e32 v2, vcc_lo, s9, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v3, vcc_lo, s10, v4
	v_add_co_ci_u32_e32 v4, vcc_lo, s11, v5, vcc_lo
	s_lshl_b64 s[8:9], s[16:17], 2
	s_lshl_b64 s[10:11], s[6:7], 2
.LBB0_1:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_4 Depth 2
	v_cmp_gt_i32_e32 vcc_lo, s6, v0
	s_and_b32 s7, s0, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s1, s7
	s_cbranch_execz .LBB0_6
; %bb.2:                                ; %.preheader
                                        ;   in Loop: Header=BB0_1 Depth=1
	v_mov_b32_e32 v10, 0
	s_and_not1_b32 vcc_lo, exec_lo, s13
	s_cbranch_vccnz .LBB0_5
; %bb.3:                                ; %.lr.ph.preheader
                                        ;   in Loop: Header=BB0_1 Depth=1
	v_dual_mov_b32 v6, v2 :: v_dual_mov_b32 v5, v1
	v_dual_mov_b32 v8, v4 :: v_dual_mov_b32 v7, v3
	s_mov_b32 s7, s5
.LBB0_4:                                ; %.lr.ph
                                        ;   Parent Loop BB0_1 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	global_load_b32 v11, v[5:6], off
	global_load_b32 v12, v[7:8], off
	v_add_co_u32 v7, vcc_lo, v7, s10
	v_add_co_ci_u32_e32 v8, vcc_lo, s11, v8, vcc_lo
	v_add_co_u32 v5, vcc_lo, v5, 4
	v_add_co_ci_u32_e32 v6, vcc_lo, 0, v6, vcc_lo
	s_add_i32 s7, s7, -1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s7, 0
	s_waitcnt vmcnt(0)
	v_fmac_f32_e32 v10, v11, v12
	s_cbranch_scc0 .LBB0_4
.LBB0_5:                                ; %._crit_edge
                                        ;   in Loop: Header=BB0_1 Depth=1
	v_add_nc_u32_e32 v5, v0, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v6, 31, v5
	v_lshlrev_b64 v[5:6], 2, v[5:6]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v5, vcc_lo, s2, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s3, v6, vcc_lo
	global_store_b32 v[5:6], v10, off
.LBB0_6:                                ; %Flow70
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	v_add_nc_u32_e32 v0, s4, v0
	v_add_co_u32 v3, s1, v3, s8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e64 v4, s1, s9, v4, s1
	v_cmp_le_i32_e32 vcc_lo, s6, v0
	s_or_b32 s12, vcc_lo, s12
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s12
	s_cbranch_execnz .LBB0_1
; %bb.7:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _ZL11matMultCUDAPKfS0_Pfiiii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 40
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 13
		.amdhsa_next_free_sgpr 18
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.section	.text._ZL11matMultCUDAPKfS0_Pfiiii,"axG",@progbits,_ZL11matMultCUDAPKfS0_Pfiiii,comdat
.Lfunc_end0:
	.size	_ZL11matMultCUDAPKfS0_Pfiiii, .Lfunc_end0-_ZL11matMultCUDAPKfS0_Pfiiii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 572
; NumSgprs: 20
; NumVgprs: 13
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 20
; NumVGPRsForWavesPerEU: 13
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         36
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 40
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _ZL11matMultCUDAPKfS0_Pfiiii
    .private_segment_fixed_size: 0
    .sgpr_count:     20
    .sgpr_spill_count: 0
    .symbol:         _ZL11matMultCUDAPKfS0_Pfiiii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     13
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
