-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Clang] Unify 'nvptx-arch' and 'amdgpu-arch' into 'offload-arch' #134713
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
set(LLVM_LINK_COMPONENTS Support) | ||
|
||
add_clang_tool(offload-arch OffloadArch.cpp NVPTXArch.cpp AMDGPUArchByKFD.cpp AMDGPUArchByHIP.cpp) | ||
|
||
add_clang_symlink(amdgpu-arch offload-arch) | ||
add_clang_symlink(nvptx-arch offload-arch) | ||
|
||
target_link_libraries(offload-arch PRIVATE clangBasic) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//===- OffloadArch.cpp - list available GPUs ------------*- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "clang/Basic/Version.h" | ||
#include "llvm/Support/CommandLine.h" | ||
#include "llvm/Support/Path.h" | ||
|
||
using namespace llvm; | ||
|
||
static cl::opt<bool> Help("h", cl::desc("Alias for -help"), cl::Hidden); | ||
|
||
// Mark all our options with this category. | ||
static cl::OptionCategory OffloadArchCategory("amdgpu-arch options"); | ||
jhuber6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
cl::opt<bool> Verbose("verbose", cl::desc("Enable verbose output"), | ||
cl::init(false), cl::cat(OffloadArchCategory)); | ||
|
||
cl::opt<bool> AMDGPU("amdgpu-only", cl::desc("Print only AMD GPUs"), | ||
cl::init(false), cl::cat(OffloadArchCategory)); | ||
|
||
cl::opt<bool> NVPTX("nvptx-only", cl::desc("Print only NVIDIA GPUs"), | ||
cl::init(false), cl::cat(OffloadArchCategory)); | ||
jhuber6 marked this conversation as resolved.
Show resolved
Hide resolved
jhuber6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
static void PrintVersion(raw_ostream &OS) { | ||
OS << clang::getClangToolFullVersion("offload-arch") << '\n'; | ||
} | ||
|
||
int printGPUsByKFD(); | ||
int printGPUsByHIP(); | ||
int printGPUsByCUDA(); | ||
|
||
int printAMD() { | ||
#ifndef _WIN32 | ||
if (!printGPUsByKFD()) | ||
return 0; | ||
#endif | ||
|
||
return printGPUsByHIP(); | ||
} | ||
|
||
int printNVIDIA() { return printGPUsByCUDA(); } | ||
|
||
int main(int argc, char *argv[]) { | ||
cl::HideUnrelatedOptions(OffloadArchCategory); | ||
|
||
cl::SetVersionPrinter(PrintVersion); | ||
cl::ParseCommandLineOptions( | ||
argc, argv, | ||
"A tool to detect the presence of offloading devices on the system. \n\n" | ||
"The tool will output each detected GPU architecture separated by a\n" | ||
"newline character. If multiple GPUs of the same architecture are found\n" | ||
"a string will be printed for each\n"); | ||
|
||
if (Help) { | ||
cl::PrintHelpMessage(); | ||
return 0; | ||
} | ||
|
||
// If this was invoked from the legacy symlinks provide the same behavior. | ||
bool AMDGPUOnly = AMDGPU || sys::path::stem(argv[0]) == "amdgpu-arch"; | ||
jhuber6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bool NVIDIAOnly = NVPTX || sys::path::stem(argv[0]) == "nvptx-arch"; | ||
|
||
int NVIDIAResult = 0; | ||
if (!AMDGPUOnly) | ||
NVIDIAResult = printNVIDIA(); | ||
|
||
int AMDResult = 0; | ||
if (!NVIDIAOnly) | ||
AMDResult = printAMD(); | ||
|
||
// We only failed if all cases returned an error. | ||
return AMDResult && NVIDIAResult; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//===----------------------------------------------------------------------===//
per #118553