Skip to content

Commit

Permalink
Remove arch from each Arch implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
n0gu-furiosa committed Apr 16, 2024
1 parent e3aa449 commit 5391f82
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
10 changes: 6 additions & 4 deletions device-api/src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ impl Arch {
sysfs: &str,
) -> DeviceResult<Box<dyn DeviceInner>> {
match self {
Arch::WarboyB0 => WarboyInner::new(*self, idx, sysfs.into())
.map(|t| Box::new(t) as Box<dyn DeviceInner>),
Arch::Renegade => RenegadeInner::new(*self, idx, sysfs.into())
.map(|t| Box::new(t) as Box<dyn DeviceInner>),
Arch::WarboyB0 => {
WarboyInner::new(idx, sysfs.into()).map(|t| Box::new(t) as Box<dyn DeviceInner>)
}
Arch::Renegade => {
RenegadeInner::new(idx, sysfs.into()).map(|t| Box::new(t) as Box<dyn DeviceInner>)
}
}
}

Expand Down
9 changes: 3 additions & 6 deletions device-api/src/arch/renegade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,20 @@ use crate::DeviceError;

#[derive(Clone, Debug)]
pub struct RenegadeInner {
arch: Arch,
devfile_index: u8,
sysfs: PathBuf,
mgmt_root: PathBuf,
mgmt_cache: MgmtCache<StaticMgmtFile>,
}

impl RenegadeInner {
pub fn new(arch: Arch, devfile_index: u8, sysfs: PathBuf) -> DeviceResult<Self> {
pub fn new(devfile_index: u8, sysfs: PathBuf) -> DeviceResult<Self> {
let mgmt_root = sysfs.join(format!(
"class/renegade_mgmt/renegade!npu{devfile_index}mgmt"
));
let mgmt_cache = MgmtCache::init(&mgmt_root, StaticMgmtFile::iter())?;

Ok(RenegadeInner {
arch,
devfile_index,
sysfs,
mgmt_root,
Expand Down Expand Up @@ -80,7 +78,7 @@ impl DeviceMgmt for RenegadeInner {

#[inline]
fn arch(&self) -> Arch {
self.arch
Arch::Renegade
}

fn name(&self) -> String {
Expand Down Expand Up @@ -171,8 +169,7 @@ mod tests {

#[test]
fn test_renegade_inner_functionality() -> eyre::Result<()> {
let device =
RenegadeInner::new(Arch::Renegade, 0, PathBuf::from("../test_data/test-1/sys"))?;
let device = RenegadeInner::new(0, PathBuf::from("../test_data/test-1/sys"))?;

assert_eq!(device.devfile_index(), 0);
assert_eq!(device.arch(), Arch::Renegade);
Expand Down
9 changes: 4 additions & 5 deletions device-api/src/arch/warboy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@ use crate::{Arch, ClockFrequency, DeviceError, DeviceFile};

#[derive(Clone, Debug)]
pub struct WarboyInner {
arch: Arch,
devfile_index: u8,
sysfs: PathBuf,
mgmt_root: PathBuf,
mgmt_cache: MgmtCache<StaticMgmtFile>,
}

impl WarboyInner {
pub fn new(arch: Arch, devfile_index: u8, sysfs: PathBuf) -> DeviceResult<Self> {
pub fn new(devfile_index: u8, sysfs: PathBuf) -> DeviceResult<Self> {
let mgmt_root = sysfs.join(format!("class/npu_mgmt/npu{devfile_index}_mgmt"));
let mgmt_cache = MgmtCache::init(&mgmt_root, StaticMgmtFile::iter())?;

Ok(WarboyInner {
arch,
devfile_index,
sysfs,
mgmt_root,
Expand Down Expand Up @@ -75,8 +73,9 @@ impl DeviceMgmt for WarboyInner {
self.devfile_index
}

#[inline]
fn arch(&self) -> Arch {
self.arch
Arch::WarboyB0
}

fn name(&self) -> String {
Expand Down Expand Up @@ -176,7 +175,7 @@ mod tests {

#[test]
fn test_warboy_inner_functionality() -> eyre::Result<()> {
let device = WarboyInner::new(Arch::WarboyB0, 0, PathBuf::from("../test_data/test-1/sys"))?;
let device = WarboyInner::new(0, PathBuf::from("../test_data/test-1/sys"))?;

assert_eq!(device.devfile_index(), 0);
assert_eq!(device.arch(), Arch::WarboyB0);
Expand Down

0 comments on commit 5391f82

Please sign in to comment.