This is an archive of the discontinued LLVM Phabricator instance.

[HIP] Warn capture this pointer in device lambda
ClosedPublic

Authored by yaxunl on Aug 20 2021, 3:16 PM.

Details

Summary

HIP currently diagnose capture of this pointer in device lambda in
host member functions. If this pointer points to managed memory,
it can be used in both device and host functions. Under this
situation, capturing this pointer in device lambda functions
in host member functions is valid usage. Change the diagnostic
about capturing this pointer to warning.

Diff Detail

Event Timeline

yaxunl requested review of this revision.Aug 20 2021, 3:16 PM
yaxunl created this revision.
tra added inline comments.Aug 20 2021, 3:47 PM
clang/lib/Sema/SemaCUDA.cpp
881–882

I assume there's no easy way to tell if it's a managed pointer or not.
Capturing a non-managed pointer would still be bad.
Should we make it a warning instead?

yaxunl marked an inline comment as done.Sep 8 2021, 9:10 AM
yaxunl added inline comments.
clang/lib/Sema/SemaCUDA.cpp
881–882

warning makes sense. will do.

Also this should apply to CUDA too. Although clang does not support __managed__ keyword for CUDA, this pointer may be allocated in managed memory through host API's.

yaxunl updated this revision to Diff 371363.Sep 8 2021, 9:13 AM
yaxunl marked an inline comment as done.
yaxunl retitled this revision from [HIP] Allow capture this pointer in device lambda to [HIP] Warn capture this pointer in device lambda.
yaxunl edited the summary of this revision. (Show Details)
tra added inline comments.Sep 8 2021, 9:30 AM
clang/lib/Sema/SemaCUDA.cpp
881–882

Also this should apply to CUDA too.

I'm not sure I understand what you mean.

Do you suggest that the warning should be issued for both HIP and CUDA? If so, the diag already applies to CUDA.

Or that we should allow capturing wrong-side this w/o diagnostics for both CUDA and HIP?

I'm fine with the former. But I do not think we should silently allow capturing wrong-side this for CUDA, because it will be an error most of the time.

tra accepted this revision.Sep 8 2021, 9:31 AM
tra added inline comments.
clang/lib/Sema/SemaCUDA.cpp
881–882

Ah. Never mind. I've replied before your latest patch update.
LGTM

This revision is now accepted and ready to land.Sep 8 2021, 9:31 AM
This revision was landed with ongoing or failed builds.Sep 8 2021, 10:45 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 8 2021, 10:45 AM