This is an archive of the discontinued LLVM Phabricator instance.

Support/ELF: Add R_AMDGPU_GOTPCREL relocation
ClosedPublic

Authored by tstellarAMD on Jun 17 2016, 2:31 PM.

Details

Summary

We will start generating this in a future patch.

Change-Id: Id5fae1e8e6887ab7bbecbf445d1834a3aed4a5c9

Diff Detail

Repository
rL LLVM

Event Timeline

tstellarAMD retitled this revision from to Support/ELF: Add R_AMDGPU_GOTPCREL relocation.
tstellarAMD updated this object.
tstellarAMD added a subscriber: llvm-commits.
rafael edited edge metadata.Jun 17 2016, 5:57 PM
rafael added a subscriber: rafael.

git-clang-format the patch.

Out of curiosity, why do you need a got? Are GPU fancy enough to have
shared libraries and symbol preemption these days?

Cheers,
Rafael

tstellarAMD edited edge metadata.

clang-format the patch.

git-clang-format the patch.

Out of curiosity, why do you need a got? Are GPU fancy enough to have
shared libraries and symbol preemption these days?

We only support generating shared libraries of GPU code. The shared libraries are loaded into memory, and then the CPU host code is essentially calling functions in the GPU libraries (not directly calling them directly, but using a GPU runtime library, like OpenCL, for example, to invoke the functions).

We don't support preemption, but we need to use a got for referencing external variables.

We only support generating shared libraries of GPU code. The shared libraries are loaded into memory, and then the CPU host code is essentially calling functions in the GPU libraries (not directly calling them directly, but using a GPU runtime library, like OpenCL, for example, to invoke the functions).

We don't support preemption, but we need to use a got for referencing external variables.

Sorry, I am still missing something.

By "external", you mean "not in the .o" or "not in the .so". You don't
need a got to access things that are in the .so if you don't support
preemption. If they are external to the .so, where are they? Is it
possible to structure a gpu program as multiple .so files?

Cheers,
Rafael

We only support generating shared libraries of GPU code. The shared libraries are loaded into memory, and then the CPU host code is essentially calling functions in the GPU libraries (not directly calling them directly, but using a GPU runtime library, like OpenCL, for example, to invoke the functions).

We don't support preemption, but we need to use a got for referencing external variables.

Sorry, I am still missing something.

By "external", you mean "not in the .o" or "not in the .so". You don't
need a got to access things that are in the .so if you don't support
preemption. If they are external to the .so, where are they? Is it
possible to structure a gpu program as multiple .so files?

"external" means not in the .so. There can be multiple .so files. A common case for this is on a multiple GPU system where you have one .so for data that is stored in device memory. This device .so is loaded into the device memory of each GPU (so one copy of the .so per device). Then you have a second .so for data that is stored in host memory. There is only a single copy of this .so which is stored in host memory that can be accessed by all devices. The .so stored in device memory will access variables defined in the .so stored in host memory.

One question I have is if we don't support pre-emption, is there some way for the whole tool chain to know this, so the linker is able to resolve more symbols at link time?

kzhuravl edited edge metadata.EditedJun 20 2016, 9:32 AM

We only support generating shared libraries of GPU code. The shared libraries are loaded into memory, and then the CPU host code is essentially calling functions in the GPU libraries (not directly calling them directly, but using a GPU runtime library, like OpenCL, for example, to invoke the functions).

We don't support preemption, but we need to use a got for referencing external variables.

Sorry, I am still missing something.

By "external", you mean "not in the .o" or "not in the .so". You don't
need a got to access things that are in the .so if you don't support
preemption. If they are external to the .so, where are they? Is it
possible to structure a gpu program as multiple .so files?

Cheers,
Rafael

Hi Rafael,

In additions to what Tom said, external variables can be allocated and defined by the host, at runtime, before dispatching GPU kernels. Here is a "memory copy" quick example:

GPU Kernel (OpenCL):

extern global int *ExternVar;

kernel void foo(global int *A, const int size) {
  int gid = get_global_id(0);
  if (gid < size)
    A[gid] = ExternVar[gid];
}

Host Code (using hsa runtime, pseudo code and hand waving):

int *hostA = NULL
hsa_memory_allocate(global_region, 4 * sizeof(int), &hostA)

int *hostExternVar = NULL
hsa_memory_allocate(global_region, 4 * sizeof(int), &hostExternVar)

for (i = 0; i < 4; i++) hostExternVar[i] = i

exec = hsa_executable_create
hsa_executable_global_variable_define(exec, "ExternVar", hostExternVar)
hsa_executable_load_code_object(exec, device, code object for GPU kernel above)

setup kernel arguments and dispatch kernel "foo"

Cool.

Lgtm with a llvm-mc testcase.

LGTM: add missing `` in docs and add a test.

docs/CodeGenerator.rst
2700 ↗(On Diff #61154)

Missing ``

kzhuravl accepted this revision.Jun 21 2016, 10:14 AM
kzhuravl edited edge metadata.

LGTM: add missing `` in docs and add a test.

This revision is now accepted and ready to land.Jun 21 2016, 10:14 AM
This revision was automatically updated to reflect the committed changes.