1use pyo3::prelude::*;
4use std::env;
5
6use pyo3::exceptions::PyRuntimeError;
7use nvml_wrapper::error::NvmlError;
8use nvml_wrapper::{cuda_driver_version_major, cuda_driver_version_minor, Nvml};
9use pretty_bytes::converter::convert;
10
11#[pyfunction]
12fn device_info() -> PyResult<String>{
13let nvml = Nvml::init().map_err(|e| PyRuntimeError::new_err(format!("NVML Init Error: {}", e)))?;
15
16 let cuda_version = nvml.sys_cuda_driver_version().map_err(|e| PyRuntimeError::new_err(format!("CUDA Version Error: {}", e)))?;
18
19 let device = nvml.device_by_index(0).map_err(|e| PyRuntimeError::new_err(format!("Device Index Error: {}", e)))?;
21
22 let name = device.name().map_err(|e| PyRuntimeError::new_err(format!("Device Name Error: {}", e)))?;
24
25 Ok(name)
26}
27
28#[pyfunction]
30fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
31 Ok((a + b).to_string())
32}
33
34#[pyfunction]
36fn sub_as_string(a: usize, b: usize) -> PyResult<String> {
37 Ok((a - b).to_string())
38}
39
40
41#[pymodule]
47fn _lib(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
48 m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
49 m.add_function(wrap_pyfunction!(sub_as_string, m)?)?;
50 m.add_function(wrap_pyfunction!(device_info, m)?)?;
51 Ok(())
52}