Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Driver] Save PTX files for SYCL kernels in the user input directory. #12422

Merged
merged 7 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions clang/lib/Driver/Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,29 @@ bool Compilation::CleanupFile(const char *File, bool IssueErrors) const {
// able to remove), or non-regular files. Underlying tools may have
// intentionally not overwritten them.

// Save the device code files(spv files) only if -fsycl-dump-device-code
// option is enabled.
// Save the device code files if -fsycl-dump-device-code option is enabled.
if (TheDriver.isDumpDeviceCodeEnabled()) {
bool IsNVPTX = false;
Arg *DumpDeviceCodeArg =
getArgs().getLastArg(options::OPT_fsycl_dump_device_code_EQ);
// Check if SYCL code is being offloaded to CUDA-enabled GPUs.
if (const Arg *SYCLTargets =
getArgs().getLastArg(options::OPT_fsycl_targets_EQ)) {
for (StringRef Val : SYCLTargets->getValues()) {
if (Val.starts_with("nvptx") || Val.starts_with("nvptx64"))
IsNVPTX = true;
}
}
std::string ExpectedDir =
DumpDeviceCodeArg ? DumpDeviceCodeArg->getValue() : "";
std::string ActualFile(File);
if (ActualFile.find(ExpectedDir) != std::string::npos &&
llvm::sys::path::extension(ActualFile).equals(".spv"))
return false;

if (ActualFile.find(ExpectedDir) != std::string::npos) {
if (IsNVPTX)
return false;
if (llvm::sys::path::extension(ActualFile).equals(".spv"))
return false;
}
}

if (!llvm::sys::fs::can_write(File) || !llvm::sys::fs::is_regular_file(File))
Expand Down
20 changes: 20 additions & 0 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ void SYCL::constructLLVMForeachCommand(Compilation &C, const JobAction &JA,
C.getArgs().MakeArgString("--out-dir=" + OutputDirName));
}

// If fsycl-dump-device-code is passed, put the PTX files
// into the path provided in fsycl-dump-device-code.
if (T->getToolChain().getTriple().isNVPTX() &&
C.getDriver().isDumpDeviceCodeEnabled() && Ext.equals("s")) {
SmallString<128> OutputDir;

Arg *DumpDeviceCodeArg =
C.getArgs().getLastArg(options::OPT_fsycl_dump_device_code_EQ);

OutputDir = (DumpDeviceCodeArg ? DumpDeviceCodeArg->getValue() : "");

// If the output directory path is empty, put the PTX files in the
// current directory.
if (OutputDir.empty())
llvm::sys::path::native(OutputDir = "./");
else
OutputDir.append(llvm::sys::path::get_separator());
ForeachArgs.push_back(C.getArgs().MakeArgString("--out-dir=" + OutputDir));
}

ForeachArgs.push_back(C.getArgs().MakeArgString("--"));
ForeachArgs.push_back(
C.getArgs().MakeArgString(InputCommand->getExecutable()));
Expand Down