Skip to content

[AMDGPU] Casting to addrspace 5 causing mem fault #104035

@yxsamliu

Description

@yxsamliu
__device__ void foo(int* xxx) {
    auto *p = (__attribute__((address_space(5)))int*)xxx;
    *p = 1;
}
__device__ void bar(int* xxx) {
    *xxx = 1;
}

__managed__ int y;
extern "C" __global__ void kernel() {
  int x;
  foo(&x);  // memfault
  //bar(&x); // works
  y = x;
}

int main() {
  kernel<<<1,1>>>();
  hipDeviceSynchronize();
  printf("%d\n", y);
}

the above code cause memfault when compiled with -fno-inline-functions. xxx is actually pointing to a private memory. it is OK to be accessed by a flat pointer but memfault when accessed by casting the flat pointer to private pointer.

compare ISA of foo and bar (https://godbolt.org/z/YqT4dhGcE ) shows casting xxx to a private pointer then accessing it generates buffer store which depends on s[0-3]. However, the kernel does not know that and does not set up s[0-3], which makes buffer store not working. flat store does not depend on s[0-3], therefore it still works.

This issue is revealed by blender crash due to enabling AAInstanceInfo by 7a68449. AAInstanceInfo will deduce that xxx is private pointer by IPA and cast flat pointer to addr space 5.

@arsenm @shiltian

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions