Std::shared_ptr in target region

#include
int main() {
#pragma omp target
std::shared_ptr spi;
}

The above code does not get built with

clang++ -std=c++17 -fopenmp -fopenmp-targets=nvptx64 test-shared_ptr.cpp

In my app, smart pointers are used everywhere and also in the target regions.

#include <memory>

We will need to provide a custom shared pointer implementation for the GPU to make this work. Can you open an issue for this?

1 Like

Sure I will.

Is there a workaround?

There is now:

Copy the code into your application, e.g., some header. Build libcxx with clang and the openmp runtimes. Use it via -stdlib=libcxx.

1 Like

In terms of the <memory_resource> header, libstdc++ is better, seems to me libc++ still categorizes it in experimental; can I write simply the same workaround for libstdc++ as well?

Something like that or similar code should work for libstdc++. You basically have to dig up all the functions that are only declared in the header but used in the code. The missing linker symbols will guide you.

1 Like

I’ve tried your code with clang-15 and I get:

$ clang++ -fuse-ld=lld -std=c++17 -stdlib=libc++ -fopenmp -fopenmp-targets=nvptx64 j1.cpp
fatal error: error in backend: Cannot select: 0xaad3a18: i64,ch = AtomicLoad<(load seq_cst (s64) from %ir.6)> 0xa9a26b8, 0xaad38e0
  0xaad38e0: i64,ch = CopyFromReg 0xa9a26b8, Register:i64 %0
    0xaad3670: i64 = Register %0
In function: _Z20__libcpp_atomic_loadIlET_PKS0_i
clang-15: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 15.0.0 (https://github.com/llvm/llvm-project 5807e59a0ab4c6fbe372af68cc7980ed6ff9239c)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /p/project/cjinb33/kitayama1/dev/clang/bin
clang-15: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-15: note: diagnostic msg: /tmp/j1-68716b.cpp
clang-15: note: diagnostic msg: /tmp/j1-4fa245.cpp
clang-15: note: diagnostic msg: /tmp/j1-68716b.sh
clang-15: note: diagnostic msg:

********************

i’ll file a bug report.

@jdoerfert would you mind taking a loo at this as I still see this fatal error with today’s master? Thanks!

We will look as we get to it. I understand you want it to be fixed now but that is not what we can promise. We need more people to work on things and those people need to be appreciated for fixing bugs. Note that this is not an OpenMP bug per se. Feel free to rope in any NVPTX people to help.

Understood and I appreciate all those who have been working on OpenMP project.