Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

函数调用的时候generic_addressing_space自动推导的问题 #80

Open
wangqinfan opened this issue Dec 1, 2023 · 2 comments
Open

Comments

@wangqinfan
Copy link
Collaborator

wangqinfan commented Dec 1, 2023

OpenCL 2.0支持generic address space,所以在定义一个函数的时候可以不指定指针的地址空间,那么在调用该函数的时候可以传入任何地址空间的指针,所以函数内部不知道怎么翻译有关该指针的访存指令。可以看下面这个例子:

// RUN: clang -cl-std=CL2.0 -target riscv32 -mcpu=ventus-gpgpu -S %s
int test2(private int *a) {
    return *a + 1;
}

int test3(int *a) {
    return *a + 1;
}

int test1() {
    private int a[2];
    return test2(a) + test3(a);
}

这里test3和test2翻成了不同的访存指令。下面是汇编:

test2:
	addi	sp, sp, 4
	sw	ra, -4(sp)
	vlw.v	v0, 0(v0)
	vadd.vi	v0, v0, 1
	lw	ra, -4(sp)
	addi	sp, sp, -4
	ret
.Lfunc_end0:
	.size	test2, .Lfunc_end0-test2

	.globl	test3
	.p2align	2
	.type	test3,@function
test3:
	addi	sp, sp, 4
	sw	ra, -4(sp)
	vlw12.v	v0, 0(v0)
	vadd.vi	v0, v0, 1
	lw	ra, -4(sp)
	addi	sp, sp, -4
	ret
.Lfunc_end1:
	.size	test3, .Lfunc_end1-test3

	.globl	test1
	.p2align	2
	.type	test1,@function
test1:
	addi	sp, sp, 4
	sw	ra, -4(sp)
	lw	ra, -4(sp)
	addi	sp, sp, -4
	ret
@Jules-Kong
Copy link
Collaborator

Jules-Kong commented Feb 22, 2024

  • 源码
    // RUN: clang -cl-std=CL2.0 -target riscv32 -mcpu=ventus-gpgpu -S %s int test3(int *a) { return *a + 1; }

  • 命令
    clang -cl-std=CL2.0 -target riscv32 -mcpu=ventus-gpgpu -S -mllvm -print-after-all test_generic_addr_2.cl &> ventus_t2.log
    clang -target amdgcn test_generic_addr_2.cl -mllvm -print-after-all -S &> amd_t2.log

  • ventus与amd的差异
    f5e47d9176cecc831f8eaa8746331e6

@zhoujingya
Copy link
Contributor

你编译AMDGPU target的时候下错了参数,clang -target amdgcn test_generic_addr_2.cl -mllvm -print-after-all -S &> amd_t2.log, 忘记加-cl-std=CL2.0了, @Jules-Kong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants