mirror of
https://github.com/vosen/ZLUDA.git
synced 2025-04-28 13:37:57 +03:00
Implement enough nvml to make GeekBench happy
This commit is contained in:
parent
871b8d1bef
commit
b7ee6d66c3
7 changed files with 3335 additions and 2 deletions
|
@ -10,10 +10,11 @@ members = [
|
|||
"zluda_lib",
|
||||
"zluda_inject",
|
||||
"zluda_redirect",
|
||||
"zluda_ml",
|
||||
"ptx",
|
||||
]
|
||||
|
||||
default-members = ["zluda_lib", "zluda_inject", "zluda_redirect"]
|
||||
default-members = ["zluda_lib", "zluda_ml", "zluda_inject", "zluda_redirect"]
|
||||
|
||||
[patch.crates-io]
|
||||
rspirv = { git = 'https://github.com/vosen/rspirv', rev = '40f5aa4dedb0d9f1ec24bdd8b6019e01996d1d74' }
|
||||
|
|
|
@ -81,6 +81,12 @@ impl Driver {
|
|||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn get_properties(&self) -> Result<sys::ze_driver_properties_t> {
|
||||
let mut result = unsafe { mem::zeroed::<sys::ze_driver_properties_t>() };
|
||||
check!(sys::zeDriverGetProperties(self.0, &mut result));
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
|
@ -359,7 +365,11 @@ impl Module {
|
|||
Module::new_logged(ctx, true, d, bin, opts)
|
||||
}
|
||||
|
||||
pub fn build_native_logged(ctx: &mut Context, d: &Device, bin: &[u8]) -> (Result<Self>, BuildLog) {
|
||||
pub fn build_native_logged(
|
||||
ctx: &mut Context,
|
||||
d: &Device,
|
||||
bin: &[u8],
|
||||
) -> (Result<Self>, BuildLog) {
|
||||
Module::new_logged(ctx, false, d, bin, None)
|
||||
}
|
||||
|
||||
|
|
12
zluda_ml/Cargo.toml
Normal file
12
zluda_ml/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "zluda_ml"
|
||||
version = "0.0.0"
|
||||
authors = ["Andrzej Janik <vosen@vosen.pl>"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
name = "nvml"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
level_zero = { path = "../level_zero" }
|
3
zluda_ml/README
Normal file
3
zluda_ml/README
Normal file
|
@ -0,0 +1,3 @@
|
|||
bindgen "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\include\nvml.h" --whitelist-function="^nvml.*" --size_t-is-usize --default-enum-style=newtype --no-layout-tests --no-doc-comments --no-derive-debug -o src/nvml.rs
|
||||
sed -i -e 's/extern "C" {//g' -e 's/-> nvmlReturn_t;/-> nvmlReturn_t { impl_::unsupported()/g' -e 's/pub fn /#[no_mangle] pub extern "C" fn /g' src/nvml.rs
|
||||
rustfmt src/nvml.rs
|
138
zluda_ml/src/impl.rs
Normal file
138
zluda_ml/src/impl.rs
Normal file
|
@ -0,0 +1,138 @@
|
|||
use level_zero as l0;
|
||||
use std::{io::Write, ops::Add};
|
||||
use std::{
|
||||
os::raw::{c_char, c_uint},
|
||||
ptr,
|
||||
};
|
||||
|
||||
use crate::nvml::nvmlReturn_t;
|
||||
|
||||
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!()
|
||||
}
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
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
|
||||
}
|
||||
|
||||
pub(crate) fn init_v2() -> Result<(), nvmlReturn_t> {
|
||||
Ok(l0::init()?)
|
||||
}
|
||||
|
||||
pub(crate) fn init_with_flags() -> Result<(), nvmlReturn_t> {
|
||||
init_v2()
|
||||
}
|
||||
|
||||
impl From<l0::sys::ze_result_t> for nvmlReturn_t {
|
||||
fn from(l0_err: l0::sys::ze_result_t) -> Self {
|
||||
match l0_err {
|
||||
l0::sys::ze_result_t::ZE_RESULT_ERROR_UNINITIALIZED => {
|
||||
nvmlReturn_t::NVML_ERROR_UNINITIALIZED
|
||||
}
|
||||
_ => nvmlReturn_t::NVML_ERROR_UNKNOWN,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Result<(), nvmlReturn_t>> for nvmlReturn_t {
|
||||
fn from(result: Result<(), nvmlReturn_t>) -> Self {
|
||||
match result {
|
||||
Ok(()) => nvmlReturn_t::NVML_SUCCESS,
|
||||
Err(e) => e,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct CountingWriter<T: std::io::Write> {
|
||||
pub base: T,
|
||||
pub len: usize,
|
||||
}
|
||||
|
||||
impl<T: std::io::Write> std::io::Write for CountingWriter<T> {
|
||||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
||||
self.len += buf.len();
|
||||
self.base.write(buf)
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> std::io::Result<()> {
|
||||
self.base.flush()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn system_get_driver_version(
|
||||
version_ptr: *mut c_char,
|
||||
length: c_uint,
|
||||
) -> Result<(), nvmlReturn_t> {
|
||||
if version_ptr == ptr::null_mut() {
|
||||
return Err(nvmlReturn_t::NVML_ERROR_INVALID_ARGUMENT);
|
||||
}
|
||||
let drivers = l0::Driver::get()?;
|
||||
let output_slice =
|
||||
unsafe { std::slice::from_raw_parts_mut(version_ptr as *mut u8, (length - 1) as usize) };
|
||||
let mut output_write = CountingWriter {
|
||||
base: output_slice,
|
||||
len: 0,
|
||||
};
|
||||
for d in drivers {
|
||||
let props = d.get_properties()?;
|
||||
let driver_version = props.driverVersion;
|
||||
write!(&mut output_write, "{}", driver_version)
|
||||
.map_err(|_| nvmlReturn_t::NVML_ERROR_UNKNOWN)?;
|
||||
unsafe { *(version_ptr.add(output_write.len)) = 0 };
|
||||
return Ok(());
|
||||
}
|
||||
Err(nvmlReturn_t::NVML_ERROR_UNKNOWN)
|
||||
}
|
3
zluda_ml/src/lib.rs
Normal file
3
zluda_ml/src/lib.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
pub mod r#impl;
|
||||
#[allow(warnings)]
|
||||
mod nvml;
|
3166
zluda_ml/src/nvml.rs
Normal file
3166
zluda_ml/src/nvml.rs
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue