2023-03-06 16:50:02 +05:30
|
|
|
//===----------- DeviceOffload.h - Device Offloading ------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements classes required for offloading to CUDA devices.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_LIB_INTERPRETER_DEVICE_OFFLOAD_H
|
|
|
|
#define LLVM_CLANG_LIB_INTERPRETER_DEVICE_OFFLOAD_H
|
|
|
|
|
|
|
|
#include "IncrementalParser.h"
|
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
#include "llvm/Support/VirtualFileSystem.h"
|
|
|
|
|
|
|
|
namespace clang {
|
2024-09-23 12:00:43 +02:00
|
|
|
struct PartialTranslationUnit;
|
|
|
|
class CompilerInstance;
|
|
|
|
class CodeGenOptions;
|
|
|
|
class TargetOptions;
|
2023-03-06 16:50:02 +05:30
|
|
|
|
|
|
|
class IncrementalCUDADeviceParser : public IncrementalParser {
|
2024-09-23 12:00:43 +02:00
|
|
|
const std::list<PartialTranslationUnit> &PTUs;
|
|
|
|
|
2023-03-06 16:50:02 +05:30
|
|
|
public:
|
|
|
|
IncrementalCUDADeviceParser(
|
2024-09-23 12:00:43 +02:00
|
|
|
std::unique_ptr<CompilerInstance> DeviceInstance,
|
|
|
|
CompilerInstance &HostInstance,
|
2023-03-06 16:50:02 +05:30
|
|
|
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS,
|
2024-09-23 12:00:43 +02:00
|
|
|
llvm::Error &Err, const std::list<PartialTranslationUnit> &PTUs);
|
2023-03-06 16:50:02 +05:30
|
|
|
|
2024-09-23 12:00:43 +02:00
|
|
|
llvm::Expected<TranslationUnitDecl *> Parse(llvm::StringRef Input) override;
|
2023-03-06 16:50:02 +05:30
|
|
|
|
2024-09-23 12:00:43 +02:00
|
|
|
// Generate PTX for the last PTU.
|
2023-03-06 16:50:02 +05:30
|
|
|
llvm::Expected<llvm::StringRef> GeneratePTX();
|
|
|
|
|
|
|
|
// Generate fatbinary contents in memory
|
|
|
|
llvm::Error GenerateFatbinary();
|
|
|
|
|
|
|
|
~IncrementalCUDADeviceParser();
|
|
|
|
|
|
|
|
protected:
|
2024-09-23 12:00:43 +02:00
|
|
|
std::unique_ptr<CompilerInstance> DeviceCI;
|
2023-03-06 16:50:02 +05:30
|
|
|
int SMVersion;
|
|
|
|
llvm::SmallString<1024> PTXCode;
|
|
|
|
llvm::SmallVector<char, 1024> FatbinContent;
|
|
|
|
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS;
|
2024-09-23 12:00:43 +02:00
|
|
|
CodeGenOptions &CodeGenOpts; // Intentionally a reference.
|
|
|
|
const TargetOptions &TargetOpts;
|
2023-03-06 16:50:02 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_LIB_INTERPRETER_DEVICE_OFFLOAD_H
|