1//===----------- DeviceOffload.h - Device Offloading ------------*- 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-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the classes required for offloading to devices.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_INTERPRETER_DEVICE_OFFLOAD_H
14#define LLVM_CLANG_LIB_INTERPRETER_DEVICE_OFFLOAD_H
15
16#include "IncrementalParser.h"
17#include "llvm/Support/Error.h"
18#include "llvm/Support/FileSystem.h"
19#include "llvm/Support/VirtualFileSystem.h"
20
21namespace clang {
22struct PartialTranslationUnit;
23class CompilerInstance;
24class CodeGenOptions;
25class TargetOptions;
26class IncrementalAction;
27
28class IncrementalDeviceParser : public IncrementalParser {
29
30public:
31 IncrementalDeviceParser(
32 CompilerInstance &DeviceInstance, CompilerInstance &HostInstance,
33 IncrementalAction *DeviceAct,
34 llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS,
35 llvm::Error &Err, std::list<PartialTranslationUnit> &PTUs);
36
37 virtual llvm::Error GenerateOffloadBinary() = 0;
38
39 ~IncrementalDeviceParser() override;
40
41protected:
42 llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS;
43 CodeGenOptions &CodeGenOpts;
44 const TargetOptions &TargetOpts;
45};
46
47class IncrementalHIPDeviceParser : public IncrementalDeviceParser {
48
49public:
50 IncrementalHIPDeviceParser(
51 CompilerInstance &DeviceInstance, CompilerInstance &HostInstance,
52 IncrementalAction *DeviceAct,
53 llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS,
54 llvm::Error &Err, std::list<PartialTranslationUnit> &PTUs);
55
56 llvm::Error GenerateOffloadBinary() override;
57
58 ~IncrementalHIPDeviceParser() override;
59};
60
61class IncrementalCUDADeviceParser : public IncrementalDeviceParser {
62
63public:
64 IncrementalCUDADeviceParser(
65 CompilerInstance &DeviceInstance, CompilerInstance &HostInstance,
66 IncrementalAction *DeviceAct,
67 llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS,
68 llvm::Error &Err, std::list<PartialTranslationUnit> &PTUs);
69
70 llvm::Error GenerateOffloadBinary() override;
71
72 ~IncrementalCUDADeviceParser() override;
73
74private:
75 // Generate PTX for the last PTU.
76 llvm::Expected<llvm::StringRef> GeneratePTX();
77
78 // Generate fatbinary contents in memory
79 llvm::Error GenerateFatbinary();
80
81 int SMVersion;
82 llvm::SmallString<1024> PTXCode;
83 llvm::SmallVector<char, 1024> FatbinContent;
84};
85
86} // namespace clang
87
88#endif // LLVM_CLANG_LIB_INTERPRETER_DEVICE_OFFLOAD_H
89