Skip to content

Commit

Permalink
feat: initial support for Clang HIP
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin Zhao <git@gzgz.dev>
  • Loading branch information
GZGavinZhao authored and sylvestre committed Jan 22, 2024
1 parent 4d81257 commit 5fa143e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/compiler/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,7 @@ mod test {
t("mm", Language::ObjectiveCxx);

t("cu", Language::Cuda);
t("hip", Language::Hip);
}

#[test]
Expand Down
70 changes: 70 additions & 0 deletions src/compiler/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,76 @@ mod test {
);
}

#[test]
fn test_parse_arguments_hip() {
let a = parses!("-c", "foo.hip", "-o", "foo.o");
assert_eq!(Some("foo.hip"), a.input.to_str());
assert_eq!(Language::Hip, a.language);
assert_map_contains!(
a.outputs,
(
"obj",
ArtifactDescriptor {
path: PathBuf::from("foo.o"),
optional: false
}
)
);
assert!(a.preprocessor_args.is_empty());
assert!(a.common_args.is_empty());
}

#[test]
fn test_parse_arguments_hip_flags() {
let a = parses!(
"-c",
"foo.cpp",
"-x",
"hip",
"--offload-arch=gfx900",
"-o",
"foo.o"
);
assert_eq!(Some("foo.cpp"), a.input.to_str());
assert_eq!(Language::Hip, a.language);
assert_map_contains!(
a.outputs,
(
"obj",
ArtifactDescriptor {
path: PathBuf::from("foo.o"),
optional: false
}
)
);
assert!(a.preprocessor_args.is_empty());
assert_eq!(ovec!["--offload-arch=gfx900"], a.common_args);

let b = parses!(
"-c",
"foo.cpp",
"-x",
"hip",
"--offload-arch=gfx900",
"-o",
"foo.o"
);
assert_eq!(Some("foo.cpp"), b.input.to_str());
assert_eq!(Language::Hip, b.language);
assert_map_contains!(
b.outputs,
(
"obj",
ArtifactDescriptor {
path: PathBuf::from("foo.o"),
optional: false
}
)
);
assert!(b.preprocessor_args.is_empty());
assert_eq!(ovec!["--offload-arch=gfx900"], b.common_args);
}

#[test]
fn test_dependent_lib() {
let a = parses!(
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pub enum Language {
ObjectiveCxx,
Cuda,
Rust,
Hip,
}

impl Language {
Expand All @@ -135,6 +136,7 @@ impl Language {
Some("cu") => Some(Language::Cuda),
// TODO cy
Some("rs") => Some(Language::Rust),
Some("hip") => Some(Language::Hip),
e => {
trace!("Unknown source extension: {}", e.unwrap_or("(None)"));
None
Expand All @@ -151,6 +153,7 @@ impl Language {
Language::ObjectiveCxx => "objc++",
Language::Cuda => "cuda",
Language::Rust => "rust",
Language::Hip => "hip",
}
}
}
Expand All @@ -167,6 +170,7 @@ impl CompilerKind {
| Language::ObjectiveCxx => "C/C++",
Language::Cuda => "CUDA",
Language::Rust => "Rust",
Language::Hip => "HIP",
}
.to_string()
}
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ where
"cu" => Some(Language::Cuda),
"rs" => Some(Language::Rust),
"cuda" => Some(Language::Cuda),
"hip" => Some(Language::Hip),
_ => cannot_cache!("-x"),
};
}
Expand Down Expand Up @@ -644,6 +645,7 @@ fn language_to_gcc_arg(lang: Language) -> Option<&'static str> {
Language::ObjectiveCxx => Some("objective-c++"),
Language::Cuda => Some("cu"),
Language::Rust => None, // Let the compiler decide
Language::Hip => Some("hip"),
Language::GenericHeader => None, // Let the compiler decide
}
}
Expand Down

0 comments on commit 5fa143e

Please sign in to comment.