134 lines · plain
1//===-- Memory.td - Memory definitions for Offload ---------*- tablegen -*-===//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 contains Offload API definitions related to memory allocations10//11//===----------------------------------------------------------------------===//12 13def ol_alloc_type_t : Enum {14 let desc = "Represents the type of allocation made with olMemAlloc.";15 let etors = [16 Etor<"HOST", "Host allocation">,17 Etor<"DEVICE", "Device allocation">,18 Etor<"MANAGED", "Managed allocation">19 ];20}21 22def olMemAlloc : Function {23 let desc = "Creates a memory allocation on the specified device.";24 let details = [25 "All allocations through olMemAlloc regardless of source share a single virtual address range. There is no risk of multiple devices returning equal pointers to different memory."26 ];27 let params = [28 Param<"ol_device_handle_t", "Device", "handle of the device to allocate on", PARAM_IN>,29 Param<"ol_alloc_type_t", "Type", "type of the allocation", PARAM_IN>,30 Param<"size_t", "Size", "size of the allocation in bytes", PARAM_IN>,31 Param<"void**", "AllocationOut", "output for the allocated pointer", PARAM_OUT>32 ];33 let returns = [34 Return<"OL_ERRC_INVALID_SIZE", [35 "`Size == 0`"36 ]>37 ];38}39 40def olMemFree : Function {41 let desc = "Frees a memory allocation previously made by olMemAlloc.";42 let params = [43 Param<"void*", "Address", "address of the allocation to free", PARAM_IN>,44 ];45 let returns = [];46}47 48def ol_mem_info_t : Enum {49 let desc = "Supported memory info.";50 let is_typed = 1;51 let etors = [52 TaggedEtor<"DEVICE", "ol_device_handle_t", "The handle of the device associated with the allocation.">,53 TaggedEtor<"BASE", "void *", "Base address of this allocation.">,54 TaggedEtor<"SIZE", "size_t", "Size of this allocation in bytes.">,55 TaggedEtor<"TYPE", "ol_alloc_type_t", "Type of this allocation.">,56 ];57}58 59def olGetMemInfo : Function {60 let desc = "Queries the given property of a memory allocation allocated with olMemAlloc.";61 let details = [62 "`olGetMemInfoSize` can be used to query the storage size required for the given query.",63 "The provided pointer can point to any location inside the allocation.",64 ];65 let params = [66 Param<"const void *", "Ptr", "pointer to the allocated memory", PARAM_IN>,67 Param<"ol_mem_info_t", "PropName", "type of the info to retrieve", PARAM_IN>,68 Param<"size_t", "PropSize", "the number of bytes pointed to by PropValue.", PARAM_IN>,69 TypeTaggedParam<"void*", "PropValue", "array of bytes holding the info. "70 "If Size is not equal to or greater to the real number of bytes needed to return the info "71 "then the OL_ERRC_INVALID_SIZE error is returned and pPlatformInfo is not used.", PARAM_OUT,72 TypeInfo<"PropName" , "PropSize">>73 ];74 let returns = [75 Return<"OL_ERRC_INVALID_SIZE", [76 "`PropSize == 0`",77 "If `PropSize` is less than the real number of bytes needed to return the info."78 ]>,79 Return<"OL_ERRC_NOT_FOUND", ["memory was not allocated by liboffload"]>80 ];81}82 83def olGetMemInfoSize : Function {84 let desc = "Returns the storage size of the given queue query.";85 let details = [86 "The provided pointer can point to any location inside the allocation.",87 ];88 let params = [89 Param<"const void *", "Ptr", "pointer to the allocated memory", PARAM_IN>,90 Param<"ol_mem_info_t", "PropName", "type of the info to query", PARAM_IN>,91 Param<"size_t*", "PropSizeRet", "pointer to the number of bytes required to store the query", PARAM_OUT>92 ];93 let returns = [94 Return<"OL_ERRC_NOT_FOUND", ["memory was not allocated by liboffload"]>95 ];96}97 98def olMemcpy : Function {99 let desc = "Enqueue a memcpy operation.";100 let details = [101 "For host pointers, use the host device belonging to the OL_PLATFORM_BACKEND_HOST platform.",102 "If a queue is specified, at least one device must be a non-host device",103 "If a queue is not specified, the memcpy happens synchronously"104 ];105 let params = [106 Param<"ol_queue_handle_t", "Queue", "handle of the queue.", PARAM_IN_OPTIONAL>,107 Param<"void*", "DstPtr", "pointer to copy to", PARAM_IN>,108 Param<"ol_device_handle_t", "DstDevice", "device that DstPtr belongs to", PARAM_IN>,109 Param<"const void*", "SrcPtr", "pointer to copy from", PARAM_IN>,110 Param<"ol_device_handle_t", "SrcDevice", "device that SrcPtr belongs to", PARAM_IN>,111 Param<"size_t", "Size", "size in bytes of data to copy", PARAM_IN>,112 ];113 let returns = [];114}115 116def olMemFill : Function {117 let desc = "Fill memory with copies of the given pattern";118 let details = [119 "Filling with patterns larger than 4 bytes may be less performant",120 "The destination pointer and queue must be associated with the same device",121 "The fill size must be a multiple of the pattern size",122 ];123 let params = [124 Param<"ol_queue_handle_t", "Queue", "handle of the queue", PARAM_IN_OPTIONAL>,125 Param<"void*", "Ptr", "destination pointer to start filling at", PARAM_IN>,126 Param<"size_t", "PatternSize", "the size of the pattern in bytes", PARAM_IN>,127 Param<"const void*", "PatternPtr", "", PARAM_IN>,128 Param<"size_t", "FillSize", "number of bytes to fill", PARAM_IN>,129 ];130 let returns = [131 Return<"OL_ERRC_INVALID_SIZE", ["`FillSize % PatternSize != 0`"]>132 ];133}134