diff --git a/openmp/libomptarget/include/omptarget.h b/openmp/libomptarget/include/omptarget.h --- a/openmp/libomptarget/include/omptarget.h +++ b/openmp/libomptarget/include/omptarget.h @@ -118,7 +118,8 @@ int64_t *ArgSizes; // Size of the argument data in bytes. int64_t *ArgTypes; // Type of the data (e.g. to / from). void **ArgNames; // Name of the data for debugging, possibly null. - void **ArgMappers; // User-defined mappers, possible null. + void **ArgMappers; // User-defined mappers, possibly null. + int64_t Tripcount; // Tripcount for the teams / distribute loop, 0 otherwise. }; /// This struct is a record of an entry point or global. For a function diff --git a/openmp/libomptarget/src/interface.cpp b/openmp/libomptarget/src/interface.cpp --- a/openmp/libomptarget/src/interface.cpp +++ b/openmp/libomptarget/src/interface.cpp @@ -377,11 +377,19 @@ if (!IsTeams) NumTeams = 0; + if (Args->Tripcount != 0) { + PM->TblMapMtx.lock(); + PM->Devices[DeviceId]->LoopTripCnt.emplace(__kmpc_global_thread_num(Loc), + Args->Tripcount); + PM->TblMapMtx.unlock(); + } + DeviceTy &Device = *PM->Devices[DeviceId]; AsyncInfoTy AsyncInfo(Device); int Rc = target(Loc, Device, HostPtr, Args->NumArgs, Args->ArgBasePtrs, Args->ArgPtrs, Args->ArgSizes, Args->ArgTypes, Args->ArgNames, - Args->ArgMappers, NumTeams, ThreadLimit, IsTeams, AsyncInfo); + Args->ArgMappers, NumTeams, ThreadLimit, Args->Tripcount, + IsTeams, AsyncInfo); if (Rc == OFFLOAD_SUCCESS) Rc = AsyncInfo.synchronize(); handleTargetOutcome(Rc == OFFLOAD_SUCCESS, Loc); diff --git a/openmp/libomptarget/src/omptarget.cpp b/openmp/libomptarget/src/omptarget.cpp --- a/openmp/libomptarget/src/omptarget.cpp +++ b/openmp/libomptarget/src/omptarget.cpp @@ -190,9 +190,9 @@ DP("Has pending ctors... call now\n"); for (auto &Entry : Lib.second.PendingCtors) { void *Ctor = Entry; - int Rc = - target(nullptr, Device, Ctor, 0, nullptr, nullptr, nullptr, - nullptr, nullptr, nullptr, 1, 1, true /*team*/, AsyncInfo); + int Rc = target(nullptr, Device, Ctor, 0, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, 1, 1, 0, true /*team*/, + AsyncInfo); if (Rc != OFFLOAD_SUCCESS) { REPORT("Running ctor " DPxMOD " failed.\n", DPxPTR(Ctor)); return OFFLOAD_FAIL; @@ -1488,7 +1488,8 @@ int target(ident_t *Loc, DeviceTy &Device, void *HostPtr, int32_t ArgNum, void **ArgBases, void **Args, int64_t *ArgSizes, int64_t *ArgTypes, map_var_info_t *ArgNames, void **ArgMappers, int32_t TeamNum, - int32_t ThreadLimit, int IsTeamConstruct, AsyncInfoTy &AsyncInfo) { + int32_t ThreadLimit, uint64_t Tripcount, int IsTeamConstruct, + AsyncInfoTy &AsyncInfo) { int32_t DeviceId = Device.DeviceID; TableMap *TM = getTableMap(HostPtr); @@ -1509,6 +1510,12 @@ } assert(TargetTable && "Global data has not been mapped\n"); + // Set tripcount. + { + std::lock_guard TblMapMtx(PM->TrlTblMtx); + Device.LoopTripCnt.emplace(__kmpc_global_thread_num(Loc), Tripcount); + } + // We need to keep bases and offsets separate. Sometimes (e.g. in OpenCL) we // need to manifest base pointers prior to launching a kernel. Even if we have // mapped an object only partially, e.g. A[N:M], although the kernel is diff --git a/openmp/libomptarget/src/private.h b/openmp/libomptarget/src/private.h --- a/openmp/libomptarget/src/private.h +++ b/openmp/libomptarget/src/private.h @@ -42,7 +42,8 @@ void **ArgBases, void **Args, int64_t *ArgSizes, int64_t *ArgTypes, map_var_info_t *ArgNames, void **ArgMappers, int32_t TeamNum, int32_t ThreadLimit, - int IsTeamConstruct, AsyncInfoTy &AsyncInfo); + uint64_t Tripcount, int IsTeamConstruct, + AsyncInfoTy &AsyncInfo); extern void handleTargetOutcome(bool Success, ident_t *Loc); extern bool checkDeviceAndCtors(int64_t &DeviceID, ident_t *Loc); diff --git a/openmp/libomptarget/src/rtl.cpp b/openmp/libomptarget/src/rtl.cpp --- a/openmp/libomptarget/src/rtl.cpp +++ b/openmp/libomptarget/src/rtl.cpp @@ -444,7 +444,7 @@ AsyncInfoTy AsyncInfo(Device); for (auto &Dtor : Device.PendingCtorsDtors[Desc].PendingDtors) { int Rc = target(nullptr, Device, Dtor, 0, nullptr, nullptr, nullptr, - nullptr, nullptr, nullptr, 1, 1, true /*team*/, + nullptr, nullptr, nullptr, 1, 1, 0, true /*team*/, AsyncInfo); if (Rc != OFFLOAD_SUCCESS) { DP("Running destructor " DPxMOD " failed.\n", DPxPTR(Dtor));