This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Make sure classes work on the device as they do on the host
ClosedPublic

Authored by jdoerfert on Apr 15 2021, 10:37 PM.

Details

Summary

We do provide operator delete(void*) in <new> but it should be
available by default. This is mostly boilerplate to test it and the
unconditional include of <new> in the header we always in include
on the device.

Diff Detail

Event Timeline

jdoerfert created this revision.Apr 15 2021, 10:37 PM
jdoerfert requested review of this revision.Apr 15 2021, 10:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2021, 10:37 PM
clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
20

I think there are legitimate use cases for writing code that doesn't include new. Can we add the forms that are meant to be available without the include here, instead of just pulling in all new?

clang/test/Headers/Inputs/include/cstdlib
5

These are in stdlib just above, no? Possibly with noexcept tags

jdoerfert added inline comments.Apr 16 2021, 3:30 PM
clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
20

Hm, what forms would you not like to see in the code by default, and why?

clang/test/Headers/Inputs/include/cstdlib
5

They are not, this is the sham layer for testing, but you are so far correct that they should be. I'll move them.

clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
20

I would prefer the default includes exactly the expressions/syntax that C++ provides by default, which may mean writing some inline here though I'm perplexed that we need to do something different to clang compiling c++. I'd have to look up which operators are magic and which are in the header.

At least some reluctance is that we don't have a gpu <new>, so this will be whatever host libstdc++/libc++ is in use, and I'd like to avoid including gpu-unaware code on the gpu wherever possible.

jdoerfert updated this revision to Diff 342433.May 3 2021, 9:52 AM
jdoerfert marked an inline comment as done.

Avoid including <new> by not wrapping <new>

JonChesterfield accepted this revision.May 3 2021, 9:59 AM

cstdlib may not exist, probably in the same situations as new not existing, but that can probably be left until the problem arises. I think this looks reasonable, and it'll unblock some applications that don't presently build.

clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
80

free(nullptr) is well formed, don't think we need the branch here

This revision is now accepted and ready to land.May 3 2021, 9:59 AM

We might want a test that includes <new> along with this header, to check they don't conflict with one another

We might want a test that includes <new> along with this header, to check they don't conflict with one another

For that I need to replicate the potentially conflicting <new> stuff in the test header mockups. I'll try it later on one system though.

For that I need to replicate the potentially conflicting <new> stuff in the test header mockups. I'll try it later on one system though.

Yep, may not be able to check in something that pulls <new> out of the host system.

It seems inconvenient that clang doesn't automatically inject the new/delete forms that are intended to be available without including new.

jdoerfert updated this revision to Diff 343279.May 5 2021, 9:32 PM
jdoerfert marked an inline comment as done.

Split the new/delete operators based on std::nothrow_t and provide the ones
that do not use this type by default, the others as part of <new>.

This revision was landed with ongoing or failed builds.May 6 2021, 12:10 AM
This revision was automatically updated to reflect the committed changes.