[Openmp-commits] [PATCH] D142512: [OpenMP][libomptarget] Fix mapping/prelock.cpp test

Kevin Sala via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Jan 25 00:56:49 PST 2023


kevinsala added a comment.

@carlo.bertolli Just tested the example below with the old plugins and it also segfaults:

  #include <assert.h>
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
  
  #include <omp.h>
  
  void *llvm_omp_target_lock_mem(void *ptr, size_t size, int device_num);
  void llvm_omp_target_unlock_mem(void *ptr, int device_num);
  
  int main(int argc, char **argv) {
      const size_t size = 1000*sizeof(int);
  
      int *ptr1 = (int *) malloc(size);
      assert(ptr1 != NULL);
  
      memset(ptr1, 0, size);
  
      int *ptr2 = (int *) llvm_omp_target_lock_mem(ptr1, size, 0);
      assert(ptr2 != NULL);
  
      fprintf(stdout, "ptr1: %p, ptr2: %p\n", ptr1, ptr2);
      fprintf(stdout, "ptr1[0]: %d\n", ptr1[0]);
      fprintf(stdout, "ptr2[0]: %d\n", ptr2[0]);
  
      return 0;
  }

When running the program, the access to `ptr2[0]` segfaults at the host side. So I don't think `ptr2` is a locked host pointer. It's the pointer returned by `hsa_amd_memory_lock` as the `agent_ptr` output parameter. And probably it's a pointer that the GPU agents should use for asynchronous memory transfers involving the buffer `[ptr1, size)`. I assumed the host locked pointer is `ptr1` directly, after `hsa_amd_memory_lock` is executed. However, I'm not 100% sure since the documentation of the lock operation on HSA AMD is a bit confusing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142512



More information about the Openmp-commits mailing list