This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP][JIT] Cleanup JIT interface, caching, and races
ClosedPublic

Authored by jdoerfert on Jan 5 2023, 12:12 PM.

Details

Summary

The JIT interface was somewhat irregular as it used multiple global
functions. It also did not cache the results of the JIT, hence multiple
GPU systems would perform the work multiple times. Finally, there might
have been races on the state if we have multi-threaded initialization of
different embedded images, or one image initialized on multiple devices.

This patch tries to rectify all of the above. The JITEngine is now a
part of the GenericPluginTy and tied to one target triple. To support
multiple "ComputeUnitKind"s (previously confusingly called Arch or
[M]CPU) and to avoid re-jitting for the same ComputeUnitKind, we keep a
map of JIT results per ComputeUnitKind. All interaction with the JIT
happens through the JITEngine directly, two functions are exposed. Both
use (shared) locks to avoid races and cache the result. All JIT-related
environment variables are now defined together.

Diff Detail

Event Timeline

jdoerfert created this revision.Jan 5 2023, 12:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2023, 12:12 PM
jdoerfert requested review of this revision.Jan 5 2023, 12:12 PM

Forgot the context, will update it later if necessary.

jdoerfert added inline comments.Jan 5 2023, 12:14 PM
openmp/libomptarget/plugins-nextgen/common/PluginInterface/JIT.h
98

I need to rename CPU to ComputeUnit here too.

When do we do multi-threading initialization?

jdoerfert updated this revision to Diff 486704.Jan 5 2023, 3:58 PM

Include context, fix some oversights.

When do we do multi-threading initialization?

TBH, I don't know. Even if not, it seems appropriate (given past errors) to design everything with multi-threading in mind, except if it is explicitly excluded. The cost for the 2 mutexes should be minimal.
I'm also not super certain we can't have two threads calling __tgt_rtl_load_binary on two devices concurrently.

tianshilei1992 accepted this revision.Jan 14 2023, 9:47 PM

LG, the name is really weird though.

This revision is now accepted and ready to land.Jan 14 2023, 9:47 PM
This revision was landed with ongoing or failed builds.Jan 15 2023, 11:44 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJan 15 2023, 11:44 AM