//===------------ Program.h - liboffload program abstraction ------------===// // // 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 // //===----------------------------------------------------------------------===// // // Declares ProgramTy, which wraps a liboffload program handle (a device // image loaded via olCreateProgram) along with the routines used to resolve // its global-variable and kernel symbols. // //===----------------------------------------------------------------------===// #ifndef _OMPTARGET_PROGRAM_H #define _OMPTARGET_PROGRAM_H #include "APITypes.h" #include "OffloadAPI.h" #include "llvm/Support/Error.h" #include "llvm/Support/MemoryBufferRef.h" class ProgramTy { public: ProgramTy() = default; /// Load \p Img onto \p Device within \p Context via liboffload. static llvm::Expected create(ol_context_handle_t Context, ol_device_handle_t Device, __tgt_device_image *Img); /// Resolve the device address of the global variable \p Name. If \p Size /// is non-null, it is set to the size in bytes of the global. llvm::Expected getGlobalAddress(const char *Name, size_t *Size = nullptr) const; /// Copy the \p Size bytes of the global variable \p Name from the host-side /// program image into \p Dst. Fails if the global's size is not \p Size. llvm::Error readGlobalFromImage(const char *Name, void *Dst, size_t Size) const; /// Return the symbol handle for the kernel \p Name. llvm::Expected getKernelAddress(const char *Name) const; ol_program_handle_t getHandle() const { return Handle; } /// The image loaded for this program. llvm::Expected getImage() const; /// The IR image this program was created from, or an empty buffer if the /// input was not IR. llvm::MemoryBufferRef getIRImage() const { return IRImage; } /// Device buffer holding the indirect call table of this program, or null. void *getIndirectCallTable() const { return IndirectCallTable; } void setIndirectCallTable(void *Table) { IndirectCallTable = Table; } private: ProgramTy(ol_program_handle_t Handle, llvm::MemoryBufferRef IRImage) : Handle(Handle), IRImage(IRImage) {} ol_program_handle_t Handle = nullptr; llvm::MemoryBufferRef IRImage; void *IndirectCallTable = nullptr; }; #endif