[all-commits] [llvm/llvm-project] b438a8: [Offload] Fix dataDelete op for TARGET_ALLOC_HOST ...

Jhonatan Cléto via All-commits all-commits at lists.llvm.org
Tue May 7 20:21:54 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b438a817bd863699715116ee7d85b454f3289c08
      https://github.com/llvm/llvm-project/commit/b438a817bd863699715116ee7d85b454f3289c08
  Author: Jhonatan Cléto <52751492+cl3to at users.noreply.github.com>
  Date:   2024-05-07 (Tue, 07 May 2024)

  Changed paths:
    M offload/plugins-nextgen/common/src/PluginInterface.cpp
    M offload/src/omptarget.cpp

  Log Message:
  -----------
  [Offload] Fix dataDelete op for TARGET_ALLOC_HOST memory type (#91134)

Summary:
The `GenericDeviceTy::dataDelete` method doesn't verify the
`TargetAllocTy` of the of the device pointer. Because of this, it can
use the `MemoryManager` to free the ptr. However, the
`TARGET_ALLOC_HOST` and `TARGET_ALLOC_SHARED` types are not allocated
using the `MemoryManager` in the `GenericDeviceTy::dataAlloc` method.
Since the `MemoryManager` uses the `DeviceAllocatorTy::free` operation
without specifying the type of the ptr, some plugins may use incorrect
operations to free ptrs of certain types. In particular, this bug causes
the CUDA plugin to use the `cuMemFree` operation on ptrs of type
`TARGET_ALLOC_HOST`, resulting in an unchecked error, as shown in the
output snippet of the test
`offload/test/api/omp_host_pinned_memory_alloc.c`:

```
omptarget --> Notifying about an unmapping: HstPtr=0x00007c6114200000
omptarget --> Call to llvm_omp_target_free_host for device 0 and address 0x00007c6114200000
omptarget --> Call to omp_get_num_devices returning 1
omptarget --> Call to omp_get_initial_device returning 1
PluginInterface --> MemoryManagerTy::free: target memory 0x00007c6114200000.
PluginInterface --> Cannot find its node. Delete it on device directly.
TARGET CUDA RTL --> Failure to free memory: Error in cuMemFree[Host]: invalid argument
omptarget --> omp_target_free deallocated device ptr
```

This patch fixes this by adding the check of the device pointer type
before calling the appropriate operation for each type.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list