Changeset View
Changeset View
Standalone View
Standalone View
openmp/libomptarget/DeviceRTL/src/Parallelism.cpp
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | else | ||||
NumThreads = (NumThreads & ~((uint32_t)mapping::getWarpSize() - 1)); | NumThreads = (NumThreads & ~((uint32_t)mapping::getWarpSize() - 1)); | ||||
return NumThreads; | return NumThreads; | ||||
} | } | ||||
// Invoke an outlined parallel function unwrapping arguments (up to 32). | // Invoke an outlined parallel function unwrapping arguments (up to 32). | ||||
void invokeMicrotask(int32_t global_tid, int32_t bound_tid, void *fn, | void invokeMicrotask(int32_t global_tid, int32_t bound_tid, void *fn, | ||||
void **args, int64_t nargs) { | void **args, int64_t nargs) { | ||||
DebugEntryRAII Entry(__FILE__, __LINE__, "<OpenMP Outlined Function>"); | |||||
switch (nargs) { | switch (nargs) { | ||||
#include "generated_microtask_cases.gen" | #include "generated_microtask_cases.gen" | ||||
default: | default: | ||||
PRINT("Too many arguments in kmp_invoke_microtask, aborting execution.\n"); | PRINT("Too many arguments in kmp_invoke_microtask, aborting execution.\n"); | ||||
__builtin_trap(); | __builtin_trap(); | ||||
} | } | ||||
} | } | ||||
} // namespace | } // namespace | ||||
extern "C" { | extern "C" { | ||||
void __kmpc_parallel_51(IdentTy *ident, int32_t, int32_t if_expr, | void __kmpc_parallel_51(IdentTy *ident, int32_t, int32_t if_expr, | ||||
int32_t num_threads, int proc_bind, void *fn, | int32_t num_threads, int proc_bind, void *fn, | ||||
void *wrapper_fn, void **args, int64_t nargs) { | void *wrapper_fn, void **args, int64_t nargs) { | ||||
FunctionTracingRAII(); | |||||
uint32_t TId = mapping::getThreadIdInBlock(); | uint32_t TId = mapping::getThreadIdInBlock(); | ||||
// Handle the serialized case first, same for SPMD/non-SPMD. | // Handle the serialized case first, same for SPMD/non-SPMD. | ||||
if (OMP_UNLIKELY(!if_expr || icv::Level)) { | if (OMP_UNLIKELY(!if_expr || icv::Level)) { | ||||
__kmpc_serialized_parallel(ident, TId); | __kmpc_serialized_parallel(ident, TId); | ||||
invokeMicrotask(TId, 0, fn, args, nargs); | invokeMicrotask(TId, 0, fn, args, nargs); | ||||
__kmpc_end_serialized_parallel(ident, TId); | __kmpc_end_serialized_parallel(ident, TId); | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | #pragma unroll | ||||
} | } | ||||
if (nargs) | if (nargs) | ||||
__kmpc_end_sharing_variables(); | __kmpc_end_sharing_variables(); | ||||
} | } | ||||
__attribute__((noinline)) bool | __attribute__((noinline)) bool | ||||
__kmpc_kernel_parallel(ParallelRegionFnTy *WorkFn) { | __kmpc_kernel_parallel(ParallelRegionFnTy *WorkFn) { | ||||
FunctionTracingRAII(); | |||||
// Work function and arguments for L1 parallel region. | // Work function and arguments for L1 parallel region. | ||||
*WorkFn = state::ParallelRegionFn; | *WorkFn = state::ParallelRegionFn; | ||||
// If this is the termination signal from the master, quit early. | // If this is the termination signal from the master, quit early. | ||||
if (!*WorkFn) | if (!*WorkFn) | ||||
return false; | return false; | ||||
// Set to true for workers participating in the parallel region. | // Set to true for workers participating in the parallel region. | ||||
uint32_t TId = mapping::getThreadIdInBlock(); | uint32_t TId = mapping::getThreadIdInBlock(); | ||||
bool ThreadIsActive = TId < state::ParallelTeamSize; | bool ThreadIsActive = TId < state::ParallelTeamSize; | ||||
return ThreadIsActive; | return ThreadIsActive; | ||||
} | } | ||||
__attribute__((noinline)) void __kmpc_kernel_end_parallel() { | __attribute__((noinline)) void __kmpc_kernel_end_parallel() { | ||||
FunctionTracingRAII(); | |||||
// In case we have modified an ICV for this thread before a ThreadState was | // In case we have modified an ICV for this thread before a ThreadState was | ||||
// created. We drop it now to not contaminate the next parallel region. | // created. We drop it now to not contaminate the next parallel region. | ||||
ASSERT(!mapping::isSPMDMode()); | ASSERT(!mapping::isSPMDMode()); | ||||
uint32_t TId = mapping::getThreadIdInBlock(); | uint32_t TId = mapping::getThreadIdInBlock(); | ||||
state::resetStateForThread(TId); | state::resetStateForThread(TId); | ||||
ASSERT(!mapping::isSPMDMode()); | ASSERT(!mapping::isSPMDMode()); | ||||
} | } | ||||
void __kmpc_serialized_parallel(IdentTy *, uint32_t TId) { | void __kmpc_serialized_parallel(IdentTy *, uint32_t TId) { | ||||
FunctionTracingRAII(); | |||||
state::enterDataEnvironment(); | state::enterDataEnvironment(); | ||||
++icv::Level; | ++icv::Level; | ||||
} | } | ||||
void __kmpc_end_serialized_parallel(IdentTy *, uint32_t TId) { | void __kmpc_end_serialized_parallel(IdentTy *, uint32_t TId) { | ||||
FunctionTracingRAII(); | |||||
state::exitDataEnvironment(); | state::exitDataEnvironment(); | ||||
--icv::Level; | --icv::Level; | ||||
} | } | ||||
uint16_t __kmpc_parallel_level(IdentTy *, uint32_t) { return omp_get_level(); } | uint16_t __kmpc_parallel_level(IdentTy *, uint32_t) { | ||||
FunctionTracingRAII(); | |||||
return omp_get_level(); | |||||
} | |||||
int32_t __kmpc_global_thread_num(IdentTy *) { return omp_get_thread_num(); } | int32_t __kmpc_global_thread_num(IdentTy *) { | ||||
FunctionTracingRAII(); | |||||
return omp_get_thread_num(); | |||||
} | |||||
void __kmpc_push_num_threads(IdentTy *, int32_t, int32_t NumThreads) { | void __kmpc_push_num_threads(IdentTy *, int32_t, int32_t NumThreads) { | ||||
FunctionTracingRAII(); | |||||
icv::NThreads = NumThreads; | icv::NThreads = NumThreads; | ||||
} | } | ||||
void __kmpc_push_num_teams(IdentTy *loc, int32_t tid, int32_t num_teams, | void __kmpc_push_num_teams(IdentTy *loc, int32_t tid, int32_t num_teams, | ||||
int32_t thread_limit) {} | int32_t thread_limit) { | ||||
FunctionTracingRAII(); | |||||
} | |||||
void __kmpc_push_proc_bind(IdentTy *loc, uint32_t tid, int proc_bind) {} | void __kmpc_push_proc_bind(IdentTy *loc, uint32_t tid, int proc_bind) { | ||||
FunctionTracingRAII(); | |||||
} | |||||
} | } | ||||
#pragma omp end declare target | #pragma omp end declare target |