From b99cfc7fd238c8680904922ff82b710394d418c7 Mon Sep 17 00:00:00 2001 From: Andrzej Janik Date: Fri, 15 Nov 2024 15:12:34 +0000 Subject: Fix building zluda_ml --- zluda_ml/Cargo.toml | 6 +-- zluda_ml/src/impl.rs | 134 --------------------------------------------------- zluda_ml/src/nvml.rs | 12 ++--- 3 files changed, 7 insertions(+), 145 deletions(-) diff --git a/zluda_ml/Cargo.toml b/zluda_ml/Cargo.toml index 4c540b4..d2e2378 100644 --- a/zluda_ml/Cargo.toml +++ b/zluda_ml/Cargo.toml @@ -2,12 +2,8 @@ name = "zluda_ml" version = "0.0.0" authors = ["Andrzej Janik "] -edition = "2018" +edition = "2021" [lib] name = "nvml" crate-type = ["cdylib"] - -[dependencies.ocl-core] -version = "0.11" -features = ["opencl_version_1_2", "opencl_version_2_0", "opencl_version_2_1"] \ No newline at end of file diff --git a/zluda_ml/src/impl.rs b/zluda_ml/src/impl.rs index 2f82008..35f3778 100644 --- a/zluda_ml/src/impl.rs +++ b/zluda_ml/src/impl.rs @@ -1,23 +1,5 @@ -use std::{ - os::raw::{c_char, c_uint}, - ptr, -}; - use crate::nvml::nvmlReturn_t; -const VERSION: &'static [u8] = b"418.40.04"; - -macro_rules! stringify_nmvlreturn_t { - ($x:ident => [ $($variant:ident),+ ]) => { - match $x { - $( - nvmlReturn_t::$variant => Some(concat!(stringify!($variant), "\0")), - )+ - _ => None - } - } -} - #[cfg(debug_assertions)] pub(crate) fn unimplemented() -> nvmlReturn_t { unimplemented!() @@ -27,119 +9,3 @@ pub(crate) fn unimplemented() -> nvmlReturn_t { pub(crate) fn unimplemented() -> nvmlReturn_t { nvmlReturn_t::NVML_ERROR_NOT_SUPPORTED } - -pub(crate) fn error_string(result: nvmlReturn_t) -> *const ::std::os::raw::c_char { - let text = stringify_nmvlreturn_t!( - result => [ - NVML_SUCCESS, - NVML_ERROR_UNINITIALIZED, - NVML_ERROR_INVALID_ARGUMENT, - NVML_ERROR_NOT_SUPPORTED, - NVML_ERROR_NO_PERMISSION, - NVML_ERROR_ALREADY_INITIALIZED, - NVML_ERROR_NOT_FOUND, - NVML_ERROR_INSUFFICIENT_SIZE, - NVML_ERROR_INSUFFICIENT_POWER, - NVML_ERROR_DRIVER_NOT_LOADED, - NVML_ERROR_TIMEOUT, - NVML_ERROR_IRQ_ISSUE, - NVML_ERROR_LIBRARY_NOT_FOUND, - NVML_ERROR_FUNCTION_NOT_FOUND, - NVML_ERROR_CORRUPTED_INFOROM, - NVML_ERROR_GPU_IS_LOST, - NVML_ERROR_RESET_REQUIRED, - NVML_ERROR_OPERATING_SYSTEM, - NVML_ERROR_LIB_RM_VERSION_MISMATCH, - NVML_ERROR_IN_USE, - NVML_ERROR_MEMORY, - NVML_ERROR_NO_DATA, - NVML_ERROR_VGPU_ECC_NOT_SUPPORTED, - NVML_ERROR_INSUFFICIENT_RESOURCES, - NVML_ERROR_UNKNOWN - ] - ); - match text { - Some(text) => text.as_ptr() as *const _, - None => ptr::null(), - } -} - -pub(crate) fn shutdown() -> nvmlReturn_t { - nvmlReturn_t::NVML_SUCCESS -} - -static mut DEVICE: Option = None; - -pub(crate) fn init() -> Result<(), nvmlReturn_t> { - let platforms = ocl_core::get_platform_ids()?; - let device = platforms.iter().find_map(|plat| { - let devices = ocl_core::get_device_ids(plat, Some(ocl_core::DeviceType::GPU), None).ok()?; - for dev in devices { - let vendor = ocl_core::get_device_info(dev, ocl_core::DeviceInfo::VendorId).ok()?; - match vendor { - ocl_core::DeviceInfoResult::VendorId(0x8086) - | ocl_core::DeviceInfoResult::VendorId(0x1002) => {} - _ => continue, - }; - let dev_type = ocl_core::get_device_info(dev, ocl_core::DeviceInfo::Type).ok()?; - if let ocl_core::DeviceInfoResult::Type(ocl_core::DeviceType::GPU) = dev_type { - return Some(dev); - } - } - None - }); - unsafe { DEVICE = device }; - if device.is_some() { - Ok(()) - } else { - Err(nvmlReturn_t::NVML_ERROR_UNKNOWN) - } -} - -pub(crate) fn init_with_flags() -> Result<(), nvmlReturn_t> { - init() -} - -impl From for nvmlReturn_t { - fn from(_: ocl_core::Error) -> Self { - nvmlReturn_t::NVML_ERROR_UNKNOWN - } -} - -impl From> for nvmlReturn_t { - fn from(result: Result<(), nvmlReturn_t>) -> Self { - match result { - Ok(()) => nvmlReturn_t::NVML_SUCCESS, - Err(e) => e, - } - } -} - -struct CountingWriter { - pub base: T, - pub len: usize, -} - -impl std::io::Write for CountingWriter { - fn write(&mut self, buf: &[u8]) -> std::io::Result { - self.len += buf.len(); - self.base.write(buf) - } - - fn flush(&mut self) -> std::io::Result<()> { - self.base.flush() - } -} - -pub(crate) unsafe fn system_get_driver_version( - version_ptr: *mut c_char, - length: c_uint, -) -> Result<(), nvmlReturn_t> { - if version_ptr == ptr::null_mut() || length == 0 { - return Err(nvmlReturn_t::NVML_ERROR_INVALID_ARGUMENT); - } - let strlen = usize::min(VERSION.len(), (length as usize) - 1); - std::ptr::copy_nonoverlapping(VERSION.as_ptr(), version_ptr as _, strlen); - *version_ptr.add(strlen) = 0; - Ok(()) -} diff --git a/zluda_ml/src/nvml.rs b/zluda_ml/src/nvml.rs index cab546a..0358bc6 100644 --- a/zluda_ml/src/nvml.rs +++ b/zluda_ml/src/nvml.rs @@ -1131,27 +1131,27 @@ pub use self::nvmlPcieLinkState_enum as nvmlPcieLinkState_t; #[no_mangle] pub extern "C" fn nvmlInit_v2() -> nvmlReturn_t { - crate::r#impl::init().into() + crate::r#impl::unimplemented() } #[no_mangle] pub extern "C" fn nvmlInit() -> nvmlReturn_t { - crate::r#impl::init().into() + crate::r#impl::unimplemented() } #[no_mangle] pub extern "C" fn nvmlInitWithFlags(flags: ::std::os::raw::c_uint) -> nvmlReturn_t { - crate::r#impl::init_with_flags().into() + crate::r#impl::unimplemented() } #[no_mangle] pub extern "C" fn nvmlShutdown() -> nvmlReturn_t { - crate::r#impl::shutdown() + crate::r#impl::unimplemented() } #[no_mangle] pub extern "C" fn nvmlErrorString(result: nvmlReturn_t) -> *const ::std::os::raw::c_char { - crate::r#impl::error_string(result) + c"".as_ptr() } #[no_mangle] @@ -1159,7 +1159,7 @@ pub unsafe extern "C" fn nvmlSystemGetDriverVersion( version: *mut ::std::os::raw::c_char, length: ::std::os::raw::c_uint, ) -> nvmlReturn_t { - crate::r#impl::system_get_driver_version(version, length).into() + crate::r#impl::unimplemented() } #[no_mangle] -- cgit v1.2.3