[Openmp-commits] [PATCH] D95155: [libomptarget] WIP build plugin without cuda.h

Jon Chesterfield via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu Jan 21 15:25:46 PST 2021


JonChesterfield added a comment.

In D95155#2513810 <https://reviews.llvm.org/D95155#2513810>, @jdoerfert wrote:

> Interesting. Should we do this instead of the pure macro stuff? Is this going to break if the argument type doesn't match the declaration parameter type, e.g.,
>
>   void f(int);
>   
>   f(0.0);

`void f(int);` translates to `void f(int x) { return some_trait::call(x); }`, the generated function has the same type as the symbol it derived from. So I think calls all work out.

Just finished getting amdgpu to the point where it builds, interesting part renders as:

  DLWRAP(hsa_amd_memory_fill, 3);
  DLWRAP(hsa_amd_register_system_event_handler, 2);
  
  DLWRAP_FINALIZE();
  
  static const char *HSALib = "libhsa-runtime64.so";
  
  hsa_status_t HSA_API hsa_init() {
    void *dynlib_handle = dlopen(HSALib, RTLD_NOW);
    if (!dynlib_handle) {
      return HSA_STATUS_ERROR;
    }
  
    size_t N = dlwrap::size();
    for (size_t i = 0; i < N; i++) {
      const char *sym = dlwrap::symbol(i);
      void *p = dlsym(dynlib_handle, sym);
      if (p == nullptr) {
        return HSA_STATUS_ERROR;
      }
      *dlwrap::pointer(i) = p;
    }
  
    return dlwrap_hsa_init();
  }
  
  hsa_status_t HSA_API hsa_shut_down() {
    hsa_status_t res = dlwrap_hsa_shut_down();
  
    void *dynlib_handle = dlopen(HSALib, RTLD_NOW);
    if (dynlib_handle) {
      dlclose(dynlib_handle);
      dlclose(dynlib_handle);
      return res;
    } else {
      return HSA_STATUS_ERROR;
    }
  }

which means the dlopen'ed version behaves the same as the statically linked one, doing the setup & teardown through the same API hook, albeit with more failure modes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95155



More information about the Openmp-commits mailing list