Changeset View
Changeset View
Standalone View
Standalone View
openmp/libomptarget/DeviceRTL/src/Kernel.cpp
Show All 24 Lines | static void inititializeRuntime(bool IsSPMD) { | ||||
// Order is important here. | // Order is important here. | ||||
synchronize::init(IsSPMD); | synchronize::init(IsSPMD); | ||||
mapping::init(IsSPMD); | mapping::init(IsSPMD); | ||||
state::init(IsSPMD); | state::init(IsSPMD); | ||||
} | } | ||||
/// Simple generic state machine for worker threads. | /// Simple generic state machine for worker threads. | ||||
static void genericStateMachine(IdentTy *Ident) { | static void genericStateMachine(IdentTy *Ident) { | ||||
FunctionTracingRAII(); | |||||
uint32_t TId = mapping::getThreadIdInBlock(); | uint32_t TId = mapping::getThreadIdInBlock(); | ||||
do { | do { | ||||
ParallelRegionFnTy WorkFn = 0; | ParallelRegionFnTy WorkFn = 0; | ||||
// Wait for the signal that we have a new work function. | // Wait for the signal that we have a new work function. | ||||
synchronize::threads(); | synchronize::threads(); | ||||
Show All 20 Lines | |||||
extern "C" { | extern "C" { | ||||
/// Initialization | /// Initialization | ||||
/// | /// | ||||
/// \param Ident Source location identification, can be NULL. | /// \param Ident Source location identification, can be NULL. | ||||
/// | /// | ||||
int32_t __kmpc_target_init(IdentTy *Ident, int8_t Mode, | int32_t __kmpc_target_init(IdentTy *Ident, int8_t Mode, | ||||
bool UseGenericStateMachine, bool) { | bool UseGenericStateMachine, bool) { | ||||
FunctionTracingRAII(); | |||||
const bool IsSPMD = Mode & OMP_TGT_EXEC_MODE_SPMD; | const bool IsSPMD = Mode & OMP_TGT_EXEC_MODE_SPMD; | ||||
if (IsSPMD) { | if (IsSPMD) { | ||||
inititializeRuntime(/* IsSPMD */ true); | inititializeRuntime(/* IsSPMD */ true); | ||||
synchronize::threads(); | synchronize::threads(); | ||||
} else { | } else { | ||||
inititializeRuntime(/* IsSPMD */ false); | inititializeRuntime(/* IsSPMD */ false); | ||||
// No need to wait since only the main threads will execute user | // No need to wait since only the main threads will execute user | ||||
// code and workers will run into a barrier right away. | // code and workers will run into a barrier right away. | ||||
Show All 16 Lines | |||||
/// De-Initialization | /// De-Initialization | ||||
/// | /// | ||||
/// In non-SPMD, this function releases the workers trapped in a state machine | /// In non-SPMD, this function releases the workers trapped in a state machine | ||||
/// and also any memory dynamically allocated by the runtime. | /// and also any memory dynamically allocated by the runtime. | ||||
/// | /// | ||||
/// \param Ident Source location identification, can be NULL. | /// \param Ident Source location identification, can be NULL. | ||||
/// | /// | ||||
void __kmpc_target_deinit(IdentTy *Ident, int8_t Mode, bool) { | void __kmpc_target_deinit(IdentTy *Ident, int8_t Mode, bool) { | ||||
FunctionTracingRAII(); | |||||
const bool IsSPMD = Mode & OMP_TGT_EXEC_MODE_SPMD; | const bool IsSPMD = Mode & OMP_TGT_EXEC_MODE_SPMD; | ||||
state::assumeInitialState(IsSPMD); | state::assumeInitialState(IsSPMD); | ||||
if (IsSPMD) | if (IsSPMD) | ||||
return; | return; | ||||
// Signal the workers to exit the state machine and exit the kernel. | // Signal the workers to exit the state machine and exit the kernel. | ||||
state::ParallelRegionFn = nullptr; | state::ParallelRegionFn = nullptr; | ||||
} | } | ||||
int8_t __kmpc_is_spmd_exec_mode() { return mapping::isSPMDMode(); } | int8_t __kmpc_is_spmd_exec_mode() { | ||||
FunctionTracingRAII(); | |||||
return mapping::isSPMDMode(); | |||||
} | |||||
} | } | ||||
#pragma omp end declare target | #pragma omp end declare target |