-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Libomptarget] Remove global ctor and use reference counting (#80499)
Summary: Currently we rely on global constructors to initialize and shut down the OpenMP runtime library and plugin manager. This causes some issues because we do not have a defined lifetime that we can rely on to release and allocate resources. This patch instead adds some simple reference counted initialization and deinitialization function. A future patch will use the `deinit` interface to more intelligently handle plugin deinitilization. Right now we do nothing and rely on `atexit` inside of the plugins to tear them down. This isn't great because it limits our ability to control these things. Note that I made the `__tgt_register_lib` functions do the initialization instead of adding calls to the new runtime functions in the linker wrapper. The reason for this is because in the past it's been easier to not introduce a new function call, since sometimes the user's compiler will link against an older `libomptarget`. Maybe if we change the name with offloading in the future we can simplify this. Depends on #80460
- Loading branch information
Showing
7 changed files
with
89 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// RUN: %libomptarget-compile-generic | ||
// RUN: env LIBOMPTARGET_DEBUG=1 %libomptarget-run-generic 2>&1 \ | ||
// RUN: %fcheck-generic | ||
|
||
// REQUIRES: libomptarget-debug | ||
|
||
#include <omp.h> | ||
#include <stdio.h> | ||
|
||
extern void __tgt_rtl_init(void); | ||
extern void __tgt_rtl_deinit(void); | ||
|
||
// Sanity checks to make sure that this works and is thread safe. | ||
int main() { | ||
// CHECK: Init offload library! | ||
// CHECK: Deinit offload library! | ||
__tgt_rtl_init(); | ||
#pragma omp parallel num_threads(8) | ||
{ | ||
__tgt_rtl_init(); | ||
__tgt_rtl_deinit(); | ||
} | ||
__tgt_rtl_deinit(); | ||
|
||
__tgt_rtl_init(); | ||
__tgt_rtl_deinit(); | ||
|
||
// CHECK: PASS | ||
printf("PASS\n"); | ||
} |