forked from meta-pytorch/monarch
-
Notifications
You must be signed in to change notification settings - Fork 0
[WIP] add hip-sys #3
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
Draft
chriscai-amd
wants to merge
2
commits into
amd/rdma
Choose a base branch
from
chcai/rdma
base: amd/rdma
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 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 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,16 @@ | ||
| [package] | ||
| name = "hip-sys" | ||
| version = "0.0.0" | ||
| authors = ["Facebook"] | ||
| edition = "2021" | ||
| license = "MIT" | ||
| links = "hip" | ||
| description = "Rust FFI bindings for HIP libraries" | ||
|
|
||
| [dependencies] | ||
| cxx = "1.0.119" | ||
| serde = { version = "1.0.185", features = ["derive", "rc"] } | ||
|
|
||
| [build-dependencies] | ||
| bindgen = "0.70.1" | ||
| build_utils = { path = "../build_utils" } |
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,107 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| use std::env; | ||
| use std::path::PathBuf; | ||
|
|
||
| use build_utils; | ||
| #[cfg(target_os = "macos")] | ||
| fn main() {} | ||
|
|
||
| #[cfg(not(target_os = "macos"))] | ||
| fn main() { | ||
| // Validate CUDA installation and get CUDA home path | ||
| // let cuda_home = match build_utils::validate_cuda_installation() { | ||
| // Ok(home) => home, | ||
| // Err(_) => { | ||
| // build_utils::print_cuda_error_help(); | ||
| // std::process::exit(1); | ||
| // } | ||
| // }; | ||
| let hip_home = "/opt/rocm"; | ||
|
|
||
| // Start building the bindgen configuration | ||
| let mut builder = bindgen::Builder::default() | ||
| // The input header we would like to generate bindings for | ||
| .header("src/wrapper.h") | ||
| .clang_arg("-x") | ||
| .clang_arg("c++") | ||
| .clang_arg("-std=gnu++20") | ||
| .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) | ||
| // Allow the specified functions and types | ||
| .allowlist_function("hip.*") | ||
| .allowlist_function("HIP.*") | ||
| .allowlist_type("hip.*") | ||
| .allowlist_type("HIP.*") | ||
| // Use newtype enum style | ||
| .default_enum_style(bindgen::EnumVariation::NewType { | ||
| is_bitfield: false, | ||
| is_global: false, | ||
| }); | ||
|
|
||
| // Add HIP include path (we already validated it exists) | ||
| let hip_include_path = format!("{}/include", hip_home); | ||
| builder = builder.clang_arg(format!("-I{}", hip_include_path)); | ||
|
|
||
| // Include headers and libs from the active environment. | ||
| let python_config = match build_utils::python_env_dirs_with_interpreter("python3") { | ||
| Ok(config) => config, | ||
| Err(_) => { | ||
| eprintln!("Warning: Failed to get Python environment directories"); | ||
| build_utils::PythonConfig { | ||
| include_dir: None, | ||
| lib_dir: None, | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| if let Some(include_dir) = &python_config.include_dir { | ||
| builder = builder.clang_arg(format!("-I{}", include_dir)); | ||
| } | ||
| if let Some(lib_dir) = &python_config.lib_dir { | ||
| println!("cargo::rustc-link-search=native={}", lib_dir); | ||
| // Set cargo metadata to inform dependent binaries about how to set their | ||
| // RPATH (see controller/build.rs for an example). | ||
| println!("cargo::metadata=LIB_PATH={}", lib_dir); | ||
| } | ||
|
|
||
| // Get CUDA library directory and emit link directives | ||
| // let cuda_lib_dir = match build_utils::get_cuda_lib_dir() { | ||
| // Ok(dir) => dir, | ||
| // Err(_) => { | ||
| // build_utils::print_cuda_lib_error_help(); | ||
| // std::process::exit(1); | ||
| // } | ||
| // }; | ||
| let hip_lib_dir ="/opt/rocm/lib"; | ||
|
|
||
| println!("cargo:rustc-link-search=native={}", hip_lib_dir); | ||
| // println!("cargo:rustc-link-lib=cuda"); | ||
| // println!("cargo:rustc-link-lib=cudart"); | ||
| println!("cargo:rustc-link-lib=hip"); | ||
|
|
||
| // Write the bindings to the $OUT_DIR/bindings.rs file | ||
| match env::var("OUT_DIR") { | ||
| Ok(out_dir) => { | ||
| let out_path = PathBuf::from(out_dir); | ||
| match builder.generate() { | ||
| Ok(bindings) => match bindings.write_to_file(out_path.join("bindings.rs")) { | ||
| Ok(_) => { | ||
| println!("cargo::rustc-cfg=cargo"); | ||
| println!("cargo::rustc-check-cfg=cfg(cargo)"); | ||
| } | ||
| Err(e) => eprintln!("Warning: Couldn't write bindings: {}", e), | ||
| }, | ||
| Err(e) => eprintln!("Warning: Unable to generate bindings: {}", e), | ||
| } | ||
| } | ||
| Err(_) => { | ||
| println!("Note: OUT_DIR not set, skipping bindings file generation"); | ||
| } | ||
| } | ||
| } |
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,53 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| use cxx::ExternType; | ||
| use cxx::type_id; | ||
|
|
||
| /// SAFETY: bindings | ||
| unsafe impl ExternType for hipStream_t { | ||
| type Id = type_id!("hipStream_t"); | ||
| type Kind = cxx::kind::Opaque; | ||
| } | ||
|
|
||
| // When building with cargo, this is actually the lib.rs file for a crate. | ||
| // Include the generated bindings.rs and suppress lints. | ||
| #[allow(non_camel_case_types)] | ||
| #[allow(non_upper_case_globals)] | ||
| #[allow(non_snake_case)] | ||
| mod inner { | ||
| #[cfg(cargo)] | ||
| include!(concat!(env!("OUT_DIR"), "/bindings.rs")); | ||
| } | ||
|
|
||
| pub use inner::*; | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use std::mem::MaybeUninit; | ||
|
|
||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn sanity() { | ||
| // SAFETY: testing bindings | ||
| unsafe { | ||
| let mut version = MaybeUninit::<i32>::uninit(); | ||
| let result = hipDriverGetVersion(version.as_mut_ptr()); | ||
| assert_eq!(result, hipError_t(0)); | ||
| } | ||
| } | ||
| } |
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,11 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <hip/hip_runtime.h> | ||
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 |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| #include "hip/hip_runtime.h" | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * All rights reserved. | ||
|
|
||
Oops, something went wrong.
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.
hipStream_t should be included here @mreso