-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
251 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = [ | ||
"icicle-runtime", | ||
] | ||
exclude = [] | ||
|
||
[workspace.package] | ||
version = "3.0.0" | ||
edition = "2021" | ||
authors = [ "Ingonyama" ] | ||
homepage = "https://www.ingonyama.com" | ||
repository = "https://github.com/ingonyama-zk/icicle" | ||
|
||
[workspace.dependencies] | ||
icicle-cuda-runtime = { path = "icicle-runtime" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "icicle-runtime" | ||
version.workspace = true | ||
edition.workspace = true | ||
authors.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
|
||
[build-dependencies] | ||
cmake = "0.1.50" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use std::ffi::{CStr, CString}; | ||
use std::os::raw::c_char; | ||
|
||
#[repr(C)] | ||
pub struct Device { | ||
pub device_type: *const std::os::raw::c_char, | ||
pub id: i32, | ||
} | ||
|
||
#[repr(C)] | ||
pub struct DeviceProperties { | ||
pub using_host_memory: bool, | ||
pub num_memory_regions: i32, | ||
pub supports_pinned_memory: bool, | ||
} | ||
|
||
impl Device { | ||
pub fn new(device_type: &str, id: i32) -> Device { | ||
let c_string = CString::new(device_type).expect("CString::new failed"); | ||
Device { | ||
device_type: c_string.into_raw(), | ||
id, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#[repr(C)] | ||
#[derive(Debug, PartialEq)] | ||
pub enum eIcicleError { | ||
Success = 0, // Operation completed successfully | ||
InvalidDevice, // The specified device is invalid | ||
OutOfMemory, // Memory allocation failed due to insufficient memory | ||
InvalidPointer, // The specified pointer is invalid | ||
AllocationFailed, // Memory allocation failed | ||
DeallocationFailed, // Memory deallocation failed | ||
CopyFailed, // Data copy operation failed | ||
SynchronizationFailed, // Device synchronization failed | ||
StreamCreationFailed, // Stream creation failed | ||
StreamDestructionFailed, // Stream destruction failed | ||
ApiNotImplemented, // The API is not implemented for a device | ||
InvalidArgument, // Invalid argument passed | ||
UnknownError, // An unknown error occurred | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
pub mod device; | ||
pub mod errors; | ||
pub mod runtime; | ||
|
||
// Re-export the types for easier access | ||
pub use device::{Device, DeviceProperties}; | ||
pub use errors::eIcicleError; | ||
pub use runtime::*; | ||
|
||
use std::ffi::CString; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_set_device() { | ||
// load backends to process | ||
let backend_install_dir = env!("DEFAULT_BACKEND_INSTALL_DIR"); | ||
assert_eq!(load_backend(&backend_install_dir, true), eIcicleError::Success); | ||
|
||
let devtype = String::from("CPU"); | ||
let dev = Device::new(&devtype, 0); | ||
assert_eq!(set_device(&dev), eIcicleError::Success); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
use std::ffi::CString; | ||
use std::os::raw::{c_char, c_void}; | ||
|
||
use crate::device::Device; | ||
use crate::errors::eIcicleError; | ||
|
||
pub type IcicleStreamHandle = *mut c_void; | ||
|
||
extern "C" { | ||
fn icicle_nop() -> eIcicleError; | ||
fn icicle_load_backend(path: *const c_char, is_recursive: bool) -> eIcicleError; | ||
fn icicle_set_device(device: &Device) -> eIcicleError; | ||
// fn icicle_malloc(ptr: *mut *mut c_void, size: usize) -> eIcicleError; | ||
// fn icicle_malloc_async(ptr: *mut *mut c_void, size: usize, stream: IcicleStreamHandle) -> eIcicleError; | ||
// fn icicle_free(ptr: *mut c_void) -> eIcicleError; | ||
// fn icicle_free_async(ptr: *mut c_void, stream: IcicleStreamHandle) -> eIcicleError; | ||
// fn icicle_get_available_memory(total: *mut usize, free: *mut usize) -> eIcicleError; | ||
// fn icicle_copy_to_host(dst: *mut u8, src: *const u8, size: usize) -> eIcicleError; | ||
// fn icicle_copy_to_host_async(dst: *mut u8, src: *const u8, size: usize, stream: IcicleStreamHandle) | ||
// -> eIcicleError; | ||
// fn icicle_copy_to_device(dst: *mut u8, src: *const u8, size: usize) -> eIcicleError; | ||
// fn icicle_copy_to_device_async( | ||
// dst: *mut u8, | ||
// src: *const u8, | ||
// size: usize, | ||
// stream: IcicleStreamHandle, | ||
// ) -> eIcicleError; | ||
// fn icicle_create_stream(stream: *mut IcicleStreamHandle) -> eIcicleError; | ||
// fn icicle_destroy_stream(stream: IcicleStreamHandle) -> eIcicleError; | ||
// fn icicle_stream_synchronize(stream: IcicleStreamHandle) -> eIcicleError; | ||
fn icicle_device_synchronize() -> eIcicleError; | ||
// fn icicle_get_device_properties(properties: *mut DeviceProperties) -> eIcicleError; | ||
} | ||
|
||
pub fn nop() -> eIcicleError { | ||
unsafe { icicle_nop() } | ||
} | ||
|
||
pub fn load_backend(path: &str, is_recursive: bool) -> eIcicleError { | ||
let c_path = CString::new(path).unwrap(); | ||
unsafe { icicle_load_backend(c_path.as_ptr(), is_recursive) } | ||
} | ||
|
||
pub fn set_device(device: &Device) -> eIcicleError { | ||
unsafe { icicle_set_device(device) } | ||
} | ||
|
||
// pub fn malloc(size: usize) -> Result<*mut c_void, eIcicleError> { | ||
// let mut ptr: *mut c_void = std::ptr::null_mut(); | ||
// let result = unsafe { icicle_malloc(&mut ptr, size) }; | ||
// if result == eIcicleError::Success { | ||
// Ok(ptr) | ||
// } else { | ||
// Err(result) | ||
// } | ||
// } | ||
|
||
// pub fn malloc_async(size: usize, stream: IcicleStreamHandle) -> Result<*mut c_void, eIcicleError> { | ||
// let mut ptr: *mut c_void = std::ptr::null_mut(); | ||
// let result = unsafe { icicle_malloc_async(&mut ptr, size, stream) }; | ||
// if result == eIcicleError::Success { | ||
// Ok(ptr) | ||
// } else { | ||
// Err(result) | ||
// } | ||
// } | ||
|
||
// pub fn free(ptr: *mut c_void) -> eIcicleError { | ||
// unsafe { icicle_free(ptr) } | ||
// } | ||
|
||
// pub fn free_async(ptr: *mut c_void, stream: IcicleStreamHandle) -> eIcicleError { | ||
// unsafe { icicle_free_async(ptr, stream) } | ||
// } | ||
|
||
// pub fn get_available_memory() -> Result<(usize, usize), eIcicleError> { | ||
// let mut total: usize = 0; | ||
// let mut free: usize = 0; | ||
// let result = unsafe { icicle_get_available_memory(&mut total, &mut free) }; | ||
// if result == eIcicleError::Success { | ||
// Ok((total, free)) | ||
// } else { | ||
// Err(result) | ||
// } | ||
// } | ||
|
||
// pub fn copy_to_host(dst: *mut u8, src: *const u8, size: usize) -> eIcicleError { | ||
// unsafe { icicle_copy_to_host(dst, src, size) } | ||
// } | ||
|
||
// pub fn copy_to_host_async(dst: *mut u8, src: *const u8, size: usize, stream: IcicleStreamHandle) -> eIcicleError { | ||
// unsafe { icicle_copy_to_host_async(dst, src, size, stream) } | ||
// } | ||
|
||
// pub fn copy_to_device(dst: *mut u8, src: *const u8, size: usize) -> eIcicleError { | ||
// unsafe { icicle_copy_to_device(dst, src, size) } | ||
// } | ||
|
||
// pub fn copy_to_device_async(dst: *mut u8, src: *const u8, size: usize, stream: IcicleStreamHandle) -> eIcicleError { | ||
// unsafe { icicle_copy_to_device_async(dst, src, size, stream) } | ||
// } | ||
|
||
// pub fn create_stream() -> Result<IcicleStreamHandle, eIcicleError> { | ||
// let mut stream: IcicleStreamHandle = std::ptr::null_mut(); | ||
// let result = unsafe { icicle_create_stream(&mut stream) }; | ||
// if result == eIcicleError::Success { | ||
// Ok(stream) | ||
// } else { | ||
// Err(result) | ||
// } | ||
// } | ||
|
||
// pub fn destroy_stream(stream: IcicleStreamHandle) -> eIcicleError { | ||
// unsafe { icicle_destroy_stream(stream) } | ||
// } | ||
|
||
// pub fn stream_synchronize(stream: IcicleStreamHandle) -> eIcicleError { | ||
// unsafe { icicle_stream_synchronize(stream) } | ||
// } | ||
|
||
pub fn device_synchronize() -> eIcicleError { | ||
unsafe { icicle_device_synchronize() } | ||
} | ||
|
||
// pub fn get_device_properties() -> Result<DeviceProperties, eIcicleError> { | ||
// let mut properties = DeviceProperties { | ||
// using_host_memory: false, | ||
// num_memory_regions: 0, | ||
// supports_pinned_memory: false, | ||
// }; | ||
// let result = unsafe { icicle_get_device_properties(&mut properties) }; | ||
// if result == eIcicleError::Success { | ||
// Ok(properties) | ||
// } else { | ||
// Err(result) | ||
// } | ||
// } |