166 lines · c
1//===-- OpenMP/InternalTypes.h -- Internal OpenMP Types ------------- C++ -===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9// Private type declarations and helper macros for OpenMP.10//11//===----------------------------------------------------------------------===//12 13#ifndef OMPTARGET_OPENMP_INTERNAL_TYPES_H14#define OMPTARGET_OPENMP_INTERNAL_TYPES_H15 16#include <cstddef>17#include <cstdint>18 19extern "C" {20 21// Compiler sends us this info:22typedef struct kmp_depend_info {23 intptr_t base_addr;24 size_t len;25 struct {26 bool in : 1;27 bool out : 1;28 bool mtx : 1;29 } flags;30} kmp_depend_info_t;31 32typedef struct kmp_tasking_flags { /* Total struct must be exactly 32 bits */33 /* Compiler flags */ /* Total compiler flags must be 16 bits */34 unsigned tiedness : 1; /* task is either tied (1) or untied (0) */35 unsigned final : 1; /* task is final(1) so execute immediately */36 unsigned merged_if0 : 1; /* no __kmpc_task_{begin/complete}_if0 calls in if037 code path */38 unsigned destructors_thunk : 1; /* set if the compiler creates a thunk to39 invoke destructors from the runtime */40 unsigned proxy : 1; /* task is a proxy task (it will be executed outside the41 context of the RTL) */42 unsigned priority_specified : 1; /* set if the compiler provides priority43 setting for the task */44 unsigned detachable : 1; /* 1 == can detach */45 unsigned hidden_helper : 1; /* 1 == hidden helper task */46 unsigned reserved : 8; /* reserved for compiler use */47 48 /* Library flags */ /* Total library flags must be 16 bits */49 unsigned tasktype : 1; /* task is either explicit(1) or implicit (0) */50 unsigned task_serial : 1; // task is executed immediately (1) or deferred (0)51 unsigned tasking_ser : 1; // all tasks in team are either executed immediately52 // (1) or may be deferred (0)53 unsigned team_serial : 1; // entire team is serial (1) [1 thread] or parallel54 // (0) [>= 2 threads]55 /* If either team_serial or tasking_ser is set, task team may be NULL */56 /* Task State Flags: */57 unsigned started : 1; /* 1==started, 0==not started */58 unsigned executing : 1; /* 1==executing, 0==not executing */59 unsigned complete : 1; /* 1==complete, 0==not complete */60 unsigned freed : 1; /* 1==freed, 0==allocated */61 unsigned native : 1; /* 1==gcc-compiled task, 0==intel */62 unsigned reserved31 : 7; /* reserved for library use */63} kmp_tasking_flags_t;64 65struct kmp_task;66typedef int32_t (*kmp_routine_entry_t)(int32_t, struct kmp_task *);67typedef struct kmp_task {68 void *shareds;69 kmp_routine_entry_t routine;70 int32_t part_id;71} kmp_task_t;72 73// Implemented in libomp, they are called from within __tgt_* functions.74int32_t __kmpc_global_thread_num(void *);75bool __kmpc_omp_has_task_team(int32_t gtid);76void **__kmpc_omp_get_target_async_handle_ptr(int32_t gtid);77int __kmpc_get_target_offload(void);78kmp_task_t *79__kmpc_omp_target_task_alloc(ident_t *loc_ref, int32_t gtid, int32_t flags,80 size_t sizeof_kmp_task_t, size_t sizeof_shareds,81 kmp_routine_entry_t task_entry, int64_t device_id);82int32_t __kmpc_omp_task_with_deps(ident_t *loc_ref, int32_t gtid,83 kmp_task_t *new_task, int32_t ndeps,84 kmp_depend_info_t *dep_list,85 int32_t ndeps_noalias,86 kmp_depend_info_t *noalias_dep_list);87void __kmpc_omp_wait_deps(ident_t *loc_ref, int32_t gtid, int32_t ndeps,88 kmp_depend_info_t *dep_list, int32_t ndeps_noalias,89 kmp_depend_info_t *noalias_dep_list);90 91/**92 * The argument set that is passed from asynchronous memory copy to block93 * version of memory copy invoked in helper task94 */95struct TargetMemcpyArgsTy {96 /**97 * Common attribuutes98 */99 void *Dst;100 const void *Src;101 int DstDevice;102 int SrcDevice;103 104 /**105 * The flag that denotes single dimensional or rectangle dimensional copy106 */107 bool IsRectMemcpy;108 109 /**110 * Arguments for single dimensional copy111 */112 size_t Length;113 size_t DstOffset;114 size_t SrcOffset;115 116 /**117 * Arguments for rectangle dimensional copy118 */119 size_t ElementSize;120 int NumDims;121 const size_t *Volume;122 const size_t *DstOffsets;123 const size_t *SrcOffsets;124 const size_t *DstDimensions;125 const size_t *SrcDimensions;126 127 /**128 * Constructor for single dimensional copy129 */130 TargetMemcpyArgsTy(void *Dst, const void *Src, size_t Length,131 size_t DstOffset, size_t SrcOffset, int DstDevice,132 int SrcDevice)133 : Dst(Dst), Src(Src), DstDevice(DstDevice), SrcDevice(SrcDevice),134 IsRectMemcpy(false), Length(Length), DstOffset(DstOffset),135 SrcOffset(SrcOffset), ElementSize(0), NumDims(0), Volume(0),136 DstOffsets(0), SrcOffsets(0), DstDimensions(0), SrcDimensions(0){};137 138 /**139 * Constructor for rectangle dimensional copy140 */141 TargetMemcpyArgsTy(void *Dst, const void *Src, size_t ElementSize,142 int NumDims, const size_t *Volume,143 const size_t *DstOffsets, const size_t *SrcOffsets,144 const size_t *DstDimensions, const size_t *SrcDimensions,145 int DstDevice, int SrcDevice)146 : Dst(Dst), Src(Src), DstDevice(DstDevice), SrcDevice(SrcDevice),147 IsRectMemcpy(true), Length(0), DstOffset(0), SrcOffset(0),148 ElementSize(ElementSize), NumDims(NumDims), Volume(Volume),149 DstOffsets(DstOffsets), SrcOffsets(SrcOffsets),150 DstDimensions(DstDimensions), SrcDimensions(SrcDimensions){};151};152 153struct TargetMemsetArgsTy {154 // Common attributes of a memset operation155 void *Ptr;156 int C;157 size_t N;158 int DeviceNum;159 160 // no constructors defined, because this is a PoD161};162 163} // extern "C"164 165#endif // OMPTARGET_OPENMP_INTERNAL_TYPES_H166