@@ -28,10 +28,10 @@ IncrementalCUDADeviceParser::IncrementalCUDADeviceParser(
28
28
std::unique_ptr<CompilerInstance> DeviceInstance,
29
29
CompilerInstance &HostInstance,
30
30
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS,
31
- llvm::Error &Err, const std::list<PartialTranslationUnit> &PTUs)
31
+ llvm::Error &Err, std::list<PartialTranslationUnit> &PTUs)
32
32
: IncrementalParser(*DeviceInstance, Err), PTUs(PTUs), VFS(FS),
33
- CodeGenOpts (HostInstance. getCodeGenOpts()),
34
- TargetOpts(HostInstance. getTargetOpts()) {
33
+ CodeGenOpts (DeviceInstance-> getCodeGenOpts ()),
34
+ TargetOpts(DeviceInstance-> getTargetOpts ()) {
35
35
if (Err)
36
36
return ;
37
37
StringRef Arch = TargetOpts.CPU ;
@@ -51,37 +51,61 @@ IncrementalCUDADeviceParser::Parse(llvm::StringRef Input) {
51
51
if (!PTU)
52
52
return PTU.takeError ();
53
53
54
- auto PTX = GeneratePTX ();
55
- if (!PTX)
56
- return PTX.takeError ();
54
+ // auto PTX = GeneratePTX();
55
+ // if (!PTX)
56
+ // return PTX.takeError();
57
57
58
- auto Err = GenerateFatbinary ();
59
- if (Err)
60
- return std::move (Err);
58
+ // auto Err = GenerateFatbinary();
59
+ // if (Err)
60
+ // return std::move(Err);
61
61
62
- std::string FatbinFileName =
63
- " /incr_module_" + std::to_string (PTUs.size ()) + " .fatbin" ;
64
- VFS->addFile (FatbinFileName, 0 ,
65
- llvm::MemoryBuffer::getMemBuffer (
66
- llvm::StringRef (FatbinContent.data (), FatbinContent.size ()),
67
- " " , false ));
62
+ // std::string FatbinFileName =
63
+ // "/incr_module_" + std::to_string(PTUs.size()) + ".fatbin";
64
+ // VFS->addFile(FatbinFileName, 0,
65
+ // llvm::MemoryBuffer::getMemBuffer(
66
+ // llvm::StringRef(FatbinContent.data(), FatbinContent.size()),
67
+ // "", false));
68
68
69
- CodeGenOpts.CudaGpuBinaryFileName = FatbinFileName;
69
+ // CodeGenOpts.CudaGpuBinaryFileName = FatbinFileName;
70
70
71
- FatbinContent.clear ();
71
+ // FatbinContent.clear();
72
72
73
73
return PTU;
74
74
}
75
75
76
+ PartialTranslationUnit &
77
+ IncrementalCUDADeviceParser::RegisterPTU (TranslationUnitDecl *TU) {
78
+ llvm::errs () << " [CUDA] RegisterPTU called. TU = " << TU << " \n " ;
79
+ PTUs.push_back (PartialTranslationUnit ());
80
+ llvm::errs () << " [CUDA] PTUs size after push: " << PTUs.size () << " \n " ;
81
+ PartialTranslationUnit &LastPTU = PTUs.back ();
82
+ LastPTU.TUPart = TU;
83
+ return LastPTU;
84
+ }
85
+
76
86
llvm::Expected<llvm::StringRef> IncrementalCUDADeviceParser::GeneratePTX () {
87
+ llvm::errs () << " [CUDA] Generating PTX. PTUs size: " << PTUs.size () << " \n " ;
88
+ assert (!PTUs.empty () && " PTUs list is empty during PTX generation!" );
77
89
auto &PTU = PTUs.back ();
78
90
std::string Error;
79
91
92
+ if (!PTU.TheModule ) {
93
+ llvm::errs () << " [CUDA] Error: PTU has no associated Module!\n " ;
94
+ } else {
95
+ llvm::errs () << " [CUDA] Module Triple: " << PTU.TheModule ->getTargetTriple ().str () << " \n " ;
96
+ }
97
+
98
+ llvm::errs () << " >>> PTU Module Target Triple: " << PTU.TheModule ->getTargetTriple ().str () << " \n " ;
99
+ llvm::errs () << " >>> Using CPU: " << TargetOpts.CPU << " \n " ;
100
+
80
101
const llvm::Target *Target = llvm::TargetRegistry::lookupTarget (
81
102
PTU.TheModule ->getTargetTriple (), Error);
82
- if (!Target)
103
+ if (!Target) {
104
+ llvm::errs () << " >>> Failed to lookup target: " << Error << " \n " ;
83
105
return llvm::make_error<llvm::StringError>(std::move (Error),
84
106
std::error_code ());
107
+ }
108
+
85
109
llvm::TargetOptions TO = llvm::TargetOptions ();
86
110
llvm::TargetMachine *TargetMachine = Target->createTargetMachine (
87
111
PTU.TheModule ->getTargetTriple (), TargetOpts.CPU , " " , TO,
@@ -173,9 +197,33 @@ llvm::Error IncrementalCUDADeviceParser::GenerateFatbinary() {
173
197
174
198
FatbinContent.append(PTXCode.begin(), PTXCode.end());
175
199
200
+ std::string FatbinFileName =
201
+ " /incr_module_" + std::to_string(PTUs.size()) + " .fatbin" ;
202
+
203
+ VFS->addFile (FatbinFileName, 0 ,
204
+ llvm::MemoryBuffer::getMemBuffer (
205
+ llvm::StringRef (FatbinContent.data(), FatbinContent.size()),
206
+ "", false));
207
+
208
+ CodeGenOpts.CudaGpuBinaryFileName = FatbinFileName;
209
+
210
+ FatbinContent.clear();
211
+
176
212
return llvm::Error::success();
177
213
}
178
214
215
+ // void IncrementalCUDADeviceParser::EmitFatbinaryToVFS(std::string &FatbinFileName) {
216
+ // std::string FatbinFileName = "/incr_module_" + std::to_string(PTUs.size()) + ".fatbin";
217
+
218
+ // VFS->addFile(FatbinFileName, 0,
219
+ // llvm::MemoryBuffer::getMemBuffer(
220
+ // llvm::StringRef(FatbinContent.data(), FatbinContent.size()),
221
+ // "", false));
222
+
223
+ // CodeGenOpts.CudaGpuBinaryFileName = FatbinFileName;
224
+ // FatbinContent.clear();
225
+ // }
226
+
179
227
IncrementalCUDADeviceParser::~IncrementalCUDADeviceParser () {}
180
228
181
229
} // namespace clang
0 commit comments