Index: libomptarget/CMakeLists.txt =================================================================== --- libomptarget/CMakeLists.txt +++ libomptarget/CMakeLists.txt @@ -7,7 +7,7 @@ # ##===----------------------------------------------------------------------===## # -# Build offloading library libomptarget.so. +# Build offloading library and related plugins. # ##===----------------------------------------------------------------------===## @@ -44,8 +44,6 @@ set(LIBOMPTARGET_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(LIBOMPTARGET_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) -libomptarget_say("Building offloading runtime library libomptarget.") - # If building this library in debug mode, we define a macro to enable # dumping progress messages at runtime. string( TOLOWER "${CMAKE_BUILD_TYPE}" LIBOMPTARGET_CMAKE_BUILD_TYPE) @@ -55,20 +53,10 @@ add_definitions(-O0) endif() -set(src_files - src/omptarget.cpp -) - -include_directories(src/) - -# Build libomptarget library with libdl dependency. -add_library(omptarget SHARED ${src_files}) -target_link_libraries(omptarget - ${CMAKE_DL_LIBS} - "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports") +include_directories(include) -# Install libomptarget under the lib destination folder. -install(TARGETS omptarget LIBRARY DESTINATION lib${OPENMP_LIBDIR_SUFFIX}) +# Build target agnostic offloading library. +add_subdirectory(src) # Retrieve the path to the resulting library so that it can be used for # testing. Index: libomptarget/exports =================================================================== --- libomptarget/exports +++ libomptarget/exports @@ -1,28 +0,0 @@ -VERS1.0 { - global: - __tgt_register_lib; - __tgt_unregister_lib; - __tgt_target_data_begin; - __tgt_target_data_end; - __tgt_target_data_update; - __tgt_target; - __tgt_target_teams; - __tgt_target_data_begin_nowait; - __tgt_target_data_end_nowait; - __tgt_target_data_update_nowait; - __tgt_target_nowait; - __tgt_target_teams_nowait; - omp_get_num_devices; - omp_get_initial_device; - omp_target_alloc; - omp_target_free; - omp_target_is_present; - omp_target_memcpy; - omp_target_memcpy_rect; - omp_target_associate_ptr; - omp_target_disassociate_ptr; - __kmpc_push_target_tripcount; - local: - *; -}; - Index: libomptarget/include/omptarget.h =================================================================== --- libomptarget/include/omptarget.h +++ libomptarget/include/omptarget.h @@ -0,0 +1,237 @@ +//===-------- omptarget.h - Target independent OpenMP target RTL -- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.txt for details. +// +//===----------------------------------------------------------------------===// +// +// Interface to be used by Clang during the codegen of a +// target region. +// +//===----------------------------------------------------------------------===// + +#ifndef _OMPTARGET_H_ +#define _OMPTARGET_H_ + +#include +#include + +#define OFFLOAD_SUCCESS (0) +#define OFFLOAD_FAIL (~0) + +#define OFFLOAD_DEVICE_DEFAULT -1 +#define HOST_DEVICE -10 + +/// Data attributes for each data reference used in an OpenMP target region. +enum tgt_map_type { + // No flags + OMP_TGT_MAPTYPE_NONE = 0x000, + // copy data from host to device + OMP_TGT_MAPTYPE_TO = 0x001, + // copy data from device to host + OMP_TGT_MAPTYPE_FROM = 0x002, + // copy regardless of the reference count + OMP_TGT_MAPTYPE_ALWAYS = 0x004, + // force unmapping of data + OMP_TGT_MAPTYPE_DELETE = 0x008, + // map the pointer as well as the pointee + OMP_TGT_MAPTYPE_PTR_AND_OBJ = 0x010, + // pass device base address to kernel + OMP_TGT_MAPTYPE_TARGET_PARAM = 0x020, + // return base device address of mapped data + OMP_TGT_MAPTYPE_RETURN_PARAM = 0x040, + // private variable - not mapped + OMP_TGT_MAPTYPE_PRIVATE = 0x080, + // copy by value - not mapped + OMP_TGT_MAPTYPE_LITERAL = 0x100, + // mapping is implicit + OMP_TGT_MAPTYPE_IMPLICIT = 0x200, + // member of struct, member given by 16 MSBs - 1 + OMP_TGT_MAPTYPE_MEMBER_OF = 0xffff000000000000 +}; + +enum OpenMPOffloadingDeclareTargetFlags { + /// Mark the entry as having a 'link' attribute. + OMP_DECLARE_TARGET_LINK = 0x01, + /// Mark the entry as being a global constructor. + OMP_DECLARE_TARGET_CTOR = 0x02, + /// Mark the entry as being a global destructor. + OMP_DECLARE_TARGET_DTOR = 0x04 +}; + +/// This struct is a record of an entry point or global. For a function +/// entry point the size is expected to be zero +struct __tgt_offload_entry { + void *addr; // Pointer to the offload entry info (function or global) + char *name; // Name of the function or global + size_t size; // Size of the entry info (0 if it is a function) + int32_t flags; // Flags associated with the entry, e.g. 'link'. + int32_t reserved; // Reserved, to be used by the runtime library. +}; + +/// This struct is a record of the device image information +struct __tgt_device_image { + void *ImageStart; // Pointer to the target code start + void *ImageEnd; // Pointer to the target code end + __tgt_offload_entry *EntriesBegin; // Begin of table with all target entries + __tgt_offload_entry *EntriesEnd; // End of table (non inclusive) +}; + +/// This struct is a record of all the host code that may be offloaded to a +/// target. +struct __tgt_bin_desc { + int32_t NumDeviceImages; // Number of device types supported + __tgt_device_image *DeviceImages; // Array of device images (1 per dev. type) + __tgt_offload_entry *HostEntriesBegin; // Begin of table with all host entries + __tgt_offload_entry *HostEntriesEnd; // End of table (non inclusive) +}; + +/// This struct contains the offload entries identified by the target runtime +struct __tgt_target_table { + __tgt_offload_entry *EntriesBegin; // Begin of the table with all the entries + __tgt_offload_entry + *EntriesEnd; // End of the table with all the entries (non inclusive) +}; + +#ifdef __cplusplus +extern "C" { +#endif + +// Implemented in libomp, they are called from within __tgt_* functions. +int omp_get_default_device(void) __attribute__((weak)); +int32_t __kmpc_omp_taskwait(void *loc_ref, int32_t gtid) __attribute__((weak)); + +int omp_get_num_devices(void); +int omp_get_initial_device(void); +void *omp_target_alloc(size_t size, int device_num); +void omp_target_free(void *device_ptr, int device_num); +int omp_target_is_present(void *ptr, int device_num); +int omp_target_memcpy(void *dst, void *src, size_t length, size_t dst_offset, + size_t src_offset, int dst_device, int src_device); +int omp_target_memcpy_rect(void *dst, void *src, size_t element_size, + int num_dims, const size_t *volume, const size_t *dst_offsets, + const size_t *src_offsets, const size_t *dst_dimensions, + const size_t *src_dimensions, int dst_device, int src_device); +int omp_target_associate_ptr(void *host_ptr, void *device_ptr, size_t size, + size_t device_offset, int device_num); +int omp_target_disassociate_ptr(void *host_ptr, int device_num); + +/// adds a target shared library to the target execution image +void __tgt_register_lib(__tgt_bin_desc *desc); + +/// removes a target shared library from the target execution image +void __tgt_unregister_lib(__tgt_bin_desc *desc); + +// creates the 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; +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); +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); + +// passes data from the target, release target memory and destroys the +// host-target mapping (top entry from the stack of data maps) created by +// the last __tgt_target_data_begin +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); +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); + +/// passes data to/from the target +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); +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); + +// Performs the same actions as data_begin in case arg_num is non-zero +// and initiates run of offloaded region on target platform; if arg_num +// is non-zero after the region execution is done it also performs the +// 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_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); +void __kmpc_push_target_tripcount(int64_t device_id, uint64_t loop_tripcount); + +#ifdef __cplusplus +} +#endif + +#ifdef OMPTARGET_DEBUG +#include +#define DEBUGP(prefix, ...) \ + { \ + fprintf(stderr, "%s --> ", prefix); \ + fprintf(stderr, __VA_ARGS__); \ + } + +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif + +#include +#define DPxMOD "0x%0*" PRIxPTR +#define DPxPTR(ptr) ((int)(2*sizeof(uintptr_t))), ((uintptr_t) (ptr)) + +/* + * To printf a pointer in hex with a fixed width of 16 digits and a leading 0x, + * use printf("ptr=" DPxMOD "...\n", DPxPTR(ptr)); + * + * DPxMOD expands to: + * "0x%0*" PRIxPTR + * where PRIxPTR expands to an appropriate modifier for the type uintptr_t on a + * specific platform, e.g. "lu" if uintptr_t is typedef'd as unsigned long: + * "0x%0*lu" + * + * Ultimately, the whole statement expands to: + * printf("ptr=0x%0*lu...\n", // the 0* modifier expects an extra argument + * // specifying the width of the output + * (int)(2*sizeof(uintptr_t)), // the extra argument specifying the width + * // 8 digits for 32bit systems + * // 16 digits for 64bit + * (uintptr_t) ptr); + */ +#else +#define DEBUGP(prefix, ...) \ + {} +#endif + +#ifdef __cplusplus +#define EXTERN extern "C" +#else +#define EXTERN extern +#endif + +#endif // _OMPTARGET_H_ Index: libomptarget/include/omptargetplugin.h =================================================================== --- libomptarget/include/omptargetplugin.h +++ libomptarget/include/omptargetplugin.h @@ -0,0 +1,92 @@ +//===-- omptargetplugin.h - Target dependent OpenMP Plugin API --*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.txt for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines an interface between target independent OpenMP offload +// runtime library libomptarget and target dependent plugin. +// +//===----------------------------------------------------------------------===// + +#ifndef _OMPTARGETPLUGIN_H_ +#define _OMPTARGETPLUGIN_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// Return the number of available devices of the type supported by the +// target RTL. +int32_t __tgt_rtl_number_of_devices(void); + +// Return an integer different from zero if the provided device image can be +// supported by the runtime. The functionality is similar to comparing the +// result of __tgt__rtl__load__binary to NULL. However, this is meant to be a +// lightweight query to determine if the RTL is suitable for an image without +// having to load the library, which can be expensive. +int32_t __tgt_rtl_is_valid_binary(__tgt_device_image *Image); + +// Initialize the specified device. In case of success return 0; otherwise +// return an error code. +int32_t __tgt_rtl_init_device(int32_t ID); + +// Pass an executable image section described by image to the specified +// device and prepare an address table of target entities. In case of error, +// return NULL. Otherwise, return a pointer to the built address table. +// Individual entries in the table may also be NULL, when the corresponding +// offload region is not supported on the target device. +__tgt_target_table *__tgt_rtl_load_binary(int32_t ID, + __tgt_device_image *Image); + +// Allocate data on the particular target device, of the specified size. +// HostPtr is a address of the host data the allocated target data +// will be associated with (HostPtr may be NULL if it is not known at +// allocation time, like for example it would be for target data that +// is allocated by omp_target_alloc() API). Return address of the +// allocated data on the target that will be used by libomptarget.so to +// initialize the target data mapping structures. These addresses are +// used to generate a table of target variables to pass to +// __tgt_rtl_run_region(). The __tgt_rtl_data_alloc() returns NULL in +// case an error occurred on the target device. +void *__tgt_rtl_data_alloc(int32_t ID, int64_t Size, void *HostPtr); + +// Pass the data content to the target device using the target address. +// In case of success, return zero. Otherwise, return an error code. +int32_t __tgt_rtl_data_submit(int32_t ID, void *TargetPtr, void *HostPtr, + int64_t Size); + +// Retrieve the data content from the target device using its address. +// In case of success, return zero. Otherwise, return an error code. +int32_t __tgt_rtl_data_retrieve(int32_t ID, void *HostPtr, void *TargetPtr, + int64_t Size); + +// De-allocate the data referenced by target ptr on the device. In case of +// success, return zero. Otherwise, return an error code. +int32_t __tgt_rtl_data_delete(int32_t ID, void *TargetPtr); + +// Transfer control to the offloaded entry Entry on the target device. +// Args and Offsets are arrays of NumArgs size of target addresses and +// offsets. An offset should be added to the target address before passing it +// to the outlined function on device side. In case of success, return zero. +// Otherwise, return an error code. +int32_t __tgt_rtl_run_target_region(int32_t ID, void *Entry, void **Args, + ptrdiff_t *Offsets, int32_t NumArgs); + +// Similar to __tgt_rtl_run_target_region, but additionally specify the +// number of teams to be created and a number of threads in each team. +int32_t __tgt_rtl_run_target_team_region(int32_t ID, void *Entry, void **Args, + ptrdiff_t *Offsets, int32_t NumArgs, + int32_t NumTeams, int32_t ThreadLimit, + uint64_t loop_tripcount); + +#ifdef __cplusplus +} +#endif + +#endif // _OMPTARGETPLUGIN_H_ Index: libomptarget/src/CMakeLists.txt =================================================================== --- libomptarget/src/CMakeLists.txt +++ libomptarget/src/CMakeLists.txt @@ -0,0 +1,27 @@ +##===----------------------------------------------------------------------===## +# +# The LLVM Compiler Infrastructure +# +# This file is dual licensed under the MIT and the University of Illinois Open +# Source Licenses. See LICENSE.txt for details. +# +##===----------------------------------------------------------------------===## +# +# Build offloading library libomptarget.so. +# +##===----------------------------------------------------------------------===## + +libomptarget_say("Building offloading runtime library libomptarget.") + +set(src_files + omptarget.cpp +) + +# Build libomptarget library with libdl dependency. +add_library(omptarget SHARED ${src_files}) +target_link_libraries(omptarget + ${CMAKE_DL_LIBS} + "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports") + +# Install libomptarget under the lib destination folder. +install(TARGETS omptarget LIBRARY DESTINATION lib${OPENMP_LIBDIR_SUFFIX}) Index: libomptarget/src/exports =================================================================== --- libomptarget/src/exports +++ libomptarget/src/exports @@ -0,0 +1,28 @@ +VERS1.0 { + global: + __tgt_register_lib; + __tgt_unregister_lib; + __tgt_target_data_begin; + __tgt_target_data_end; + __tgt_target_data_update; + __tgt_target; + __tgt_target_teams; + __tgt_target_data_begin_nowait; + __tgt_target_data_end_nowait; + __tgt_target_data_update_nowait; + __tgt_target_nowait; + __tgt_target_teams_nowait; + omp_get_num_devices; + omp_get_initial_device; + omp_target_alloc; + omp_target_free; + omp_target_is_present; + omp_target_memcpy; + omp_target_memcpy_rect; + omp_target_associate_ptr; + omp_target_disassociate_ptr; + __kmpc_push_target_tripcount; + local: + *; +}; + Index: libomptarget/src/omptarget.h =================================================================== --- libomptarget/src/omptarget.h +++ libomptarget/src/omptarget.h @@ -1,237 +0,0 @@ -//===-------- omptarget.h - Target independent OpenMP target RTL -- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.txt for details. -// -//===----------------------------------------------------------------------===// -// -// Interface to be used by Clang during the codegen of a -// target region. -// -//===----------------------------------------------------------------------===// - -#ifndef _OMPTARGET_H_ -#define _OMPTARGET_H_ - -#include -#include - -#define OFFLOAD_SUCCESS (0) -#define OFFLOAD_FAIL (~0) - -#define OFFLOAD_DEVICE_DEFAULT -1 -#define HOST_DEVICE -10 - -/// Data attributes for each data reference used in an OpenMP target region. -enum tgt_map_type { - // No flags - OMP_TGT_MAPTYPE_NONE = 0x000, - // copy data from host to device - OMP_TGT_MAPTYPE_TO = 0x001, - // copy data from device to host - OMP_TGT_MAPTYPE_FROM = 0x002, - // copy regardless of the reference count - OMP_TGT_MAPTYPE_ALWAYS = 0x004, - // force unmapping of data - OMP_TGT_MAPTYPE_DELETE = 0x008, - // map the pointer as well as the pointee - OMP_TGT_MAPTYPE_PTR_AND_OBJ = 0x010, - // pass device base address to kernel - OMP_TGT_MAPTYPE_TARGET_PARAM = 0x020, - // return base device address of mapped data - OMP_TGT_MAPTYPE_RETURN_PARAM = 0x040, - // private variable - not mapped - OMP_TGT_MAPTYPE_PRIVATE = 0x080, - // copy by value - not mapped - OMP_TGT_MAPTYPE_LITERAL = 0x100, - // mapping is implicit - OMP_TGT_MAPTYPE_IMPLICIT = 0x200, - // member of struct, member given by 4 MSBs - 1 - OMP_TGT_MAPTYPE_MEMBER_OF = 0xffff000000000000 -}; - -enum OpenMPOffloadingDeclareTargetFlags { - /// Mark the entry as having a 'link' attribute. - OMP_DECLARE_TARGET_LINK = 0x01, - /// Mark the entry as being a global constructor. - OMP_DECLARE_TARGET_CTOR = 0x02, - /// Mark the entry as being a global destructor. - OMP_DECLARE_TARGET_DTOR = 0x04 -}; - -/// This struct is a record of an entry point or global. For a function -/// entry point the size is expected to be zero -struct __tgt_offload_entry { - void *addr; // Pointer to the offload entry info (function or global) - char *name; // Name of the function or global - size_t size; // Size of the entry info (0 if it is a function) - int32_t flags; // Flags associated with the entry, e.g. 'link'. - int32_t reserved; // Reserved, to be used by the runtime library. -}; - -/// This struct is a record of the device image information -struct __tgt_device_image { - void *ImageStart; // Pointer to the target code start - void *ImageEnd; // Pointer to the target code end - __tgt_offload_entry *EntriesBegin; // Begin of table with all target entries - __tgt_offload_entry *EntriesEnd; // End of table (non inclusive) -}; - -/// This struct is a record of all the host code that may be offloaded to a -/// target. -struct __tgt_bin_desc { - int32_t NumDeviceImages; // Number of device types supported - __tgt_device_image *DeviceImages; // Array of device images (1 per dev. type) - __tgt_offload_entry *HostEntriesBegin; // Begin of table with all host entries - __tgt_offload_entry *HostEntriesEnd; // End of table (non inclusive) -}; - -/// This struct contains the offload entries identified by the target runtime -struct __tgt_target_table { - __tgt_offload_entry *EntriesBegin; // Begin of the table with all the entries - __tgt_offload_entry - *EntriesEnd; // End of the table with all the entries (non inclusive) -}; - -#ifdef __cplusplus -extern "C" { -#endif - -// Implemented in libomp, they are called from within __tgt_* functions. -int omp_get_default_device(void) __attribute__((weak)); -int32_t __kmpc_omp_taskwait(void *loc_ref, int32_t gtid) __attribute__((weak)); - -int omp_get_num_devices(void); -int omp_get_initial_device(void); -void *omp_target_alloc(size_t size, int device_num); -void omp_target_free(void *device_ptr, int device_num); -int omp_target_is_present(void *ptr, int device_num); -int omp_target_memcpy(void *dst, void *src, size_t length, size_t dst_offset, - size_t src_offset, int dst_device, int src_device); -int omp_target_memcpy_rect(void *dst, void *src, size_t element_size, - int num_dims, const size_t *volume, const size_t *dst_offsets, - const size_t *src_offsets, const size_t *dst_dimensions, - const size_t *src_dimensions, int dst_device, int src_device); -int omp_target_associate_ptr(void *host_ptr, void *device_ptr, size_t size, - size_t device_offset, int device_num); -int omp_target_disassociate_ptr(void *host_ptr, int device_num); - -/// adds a target shared library to the target execution image -void __tgt_register_lib(__tgt_bin_desc *desc); - -/// removes a target shared library from the target execution image -void __tgt_unregister_lib(__tgt_bin_desc *desc); - -// creates the 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; -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); -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); - -// passes data from the target, release target memory and destroys the -// host-target mapping (top entry from the stack of data maps) created by -// the last __tgt_target_data_begin -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); -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); - -/// passes data to/from the target -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); -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); - -// Performs the same actions as data_begin in case arg_num is non-zero -// and initiates run of offloaded region on target platform; if arg_num -// is non-zero after the region execution is done it also performs the -// 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_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); -void __kmpc_push_target_tripcount(int64_t device_id, uint64_t loop_tripcount); - -#ifdef __cplusplus -} -#endif - -#ifdef OMPTARGET_DEBUG -#include -#define DEBUGP(prefix, ...) \ - { \ - fprintf(stderr, "%s --> ", prefix); \ - fprintf(stderr, __VA_ARGS__); \ - } - -#ifndef __STDC_FORMAT_MACROS -#define __STDC_FORMAT_MACROS -#endif - -#include -#define DPxMOD "0x%0*" PRIxPTR -#define DPxPTR(ptr) ((int)(2*sizeof(uintptr_t))), ((uintptr_t) (ptr)) - -/* - * To printf a pointer in hex with a fixed width of 16 digits and a leading 0x, - * use printf("ptr=" DPxMOD "...\n", DPxPTR(ptr)); - * - * DPxMOD expands to: - * "0x%0*" PRIxPTR - * where PRIxPTR expands to an appropriate modifier for the type uintptr_t on a - * specific platform, e.g. "lu" if uintptr_t is typedef'd as unsigned long: - * "0x%0*lu" - * - * Ultimately, the whole statement expands to: - * printf("ptr=0x%0*lu...\n", // the 0* modifier expects an extra argument - * // specifying the width of the output - * (int)(2*sizeof(uintptr_t)), // the extra argument specifying the width - * // 8 digits for 32bit systems - * // 16 digits for 64bit - * (uintptr_t) ptr); - */ -#else -#define DEBUGP(prefix, ...) \ - {} -#endif - -#ifdef __cplusplus -#define EXTERN extern "C" -#else -#define EXTERN extern -#endif - -#endif // _OMPTARGET_H_ Index: libomptarget/src/omptargetplugin.h =================================================================== --- libomptarget/src/omptargetplugin.h +++ libomptarget/src/omptargetplugin.h @@ -1,92 +0,0 @@ -//===-- omptargetplugin.h - Target dependent OpenMP Plugin API --*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.txt for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines an interface between target independent OpenMP offload -// runtime library libomptarget and target dependent plugin. -// -//===----------------------------------------------------------------------===// - -#ifndef _OMPTARGETPLUGIN_H_ -#define _OMPTARGETPLUGIN_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// Return the number of available devices of the type supported by the -// target RTL. -int32_t __tgt_rtl_number_of_devices(void); - -// Return an integer different from zero if the provided device image can be -// supported by the runtime. The functionality is similar to comparing the -// result of __tgt__rtl__load__binary to NULL. However, this is meant to be a -// lightweight query to determine if the RTL is suitable for an image without -// having to load the library, which can be expensive. -int32_t __tgt_rtl_is_valid_binary(__tgt_device_image *Image); - -// Initialize the specified device. In case of success return 0; otherwise -// return an error code. -int32_t __tgt_rtl_init_device(int32_t ID); - -// Pass an executable image section described by image to the specified -// device and prepare an address table of target entities. In case of error, -// return NULL. Otherwise, return a pointer to the built address table. -// Individual entries in the table may also be NULL, when the corresponding -// offload region is not supported on the target device. -__tgt_target_table *__tgt_rtl_load_binary(int32_t ID, - __tgt_device_image *Image); - -// Allocate data on the particular target device, of the specified size. -// HostPtr is a address of the host data the allocated target data -// will be associated with (HostPtr may be NULL if it is not known at -// allocation time, like for example it would be for target data that -// is allocated by omp_target_alloc() API). Return address of the -// allocated data on the target that will be used by libomptarget.so to -// initialize the target data mapping structures. These addresses are -// used to generate a table of target variables to pass to -// __tgt_rtl_run_region(). The __tgt_rtl_data_alloc() returns NULL in -// case an error occurred on the target device. -void *__tgt_rtl_data_alloc(int32_t ID, int64_t Size, void *HostPtr); - -// Pass the data content to the target device using the target address. -// In case of success, return zero. Otherwise, return an error code. -int32_t __tgt_rtl_data_submit(int32_t ID, void *TargetPtr, void *HostPtr, - int64_t Size); - -// Retrieve the data content from the target device using its address. -// In case of success, return zero. Otherwise, return an error code. -int32_t __tgt_rtl_data_retrieve(int32_t ID, void *HostPtr, void *TargetPtr, - int64_t Size); - -// De-allocate the data referenced by target ptr on the device. In case of -// success, return zero. Otherwise, return an error code. -int32_t __tgt_rtl_data_delete(int32_t ID, void *TargetPtr); - -// Transfer control to the offloaded entry Entry on the target device. -// Args and Offsets are arrays of NumArgs size of target addresses and -// offsets. An offset should be added to the target address before passing it -// to the outlined function on device side. In case of success, return zero. -// Otherwise, return an error code. -int32_t __tgt_rtl_run_target_region(int32_t ID, void *Entry, void **Args, - ptrdiff_t *Offsets, int32_t NumArgs); - -// Similar to __tgt_rtl_run_target_region, but additionally specify the -// number of teams to be created and a number of threads in each team. -int32_t __tgt_rtl_run_target_team_region(int32_t ID, void *Entry, void **Args, - ptrdiff_t *Offsets, int32_t NumArgs, - int32_t NumTeams, int32_t ThreadLimit, - uint64_t loop_tripcount); - -#ifdef __cplusplus -} -#endif - -#endif // _OMPTARGETPLUGIN_H_