brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.9 KiB · 8c150b6 Raw
132 lines · c
1//===-- Shared/APITypes.h - Offload and plugin API 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// This file defines types used in the interface between the user code, the10// target independent offload runtime library, and target dependent plugins.11//12//===----------------------------------------------------------------------===//13 14#ifndef OMPTARGET_SHARED_API_TYPES_H15#define OMPTARGET_SHARED_API_TYPES_H16 17#include "Environment.h"18 19#include "llvm/ADT/SmallVector.h"20#include "llvm/Frontend/Offloading/Utility.h"21 22#include <cstddef>23#include <cstdint>24#include <mutex>25 26extern "C" {27 28/// This struct is a record of the device image information29struct __tgt_device_image {30  void *ImageStart; // Pointer to the target code start31  void *ImageEnd;   // Pointer to the target code end32  llvm::offloading::EntryTy33      *EntriesBegin; // Begin of table with all target entries34  llvm::offloading::EntryTy *EntriesEnd; // End of table (non inclusive)35};36 37struct __tgt_device_info {38  void *Context = nullptr;39  void *Device = nullptr;40  void *Platform = nullptr;41};42 43/// This struct is a record of all the host code that may be offloaded to a44/// target.45struct __tgt_bin_desc {46  int32_t NumDeviceImages;          // Number of device types supported47  __tgt_device_image *DeviceImages; // Array of device images (1 per dev. type)48  llvm::offloading::EntryTy49      *HostEntriesBegin; // Begin of table with all host entries50  llvm::offloading::EntryTy *HostEntriesEnd; // End of table (non inclusive)51};52 53/// This struct contains the offload entries identified by the target runtime54struct __tgt_target_table {55  llvm::offloading::EntryTy56      *EntriesBegin; // Begin of the table with all the entries57  llvm::offloading::EntryTy58      *EntriesEnd; // End of the table with all the entries (non inclusive)59};60 61/// This struct contains a handle to a loaded binary in the plugin device.62struct __tgt_device_binary {63  uintptr_t handle;64};65 66// clang-format on67 68/// This struct contains information exchanged between different asynchronous69/// operations for device-dependent optimization and potential synchronization70struct __tgt_async_info {71  // A pointer to a queue-like structure where offloading operations are issued.72  // We assume to use this structure to do synchronization. In CUDA backend, it73  // is CUstream.74  void *Queue = nullptr;75 76  /// A collection of allocations that are associated with this stream and that77  /// should be freed after finalization.78  llvm::SmallVector<void *, 2> AssociatedAllocations;79 80  /// Mutex to guard access to AssociatedAllocations and the Queue.81  std::mutex Mutex;82 83  /// The kernel launch environment used to issue a kernel. Stored here to84  /// ensure it is a valid location while the transfer to the device is85  /// happening.86  KernelLaunchEnvironmentTy KernelLaunchEnvironment;87};88 89/// This struct contains all of the arguments to a target kernel region launch.90struct KernelArgsTy {91  uint32_t Version = 0; // Version of this struct for ABI compatibility.92  uint32_t NumArgs = 0; // Number of arguments in each input pointer.93  void **ArgBasePtrs =94      nullptr;                 // Base pointer of each argument (e.g. a struct).95  void **ArgPtrs = nullptr;    // Pointer to the argument data.96  int64_t *ArgSizes = nullptr; // Size of the argument data in bytes.97  int64_t *ArgTypes = nullptr; // Type of the data (e.g. to / from).98  void **ArgNames = nullptr;   // Name of the data for debugging, possibly null.99  void **ArgMappers = nullptr; // User-defined mappers, possibly null.100  uint64_t Tripcount =101      0; // Tripcount for the teams / distribute loop, 0 otherwise.102  struct {103    uint64_t NoWait : 1; // Was this kernel spawned with a `nowait` clause.104    uint64_t IsCUDA : 1; // Was this kernel spawned via CUDA.105    uint64_t Unused : 62;106  } Flags = {0, 0, 0};107  // The number of teams (for x,y,z dimension).108  uint32_t NumTeams[3] = {0, 0, 0};109  // The number of threads (for x,y,z dimension).110  uint32_t ThreadLimit[3] = {0, 0, 0};111  uint32_t DynCGroupMem = 0; // Amount of dynamic cgroup memory requested.112};113static_assert(sizeof(KernelArgsTy().Flags) == sizeof(uint64_t),114              "Invalid struct size");115static_assert(sizeof(KernelArgsTy) ==116                  (8 * sizeof(int32_t) + 3 * sizeof(int64_t) +117                   4 * sizeof(void **) + 2 * sizeof(int64_t *)),118              "Invalid struct size");119 120/// Flat array of kernel launch parameters and their total size.121struct KernelLaunchParamsTy {122  /// Size of the Data array.123  size_t Size = 0;124  /// Flat array of kernel parameters.125  void *Data = nullptr;126  /// Ptrs to the Data entries. Only strictly required for the host plugin.127  void **Ptrs = nullptr;128};129}130 131#endif // OMPTARGET_SHARED_API_TYPES_H132