mirror of
https://github.com/pykeio/ort
synced 2026-04-25 16:34:55 +02:00
chore: use 2024 edition Rust
This commit is contained in:
4
.github/workflows/code-quality.yml
vendored
4
.github/workflows/code-quality.yml
vendored
@@ -39,7 +39,7 @@ jobs:
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@nightly
|
||||
with:
|
||||
toolchain: nightly-2025-08-30
|
||||
toolchain: nightly-2025-09-28
|
||||
components: rustfmt, clippy
|
||||
- name: Check fmt
|
||||
run: cargo fmt --all -- --check
|
||||
@@ -55,7 +55,7 @@ jobs:
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@nightly
|
||||
with:
|
||||
toolchain: nightly-2025-08-30
|
||||
toolchain: nightly-2025-09-28
|
||||
- name: Get Rust version
|
||||
id: rust-version
|
||||
run: echo "::set-output name=version::$(cargo --version | cut -d ' ' -f 2)"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
[workspace]
|
||||
resolver = "3"
|
||||
members = [ 'ort-sys' ]
|
||||
default-members = [ '.' ]
|
||||
exclude = [
|
||||
@@ -22,7 +23,7 @@ exclude = [
|
||||
name = "ort"
|
||||
description = "A safe Rust wrapper for ONNX Runtime 1.23 - Optimize and accelerate machine learning inference & training"
|
||||
version = "2.0.0-rc.10"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
rust-version = "1.85"
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/pykeio/ort"
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
name = "ort-candle"
|
||||
description = "ort + candle = 🦀 - An alternative backend for ort, powered by candle."
|
||||
version = "0.2.0+0.9"
|
||||
edition = "2021"
|
||||
rust-version = "1.70"
|
||||
edition = "2024"
|
||||
rust-version = "1.85"
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/pykeio/ort"
|
||||
homepage = "https://ort.pyke.io/backends/candle"
|
||||
@@ -14,7 +14,7 @@ authors = [
|
||||
]
|
||||
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
resolver = "3"
|
||||
members = [ "standalone" ]
|
||||
default-members = []
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name = "ort-candle-standalone"
|
||||
publish = false
|
||||
version = "1.23.1"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[package.metadata.winresource]
|
||||
ProductName = "ONNX Runtime (candle)"
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
name = "ort-tract"
|
||||
description = "ort + tract = 🦀 - An alternative backend for ort, powered by tract."
|
||||
version = "0.2.0+0.22"
|
||||
edition = "2021"
|
||||
rust-version = "1.70"
|
||||
edition = "2024"
|
||||
rust-version = "1.85"
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/pykeio/ort"
|
||||
homepage = "https://ort.pyke.io/backends/tract"
|
||||
@@ -14,7 +14,7 @@ authors = [
|
||||
]
|
||||
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
resolver = "3"
|
||||
members = [ "standalone" ]
|
||||
default-members = []
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name = "ort-tract-standalone"
|
||||
publish = false
|
||||
version = "1.23.1"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[package.metadata.winresource]
|
||||
ProductName = "ONNX Runtime (tract)"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
publish = false
|
||||
name = "example-async-gpt2-api"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
ort = { path = "../../", features = [ "fetch-models" ] }
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
publish = false
|
||||
name = "example-cudarc"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
ort = { path = "../../", features = [ "cuda", "fetch-models" ] }
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::{ops::Mul, path::Path};
|
||||
|
||||
use cudarc::driver::{CudaDevice, DevicePtr, DevicePtrMut, sys::CUdeviceptr};
|
||||
use cudarc::driver::{CudaDevice, DevicePtr};
|
||||
use image::{GenericImageView, ImageBuffer, Rgba, imageops::FilterType};
|
||||
use ndarray::Array;
|
||||
use ort::{
|
||||
execution_providers::{CUDAExecutionProvider, ExecutionProvider},
|
||||
execution_providers::CUDAExecutionProvider,
|
||||
memory::{AllocationDevice, AllocatorType, MemoryInfo, MemoryType},
|
||||
session::Session,
|
||||
tensor::Shape,
|
||||
@@ -48,12 +48,12 @@ fn main() -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
let device = CudaDevice::new(0)?;
|
||||
let device_data = device.htod_sync_copy(&input.into_raw_vec())?;
|
||||
let device_data = device.htod_sync_copy(&input.into_raw_vec_and_offset().0)?;
|
||||
let tensor: TensorRefMut<'_, f32> = unsafe {
|
||||
TensorRefMut::from_raw(
|
||||
MemoryInfo::new(AllocationDevice::CUDA, 0, AllocatorType::Device, MemoryType::Default)?,
|
||||
(*device_data.device_ptr() as usize as *mut ()).cast(),
|
||||
Shape::from([1, 3, 512, 512])
|
||||
Shape::from([1i64, 3, 512, 512])
|
||||
)
|
||||
.unwrap()
|
||||
};
|
||||
@@ -63,7 +63,7 @@ fn main() -> anyhow::Result<()> {
|
||||
|
||||
// convert to 8-bit
|
||||
let output = output.mul(255.0).map(|x| *x as u8);
|
||||
let output = output.into_raw_vec();
|
||||
let (output, _) = output.into_raw_vec_and_offset();
|
||||
|
||||
// change rgb to rgba
|
||||
let output_img = ImageBuffer::from_fn(512, 512, |x, y| {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
publish = false
|
||||
name = "example-custom-ops"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
ort = { path = "../../" }
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
publish = false
|
||||
name = "example-gpt2"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
ort = { path = "../../", features = [ "fetch-models" ] }
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
publish = false
|
||||
name = "example-model-info"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
ort = { path = "../../" }
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
publish = false
|
||||
name = "example-modnet"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
ort = { path = "../../", features = [ "fetch-models" ] }
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::{ops::Mul, path::Path};
|
||||
|
||||
use image::{GenericImageView, ImageBuffer, Rgba, imageops::FilterType};
|
||||
use ndarray::Array;
|
||||
use ort::{execution_providers::CUDAExecutionProvider, inputs, session::Session, value::TensorRef};
|
||||
use ort::{inputs, session::Session, value::TensorRef};
|
||||
use show_image::{AsImageView, WindowOptions, event};
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
@@ -66,10 +66,13 @@ fn main() -> ort::Result<()> {
|
||||
let window = show_image::context()
|
||||
.run_function_wait(move |context| -> Result<_, String> {
|
||||
let mut window = context
|
||||
.create_window("ort + modnet", WindowOptions {
|
||||
size: Some([img_width, img_height]),
|
||||
..WindowOptions::default()
|
||||
})
|
||||
.create_window(
|
||||
"ort + modnet",
|
||||
WindowOptions {
|
||||
size: Some([img_width, img_height]),
|
||||
..WindowOptions::default()
|
||||
}
|
||||
)
|
||||
.map_err(|e| e.to_string())?;
|
||||
window.set_image("photo", &output.as_image_view().map_err(|e| e.to_string())?);
|
||||
Ok(window.proxy())
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
publish = false
|
||||
name = "example-phi-3-vision"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
ort = { path = "../../" }
|
||||
@@ -42,7 +42,3 @@ azure = [ "ort/azure" ]
|
||||
|
||||
backend-candle = [ "ort/alternative-backend", "dep:ort-candle" ]
|
||||
backend-tract = [ "ort/alternative-backend", "dep:ort-tract" ]
|
||||
|
||||
[[example]]
|
||||
name = "gpt2"
|
||||
path = "gpt2.rs"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
publish = false
|
||||
name = "example-sentence-transformers"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
ort = { path = "../../", features = [ "fetch-models" ] }
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
publish = false
|
||||
name = "example-training"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
ort = { path = "../../", features = [ "training" ] }
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
publish = false
|
||||
name = "example-wasm-emscripten"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[[bin]]
|
||||
path = "src/main.rs"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
publish = false
|
||||
name = "example-yolov8"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
ort = { path = "../../", features = [ "fetch-models" ] }
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name = "ort-sys"
|
||||
description = "Unsafe Rust bindings for ONNX Runtime 1.23 - Optimize and Accelerate Machine Learning Inferencing"
|
||||
version = "2.0.0-rc.10"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
rust-version = "1.85"
|
||||
links = "onnxruntime"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
@@ -10,7 +10,7 @@ pub const PYKE_ROOT: &str = "ort.pyke.io";
|
||||
macro_rules! win32_extern {
|
||||
($library:literal $abi:literal $($link_name:literal)? $(#[$doc:meta])? fn $($function:tt)*) => (
|
||||
#[link(name = $library, kind = "raw-dylib", modifiers = "+verbatim", import_name_type = "undecorated")]
|
||||
extern $abi {
|
||||
unsafe extern $abi {
|
||||
$(#[$doc])?
|
||||
$(#[link_name=$link_name])?
|
||||
fn $($function)*;
|
||||
@@ -21,7 +21,7 @@ macro_rules! win32_extern {
|
||||
macro_rules! win32_extern {
|
||||
($library:literal $abi:literal $($link_name:literal)? $(#[$doc:meta])? fn $($function:tt)*) => (
|
||||
#[link(name = $library, kind = "raw-dylib", modifiers = "+verbatim")]
|
||||
extern "C" {
|
||||
unsafe extern "C" {
|
||||
$(#[$doc])?
|
||||
$(#[link_name=$link_name])?
|
||||
fn $($function)*;
|
||||
|
||||
@@ -774,7 +774,7 @@ pub struct OrtApiBase {
|
||||
#[doc = " \\brief Returns a null terminated string of the version of the Onnxruntime library (eg: \"1.8.1\")\n\n \\return UTF-8 encoded version string. Do not deallocate the returned buffer."]
|
||||
pub GetVersionString: unsafe extern "system" fn() -> *const core::ffi::c_char
|
||||
}
|
||||
extern "system" {
|
||||
unsafe extern "system" {
|
||||
#[doc = " \\brief The Onnxruntime library's entry point to access the C API\n\n Call this to get the a pointer to an ::OrtApiBase"]
|
||||
pub fn OrtGetApiBase() -> *const OrtApiBase;
|
||||
}
|
||||
@@ -1619,7 +1619,7 @@ pub struct OrtCustomOp {
|
||||
pub GetAliasMap: Option<unsafe extern "system" fn(input_index: *mut *mut core::ffi::c_int, output_index: *mut *mut core::ffi::c_int) -> usize>,
|
||||
pub ReleaseAliasMap: Option<unsafe extern "system" fn(input_index: *mut core::ffi::c_int, output_index: *mut *mut core::ffi::c_int)>
|
||||
}
|
||||
extern "system" {
|
||||
unsafe extern "system" {
|
||||
pub fn OrtSessionOptionsAppendExecutionProvider_CUDA(options: *mut OrtSessionOptions, device_id: core::ffi::c_int) -> OrtStatusPtr;
|
||||
pub fn OrtSessionOptionsAppendExecutionProvider_ROCM(options: *mut OrtSessionOptions, device_id: core::ffi::c_int) -> OrtStatusPtr;
|
||||
pub fn OrtSessionOptionsAppendExecutionProvider_MIGraphX(options: *mut OrtSessionOptions, device_id: core::ffi::c_int) -> OrtStatusPtr;
|
||||
|
||||
@@ -42,21 +42,21 @@ impl Error {
|
||||
}
|
||||
|
||||
pub unsafe fn consume_sys(status: *mut OrtStatus) -> Box<Error> {
|
||||
Box::from_raw(status.cast::<Error>())
|
||||
unsafe { Box::from_raw(status.cast::<Error>()) }
|
||||
}
|
||||
}
|
||||
|
||||
unsafe extern "system" fn CreateStatus(code: OrtErrorCode, msg: *const ::core::ffi::c_char) -> OrtStatusPtr {
|
||||
let msg = CString::from_raw(msg.cast_mut());
|
||||
let msg = unsafe { CString::from_raw(msg.cast_mut()) };
|
||||
Error::new_sys(code, msg.to_string_lossy())
|
||||
}
|
||||
|
||||
unsafe extern "system" fn GetErrorCode(status: *const OrtStatus) -> OrtErrorCode {
|
||||
Error::cast_from_sys(status).code
|
||||
unsafe { Error::cast_from_sys(status) }.code
|
||||
}
|
||||
|
||||
unsafe extern "system" fn GetErrorMessage(status: *const OrtStatus) -> *const ::core::ffi::c_char {
|
||||
Error::cast_from_sys(status).message_ptr()
|
||||
unsafe { Error::cast_from_sys(status) }.message_ptr()
|
||||
}
|
||||
|
||||
unsafe extern "system" fn CreateEnv(log_severity_level: OrtLoggingLevel, logid: *const ::core::ffi::c_char, out: *mut *mut OrtEnv) -> OrtStatusPtr {
|
||||
@@ -441,12 +441,12 @@ unsafe extern "system" fn MemoryInfoGetMemType(ptr: *const OrtMemoryInfo, out: *
|
||||
}
|
||||
|
||||
unsafe extern "system" fn MemoryInfoGetType(ptr: *const OrtMemoryInfo, out: *mut OrtAllocatorType) -> OrtStatusPtr {
|
||||
*out = OrtAllocatorType::OrtDeviceAllocator;
|
||||
unsafe { *out = OrtAllocatorType::OrtDeviceAllocator };
|
||||
OrtStatusPtr::default()
|
||||
}
|
||||
|
||||
unsafe extern "system" fn AllocatorAlloc(ort_allocator: *mut OrtAllocator, size: usize, out: *mut *mut ::core::ffi::c_void) -> OrtStatusPtr {
|
||||
*out = unsafe { &*ort_allocator }.Alloc.unwrap()(ort_allocator, size);
|
||||
unsafe { *out = (&*ort_allocator).Alloc.unwrap()(ort_allocator, size) };
|
||||
if unsafe { *out }.is_null() {
|
||||
return Error::new_sys(OrtErrorCode::ORT_RUNTIME_EXCEPTION, "Allocation failed");
|
||||
}
|
||||
@@ -454,12 +454,12 @@ unsafe extern "system" fn AllocatorAlloc(ort_allocator: *mut OrtAllocator, size:
|
||||
}
|
||||
|
||||
unsafe extern "system" fn AllocatorFree(ort_allocator: *mut OrtAllocator, p: *mut ::core::ffi::c_void) -> OrtStatusPtr {
|
||||
unsafe { &*ort_allocator }.Free.unwrap()(ort_allocator, p);
|
||||
unsafe { (&*ort_allocator).Free.unwrap()(ort_allocator, p) };
|
||||
OrtStatusPtr::default()
|
||||
}
|
||||
|
||||
unsafe extern "system" fn AllocatorGetInfo(ort_allocator: *const OrtAllocator, out: *mut *const OrtMemoryInfo) -> OrtStatusPtr {
|
||||
*out = unsafe { &*ort_allocator }.Info.unwrap()(ort_allocator);
|
||||
unsafe { *out = (&*ort_allocator).Info.unwrap()(ort_allocator) };
|
||||
OrtStatusPtr::default()
|
||||
}
|
||||
|
||||
@@ -549,7 +549,7 @@ unsafe extern "system" fn KernelContext_GetOutput(
|
||||
unsafe extern "system" fn ReleaseEnv(input: *mut OrtEnv) {}
|
||||
|
||||
unsafe extern "system" fn ReleaseStatus(input: *mut OrtStatus) {
|
||||
drop(Error::consume_sys(input));
|
||||
drop(unsafe { Error::consume_sys(input) });
|
||||
}
|
||||
|
||||
unsafe extern "system" fn ReleaseMemoryInfo(input: *mut OrtMemoryInfo) {}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
style_edition = "2024"
|
||||
unstable_features = true
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ impl BitOr for CUDAAttentionBackend {
|
||||
}
|
||||
|
||||
/// The type of search done for cuDNN convolution algorithms.
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub enum CuDNNConvAlgorithmSearch {
|
||||
/// Expensive exhaustive benchmarking using [`cudnnFindConvolutionForwardAlgorithmEx`][exhaustive].
|
||||
/// This function will attempt all possible algorithms for `cudnnConvolutionForward` to find the fastest algorithm.
|
||||
@@ -54,6 +54,7 @@ pub enum CuDNNConvAlgorithmSearch {
|
||||
/// possible convolution algorithms are tested.
|
||||
///
|
||||
/// [exhaustive]: https://docs.nvidia.com/deeplearning/cudnn/api/index.html#cudnnFindConvolutionForwardAlgorithmEx
|
||||
#[default]
|
||||
Exhaustive,
|
||||
/// Lightweight heuristic-based search using [`cudnnGetConvolutionForwardAlgorithm_v7`][heuristic].
|
||||
/// Heuristic search sorts available convolution algorithms by expected (based on internal heuristic) relative
|
||||
@@ -75,12 +76,6 @@ pub enum CuDNNConvAlgorithmSearch {
|
||||
Default
|
||||
}
|
||||
|
||||
impl Default for CuDNNConvAlgorithmSearch {
|
||||
fn default() -> Self {
|
||||
Self::Exhaustive
|
||||
}
|
||||
}
|
||||
|
||||
/// [CUDA execution provider](https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html) for NVIDIA
|
||||
/// CUDA-enabled GPUs.
|
||||
#[derive(Debug, Default, Clone)]
|
||||
|
||||
@@ -286,7 +286,7 @@ impl ToAttribute for Vec<f32> {
|
||||
where
|
||||
Self: Sized
|
||||
{
|
||||
self.as_slice().to_attribute(name)
|
||||
unsafe { self.as_slice().to_attribute(name) }
|
||||
}
|
||||
|
||||
private_impl!();
|
||||
@@ -352,7 +352,7 @@ impl ToAttribute for Vec<i64> {
|
||||
where
|
||||
Self: Sized
|
||||
{
|
||||
self.as_slice().to_attribute(name)
|
||||
unsafe { self.as_slice().to_attribute(name) }
|
||||
}
|
||||
|
||||
private_impl!();
|
||||
@@ -411,7 +411,7 @@ impl ToAttribute for Vec<String> {
|
||||
where
|
||||
Self: Sized
|
||||
{
|
||||
self.as_slice().to_attribute(name)
|
||||
unsafe { self.as_slice().to_attribute(name) }
|
||||
}
|
||||
|
||||
private_impl!();
|
||||
@@ -422,7 +422,7 @@ impl ToAttribute for Vec<&str> {
|
||||
where
|
||||
Self: Sized
|
||||
{
|
||||
self.as_slice().to_attribute(name)
|
||||
unsafe { self.as_slice().to_attribute(name) }
|
||||
}
|
||||
|
||||
private_impl!();
|
||||
|
||||
@@ -144,7 +144,7 @@ impl ValueType {
|
||||
let mut contained_type: *mut ort_sys::OrtTypeInfo = ptr::null_mut();
|
||||
ortsys![unsafe GetOptionalContainedTypeInfo(info_ptr.as_ptr(), &mut contained_type).expect("infallible"); nonNull(contained_type)];
|
||||
|
||||
ValueType::Optional(Box::new(ValueType::from_type_info(contained_type)))
|
||||
ValueType::Optional(Box::new(unsafe { ValueType::from_type_info(contained_type) }))
|
||||
}
|
||||
_ => unreachable!()
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
publish = false
|
||||
name = "leak-check"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[[bin]]
|
||||
name = "leak-check"
|
||||
|
||||
Reference in New Issue
Block a user