[PATCH] D123471: [CUDA] Create offloading entries when using the new driver

Joseph Huber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 11 13:24:48 PDT 2022


jhuber6 added a comment.

In D123471#3443612 <https://reviews.llvm.org/D123471#3443612>, @yaxunl wrote:

> Is OpenMP runtime able to find these entries without registering them through some API functions? If so, do you have a pointer to the code doing that?

Yes, the linker will define `__start/__stop` symbols for any sections found with a section name that is a valid C-identifier. If you compile the following file with any OpenMP offloading code you should be able to print out all the symbol names that will be registered when the runtime is initialized.

  #include <stdint.h>
  #include <stdio.h>
  struct __tgt_offload_entry {
    void *addr;  // Pointer to the offload entry info.
                 // (function or global)
    char *name;  // Name of the function or global.
    size_t size; // Size of the entry info (0 if it a function).
    int32_t flags;
    int32_t reserved;
  };
  
  extern struct __tgt_offload_entry __start_omp_offloading_entries;
  extern struct __tgt_offload_entry __stop_omp_offloading_entries;
  
  __attribute__((constructor)) void print() {
    struct __tgt_offload_entry *iter = &__start_omp_offloading_entries;
    for (; iter != &__stop_omp_offloading_entries; ++iter)
      printf("%s\n", iter->name);
  }

And then compile like

  $ clang input.c -fopenmp -fopenmp-targets=nvptx64 -c
  $ clang print.c -c
  $ clang input.o print.o -fopenmp -fopenmp-targets=nvptx64
  $ ./a.out 
  x
  __omp_offloading_fd02_605785f3_main_l8



> most CUDA/HIP programs assume -fno-gpu-rdc mode, which have multiple sections containing these entries merged by linker, with gaps between them. How do runtime identify such gaps and skip them?

I'm making the executive decision to always enable `fgpu-rdc` when using this new driver in the future. The above is handled by the linker so there shouldn't be any gaps.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123471/new/

https://reviews.llvm.org/D123471



More information about the cfe-commits mailing list