From 5391f82f2c882c2274eee473cab648f310c05f2e Mon Sep 17 00:00:00 2001 From: Sungyoon Jeong Date: Tue, 16 Apr 2024 17:58:27 +0900 Subject: [PATCH] Remove `arch` from each Arch implementations --- device-api/src/arch/mod.rs | 10 ++++++---- device-api/src/arch/renegade.rs | 9 +++------ device-api/src/arch/warboy.rs | 9 ++++----- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/device-api/src/arch/mod.rs b/device-api/src/arch/mod.rs index b6cf4c0..75678ad 100644 --- a/device-api/src/arch/mod.rs +++ b/device-api/src/arch/mod.rs @@ -38,10 +38,12 @@ impl Arch { sysfs: &str, ) -> DeviceResult> { match self { - Arch::WarboyB0 => WarboyInner::new(*self, idx, sysfs.into()) - .map(|t| Box::new(t) as Box), - Arch::Renegade => RenegadeInner::new(*self, idx, sysfs.into()) - .map(|t| Box::new(t) as Box), + Arch::WarboyB0 => { + WarboyInner::new(idx, sysfs.into()).map(|t| Box::new(t) as Box) + } + Arch::Renegade => { + RenegadeInner::new(idx, sysfs.into()).map(|t| Box::new(t) as Box) + } } } diff --git a/device-api/src/arch/renegade.rs b/device-api/src/arch/renegade.rs index de28749..fe0a107 100644 --- a/device-api/src/arch/renegade.rs +++ b/device-api/src/arch/renegade.rs @@ -14,7 +14,6 @@ use crate::DeviceError; #[derive(Clone, Debug)] pub struct RenegadeInner { - arch: Arch, devfile_index: u8, sysfs: PathBuf, mgmt_root: PathBuf, @@ -22,14 +21,13 @@ pub struct RenegadeInner { } impl RenegadeInner { - pub fn new(arch: Arch, devfile_index: u8, sysfs: PathBuf) -> DeviceResult { + pub fn new(devfile_index: u8, sysfs: PathBuf) -> DeviceResult { 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, @@ -80,7 +78,7 @@ impl DeviceMgmt for RenegadeInner { #[inline] fn arch(&self) -> Arch { - self.arch + Arch::Renegade } fn name(&self) -> String { @@ -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); diff --git a/device-api/src/arch/warboy.rs b/device-api/src/arch/warboy.rs index 079bffe..a5c0047 100644 --- a/device-api/src/arch/warboy.rs +++ b/device-api/src/arch/warboy.rs @@ -13,7 +13,6 @@ use crate::{Arch, ClockFrequency, DeviceError, DeviceFile}; #[derive(Clone, Debug)] pub struct WarboyInner { - arch: Arch, devfile_index: u8, sysfs: PathBuf, mgmt_root: PathBuf, @@ -21,12 +20,11 @@ pub struct WarboyInner { } impl WarboyInner { - pub fn new(arch: Arch, devfile_index: u8, sysfs: PathBuf) -> DeviceResult { + pub fn new(devfile_index: u8, sysfs: PathBuf) -> DeviceResult { 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, @@ -75,8 +73,9 @@ impl DeviceMgmt for WarboyInner { self.devfile_index } + #[inline] fn arch(&self) -> Arch { - self.arch + Arch::WarboyB0 } fn name(&self) -> String { @@ -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);