Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Dec 31, 2024
2 parents 1d54cc0 + 94089e5 commit 49e1438
Show file tree
Hide file tree
Showing 22 changed files with 1,481 additions and 149 deletions.
72 changes: 36 additions & 36 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
name: CI

on:
pull_request:
branches: ["main"]
pull_request:
branches: ["main"]

env:
CARGO_TERM_COLOR: always
CARGO_TERM_COLOR: always

jobs:
test:
name: Test
runs-on: self-hosted
steps:
- uses: actions/checkout@v4

- name: Rust Cache
uses: Swatinem/rust-cache@v2

- name: Check formatting
run: cargo fmt --all -- --check

# - name: Clippy
# run: cargo clippy -- -D warnings

- name: Run tests
run: cargo test --verbose

coverage:
name: Coverage
runs-on: self-hosted
steps:
- uses: actions/checkout@v4

- name: Generate code coverage
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
fail_ci_if_error: true
test:
name: Test
runs-on: self-hosted
steps:
- uses: actions/checkout@v4

- name: Rust Cache
uses: Swatinem/rust-cache@v2

- name: Check formatting
run: cargo fmt --all -- --check

- name: Run tests
run: cargo test --verbose

coverage:
name: Coverage
runs-on: self-hosted
steps:
- uses: actions/checkout@v4

- name: Install cargo-llvm-cov
run: cargo install cargo-llvm-cov

- name: Generate code coverage
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
fail_ci_if_error: true
45 changes: 39 additions & 6 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,60 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: release
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Run release-plz
uses: release-plz/action@v0.5
with:
ref: release
command: release-pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_TOKEN }}

docs:
runs-on: self-hosted
build_docs:
name: Build Docs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: release
- name: Generate Docs
run: cargo doc --no-deps --document-private-items
- name: Add index.html
run: |
echo '<meta http-equiv="refresh" content="0; url=your_crate_name/index.html">' > target/doc/index.html
echo '<meta http-equiv="refresh" content="0; url=hip-rs/index.html">' > target/doc/index.html
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Configure cache
uses: Swatinem/rust-cache@v2
- name: Setup pages
id: pages
uses: actions/configure-pages@v5
- name: Clean docs folder
run: cargo clean --doc
- name: Build docs
run: cargo doc --no-deps
- name: Add redirect
run: echo '<meta http-equiv="refresh" content="0;url=hip-rs/index.html">' > target/doc/index.html
- name: Remove lock file
run: rm target/doc/.lock
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./target/doc
path: target/doc
deploy_docs:
name: Deploy Docs
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hip-rs"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
authors = ["Anders Smedegaard Pedersen <anders@smedegaard.io>"]
description = "A Rust wrapper for AMD's Heterogeneous-computing Interface for Portability (HIP), used for GPU interop."
Expand Down
5 changes: 4 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ fn main() {
return;
}

// link hipBLAS
println!("cargo:rustc-link-lib=dylib=hipblas");

// Tell cargo when to rerun this build script
println!("cargo:rerun-if-changed=src/core/sys/wrapper.h");
println!("cargo:rerun-if-changed=build.rs");
Expand All @@ -38,7 +41,7 @@ fn main() {
fn generate_bindings(hip_include_path: &str) {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let bindings = bindgen::Builder::default()
.header("src/core/sys/wrapper.h")
.header("src/sys/wrapper.h")
.clang_arg(&format!("-I{}", hip_include_path))
.clang_arg("-D__HIP_PLATFORM_AMD__")
// Blocklist problematic items
Expand Down
39 changes: 21 additions & 18 deletions src/core/device.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use super::sys;
use super::{DeviceP2PAttribute, HipError, HipErrorKind, HipResult, MemPool, PCIBusId, Result};
#[allow(unused_imports)]
use super::result::{HipError, HipResult, HipStatus};
use super::{DeviceP2PAttribute, MemPool, PCIBusId};
use crate::result::ResultExt;
use crate::sys;
use semver::Version;
use std::ffi::CStr;
use std::i32;
Expand Down Expand Up @@ -42,7 +45,7 @@ impl Device {
/// # Returns
/// * `Result<Version>` - On success, returns a `Version` struct containing the major and minor version
/// numbers of the device's compute capability. On failure, returns an error indicating what went wrong.
pub fn device_compute_capability(&self) -> Result<Version> {
pub fn device_compute_capability(&self) -> HipResult<Version> {
unsafe {
let mut major: i32 = -1;
let mut minor: i32 = -1;
Expand All @@ -61,7 +64,7 @@ impl Device {
/// Returns `HipError` if:
/// * The device is invalid
/// * The runtime is not initialized
pub fn device_total_mem(&self) -> Result<usize> {
pub fn device_total_mem(&self) -> HipResult<usize> {
unsafe {
let mut size: usize = 0;
let code = sys::hipDeviceTotalMem(&mut size, self.id);
Expand All @@ -80,7 +83,7 @@ impl Device {
/// * The device ID is invalid
/// * There was an error retrieving the device name
/// * The name string could not be converted to valid UTF-8
pub fn get_device_name(&self) -> Result<String> {
pub fn get_device_name(&self) -> HipResult<String> {
const buffer_size: usize = 64;
let mut buffer = vec![0i8; buffer_size];

Expand All @@ -105,7 +108,7 @@ impl Device {
/// * The device is invalid
/// * The runtime is not initialized
/// * There was an error retrieving the UUID
fn get_device_uuid_bytes(&self) -> Result<[i8; 16]> {
fn get_device_uuid_bytes(&self) -> HipResult<[i8; 16]> {
let mut hip_bytes = sys::hipUUID_t { bytes: [0; 16] };
unsafe {
let code = sys::hipDeviceGetUuid(&mut hip_bytes, self.id);
Expand All @@ -128,7 +131,7 @@ impl Device {
/// * The device is invalid
/// * The runtime is not initialized
/// * There was an error retrieving the UUID
pub fn get_device_uuid(&self) -> Result<Uuid> {
pub fn get_device_uuid(&self) -> HipResult<Uuid> {
Self::get_device_uuid_bytes(self).map(|bytes| {
let uuid_bytes: [u8; 16] = bytes.map(|b| b as u8);
Uuid::from_bytes(uuid_bytes)
Expand All @@ -148,7 +151,7 @@ impl Device {
/// * The device is invalid
/// * The runtime is not initialized
/// * There was an error retrieving the PCI bus ID
pub fn get_device_pci_bus_id(&self) -> Result<PCIBusId> {
pub fn get_device_pci_bus_id(&self) -> HipResult<PCIBusId> {
let mut pci_bus_id = PCIBusId::new();
unsafe {
let code =
Expand All @@ -167,7 +170,7 @@ impl Device {
/// * The device ID is invalid
/// * The operation is not supported on this device/platform
/// * There was an error retrieving the memory pool
pub fn get_default_mem_pool(&self) -> Result<MemPool> {
pub fn get_default_mem_pool(&self) -> HipResult<MemPool> {
let mut mem_pool = std::ptr::null_mut();
unsafe {
let code = sys::hipDeviceGetDefaultMemPool(&mut mem_pool, self.id);
Expand All @@ -191,7 +194,7 @@ impl Device {
/// Returns `HipError` if:
/// * No device is currently active
/// * The HIP runtime is not initialized
pub fn synchronize() -> Result<()> {
pub fn synchronize() -> HipResult<()> {
unsafe {
let code = sys::hipDeviceSynchronize();
((), code).to_result()
Expand All @@ -207,7 +210,7 @@ pub fn synchronize() -> Result<()> {
/// Returns `HipError` if:
/// * The runtime is not initialized (`HipErrorKind::NotInitialized`)
/// * The operation fails for other reasons
pub fn get_device_count() -> Result<i32> {
pub fn get_device_count() -> HipResult<i32> {
unsafe {
let mut count = 0;
let code = sys::hipGetDeviceCount(&mut count);
Expand Down Expand Up @@ -239,7 +242,7 @@ pub fn get_device_p2p_attribute(
attr: DeviceP2PAttribute,
src_device: Device,
dst_device: Device,
) -> Result<i32> {
) -> HipResult<i32> {
let mut value = -1;
unsafe {
let code =
Expand All @@ -260,7 +263,7 @@ pub fn get_device_p2p_attribute(
/// * No device is currently active
/// * HIP runtime is not initialized
/// * There was an error accessing device information
pub fn get_device() -> Result<Device> {
pub fn get_device() -> HipResult<Device> {
unsafe {
let mut device_id: i32 = -1;
let code = sys::hipGetDevice(&mut device_id);
Expand All @@ -285,7 +288,7 @@ pub fn get_device() -> Result<Device> {
/// * The device ID is invalid (greater than or equal to device count)
/// * The HIP runtime is not initialized
/// * The specified device has encountered a previous error and is in a broken state
pub fn set_device(device: Device) -> Result<Device> {
pub fn set_device(device: Device) -> HipResult<Device> {
unsafe {
let code = sys::hipSetDevice(device.id);
(device, code).to_result()
Expand All @@ -305,7 +308,7 @@ pub fn set_device(device: Device) -> Result<Device> {
/// * The PCI bus ID string is invalid
/// * No device with the specified PCI bus ID exists
/// * The runtime is not initialized
pub fn get_device_by_pci_bus_id(mut pci_bus_id: PCIBusId) -> Result<Device> {
pub fn get_device_by_pci_bus_id(mut pci_bus_id: PCIBusId) -> HipResult<Device> {
let mut device_id = i32::MAX;
unsafe {
let code = sys::hipDeviceGetByPCIBusId(&mut device_id, pci_bus_id.as_mut_ptr());
Expand All @@ -330,7 +333,7 @@ mod tests {
}
Err(e) => {
// Check if the error is "not supported" which is acceptable
if e.kind != HipErrorKind::NotSupported {
if e.status != HipStatus::NotSupported {
panic!("Unexpected error getting default memory pool: {:?}", e);
}
println!("Memory pools not supported on this device/platform");
Expand Down Expand Up @@ -369,7 +372,7 @@ mod tests {
let invalid_device = Device::new(99);
let result = invalid_device.get_device_pci_bus_id();
assert!(result.is_err());
assert_eq!(result.unwrap_err().kind, HipErrorKind::InvalidDevice);
assert_eq!(result.unwrap_err().status, HipStatus::InvalidDevice);
}

#[test]
Expand Down Expand Up @@ -452,6 +455,6 @@ mod tests {
let invalid_device = Device::new(99);
let result = set_device(invalid_device);
assert!(result.is_err());
assert_eq!(result.unwrap_err().kind, HipErrorKind::InvalidDevice);
assert_eq!(result.unwrap_err().status, HipStatus::InvalidDevice);
}
}
9 changes: 5 additions & 4 deletions src/core/device_types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::sys;
use super::{HipError, HipErrorKind, HipResult, Result};
#[allow(unused_imports)]
use super::result::{HipError, HipResult, HipStatus};
use crate::sys;
use std::ffi::CStr;
use std::i32;

Expand Down Expand Up @@ -86,7 +87,7 @@ impl From<DeviceP2PAttribute> for u32 {
impl TryFrom<u32> for DeviceP2PAttribute {
type Error = HipError;

fn try_from(value: sys::hipDeviceP2PAttr) -> Result<Self> {
fn try_from(value: sys::hipDeviceP2PAttr) -> Result<Self, Self::Error> {
match value {
sys::hipDeviceP2PAttr_hipDevP2PAttrPerformanceRank => Ok(Self::PerformanceRank),
sys::hipDeviceP2PAttr_hipDevP2PAttrAccessSupported => Ok(Self::AccessSupported),
Expand All @@ -96,7 +97,7 @@ impl TryFrom<u32> for DeviceP2PAttribute {
sys::hipDeviceP2PAttr_hipDevP2PAttrHipArrayAccessSupported => {
Ok(Self::HipArrayAccessSupported)
}
_ => Err(HipError::from_kind(HipErrorKind::InvalidValue)),
_ => Err(HipError::from_status(HipStatus::InvalidValue)),
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/core/hip_call.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
use super::{sys, HipResult, Result};
#[allow(unused_imports)]
use {
super::result::{HipResult, HipStatus},
crate::result::ResultExt,
crate::sys,
};

#[macro_export]
macro_rules! hip_call {
($call:expr) => {{
let code = unsafe { $call };
((), code).to_result()
let code: u32 = unsafe { $call };
let result: HipResult<()> = ((), code).to_result();
result
}};
}

Expand Down
Loading

0 comments on commit 49e1438

Please sign in to comment.