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 @@ -324,45 +324,6 @@ // same action as data_end above. The following types are used; this // function returns 0 if it was able to transfer the execution to a // target and an int different from zero otherwise. -int __tgt_target(int64_t DeviceId, void *HostPtr, int32_t ArgNum, - void **ArgsBase, void **Args, int64_t *ArgSizes, - int64_t *ArgTypes); -int __tgt_target_nowait(int64_t DeviceId, void *HostPtr, int32_t ArgNum, - void **ArgsBase, void **Args, int64_t *ArgSizes, - int64_t *ArgTypes, int32_t DepNum, void *DepList, - int32_t NoAliasDepNum, void *NoAliasDepList); -int __tgt_target_mapper(ident_t *Loc, int64_t DeviceId, void *HostPtr, - int32_t ArgNum, void **ArgsBase, void **Args, - int64_t *ArgSizes, int64_t *ArgTypes, - map_var_info_t *ArgNames, void **ArgMappers); -int __tgt_target_nowait_mapper(ident_t *Loc, int64_t DeviceId, void *HostPtr, - int32_t ArgNum, void **ArgsBase, void **Args, - int64_t *ArgSizes, int64_t *ArgTypes, - map_var_info_t *ArgNames, void **ArgMappers, - int32_t DepNum, void *DepList, - int32_t NoAliasDepNum, void *NoAliasDepList); - -int __tgt_target_teams(int64_t DeviceId, void *HostPtr, int32_t ArgNum, - void **ArgsBase, void **Args, int64_t *ArgSizes, - int64_t *ArgTypes, int32_t NumTeams, - int32_t ThreadLimit); -int __tgt_target_teams_nowait(int64_t DeviceId, void *HostPtr, int32_t ArgNum, - void **ArgsBase, void **Args, int64_t *ArgSizes, - int64_t *ArgTypes, int32_t NumTeams, - int32_t ThreadLimit, int32_t DepNum, - void *DepList, int32_t NoAliasDepNum, - void *NoAliasDepList); -int __tgt_target_teams_mapper(ident_t *Loc, int64_t DeviceId, void *HostPtr, - int32_t ArgNum, void **ArgsBase, void **Args, - int64_t *ArgSizes, int64_t *ArgTypes, - map_var_info_t *ArgNames, void **ArgMappers, - int32_t NumTeams, int32_t ThreadLimit); -int __tgt_target_teams_nowait_mapper( - ident_t *loc, int64_t device_id, void *host_ptr, int32_t arg_num, - void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types, - map_var_info_t *arg_names, void **arg_mappers, int32_t num_teams, - int32_t thread_limit, int32_t depNum, void *depList, int32_t noAliasDepNum, - void *noAliasDepList); int __tgt_target_kernel(ident_t *Loc, int64_t DeviceId, int32_t NumTeams, int32_t ThreadLimit, void *HostPtr, __tgt_kernel_arguments *Args); @@ -372,11 +333,6 @@ void *DepList, int32_t NoAliasDepNum, void *NoAliasDepList); -void __kmpc_push_target_tripcount(int64_t DeviceId, uint64_t LoopTripcount); - -void __kmpc_push_target_tripcount_mapper(ident_t *Loc, int64_t DeviceId, - uint64_t LoopTripcount); - void __tgt_set_info_flag(uint32_t); int __tgt_print_device_info(int64_t DeviceId); diff --git a/openmp/libomptarget/src/CMakeLists.txt b/openmp/libomptarget/src/CMakeLists.txt --- a/openmp/libomptarget/src/CMakeLists.txt +++ b/openmp/libomptarget/src/CMakeLists.txt @@ -19,6 +19,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/interop.cpp ${CMAKE_CURRENT_SOURCE_DIR}/omptarget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rtl.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/LegacyAPI.cpp ) set(LIBOMPTARGET_SRC_FILES ${LIBOMPTARGET_SRC_FILES} PARENT_SCOPE) diff --git a/openmp/libomptarget/src/LegacyAPI.cpp b/openmp/libomptarget/src/LegacyAPI.cpp new file mode 100644 --- /dev/null +++ b/openmp/libomptarget/src/LegacyAPI.cpp @@ -0,0 +1,184 @@ +//===-------- LegacyAPI.cpp - Target independent OpenMP target RTL --------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Legacy interfaces for libomptarget used to maintain backwards-compatibility. +// +//===----------------------------------------------------------------------===// + +#include "omptarget.h" +#include "private.h" + +EXTERN void __tgt_target_data_begin(int64_t DeviceId, int32_t ArgNum, + void **ArgsBase, void **Args, + int64_t *ArgSizes, int64_t *ArgTypes) { + TIMESCOPE(); + __tgt_target_data_begin_mapper(nullptr, DeviceId, ArgNum, ArgsBase, Args, + ArgSizes, ArgTypes, nullptr, nullptr); +} + +EXTERN void __tgt_target_data_begin_nowait(int64_t DeviceId, int32_t ArgNum, + void **ArgsBase, void **Args, + int64_t *ArgSizes, int64_t *ArgTypes, + int32_t DepNum, void *DepList, + int32_t NoAliasDepNum, + void *NoAliasDepList) { + TIMESCOPE(); + + __tgt_target_data_begin_mapper(nullptr, DeviceId, ArgNum, ArgsBase, Args, + ArgSizes, ArgTypes, nullptr, nullptr); +} + +EXTERN void __tgt_target_data_end(int64_t DeviceId, int32_t ArgNum, + void **ArgsBase, void **Args, + int64_t *ArgSizes, int64_t *ArgTypes) { + TIMESCOPE(); + __tgt_target_data_end_mapper(nullptr, DeviceId, ArgNum, ArgsBase, Args, + ArgSizes, ArgTypes, nullptr, nullptr); +} + +EXTERN void __tgt_target_data_update(int64_t DeviceId, int32_t ArgNum, + void **ArgsBase, void **Args, + int64_t *ArgSizes, int64_t *ArgTypes) { + TIMESCOPE(); + __tgt_target_data_update_mapper(nullptr, DeviceId, ArgNum, ArgsBase, Args, + ArgSizes, ArgTypes, nullptr, nullptr); +} + +EXTERN void __tgt_target_data_update_nowait( + int64_t DeviceId, int32_t ArgNum, void **ArgsBase, void **Args, + int64_t *ArgSizes, int64_t *ArgTypes, int32_t DepNum, void *DepList, + int32_t NoAliasDepNum, void *NoAliasDepList) { + TIMESCOPE(); + + __tgt_target_data_update_mapper(nullptr, DeviceId, ArgNum, ArgsBase, Args, + ArgSizes, ArgTypes, nullptr, nullptr); +} + +EXTERN void __tgt_target_data_end_nowait(int64_t DeviceId, int32_t ArgNum, + void **ArgsBase, void **Args, + int64_t *ArgSizes, int64_t *ArgTypes, + int32_t DepNum, void *DepList, + int32_t NoAliasDepNum, + void *NoAliasDepList) { + TIMESCOPE(); + + __tgt_target_data_end_mapper(nullptr, DeviceId, ArgNum, ArgsBase, Args, + ArgSizes, ArgTypes, nullptr, nullptr); +} + +EXTERN int __tgt_target_mapper(ident_t *Loc, int64_t DeviceId, void *HostPtr, + int32_t ArgNum, void **ArgsBase, void **Args, + int64_t *ArgSizes, int64_t *ArgTypes, + map_var_info_t *ArgNames, void **ArgMappers) { + TIMESCOPE_WITH_IDENT(Loc); + __tgt_kernel_arguments KernelArgs{ + 1, ArgNum, ArgsBase, Args, ArgSizes, ArgTypes, ArgNames, ArgMappers, -1}; + return __tgt_target_kernel(Loc, DeviceId, -1, -1, HostPtr, &KernelArgs); +} + +EXTERN int __tgt_target(int64_t DeviceId, void *HostPtr, int32_t ArgNum, + void **ArgsBase, void **Args, int64_t *ArgSizes, + int64_t *ArgTypes) { + TIMESCOPE(); + return __tgt_target_mapper(nullptr, DeviceId, HostPtr, ArgNum, ArgsBase, Args, + ArgSizes, ArgTypes, nullptr, nullptr); +} + +EXTERN int __tgt_target_nowait(int64_t DeviceId, void *HostPtr, int32_t ArgNum, + void **ArgsBase, void **Args, int64_t *ArgSizes, + int64_t *ArgTypes, int32_t DepNum, void *DepList, + int32_t NoAliasDepNum, void *NoAliasDepList) { + TIMESCOPE(); + + return __tgt_target_mapper(nullptr, DeviceId, HostPtr, ArgNum, ArgsBase, Args, + ArgSizes, ArgTypes, nullptr, nullptr); +} + +EXTERN int __tgt_target_nowait_mapper( + ident_t *Loc, int64_t DeviceId, void *HostPtr, int32_t ArgNum, + void **ArgsBase, void **Args, int64_t *ArgSizes, int64_t *ArgTypes, + map_var_info_t *ArgNames, void **ArgMappers, int32_t DepNum, void *DepList, + int32_t NoAliasDepNum, void *NoAliasDepList) { + TIMESCOPE_WITH_IDENT(Loc); + + return __tgt_target_mapper(Loc, DeviceId, HostPtr, ArgNum, ArgsBase, Args, + ArgSizes, ArgTypes, ArgNames, ArgMappers); +} + +EXTERN int __tgt_target_teams_mapper(ident_t *Loc, int64_t DeviceId, + void *HostPtr, int32_t ArgNum, + void **ArgsBase, void **Args, + int64_t *ArgSizes, int64_t *ArgTypes, + map_var_info_t *ArgNames, + void **ArgMappers, int32_t NumTeams, + int32_t ThreadLimit) { + TIMESCOPE_WITH_IDENT(Loc); + + __tgt_kernel_arguments KernelArgs{ + 1, ArgNum, ArgsBase, Args, ArgSizes, ArgTypes, ArgNames, ArgMappers, -1}; + return __tgt_target_kernel(Loc, DeviceId, NumTeams, ThreadLimit, HostPtr, + &KernelArgs); +} + +EXTERN int __tgt_target_teams(int64_t DeviceId, void *HostPtr, int32_t ArgNum, + void **ArgsBase, void **Args, int64_t *ArgSizes, + int64_t *ArgTypes, int32_t NumTeams, + int32_t ThreadLimit) { + TIMESCOPE(); + return __tgt_target_teams_mapper(nullptr, DeviceId, HostPtr, ArgNum, ArgsBase, + Args, ArgSizes, ArgTypes, nullptr, nullptr, + NumTeams, ThreadLimit); +} + +EXTERN int __tgt_target_teams_nowait(int64_t DeviceId, void *HostPtr, + int32_t ArgNum, void **ArgsBase, + void **Args, int64_t *ArgSizes, + int64_t *ArgTypes, int32_t NumTeams, + int32_t ThreadLimit, int32_t DepNum, + void *DepList, int32_t NoAliasDepNum, + void *NoAliasDepList) { + TIMESCOPE(); + + return __tgt_target_teams_mapper(nullptr, DeviceId, HostPtr, ArgNum, ArgsBase, + Args, ArgSizes, ArgTypes, nullptr, nullptr, + NumTeams, ThreadLimit); +} + +EXTERN int __tgt_target_teams_nowait_mapper( + ident_t *Loc, int64_t DeviceId, void *HostPtr, int32_t ArgNum, + void **ArgsBase, void **Args, int64_t *ArgSizes, int64_t *ArgTypes, + map_var_info_t *ArgNames, void **ArgMappers, int32_t NumTeams, + int32_t ThreadLimit, int32_t DepNum, void *DepList, int32_t NoAliasDepNum, + void *NoAliasDepList) { + TIMESCOPE_WITH_IDENT(Loc); + + return __tgt_target_teams_mapper(Loc, DeviceId, HostPtr, ArgNum, ArgsBase, + Args, ArgSizes, ArgTypes, ArgNames, + ArgMappers, NumTeams, ThreadLimit); +} + +EXTERN void __kmpc_push_target_tripcount_mapper(ident_t *Loc, int64_t DeviceId, + uint64_t LoopTripcount) { + TIMESCOPE_WITH_IDENT(Loc); + if (checkDeviceAndCtors(DeviceId, Loc)) { + DP("Not offloading to device %" PRId64 "\n", DeviceId); + return; + } + + DP("__kmpc_push_target_tripcount(%" PRId64 ", %" PRIu64 ")\n", DeviceId, + LoopTripcount); + PM->TblMapMtx.lock(); + PM->Devices[DeviceId]->LoopTripCnt.emplace(__kmpc_global_thread_num(NULL), + LoopTripcount); + PM->TblMapMtx.unlock(); +} + +EXTERN void __kmpc_push_target_tripcount(int64_t DeviceId, + uint64_t LoopTripcount) { + __kmpc_push_target_tripcount_mapper(nullptr, DeviceId, LoopTripcount); +} 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 @@ -64,26 +64,6 @@ /// creates host-to-target data mapping, stores it in the /// libomptarget.so internal structure (an entry in a stack of data maps) /// and passes the data to the device. -EXTERN void __tgt_target_data_begin(int64_t DeviceId, int32_t ArgNum, - void **ArgsBase, void **Args, - int64_t *ArgSizes, int64_t *ArgTypes) { - TIMESCOPE(); - __tgt_target_data_begin_mapper(nullptr, DeviceId, ArgNum, ArgsBase, Args, - ArgSizes, ArgTypes, nullptr, nullptr); -} - -EXTERN void __tgt_target_data_begin_nowait(int64_t DeviceId, int32_t ArgNum, - void **ArgsBase, void **Args, - int64_t *ArgSizes, int64_t *ArgTypes, - int32_t DepNum, void *DepList, - int32_t NoAliasDepNum, - void *NoAliasDepList) { - TIMESCOPE(); - - __tgt_target_data_begin_mapper(nullptr, DeviceId, ArgNum, ArgsBase, Args, - ArgSizes, ArgTypes, nullptr, nullptr); -} - EXTERN void __tgt_target_data_begin_mapper(ident_t *Loc, int64_t DeviceId, int32_t ArgNum, void **ArgsBase, void **Args, int64_t *ArgSizes, @@ -134,26 +114,6 @@ /// passes data from the target, releases target memory and destroys /// the host-target mapping (top entry from the stack of data maps) /// created by the last __tgt_target_data_begin. -EXTERN void __tgt_target_data_end(int64_t DeviceId, int32_t ArgNum, - void **ArgsBase, void **Args, - int64_t *ArgSizes, int64_t *ArgTypes) { - TIMESCOPE(); - __tgt_target_data_end_mapper(nullptr, DeviceId, ArgNum, ArgsBase, Args, - ArgSizes, ArgTypes, nullptr, nullptr); -} - -EXTERN void __tgt_target_data_end_nowait(int64_t DeviceId, int32_t ArgNum, - void **ArgsBase, void **Args, - int64_t *ArgSizes, int64_t *ArgTypes, - int32_t DepNum, void *DepList, - int32_t NoAliasDepNum, - void *NoAliasDepList) { - TIMESCOPE(); - - __tgt_target_data_end_mapper(nullptr, DeviceId, ArgNum, ArgsBase, Args, - ArgSizes, ArgTypes, nullptr, nullptr); -} - EXTERN void __tgt_target_data_end_mapper(ident_t *Loc, int64_t DeviceId, int32_t ArgNum, void **ArgsBase, void **Args, int64_t *ArgSizes, @@ -200,24 +160,6 @@ ArgTypes, ArgNames, ArgMappers); } -EXTERN void __tgt_target_data_update(int64_t DeviceId, int32_t ArgNum, - void **ArgsBase, void **Args, - int64_t *ArgSizes, int64_t *ArgTypes) { - TIMESCOPE(); - __tgt_target_data_update_mapper(nullptr, DeviceId, ArgNum, ArgsBase, Args, - ArgSizes, ArgTypes, nullptr, nullptr); -} - -EXTERN void __tgt_target_data_update_nowait( - int64_t DeviceId, int32_t ArgNum, void **ArgsBase, void **Args, - int64_t *ArgSizes, int64_t *ArgTypes, int32_t DepNum, void *DepList, - int32_t NoAliasDepNum, void *NoAliasDepList) { - TIMESCOPE(); - - __tgt_target_data_update_mapper(nullptr, DeviceId, ArgNum, ArgsBase, Args, - ArgSizes, ArgTypes, nullptr, nullptr); -} - EXTERN void __tgt_target_data_update_mapper(ident_t *Loc, int64_t DeviceId, int32_t ArgNum, void **ArgsBase, void **Args, int64_t *ArgSizes, @@ -255,83 +197,6 @@ ArgSizes, ArgTypes, ArgNames, ArgMappers); } -EXTERN int __tgt_target(int64_t DeviceId, void *HostPtr, int32_t ArgNum, - void **ArgsBase, void **Args, int64_t *ArgSizes, - int64_t *ArgTypes) { - TIMESCOPE(); - return __tgt_target_mapper(nullptr, DeviceId, HostPtr, ArgNum, ArgsBase, Args, - ArgSizes, ArgTypes, nullptr, nullptr); -} - -EXTERN int __tgt_target_nowait(int64_t DeviceId, void *HostPtr, int32_t ArgNum, - void **ArgsBase, void **Args, int64_t *ArgSizes, - int64_t *ArgTypes, int32_t DepNum, void *DepList, - int32_t NoAliasDepNum, void *NoAliasDepList) { - TIMESCOPE(); - - return __tgt_target_mapper(nullptr, DeviceId, HostPtr, ArgNum, ArgsBase, Args, - ArgSizes, ArgTypes, nullptr, nullptr); -} - -EXTERN int __tgt_target_mapper(ident_t *Loc, int64_t DeviceId, void *HostPtr, - int32_t ArgNum, void **ArgsBase, void **Args, - int64_t *ArgSizes, int64_t *ArgTypes, - map_var_info_t *ArgNames, void **ArgMappers) { - TIMESCOPE_WITH_IDENT(Loc); - __tgt_kernel_arguments KernelArgs{1, ArgNum, ArgsBase, Args, - ArgSizes, ArgTypes, ArgNames, ArgMappers}; - return __tgt_target_kernel(Loc, DeviceId, -1, 0, HostPtr, &KernelArgs); -} - -EXTERN int __tgt_target_nowait_mapper( - ident_t *Loc, int64_t DeviceId, void *HostPtr, int32_t ArgNum, - void **ArgsBase, void **Args, int64_t *ArgSizes, int64_t *ArgTypes, - map_var_info_t *ArgNames, void **ArgMappers, int32_t DepNum, void *DepList, - int32_t NoAliasDepNum, void *NoAliasDepList) { - TIMESCOPE_WITH_IDENT(Loc); - - return __tgt_target_mapper(Loc, DeviceId, HostPtr, ArgNum, ArgsBase, Args, - ArgSizes, ArgTypes, ArgNames, ArgMappers); -} - -EXTERN int __tgt_target_teams(int64_t DeviceId, void *HostPtr, int32_t ArgNum, - void **ArgsBase, void **Args, int64_t *ArgSizes, - int64_t *ArgTypes, int32_t TeamNum, - int32_t ThreadLimit) { - TIMESCOPE(); - return __tgt_target_teams_mapper(nullptr, DeviceId, HostPtr, ArgNum, ArgsBase, - Args, ArgSizes, ArgTypes, nullptr, nullptr, - TeamNum, ThreadLimit); -} - -EXTERN int __tgt_target_teams_nowait(int64_t DeviceId, void *HostPtr, - int32_t ArgNum, void **ArgsBase, - void **Args, int64_t *ArgSizes, - int64_t *ArgTypes, int32_t TeamNum, - int32_t ThreadLimit, int32_t DepNum, - void *DepList, int32_t NoAliasDepNum, - void *NoAliasDepList) { - TIMESCOPE(); - - return __tgt_target_teams_mapper(nullptr, DeviceId, HostPtr, ArgNum, ArgsBase, - Args, ArgSizes, ArgTypes, nullptr, nullptr, - TeamNum, ThreadLimit); -} - -EXTERN int __tgt_target_teams_mapper(ident_t *Loc, int64_t DeviceId, - void *HostPtr, int32_t ArgNum, - void **ArgsBase, void **Args, - int64_t *ArgSizes, int64_t *ArgTypes, - map_var_info_t *ArgNames, - void **ArgMappers, int32_t TeamNum, - int32_t ThreadLimit) { - TIMESCOPE_WITH_IDENT(Loc); - __tgt_kernel_arguments KernelArgs{1, ArgNum, ArgsBase, Args, - ArgSizes, ArgTypes, ArgNames, ArgMappers}; - return __tgt_target_kernel(Loc, DeviceId, TeamNum, ThreadLimit, HostPtr, - &KernelArgs); -} - /// Implements a kernel entry that executes the target region on the specified /// device. /// @@ -432,27 +297,6 @@ MapComponentInfoTy(Base, Begin, Size, Type, Name)); } -EXTERN void __kmpc_push_target_tripcount(int64_t DeviceId, - uint64_t LoopTripcount) { - __kmpc_push_target_tripcount_mapper(nullptr, DeviceId, LoopTripcount); -} - -EXTERN void __kmpc_push_target_tripcount_mapper(ident_t *Loc, int64_t DeviceId, - uint64_t LoopTripcount) { - TIMESCOPE_WITH_IDENT(Loc); - if (checkDeviceAndCtors(DeviceId, Loc)) { - DP("Not offloading to device %" PRId64 "\n", DeviceId); - return; - } - - DP("__kmpc_push_target_tripcount(%" PRId64 ", %" PRIu64 ")\n", DeviceId, - LoopTripcount); - PM->TblMapMtx.lock(); - PM->Devices[DeviceId]->LoopTripCnt.emplace(__kmpc_global_thread_num(NULL), - LoopTripcount); - PM->TblMapMtx.unlock(); -} - EXTERN void __tgt_set_info_flag(uint32_t NewInfoLevel) { std::atomic &InfoLevel = getInfoLevelInternal(); InfoLevel.store(NewInfoLevel);