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 implements classes required for offloading to CUDA 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/FileSystem.h" 18 #include "llvm/Support/VirtualFileSystem.h" 19 20 namespace clang { 21 struct PartialTranslationUnit; 22 class CompilerInstance; 23 class CodeGenOptions; 24 class TargetOptions; 25 26 class IncrementalCUDADeviceParser : public IncrementalParser { 27 const std::list<PartialTranslationUnit> &PTUs; 28 29 public: 30 IncrementalCUDADeviceParser( 31 CompilerInstance &DeviceInstance, CompilerInstance &HostInstance, 32 llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS, 33 llvm::Error &Err, const std::list<PartialTranslationUnit> &PTUs); 34 35 // Generate PTX for the last PTU. 36 llvm::Expected<llvm::StringRef> GeneratePTX(); 37 38 // Generate fatbinary contents in memory 39 llvm::Error GenerateFatbinary(); 40 41 ~IncrementalCUDADeviceParser(); 42 43 protected: 44 int SMVersion; 45 llvm::SmallString<1024> PTXCode; 46 llvm::SmallVector<char, 1024> FatbinContent; 47 llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS; 48 CodeGenOptions &CodeGenOpts; // Intentionally a reference. 49 const TargetOptions &TargetOpts; 50 }; 51 52 } // namespace clang 53 54 #endif // LLVM_CLANG_LIB_INTERPRETER_DEVICE_OFFLOAD_H 55