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 @@ -326,45 +326,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 device_id, void *host_ptr, int32_t arg_num, - void **args_base, void **args, int64_t *arg_sizes, - int64_t *arg_types); -int __tgt_target_nowait(int64_t device_id, void *host_ptr, int32_t arg_num, - void **args_base, void **args, int64_t *arg_sizes, - int64_t *arg_types, int32_t depNum, void *depList, - int32_t noAliasDepNum, void *noAliasDepList); -int __tgt_target_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); -int __tgt_target_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 depNum, void *depList, - int32_t noAliasDepNum, void *noAliasDepList); - -int __tgt_target_teams(int64_t device_id, void *host_ptr, int32_t arg_num, - void **args_base, void **args, int64_t *arg_sizes, - int64_t *arg_types, int32_t num_teams, - int32_t thread_limit); -int __tgt_target_teams_nowait(int64_t device_id, void *host_ptr, - int32_t arg_num, void **args_base, void **args, - int64_t *arg_sizes, int64_t *arg_types, - int32_t num_teams, int32_t thread_limit, - int32_t depNum, void *depList, - int32_t noAliasDepNum, void *noAliasDepList); -int __tgt_target_teams_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); -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, int32_t Version); @@ -374,11 +335,6 @@ int32_t DepNum, void *DepList, int32_t NoAliasDepNum, void *NoAliasDepList); -void __kmpc_push_target_tripcount(int64_t device_id, uint64_t loop_tripcount); - -void __kmpc_push_target_tripcount_mapper(ident_t *loc, int64_t device_id, - uint64_t loop_tripcount); - void __tgt_set_info_flag(uint32_t); int __tgt_print_device_info(int64_t device_id); 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,185 @@ +//===-------- 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 device_id, int32_t arg_num, + void **args_base, void **args, + int64_t *arg_sizes, int64_t *arg_types) { + TIMESCOPE(); + __tgt_target_data_begin_mapper(nullptr, device_id, arg_num, args_base, args, + arg_sizes, arg_types, nullptr, nullptr); +} + +EXTERN void __tgt_target_data_begin_nowait(int64_t device_id, int32_t arg_num, + void **args_base, void **args, + int64_t *arg_sizes, + int64_t *arg_types, int32_t depNum, + void *depList, int32_t noAliasDepNum, + void *noAliasDepList) { + TIMESCOPE(); + + __tgt_target_data_begin_mapper(nullptr, device_id, arg_num, args_base, args, + arg_sizes, arg_types, nullptr, nullptr); +} + +EXTERN void __tgt_target_data_end(int64_t device_id, int32_t arg_num, + void **args_base, void **args, + int64_t *arg_sizes, int64_t *arg_types) { + TIMESCOPE(); + __tgt_target_data_end_mapper(nullptr, device_id, arg_num, args_base, args, + arg_sizes, arg_types, nullptr, nullptr); +} + +EXTERN void __tgt_target_data_update(int64_t device_id, int32_t arg_num, + void **args_base, void **args, + int64_t *arg_sizes, int64_t *arg_types) { + TIMESCOPE(); + __tgt_target_data_update_mapper(nullptr, device_id, arg_num, args_base, args, + arg_sizes, arg_types, nullptr, nullptr); +} + +EXTERN void __tgt_target_data_update_nowait( + int64_t device_id, int32_t arg_num, void **args_base, void **args, + int64_t *arg_sizes, int64_t *arg_types, int32_t depNum, void *depList, + int32_t noAliasDepNum, void *noAliasDepList) { + TIMESCOPE(); + + __tgt_target_data_update_mapper(nullptr, device_id, arg_num, args_base, args, + arg_sizes, arg_types, nullptr, nullptr); +} + +EXTERN void __tgt_target_data_end_nowait(int64_t device_id, int32_t arg_num, + void **args_base, void **args, + int64_t *arg_sizes, int64_t *arg_types, + int32_t depNum, void *depList, + int32_t noAliasDepNum, + void *noAliasDepList) { + TIMESCOPE(); + + __tgt_target_data_end_mapper(nullptr, device_id, arg_num, args_base, args, + arg_sizes, arg_types, nullptr, nullptr); +} + +EXTERN int __tgt_target_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) { + TIMESCOPE_WITH_IDENT(loc); + __tgt_kernel_arguments Args{arg_num, args_base, args, arg_sizes, + arg_types, arg_names, arg_mappers}; + return __tgt_target_kernel(loc, device_id, -1, -1, host_ptr, &Args, 1); +} + +EXTERN int __tgt_target(int64_t device_id, void *host_ptr, int32_t arg_num, + void **args_base, void **args, int64_t *arg_sizes, + int64_t *arg_types) { + TIMESCOPE(); + return __tgt_target_mapper(nullptr, device_id, host_ptr, arg_num, args_base, + args, arg_sizes, arg_types, nullptr, nullptr); +} + +EXTERN int __tgt_target_nowait(int64_t device_id, void *host_ptr, + int32_t arg_num, void **args_base, void **args, + int64_t *arg_sizes, int64_t *arg_types, + int32_t depNum, void *depList, + int32_t noAliasDepNum, void *noAliasDepList) { + TIMESCOPE(); + + return __tgt_target_mapper(nullptr, device_id, host_ptr, arg_num, args_base, + args, arg_sizes, arg_types, nullptr, nullptr); +} + +EXTERN int __tgt_target_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 depNum, + void *depList, int32_t noAliasDepNum, void *noAliasDepList) { + TIMESCOPE_WITH_IDENT(loc); + + return __tgt_target_mapper(loc, device_id, host_ptr, arg_num, args_base, args, + arg_sizes, arg_types, arg_names, arg_mappers); +} + +EXTERN int __tgt_target_teams_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 team_num, + int32_t thread_limit) { + TIMESCOPE_WITH_IDENT(loc); + + __tgt_kernel_arguments Args{arg_num, args_base, args, arg_sizes, + arg_types, arg_names, arg_mappers}; + return __tgt_target_kernel(loc, device_id, team_num, thread_limit, host_ptr, + &Args, 1); +} + +EXTERN int __tgt_target_teams(int64_t device_id, void *host_ptr, + int32_t arg_num, void **args_base, void **args, + int64_t *arg_sizes, int64_t *arg_types, + int32_t team_num, int32_t thread_limit) { + TIMESCOPE(); + return __tgt_target_teams_mapper(nullptr, device_id, host_ptr, arg_num, + args_base, args, arg_sizes, arg_types, + nullptr, nullptr, team_num, thread_limit); +} + +EXTERN int __tgt_target_teams_nowait(int64_t device_id, void *host_ptr, + int32_t arg_num, void **args_base, + void **args, int64_t *arg_sizes, + int64_t *arg_types, int32_t team_num, + int32_t thread_limit, int32_t depNum, + void *depList, int32_t noAliasDepNum, + void *noAliasDepList) { + TIMESCOPE(); + + return __tgt_target_teams_mapper(nullptr, device_id, host_ptr, arg_num, + args_base, args, arg_sizes, arg_types, + nullptr, nullptr, team_num, thread_limit); +} + +EXTERN 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 team_num, + int32_t thread_limit, int32_t depNum, void *depList, int32_t noAliasDepNum, + void *noAliasDepList) { + TIMESCOPE_WITH_IDENT(loc); + + return __tgt_target_teams_mapper(loc, device_id, host_ptr, arg_num, args_base, + args, arg_sizes, arg_types, arg_names, + arg_mappers, team_num, thread_limit); +} + +EXTERN void __kmpc_push_target_tripcount_mapper(ident_t *loc, int64_t device_id, + uint64_t loop_tripcount) { + TIMESCOPE_WITH_IDENT(loc); + if (checkDeviceAndCtors(device_id, loc)) { + DP("Not offloading to device %" PRId64 "\n", device_id); + return; + } + + DP("__kmpc_push_target_tripcount(%" PRId64 ", %" PRIu64 ")\n", device_id, + loop_tripcount); + PM->TblMapMtx.lock(); + PM->Devices[device_id]->LoopTripCnt.emplace(__kmpc_global_thread_num(NULL), + loop_tripcount); + PM->TblMapMtx.unlock(); +} + +EXTERN void __kmpc_push_target_tripcount(int64_t device_id, + uint64_t loop_tripcount) { + __kmpc_push_target_tripcount_mapper(nullptr, device_id, loop_tripcount); +} 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 device_id, int32_t arg_num, - void **args_base, void **args, - int64_t *arg_sizes, int64_t *arg_types) { - TIMESCOPE(); - __tgt_target_data_begin_mapper(nullptr, device_id, arg_num, args_base, args, - arg_sizes, arg_types, nullptr, nullptr); -} - -EXTERN void __tgt_target_data_begin_nowait(int64_t device_id, int32_t arg_num, - void **args_base, void **args, - int64_t *arg_sizes, - int64_t *arg_types, int32_t depNum, - void *depList, int32_t noAliasDepNum, - void *noAliasDepList) { - TIMESCOPE(); - - __tgt_target_data_begin_mapper(nullptr, device_id, arg_num, args_base, args, - arg_sizes, arg_types, nullptr, nullptr); -} - EXTERN void __tgt_target_data_begin_mapper(ident_t *loc, int64_t device_id, int32_t arg_num, void **args_base, void **args, int64_t *arg_sizes, @@ -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 device_id, int32_t arg_num, - void **args_base, void **args, - int64_t *arg_sizes, int64_t *arg_types) { - TIMESCOPE(); - __tgt_target_data_end_mapper(nullptr, device_id, arg_num, args_base, args, - arg_sizes, arg_types, nullptr, nullptr); -} - -EXTERN void __tgt_target_data_end_nowait(int64_t device_id, int32_t arg_num, - void **args_base, void **args, - int64_t *arg_sizes, int64_t *arg_types, - int32_t depNum, void *depList, - int32_t noAliasDepNum, - void *noAliasDepList) { - TIMESCOPE(); - - __tgt_target_data_end_mapper(nullptr, device_id, arg_num, args_base, args, - arg_sizes, arg_types, nullptr, nullptr); -} - EXTERN void __tgt_target_data_end_mapper(ident_t *loc, int64_t device_id, int32_t arg_num, void **args_base, void **args, int64_t *arg_sizes, @@ -200,24 +160,6 @@ arg_sizes, arg_types, arg_names, arg_mappers); } -EXTERN void __tgt_target_data_update(int64_t device_id, int32_t arg_num, - void **args_base, void **args, - int64_t *arg_sizes, int64_t *arg_types) { - TIMESCOPE(); - __tgt_target_data_update_mapper(nullptr, device_id, arg_num, args_base, args, - arg_sizes, arg_types, nullptr, nullptr); -} - -EXTERN void __tgt_target_data_update_nowait( - int64_t device_id, int32_t arg_num, void **args_base, void **args, - int64_t *arg_sizes, int64_t *arg_types, int32_t depNum, void *depList, - int32_t noAliasDepNum, void *noAliasDepList) { - TIMESCOPE(); - - __tgt_target_data_update_mapper(nullptr, device_id, arg_num, args_base, args, - arg_sizes, arg_types, nullptr, nullptr); -} - EXTERN void __tgt_target_data_update_mapper(ident_t *loc, int64_t device_id, int32_t arg_num, void **args_base, void **args, int64_t *arg_sizes, @@ -255,98 +197,6 @@ arg_sizes, arg_types, arg_names, arg_mappers); } -EXTERN int __tgt_target(int64_t device_id, void *host_ptr, int32_t arg_num, - void **args_base, void **args, int64_t *arg_sizes, - int64_t *arg_types) { - TIMESCOPE(); - return __tgt_target_mapper(nullptr, device_id, host_ptr, arg_num, args_base, - args, arg_sizes, arg_types, nullptr, nullptr); -} - -EXTERN int __tgt_target_nowait(int64_t device_id, void *host_ptr, - int32_t arg_num, void **args_base, void **args, - int64_t *arg_sizes, int64_t *arg_types, - int32_t depNum, void *depList, - int32_t noAliasDepNum, void *noAliasDepList) { - TIMESCOPE(); - - return __tgt_target_mapper(nullptr, device_id, host_ptr, arg_num, args_base, - args, arg_sizes, arg_types, nullptr, nullptr); -} - -EXTERN int __tgt_target_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) { - TIMESCOPE_WITH_IDENT(loc); - __tgt_kernel_arguments Args{arg_num, args_base, args, arg_sizes, - arg_types, arg_names, arg_mappers}; - return __tgt_target_kernel(loc, device_id, -1, -1, host_ptr, &Args, 1); -} - -EXTERN int __tgt_target_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 depNum, - void *depList, int32_t noAliasDepNum, void *noAliasDepList) { - TIMESCOPE_WITH_IDENT(loc); - - return __tgt_target_mapper(loc, device_id, host_ptr, arg_num, args_base, args, - arg_sizes, arg_types, arg_names, arg_mappers); -} - -EXTERN int __tgt_target_teams(int64_t device_id, void *host_ptr, - int32_t arg_num, void **args_base, void **args, - int64_t *arg_sizes, int64_t *arg_types, - int32_t team_num, int32_t thread_limit) { - TIMESCOPE(); - return __tgt_target_teams_mapper(nullptr, device_id, host_ptr, arg_num, - args_base, args, arg_sizes, arg_types, - nullptr, nullptr, team_num, thread_limit); -} - -EXTERN int __tgt_target_teams_nowait(int64_t device_id, void *host_ptr, - int32_t arg_num, void **args_base, - void **args, int64_t *arg_sizes, - int64_t *arg_types, int32_t team_num, - int32_t thread_limit, int32_t depNum, - void *depList, int32_t noAliasDepNum, - void *noAliasDepList) { - TIMESCOPE(); - - return __tgt_target_teams_mapper(nullptr, device_id, host_ptr, arg_num, - args_base, args, arg_sizes, arg_types, - nullptr, nullptr, team_num, thread_limit); -} - -EXTERN int __tgt_target_teams_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 team_num, - int32_t thread_limit) { - TIMESCOPE_WITH_IDENT(loc); - - __tgt_kernel_arguments Args{arg_num, args_base, args, arg_sizes, - arg_types, arg_names, arg_mappers}; - return __tgt_target_kernel(loc, device_id, team_num, thread_limit, host_ptr, - &Args, 1); -} - -EXTERN 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 team_num, - int32_t thread_limit, int32_t depNum, void *depList, int32_t noAliasDepNum, - void *noAliasDepList) { - TIMESCOPE_WITH_IDENT(loc); - - return __tgt_target_teams_mapper(loc, device_id, host_ptr, arg_num, args_base, - args, arg_sizes, arg_types, arg_names, - arg_mappers, team_num, thread_limit); -} - /// Implements a kernel entry that executes the target region on the specified /// device. /// @@ -451,27 +301,6 @@ MapComponentInfoTy(base, begin, size, type, name)); } -EXTERN void __kmpc_push_target_tripcount(int64_t device_id, - uint64_t loop_tripcount) { - __kmpc_push_target_tripcount_mapper(nullptr, device_id, loop_tripcount); -} - -EXTERN void __kmpc_push_target_tripcount_mapper(ident_t *loc, int64_t device_id, - uint64_t loop_tripcount) { - TIMESCOPE_WITH_IDENT(loc); - if (checkDeviceAndCtors(device_id, loc)) { - DP("Not offloading to device %" PRId64 "\n", device_id); - return; - } - - DP("__kmpc_push_target_tripcount(%" PRId64 ", %" PRIu64 ")\n", device_id, - loop_tripcount); - PM->TblMapMtx.lock(); - PM->Devices[device_id]->LoopTripCnt.emplace(__kmpc_global_thread_num(NULL), - loop_tripcount); - PM->TblMapMtx.unlock(); -} - EXTERN void __tgt_set_info_flag(uint32_t NewInfoLevel) { std::atomic &InfoLevel = getInfoLevelInternal(); InfoLevel.store(NewInfoLevel);