This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Eliminate the ThreadStates array in favor of indirection
ClosedPublic

Authored by jdoerfert on Oct 2 2022, 9:50 AM.

Details

Summary

If we have thread states, the program is going to be rather slow. If we
don't we want to avoid wasting shared memory. This patch introduces a
slight penalty (malloc + indirection) for the slow path and reduces
resource usage for the fast path.

Diff Detail

Event Timeline

jdoerfert created this revision.Oct 2 2022, 9:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 2 2022, 9:50 AM
jdoerfert requested review of this revision.Oct 2 2022, 9:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 2 2022, 9:50 AM
Herald added a subscriber: sstefan1. · View Herald Transcript
jdoerfert updated this revision to Diff 464562.Oct 2 2022, 9:54 AM

Use assumption more aggressively

tianshilei1992 added inline comments.Oct 3 2022, 9:16 AM
openmp/libomptarget/DeviceRTL/include/State.h
112

Does it work if we just have ThreadStateTy *ThreadStates?

openmp/libomptarget/DeviceRTL/src/State.cpp
270

Is it a valid state when it reaches to this point? If not, I think it'd better to have an assertion here.

jdoerfert added inline comments.Oct 3 2022, 12:18 PM
openmp/libomptarget/DeviceRTL/include/State.h
112

We could, yes. Requires to rewrite the code more :(

openmp/libomptarget/DeviceRTL/src/State.cpp
270

State is valid, yes. I guess we can assert load returns non zero.

jdoerfert updated this revision to Diff 464991.Oct 4 2022, 6:23 AM

Add assertion

openmp/libomptarget/DeviceRTL/include/State.h
112

Not without rewriting a lot. We use the pointer to build a list of nested thread states. Otherwise we would need to set it up to build the list and have the head in the outermost array, or traverse the list on a lookup, neither seems worth it now.

This revision is now accepted and ready to land.Oct 4 2022, 6:32 AM
jdoerfert updated this revision to Diff 465027.Oct 4 2022, 8:51 AM

Fix some issues